protected virtual void SetMissingIdFromRequestUri(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Id)) { response.Id = httpResponse.RequestMessage.ExtractIdFromUri(true); } }
public virtual async Task MaterializeAsync(AttachmentResponse response, HttpResponseMessage httpResponse) { SetMissingIdFromRequestUri(response, httpResponse); SetMissingRevFromRequestHeaders(response, httpResponse); SetMissingNameFromRequestUri(response, httpResponse); await SetContentAsync(response, httpResponse).ForAwait(); }
protected virtual void SetMissingRevFromRequestHeaders(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Rev)) { response.Rev = httpResponse.Headers.GetETag(); } }
protected virtual void SetMissingNameFromRequestUri(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Name)) { response.Name = httpResponse.RequestMessage.ExtractAttachmentNameFromUri(); } }
public HttpResponseMessage DeleteAttachment(long docId) { AttachmentViewModel viewModel = new AttachmentViewModel() { DocumentID = docId }; var successMessage = string.Empty; try { AttachmentResponse resonse = docrepositoryService.DeleteAttachment( new AttachmentRequest() { AttachmentViewModel = viewModel }); if (resonse.Exception != null) { successMessage = resonse.Exception.Message; } else { successMessage = "Successfully Deleted Attachement"; } } catch (Exception ex) { successMessage = ex.Message; } return(Request.CreateResponse(successMessage)); }
public virtual void Materialize(AttachmentResponse response, HttpResponseMessage httpResponse) { SetMissingIdFromRequestUri(response, httpResponse); SetMissingRevFromRequestHeaders(response, httpResponse); SetMissingNameFromRequestUri(response, httpResponse); SetContent(response, httpResponse); }
protected virtual void PopulateMissingNameFromRequestUri(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Name)) { response.Name = httpResponse.RequestMessage.GetUriSegmentByRightOffset(); } }
public static void Run() { // ExStart:1 PdfApi pdfApi = new PdfApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH); String name = "SampleAttachment"; String fileName = name + ".pdf"; int attachmentIndex = 1; String storage = ""; String folder = ""; try { // Upload source file to aspose cloud storage storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName)); // Invoke Aspose.PDF Cloud SDK API to get specific attachment from a pdf AttachmentResponse apiResponse = pdfApi.GetDocumentAttachmentByIndex(fileName, attachmentIndex, storage, folder); if (apiResponse != null && apiResponse.Status.Equals("OK")) { Attachment attach = apiResponse.Attachment; Console.WriteLine("Name :: " + attach.Name); Console.WriteLine("MimeType :: " + attach.MimeType); Console.ReadKey(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); } // ExEnd:1 }
public Attachment(AttachmentResponse response) { Id = response.Id; Url = response.Url; FileName = response.FileName != null ? new CipherString(response.FileName) : null; SetSize(response.Size); SizeName = response.SizeName; }
private AttachmentResponse GetAttachmentsFromExchangeServerUsingEWSManagedApi(AttachmentRequest request) { var attachmentsProcessedCount = 0; var attachmentNames = new List <string>(); // Creo un oggetto di tipo ExchangeService ExchangeService service = new ExchangeService(); //imposto il token di autenticazione ricevuto dall'add-in service.Credentials = new OAuthCredentials(request.attachmentToken); //imposto la url del server Exchange service.Url = new Uri(request.ewsUrl); // Richiede gli allegati al server var getAttachmentsResponse = service.GetAttachments( request.attachments.Select(a => a.id).ToArray(), null, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent)); if (getAttachmentsResponse.OverallResult == ServiceResult.Success) { foreach (var attachmentResponse in getAttachmentsResponse) { attachmentNames.Add(attachmentResponse.Attachment.Name); if (attachmentResponse.Attachment is FileAttachment) { //mette il contenuto dell'allegato in uno stream FileAttachment fileAttachment = attachmentResponse.Attachment as FileAttachment; Stream s = new MemoryStream(fileAttachment.Content); // Qui è possibile processare il contenuto dell'allegato } if (attachmentResponse.Attachment is ItemAttachment) { //mette il contenuto dell'allegato in uno stream ItemAttachment itemAttachment = attachmentResponse.Attachment as ItemAttachment; Stream s = new MemoryStream(itemAttachment.Item.MimeContent.Content); // Qui è possibile processare il contenuto dell'allegato } attachmentsProcessedCount++; } } // La risposta contiene il nome ed il numero degli allegati che sono stati // processati dal servizio var response = new AttachmentResponse(); response.attachmentNames = attachmentNames.ToArray(); response.attachmentsProcessed = attachmentsProcessedCount; return(response); }
public AttachmentData(AttachmentResponse response) { Id = response.Id; Url = response.Url; FileName = response.FileName; Key = response.Key; Size = response.Size; SizeName = response.SizeName; }
public AttachmentData(AttachmentResponse response, string cipherId) { Id = response.Id; LoginId = cipherId; Url = response.Url; FileName = response.FileName; Size = response.Size; SizeName = response.SizeName; }
public AttachmentResponse GeAttachment(AttachmentRequest request) { AttachmentResponse response = new AttachmentResponse(); Attachment attachment = attachmentRepository.FindBy(Convert.ToInt16(request.AttachmentViewModel.DocumentID)); if (attachment != null) { AttachmentViewModel attachmentViewModel = Mapper.Map <Attachment, AttachmentViewModel>(attachment); response.AttachmentViewModel = attachmentViewModel; } return(response); }
protected async virtual void OnSuccessfulResponse(AttachmentResponse response, HttpResponseMessage httpResponse) { using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait()) { PopulateMissingIdFromRequestUri(response, httpResponse); PopulateMissingNameFromRequestUri(response, httpResponse); PopulateMissingRevFromRequestHeaders(response, httpResponse); content.Position = 0; response.Content = httpResponse.Content.ReadAsByteArrayAsync().Result; } }
protected virtual void OnSuccessfulResponse(AttachmentResponse response, HttpResponseMessage httpResponse) { using (var content = httpResponse.Content.ReadAsStream()) { PopulateMissingIdFromRequestUri(response, httpResponse); PopulateMissingNameFromRequestUri(response, httpResponse); PopulateMissingRevFromRequestHeaders(response, httpResponse); content.Position = 0; response.Content = httpResponse.Content.ReadAsByteArrayAsync().Result; } }
public void Pdf_Attachments_Tests() { try { AttachmentsResponse attachmentsResponse = pdfService.Attachments.ReadDocumentAttachmentsInfo("pdf-sample.pdf", Utils.CloudStorage_Input_Folder); AttachmentResponse AttachmentResponse = pdfService.Attachments.ReadDocumentAttachmentInfoByItsIndex("pdf-sample.pdf", 1, Utils.CloudStorage_Input_Folder); pdfService.Attachments.DownloadDocumentAttachmentContentByItsIndex("pdf-sample.pdf", 1, Utils.CloudStorage_Input_Folder, Utils.Local_Output_Path + "pdf-out-attach.png"); } catch (Exception ex) { Assert.Fail(ex.Message); } }
protected virtual void OnSuccessfulAttachmentResponseContentMaterializer(HttpResponseMessage response, AttachmentResponse result) { using (var content = response.Content.ReadAsStream()) { AssignMissingIdFromRequestUri(response, result); AssignMissingNameFromRequestUri(response, result); AssignMissingRevFromRequestHeaders(response, result); content.Position = 0; using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding)) { result.Content = Convert.FromBase64String(reader.ReadToEnd()); } } }
public static AttachmentResponse ToAttachmentResponse(this Domain.Attachment.Attachment attachment) { var attachmentResponse = new AttachmentResponse(); if (attachment != null) { attachmentResponse.Id = attachment.Id; attachmentResponse.ContentType = attachment.ContentType; attachmentResponse.Created = attachment.Created; attachmentResponse.FileName = attachment.FileName; attachmentResponse.MessageId = attachment.MessageId; attachmentResponse.Size = attachment.Size; } return(attachmentResponse); }
public void TestGetAttachmentInfo_paramCanBeOptional() { WebClient agent = new WebClient(); string output = agent.DownloadString( "http://localhost:8080/api/get?apikey=b&object_id=" + objectId1); Assert.AreNotEqual("", output); AttachmentResponse res = fastJSON.JSON.Instance.ToObject <AttachmentResponse>(output); Assert.AreEqual(200, res.status); Assert.AreEqual(0, res.api_ret_code); Assert.AreEqual("success", res.api_ret_message); Assert.AreEqual(doc.object_id, res.attachment.object_id); Assert.AreEqual(doc.title, res.attachment.title); Assert.AreEqual(doc.description, res.attachment.description); }
public AttachmentResponse PreprodStatus(List <Release> activeReleases) { AttachmentResponse response = new AttachmentResponse(); Attachment attachment = PreprodFreeStatus(); if (activeReleases != null && activeReleases.Count > 0) { attachment.Text = "Preprod is taken"; attachment.Color = "warning"; foreach (var release in activeReleases) { attachment.Fields.Add(new Field("User", release.User, true)); attachment.Fields.Add(new Field("Ticket(s)", release.Tickets, true)); //attachment.Fields.Add(new Field("Date", release.Started.ToShortDateString(), false)); } } response.Attachments.Add(attachment); return(response); }
public async Task <List <AttachmentResponse> > FindDocuments(string documentType, List <Models.AdditionalParametersRequest> filterConditions) { var res = new List <AttachmentResponse>(); DataAccessLayer.DocumentManagement2SoapService.AttributeTypeWithAnyAttribute[] documentTypeAttributes = await getDocumentTypeAttributesAsync(documentType); DocumentTypeAttributeItem docMetadata = await GetDocumentMetadataAsync(documentType); var searchParams = docMetadata.SearchAttributes?.Select(x => x.DataSourceProperty); var filter = getFilters(filterConditions.Where(x => searchParams.Contains(x.Name)).ToList(), docMetadata.SearchAttributes.ToList()); DataAccessLayer.DocumentManagement2SoapService.document[] docs = await _service.FindDocument(filter); docs.ToList().ForEach(doc => { var attach = new AttachmentResponse(); docMetadata.DisplayParameters.ToList().ForEach(displayParameter => { var destAttribute = documentTypeAttributes.FirstOrDefault(x => x.name == displayParameter.AttributeName); var dataType = displayParameter.Type ?? destAttribute?.AnyAttr.First(z => z.Name == "propertyType")?.Value; attach.AttachmentsAttributes.Add( new AttachmentsAttribute() { Name = displayParameter.AttributeName, Value = ChangePropertyValueFormat(doc.AnyAttr.First(z => z.Name == displayParameter.AttributeName).Value, dataType, displayParameter.Format), DisplayName = displayParameter.DisplayName, DisplayOrder = displayParameter.DisplayOrder } ); }); res.Add(attach); }); return(res); }
protected virtual void SetMissingRevFromRequestHeaders(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Rev)) response.Rev = httpResponse.Headers.GetETag(); }
protected override async Task <ConversationResponse <WeatherSettings> > ContinueConversationAsync(IStore blobStore, ActivityRequest request, WeatherSettings priorConversation) { if (request.SanitizedText.Contains("quit")) { priorConversation = null; // Reset the game state } string input = request.SanitizedText.ToLower(); List <string> responseText = new List <string>(); List <AttachmentResponse> attachments = new List <AttachmentResponse>(); if (input.Contains("weather")) { input = input.Replace("weather", string.Empty).Trim(); if (!string.IsNullOrWhiteSpace(input)) { // The rest of the input is the location, so update our geo-coordinate try { GeoCoordinate coordinate = await this.locationFinder.GetLocationAsync(input).ConfigureAwait(false); Station closestStation = StationLocator.FindClosestStation(coordinate); string distanceToStation = $", {(int)(closestStation.Location.GetDistanceTo(coordinate) / 10.0) / 100.0} km away."; if (closestStation.Callsign != priorConversation.Station) { responseText.Add($"Using {closestStation.Callsign} near {closestStation.City}{distanceToStation}"); priorConversation.Station = closestStation.Callsign; } else { responseText.Add($"{closestStation.Callsign}, the currently-selected station, is still the closest NOAA station{distanceToStation}"); } } catch (Exception ex) { responseText.Add(ex.Message + ": " + ex.StackTrace); } } // Actually get the weather. AttachmentResponse radarImage = await LayerRetriever.GetRadarImageAsync(priorConversation, blobStore, "weather-images", TimeSpan.FromDays(3 * 30)).ConfigureAwait(false); attachments.Add(radarImage); } else if (input.Contains("layers") || input.Contains("layer")) { input = input.Replace("layers", string.Empty).Replace("layer", string.Empty).Trim(); if (input.Contains("add")) { input = input.Replace("add", string.Empty).Trim(); RadarLayerType layer = RadarLayerTypeNames.GetLayer(input); if (layer == RadarLayerType.Unknown) { responseText.Add($"Unknown layer '{input}'"); OutputValidLayers(responseText); } else { string response = priorConversation.LayerStack.AddLayer(layer); if (!string.IsNullOrEmpty(response)) { responseText.Add(response); } OutputCurrentLayers(priorConversation, responseText); } } else if (input.Contains("remove")) { input = input.Replace("remove", string.Empty).Trim(); RadarLayerType layer = RadarLayerTypeNames.GetLayer(input); if (layer == RadarLayerType.Unknown) { responseText.Add($"Unknown layer '{input}'"); OutputValidLayers(responseText); } else { string response = priorConversation.LayerStack.RemoveLayer(layer); if (!string.IsNullOrEmpty(response)) { responseText.Add(response); } OutputCurrentLayers(priorConversation, responseText); } } else if (input.Contains("promote")) { input = input.Replace("promote", string.Empty).Trim(); RadarLayerType layer = RadarLayerTypeNames.GetLayer(input); if (layer == RadarLayerType.Unknown) { responseText.Add($"Unknown layer '{input}'"); OutputValidLayers(responseText); } else { string response = priorConversation.LayerStack.PromoteLayer(layer); if (!string.IsNullOrEmpty(response)) { responseText.Add(response); } OutputCurrentLayers(priorConversation, responseText); } } else if (input.Contains("demote")) { input = input.Replace("demote", string.Empty).Trim(); RadarLayerType layer = RadarLayerTypeNames.GetLayer(input); if (layer == RadarLayerType.Unknown) { responseText.Add($"Unknown layer '{input}'"); OutputValidLayers(responseText); } else { string response = priorConversation.LayerStack.DemoteLayer(layer); if (!string.IsNullOrEmpty(response)) { responseText.Add(response); } OutputCurrentLayers(priorConversation, responseText); } } else { responseText.Add("Valid layer commands are 'add', 'remove', 'promote', or 'demote'"); OutputValidLayers(responseText); OutputCurrentLayers(priorConversation, responseText); } } else { responseText.Add("Unknown command!"); responseText.Add(this.GetHelpText()); } return(new ConversationResponse <WeatherSettings>(priorConversation, new ActivityResponse(string.Join("\r\n\r\n", responseText), attachments))); }
public static AttachmentResponseAssertions Should(this AttachmentResponse response) { return(new AttachmentResponseAssertions(response)); }
public AttachmentResponseAssertions(AttachmentResponse response) { Response = response; }
protected virtual void SetMissingNameFromRequestUri(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Name)) response.Name = httpResponse.RequestMessage.RequestUri.Segments.LastOrDefault(); }
protected virtual void PopulateMissingNameFromRequestUri(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Name)) response.Name = httpResponse.RequestMessage.GetUriSegmentByRightOffset(); }
protected virtual async void SetContent(AttachmentResponse response, HttpResponseMessage httpResponse) { response.Content = await httpResponse.Content.ReadAsByteArrayAsync().ForAwait(); }
protected virtual void AssignMissingNameFromRequestUri(HttpResponseMessage response, AttachmentResponse result) { if (string.IsNullOrWhiteSpace(result.Name)) { result.Name = response.RequestMessage.GetUriSegmentByRightOffset(); } }
public async Task DownloadAndDecryptAttachmentAsync_RequestsTimeLimitedUrl(SutProvider <CipherService> sutProvider, string cipherId, AttachmentView attachment, AttachmentResponse response) { sutProvider.GetDependency <IApiService>().GetAttachmentData(cipherId, attachment.Id) .Returns(response); await sutProvider.Sut.DownloadAndDecryptAttachmentAsync(cipherId, attachment, null); await sutProvider.GetDependency <IApiService>().Received(1).GetAttachmentData(cipherId, attachment.Id); }
protected virtual void SetMissingIdFromRequestUri(AttachmentResponse response, HttpResponseMessage httpResponse) { if (string.IsNullOrWhiteSpace(response.Id)) response.Id = httpResponse.RequestMessage.ExtractIdFromUri(true); }