private Stream DownloadFile(string storageName, string path, string versionId = null) { var request = new GetDownloadRequest(); request.Path = path; request.Storage = storageName; request.VersionId = versionId; Stream response = null; try { response = StorageApi.GetDownload(request); } catch (Exception ex) { var msg = new string[] { "Invalid version id specified", //AmazonS3 "Invalid snapshot time", //Windows Azure "Value should match pattern", //DropBox }; Assert.IsTrue(msg.Where(x => ex.Message.Contains(x)).Any(), ex.Message); return(null); } Assert.IsNotNull(response); return(response); }
public void FileGetDownloadTest() { GetDownloadRequest request = new GetDownloadRequest(); request.path = Path.Combine(dataFolder, "TestFile.pdf"); request.storage = storageName; request.versionId = null; var response = FileApi.GetDownload(request); Assert.IsNotNull(response); }
public byte[] Download(string documentName) { var storageConfiguration = CreateStorageConfiguration(); var storageApi = CreateStorageApi(storageConfiguration); var downloadRequest = new GetDownloadRequest(documentName); using (var stream = storageApi.GetDownload(downloadRequest)) { return(stream.ReadAsBytes()); } }
internal byte[] FetchFileFromCloud(string fileName) { var storageConfiguration = CreateStorageConfiguration(); var storageApi = CreateStorageApi(storageConfiguration); var downloadRequest = new GetDownloadRequest(fileName); using (var stream = storageApi.GetDownload(downloadRequest)) { return(stream.ReadAsBytes()); } }
public byte[] DownloadPdf(string pdfPath, string fileName) { dynamic bytesOfDownloadedPdf; var storageApi = new StorageApi(_apiKey, _appSid); var request = new GetDownloadRequest(fileName); using (var response = storageApi.GetDownload(request)) { var bytes = response.ReadAsBytes(); File.WriteAllBytes(pdfPath, bytes); bytesOfDownloadedPdf = File.ReadAllBytes(pdfPath); } return(bytesOfDownloadedPdf); }
public byte[] DownloadFile(string fileName, string path) { StorageApi storageApi = new StorageApi(_apiKey, _appSid); if (string.IsNullOrWhiteSpace(fileName)) { return(new byte[0]); } var request = new GetDownloadRequest(fileName); using (var response = storageApi.GetDownload(request)) { if (response == null) { return(new byte[0]); } var bytes = response.ReadAsBytes(); File.WriteAllBytes(path, bytes); return(bytes); } }
public static GetDownloadResponse GetDownloadByProductID(GetDownloadRequest request) { GetDownloadResponse response = new GetDownloadResponse(); response.DownloadList = new List <DownloadAssignment>(); response.Error = new Handler.ErrorObject(); try { var bussines = DownloadAssignmentData.Select.GetDownloadByProductID(request.ProductID); if (!bussines.Item1.Error) { foreach (var item in bussines.Item2) { response.DownloadList.Add(new DownloadAssignment() { id = item.id, amount = item.amount, detail = item.detail, idCategory = item.idCategory, idEmployee = item.idEmployee, idProduct = item.idProduct, createDate = item.createDate, upDateDate = item.upDateDate, deleteDate = item.deleteDate, state = item.state }); } } else { response.Error.InfoError(bussines.Item1); } } catch (Exception ex) { response.Error.InfoError(ex); } return(response); }
public void IfTokenIsNotValidRefreshTokenShouldBeSuccessfully() { // Arrange var api = new StorageApi( new Configuration { AppKey = AppKey, AppSid = AppSid, ApiBaseUrl = "http://localhost:8081", AuthType = AuthType.OAuth2, DebugMode = true }); using (var stream = this.ToStream("content")) { var request = new GetDownloadRequest(); request.Path = Path.Combine(TempFolderPath, "TestFile.pdf"); request.Storage = StorageName; api.GetDownload(request); Thread.Sleep(2000); stream.Flush(); stream.Position = 0; var mockFactory = new MockFactory(); var traceListenerMock = mockFactory.CreateMock <TraceListener>(); Trace.Listeners.Add(traceListenerMock.MockObject); traceListenerMock.Expects.One.Method(p => p.WriteLine(string.Empty)).With(Is.StringContaining("grant_type=refresh_token")); traceListenerMock.Expects.AtLeastOne.Method(p => p.WriteLine(string.Empty)).With(Is.Anything); // Act api.GetDownload(request); // Assert mockFactory.VerifyAllExpectationsHaveBeenMet(); } }
public object DownloadDocument(string fileName, string pdfPath) { if (fileName.Trim().Equals("")) { return("You have supplied invalid path, please try again."); } var storage = new StorageApi(_apiKey, _appSid); var request = new GetDownloadRequest(fileName); using (var response = storage.GetDownload(request)) { if (response == null) { return("The file you're trying to download does not exist."); } var bytes = response.ReadAsBytes(); File.WriteAllBytes(pdfPath, bytes); return($"You have successfully downloaded {fileName}."); }; }
/// <summary> /// Download a specific file /// </summary> /// <param name="request">Request. <see cref="GetDownloadRequest" /></param> /// <returns><see cref="System.IO.Stream"/></returns> public System.IO.Stream GetDownload(GetDownloadRequest request) { // verify the required parameter 'path' is set if (request.Path == null) { throw new ApiException(400, "Missing required parameter 'path' when calling GetDownload"); } // create path and map variables var resourcePath = this.configuration.GetApiRootUrl() + "/storage/file"; resourcePath = Regex .Replace(resourcePath, "\\*", string.Empty) .Replace("&", "&") .Replace("/?", "?"); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "path", request.Path); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "versionId", request.VersionId); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storage", request.Storage); try { return(this.apiInvoker.InvokeBinaryApi( resourcePath, "GET", null, null, null)); } catch (ApiException ex) { if (ex.ErrorCode == 404) { return(null); } throw; } }
public static GetDownloadResponse GetDownload(GetDownloadRequest request) { GetDownloadResponse response = new GetDownloadResponse(); response.Error = new Handler.ErrorObject(); response.Download = new DownloadAssignment(); try { var bussines = DownloadAssignmentData.Select.GetDownload(request.DownloadID); if (!bussines.Item1.Error) { response.Download = new DownloadAssignment() { id = bussines.Item2.id, amount = bussines.Item2.amount, detail = bussines.Item2.detail, idCategory = bussines.Item2.idCategory, idEmployee = bussines.Item2.idEmployee, idProduct = bussines.Item2.idProduct, createDate = bussines.Item2.createDate, upDateDate = bussines.Item2.upDateDate, deleteDate = bussines.Item2.deleteDate, state = bussines.Item2.state }; } else { response.Error.InfoError(bussines.Item1); } } catch (Exception ex) { response.Error.InfoError(ex); } return(response); }
public DownloadResultsTransferObject DownloadDocumentFromTheCloud(string name, string path) { var results = new DownloadResultsTransferObject(); if (Invalid(name)) { results.ErrorMessage = "Invalid file name"; return(results); } var request = new GetDownloadRequest(name); using (var response = _storageApi.GetDownload(request)) { if (response == null) { results.ErrorMessage = "File you looking for does not exist, check filename and try again"; return(results); } results.Bytes = response.ReadAsBytes(); File.WriteAllBytes(path, results.Bytes); } return(results); }
public static GetDownloadResponse DownloadAmount(GetDownloadRequest request) { GetDownloadResponse response = new GetDownloadResponse(); response.Error = new Handler.ErrorObject(); try { var result = DownloadAssignmentData.Update.DownloadAmount(request.DownloadID, request.amount); if (result.Item1.Error) { response.Error.InfoError(result.Item1); } else { response.Message = result.Item2; } } catch (Exception ex) { response.Error.InfoError(ex); } return(response); }
public static GetDownloadResponse Download(GetDownloadResponse AssignmentInformation, GetDownloadRequest request) { GetDownloadResponse response = new GetDownloadResponse(); response.Error = new Handler.ErrorObject(); try { DownloadAmount(request); var result = Transaction.TransactionConfigurateBussines.Insert.TransactionConfigurate(request.DownloadID, request.TransactionTypeID, AssignmentInformation.transaction); #region Assignment Update AssignmentBussines.GetAssignmentRequest req = new AssignmentBussines.GetAssignmentRequest() { ProductID = (int)AssignmentInformation.Download.idProduct, CategoryID = (int)request.CategoryID }; var data = AssignmentBussines.Select.GetAssignmentToProductIDAndCategory(req).Assignment; int newAmountCellar = (int)data.amount - (int)AssignmentInformation.transaction.amount; AssignmentBussines.GetAssignmentRequest requestCellar = new AssignmentBussines.GetAssignmentRequest() { AssignmentID = data.id, amount = newAmountCellar }; AssignmentBussines.Update.AssignmentAmount(requestCellar); #endregion #region Condition Update TransactionConfigurateBussines.Insert.ConditionBackUpdate(2, data.id, (int)AssignmentInformation.transaction.idConditionProduct, (int)AssignmentInformation.transaction.amount); #endregion response.Message = result.Message.ToString(); } catch (Exception ex) { response.Error.InfoError(ex); } return(response); }
/// <summary> /// Sends back specified file from specified folder inside OutputDirectory. /// </summary> /// <param name="folder">Folder inside OutputDirectory.</param> /// <param name="file">File.</param> /// <returns>HTTP response with file.</returns> public FileResult DownloadFile(string file) { GetDownloadRequest getDownloadRequest = new GetDownloadRequest(file); return(File(storageApi.GetDownload(getDownloadRequest), "application/octet-stream", file)); }