public ActionResult AddAttachments(IEnumerable <HttpPostedFileBase> files, string uniqueId) { var attachmentResult = new AttachmentResult(); var uploadFileDirectory = WebConfigurationManager.AppSettings["uploadDirectory"]; var baseDir = Path.Combine(uploadFileDirectory, uniqueId); if (!Directory.Exists(baseDir)) { Directory.CreateDirectory(baseDir); } foreach (var file in files) { string filePath = Path.Combine(baseDir, file.FileName); if (!System.IO.File.Exists(filePath)) { System.IO.File.WriteAllBytes(filePath, ReadData(file.InputStream)); } } foreach (var file in Directory.GetFiles(baseDir)) { attachmentResult.Files.Add(Path.GetFileName(file)); } attachmentResult.UniqueId = uniqueId; return(Json(attachmentResult, JsonRequestBehavior.AllowGet)); }
public void FixedNullAttachmentResultImplicitOperator() { AttachmentResult <string> r = null; string s = r; Assert.IsNull(s); }
/// <summary> /// Sends an Attachment Response. /// </summary> /// <param name="result">The result of the attachment</param> /// <param name="messageID">The messageID to be used. If not present, random one will be generated.</param> /// <param name="header">The header to be used in the message. If not present, default one will be generated.</param> public void SendAttachmentResponse6(AttachmentResult result, string messageID = null, MessageHeader header = null) { MessageData data = MessageManager.GetAttachmentResponseData(result); MessageHeader messageHeader = header ?? MessageManager.GetHeader(userName, messageID, DataType.AttachmentResponse); SendMessage(messageHeader, data); }
public AttachmentResult GetFiles() { try { var attachments = FilesManagementService.GetAttachments(null).ToList(); string storageRoot = ConfigurationManager.AppSettings["FileUploadPath"]; var result = new AttachmentResult { Files = attachments, ServerPath = storageRoot, Message = "Данные успешно загружены", Code = "200" }; return(result); } catch (Exception e) { return(new AttachmentResult { Message = "Произошла ошибка при получении данных", Code = "500" }); } }
private async Task UpdateAttachments(TSource document, CancellationToken cancellationToken = default) { foreach (CouchAttachment attachment in document.Attachments.GetAddedAttachments()) { if (attachment.FileInfo == null) { continue; } using var stream = new StreamContent( new FileStream(attachment.FileInfo.FullName, FileMode.Open)); AttachmentResult response = await NewRequest() .AppendPathSegment(document.Id) .AppendPathSegment(Uri.EscapeUriString(attachment.Name)) .WithHeader("Content-Type", attachment.ContentType) .WithHeader("If-Match", document.Rev) .PutAsync(stream, cancellationToken) .ReceiveJson <AttachmentResult>() .ConfigureAwait(false); if (response.Ok) { document.Rev = response.Rev; attachment.FileInfo = null; } } foreach (CouchAttachment attachment in document.Attachments.GetDeletedAttachments()) { AttachmentResult response = await NewRequest() .AppendPathSegment(document.Id) .AppendPathSegment(attachment.Name) .WithHeader("If-Match", document.Rev) .DeleteAsync(cancellationToken) .ReceiveJson <AttachmentResult>() .ConfigureAwait(false); if (response.Ok) { document.Rev = response.Rev; document.Attachments.RemoveAttachment(attachment); } } InitAttachments(document); }
public Stream GetFile(string parentId) { var session = _store.OpenSession(); List <PhotoModel> list = session.Query <PhotoModel>().Where(x => x.ParentId == parentId).ToList(); if (list.Count == 1) { PhotoModel m = list[0]; AttachmentResult r = session.Advanced.Attachments.Get(m, m.Name); return(r.Stream); } else { return(null); } }
public async Task Examples() { using (var documentStore = new DocumentStore { Urls = new[] { "http://localhost:8080" }, Database = "Northwind" }) { #region Client_Operations_1 using (AttachmentResult fetchedAttachment = documentStore.Operations.Send(new GetAttachmentOperation("users/1", "file.txt", AttachmentType.Document, null))) { //do stuff with the attachment stream --> fetchedAttachment.Stream } #endregion #region Client_Operations_1_async using (AttachmentResult fetchedAttachment = await documentStore.Operations.SendAsync(new GetAttachmentOperation("users/1", "file.txt", AttachmentType.Document, null))) { //do stuff with the attachment stream --> fetchedAttachment.Stream } #endregion #region Maintenance_Operations_1 documentStore.Maintenance.Send(new StopIndexOperation("Orders/ByCompany")); #endregion #region Maintenance_Operations_1_async await documentStore.Maintenance.SendAsync(new StopIndexOperation("Orders/ByCompany")); #endregion #region Server_Operations_1 var getBuildNumberResult = documentStore.Maintenance.Server.Send(new GetBuildNumberOperation()); Console.WriteLine(getBuildNumberResult.BuildVersion); #endregion #region Server_Operations_1_async var buildNumber = await documentStore.Maintenance.Server.SendAsync(new GetBuildNumberOperation()); Console.WriteLine(buildNumber.BuildVersion); #endregion } }
public IActionResult GetFiles() { try { var attachments = FilesManagementService.GetAttachments(null).ToList(); var storageRoot = ConfigurationManager.AppSettings["FileUploadPath"]; var result = new AttachmentResult { Files = attachments, ServerPath = storageRoot }; return(Ok(result)); } catch (Exception ex) { return(ServerError500(ex.Message)); } }
/// <summary> /// Updates the specified attachment of feature. /// </summary> private async void UpdateButton_Click(object sender, RoutedEventArgs e) { var featureID = (Int64)AttachmentList.Tag; var info = (AttachmentInfoItem)((FrameworkElement)sender).DataContext; var layer = MyMapView.Map.Layers["Incidents"] as FeatureLayer; var table = (ArcGISFeatureTable)layer.FeatureTable; string message = null; try { var file = await GetFileAsync(); if (file == null) { return; } AttachmentResult updateResult = null; using (var stream = await file.OpenStreamForReadAsync()) { updateResult = await table.UpdateAttachmentAsync(featureID, info.ID, stream, file.Name); } if (updateResult != null) { if (updateResult.Error != null) { message = string.Format("Update on attachment [{0}] of feature [{1}] failed.\n {2}", info.ID, featureID, updateResult.Error.Message); } await SaveEditsAsync(); await QueryAttachmentsAsync(featureID); } } catch (Exception ex) { message = ex.Message; } if (!string.IsNullOrWhiteSpace(message)) { await new MessageDialog(message).ShowAsync(); } }
/// <summary> /// Adds new attachment to feature. /// </summary> private async void AddButton_Click(object sender, RoutedEventArgs e) { var featureID = (Int64)AttachmentList.Tag; var layer = MyMapView.Map.Layers["Incidents"] as FeatureLayer; var table = (ArcGISFeatureTable)layer.FeatureTable; string message = null; try { var file = await GetFileAsync(); if (file == null) { return; } AttachmentResult addResult = null; using (var stream = await file.OpenStreamForReadAsync()) { addResult = await table.AddAttachmentAsync(featureID, stream, file.Name); } if (addResult != null) { if (addResult.Error != null) { message = string.Format("Add attachment to feature [{0}] failed.\n {1}", featureID, addResult.Error.Message); } await SaveEditsAsync(); await QueryAttachmentsAsync(featureID); } } catch (Exception ex) { message = ex.Message; } if (!string.IsNullOrWhiteSpace(message)) { await new MessageDialog(message).ShowAsync(); } }
protected virtual AttachmentResult Parse(string result) { var r = new AttachmentResult { Message = result, Code = AttachmentResultCode.Ok }; if (result != null) { if (result.Contains("not found")) { r.Code = AttachmentResultCode.NotFound; } else if (result.Contains("doesn't exist")) { r.Code = AttachmentResultCode.NotFound; } else if (result.ToUpperInvariant().Contains("ERROR")) { r.Code = AttachmentResultCode.Error; } } return(r); }
public void GetAttachment() { using (var store = new DocumentStore()) { #region GetAttachment using (var session = store.OpenSession()) { Album album = session.Load <Album>("albums/1"); using (AttachmentResult file1 = session.Advanced.Attachments.Get(album, "001.jpg")) using (AttachmentResult file2 = session.Advanced.Attachments.Get("albums/1", "002.jpg")) { Stream stream = file1.Stream; AttachmentDetails attachmentDetails = file1.Details; string name = attachmentDetails.Name; string contentType = attachmentDetails.ContentType; string hash = attachmentDetails.Hash; long size = attachmentDetails.Size; string documentId = attachmentDetails.DocumentId; string changeVector = attachmentDetails.ChangeVector; } AttachmentName[] attachmentNames = session.Advanced.Attachments.GetNames(album); foreach (AttachmentName attachmentName in attachmentNames) { string name = attachmentName.Name; string contentType = attachmentName.ContentType; string hash = attachmentName.Hash; long size = attachmentName.Size; } bool exists = session.Advanced.Attachments.Exists("albums/1", "003.jpg"); } #endregion } }
/// <summary> /// Create an AttachmentResponse type data part. /// </summary> /// <param name="result">The description of the result.</param> /// <returns>The created AttachmentResponseData object.</returns> public static AttachmentResponseData GetAttachmentResponseData(AttachmentResult result) { return(new AttachmentResponseData(result)); }