/// <summary> /// Initializes a new instance of the <see cref="BaseTestContext"/> class. /// </summary> protected BaseTestContext() { // To run tests with your own credentials please substitute code bellow with this one // this.keys = new Keys { AppKey = "your app key", AppSid = "your app sid" }; var serverCreds = DirectoryHelper.GetPath("Settings", "servercreds.json"); this.keys = JsonConvert.DeserializeObject <Keys>(File.ReadAllText(serverCreds)); if (this.keys == null) { throw new FileNotFoundException("servercreds.json doesn't contain AppKey and AppSid"); } var configuration = new Configuration { ApiBaseUrl = this.keys.BaseProductUri, AppKey = this.keys.AppKey, AppSid = this.keys.AppSid }; this.ConversionApi = new ConversionApi( configuration.AppKey, configuration.AppSid, configuration.ApiBaseUrl + "/v1.1"); this.DocumentApi = new DocumentApi( configuration.AppKey, configuration.AppSid, configuration.ApiBaseUrl + "/v1.1"); this.TranslationApi = new TranslationApi( configuration.AppKey, configuration.AppSid, configuration.ApiBaseUrl + "/v1.1"); this.OcrApi = new OcrApi( configuration.AppKey, configuration.AppSid, configuration.ApiBaseUrl + "/v1.1"); this.SummarizationApi = new SummarizationApi( configuration.AppKey, configuration.AppSid, configuration.ApiBaseUrl + "/v1.1"); Aspose.Storage.Cloud.Sdk.Configuration storageConf = new Storage.Cloud.Sdk.Configuration() { ApiBaseUrl = configuration.ApiBaseUrl, // + "/v1.1", AppKey = configuration.AppKey, AppSid = configuration.AppSid }; this.StorageApi = new StorageApi(storageConf); }
public static bool uploadToStorage(string storagePath, string srcDir = null) { var name = Path.GetFileName(storagePath); Configuration storageConf = new Storage.Cloud.Sdk.Configuration() { ApiBaseUrl = CommonSettings.BasePath, AppKey = CommonSettings.AppKey, AppSid = CommonSettings.AppSID }; StorageApi storageApi = new StorageApi(storageConf); // Upload source file to aspose cloud storage var srcPath = Path.Combine(srcDir ?? CommonSettings.DataFolder, name); if (File.Exists(srcPath)) { using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) { var reqCr = new PutCreateRequest(storagePath, fstr); var respCr = storageApi.PutCreate(reqCr); var reqExist = new GetIsExistRequest(storagePath); var respExist = storageApi.GetIsExist(reqExist); return(respExist.FileExist.IsExist.HasValue && respExist.FileExist.IsExist.Value); } } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } }