1
1
/*
2
- * Copyright (c) 2018 Aspose Pty Ltd. All Rights Reserved.
2
+ * Copyright (c) 2020 Aspose Pty Ltd. All Rights Reserved.
3
3
*
4
4
* Licensed under the MIT (the "License");
5
5
* you may not use this file except in compliance with the License.
14
14
* limitations under the License.
15
15
*/
16
16
17
- using Aspose . Omr . Cloud . Sdk ;
18
- using Aspose . Omr . Cloud . Sdk . Model ;
19
- using Aspose . Omr . Cloud . Sdk . Model . Requests ;
20
-
21
17
namespace Aspose . OMR . Demo
22
18
{
23
19
using System ;
24
20
using System . Collections . Generic ;
25
21
using System . IO ;
26
- using Storage . Cloud . Sdk ;
27
- using Storage . Cloud . Sdk . Api ;
28
- using Storage . Cloud . Sdk . Model ;
29
- using Storage . Cloud . Sdk . Model . Requests ;
22
+ using Aspose . Omr . Cloud . Sdk ;
23
+ using Aspose . Omr . Cloud . Sdk . Api ;
24
+ using Aspose . Omr . Cloud . Sdk . Model ;
25
+ using Aspose . Omr . Cloud . Sdk . Model . Requests ;
30
26
using Newtonsoft . Json ;
31
27
using Newtonsoft . Json . Linq ;
32
28
using FileInfo = Aspose . Omr . Cloud . Sdk . Model . FileInfo ;
@@ -125,6 +121,16 @@ class OmrDemo
125
121
/// </summary>
126
122
private StorageApi StorageApi = null ;
127
123
124
+ /// <summary>
125
+ /// Instance of Cloud Folder API
126
+ /// </summary>
127
+ private FolderApi FolderApi = null ;
128
+
129
+ /// <summary>
130
+ /// Instance of Cloud File API
131
+ /// </summary>
132
+ private FileApi FileApi = null ;
133
+
128
134
/// <summary>
129
135
/// Instance of OMR API
130
136
/// </summary>
@@ -137,35 +143,36 @@ public OmrDemo()
137
143
string configFileRelativePath = Path . Combine ( this . demoDataSubmoduleName , this . configFileName ) ;
138
144
139
145
// Locate submodule folder containing demo data and config
140
- //while (current != null && !File.Exists(Path.Combine(current.FullName, configFileRelativePath)))
141
- //{
142
- // current = current.Parent;
143
- //}
144
-
145
-
146
+ while ( current != null && ! File . Exists ( Path . Combine ( current . FullName , configFileRelativePath ) ) )
147
+ {
148
+ current = current . Parent ;
149
+ }
146
150
147
151
// Check if config file exists
148
152
if ( current == null )
149
153
{
150
154
throw new Exception ( $ "Unable to find { this . configFileName } ") ;
151
155
}
152
156
153
- // string configFilePath = Path.Combine(current.FullName, configFileRelativePath);
154
- string configFilePath = Path . Combine ( $ "C:\\ Users\\ MAKS\\ Desktop\\ Новая папка\\ aspose-omr-cloud-dotnet", configFileRelativePath ) ;
157
+ string configFilePath = Path . Combine ( current . FullName , configFileRelativePath ) ;
155
158
156
159
// parse config
157
160
this . Config = JObject . Parse ( File . ReadAllText ( configFilePath ) ) ;
158
161
this . DataFolder = Path . Combine ( Directory . GetParent ( configFilePath ) . FullName , this . Config [ "data_folder" ] . ToString ( ) ) ;
159
162
160
163
// create storage api and provide parameters
161
164
string baseHost = new Uri ( this . Basepath ) . GetComponents ( UriComponents . SchemeAndServer , UriFormat . SafeUnescaped ) . ToString ( ) ;
165
+
162
166
Configuration storageConfiguration = new Configuration ( ) ;
163
167
storageConfiguration . AppKey = this . AppKey ;
164
168
storageConfiguration . AppSid = this . AppSid ;
165
169
storageConfiguration . ApiBaseUrl = baseHost ;
170
+
166
171
this . StorageApi = new StorageApi ( storageConfiguration ) ;
172
+ this . FolderApi = new FolderApi ( storageConfiguration ) ;
173
+ this . FileApi = new FileApi ( storageConfiguration ) ;
167
174
168
- this . OmrApi = new OmrApi ( this . AppKey , this . AppSid ) ;
175
+ this . OmrApi = new OmrApi ( storageConfiguration ) ;
169
176
}
170
177
171
178
/// <summary>
@@ -330,8 +337,8 @@ protected void UploadFile(string srcFile, string dstPath)
330
337
{
331
338
using ( FileStream fs = new FileStream ( srcFile , FileMode . Open ) )
332
339
{
333
- UploadResponse response = this . StorageApi . PutCreate ( new PutCreateRequest ( dstPath , fs ) ) ;
334
- Console . WriteLine ( $ "File { dstPath } uploaded successfully with response { response . Status } ") ;
340
+ FilesUploadResult response = FileApi . UploadFile ( new UploadFileRequest ( dstPath , fs ) ) ;
341
+ Console . WriteLine ( $ "File { dstPath } uploaded successfully with response { response } ") ;
335
342
}
336
343
}
337
344
@@ -342,18 +349,18 @@ protected void UploadFile(string srcFile, string dstPath)
342
349
protected void UploadDemoFiles ( string dataDirPath )
343
350
{
344
351
// check if folder already exists on storage
345
- FileExistResponse response = this . StorageApi . GetIsExist ( new GetIsExistRequest ( this . LogosFolderName ) ) ;
346
- if ( response . FileExist . IsExist == false )
352
+ ObjectExist response = this . StorageApi . ObjectExists ( new ObjectExistsRequest ( this . LogosFolderName ) ) ;
353
+ if ( response . Exists == false )
347
354
{
348
- this . StorageApi . PutCreateFolder ( new PutCreateFolderRequest ( this . LogosFolderName ) ) ;
355
+ FolderApi . CreateFolder ( new CreateFolderRequest ( this . LogosFolderName , "storage" ) ) ;
349
356
}
350
357
351
358
// upload logo images
352
359
foreach ( string logo in this . templateLogosImagesNames )
353
360
{
354
361
string destLogoPath = $ "{ this . LogosFolderName } /{ logo } ";
355
- response = this . StorageApi . GetIsExist ( new GetIsExistRequest ( destLogoPath ) ) ;
356
- if ( response . FileExist . IsExist == false )
362
+ response = this . StorageApi . ObjectExists ( new ObjectExistsRequest ( destLogoPath ) ) ;
363
+ if ( response . Exists == false )
357
364
{
358
365
this . UploadFile ( Path . Combine ( dataDirPath , logo ) , destLogoPath ) ;
359
366
}
0 commit comments