public void Create(AttachmentData attachmentData) { if (!_userContext.GetCurrentUser().HasRole(UserRole.Member)) { throw new ArgumentException(Messages.InsufficientSecurityClearance); } if (attachmentData.Id == Guid.Empty) { throw new ArgumentException("An ID must be supplied for the attachment."); } if (String.IsNullOrEmpty(attachmentData.Filename)) { throw new ArgumentException(Messages.FileNameRequired); } if (attachmentData.Filename.Length > 2000) { throw new ArgumentException(Messages.FileNameTooLarge); } if (String.IsNullOrEmpty(attachmentData.ContentType)) { throw new ArgumentException(Messages.ContentTypeNotSupplied); } if (attachmentData.Content == null) { throw new ArgumentException(Messages.ContentNotSupplied); } _jobAttachmentDataRepository.Put(attachmentData); }
public async void Populate(AttachmentData attachment) { await _UIDispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { AttachmentPopulatedEvent?.Invoke(this, attachment); }); }
/// <summary> /// Create an email attachment from <see cref="AttachmentData"/> object /// <para> /// For more information look at https://msdn.microsoft.com/en-us/library/gg328344(v=crm.7).aspx /// </para> /// </summary> /// <param name="emailId">Existing <c>Email Activity</c> Id</param> /// <param name="attachmentFile"><see cref="AttachmentData"/> object</param> /// <returns>Created record Id (<see cref="System.Guid"/>)</returns> public Guid Attach(Guid emailId, AttachmentData attachmentFile) { ExceptionThrow.IfGuidEmpty(emailId, "emailId"); ExceptionThrow.IfNull(attachmentFile, "attachmentFile"); return(Attach(emailId, attachmentFile.Data.ByteArray, attachmentFile.Meta.Name)); }
public SysLogDescriptor(SysLogType logType, AttachmentData att, string log, bool isReceived = false) { this.LogType = LogType; this.Attachment = att; this.SystemLog = log; IsReceived = isReceived; }
public async Task GetPostImages_returns_list_with_one_image_if_subattachments_field_is_null_and_media_field_contains_one_image() { //arrange _fileService.Setup(f => f.CreateAsync(It.IsAny <CreateFileRequest>(), It.IsAny <Stream>())).ReturnsAsync(new FileInfoDTO { Id = Guid.NewGuid(), Name = "Image", ContentType = "image/png", SizeKB = 1000 }); _facebookClient.Setup(f => f.GetImage(It.IsAny <string>())) .ReturnsAsync(() => new HttpResponseMessage(HttpStatusCode.OK) { Content = new MultipartContent { Headers = { ContentType = MediaTypeHeaderValue.Parse("image/png") } }, }); AttachmentData attachments = new AttachmentData { Subattachments = null, Media = new Media { Image = new Image() } }; //act var list = await _fbPostCreator.GetPostImages(attachments, "123456789"); //assert Assert.Equal(1, list.Count); }
private void SaveAttachmentContents(AttachmentData attachmentData, string attachmentPath) { var encoding = new UTF8Encoding(false); using (Stream attachmentStream = reportContainer.OpenWrite(attachmentPath, attachmentData.ContentType, encoding)) attachmentData.SaveContents(attachmentStream, encoding); }
public async Task <ICollection <PostFile> > GetPostImages(AttachmentData attachments, string postId) { var fileList = new List <PostFile>(); var arrayOfImages = attachments.Subattachments?.Data ?? new List <SubAttachmentData>(); if (arrayOfImages.Count == 0) { var mainImage = attachments.Media?.Image; if (mainImage != null) { arrayOfImages.Add(new SubAttachmentData { Media = new Media { Image = mainImage } }); } } foreach (var image in arrayOfImages) { var info = await GetFileInfo(image, postId); if (info != null) { fileList.Add(FileMapper.ConvertToPostFile(info)); } } return(fileList); }
internal static GenericField CreateAttachment(AttachmentData data, string contentType) { var gfs = new List <GenericField> { CreateGenericField("ContentType", DataTypeEnum.STRING, contentType), // "text/plain", "application/x-zip-compressed" CreateGenericField("FileName", DataTypeEnum.STRING, data.AttachmentName), CreateGenericField("Data", DataTypeEnum.BASE64_BINARY, data.AttachmentContent) }; // add a file attachment var result = new GenericField { name = "FileAttachments", DataValue = new DataValue { ItemsElementName = new [] { ItemsChoiceType.ObjectValueList }, Items = new [] { new GenericObject() { ObjectType = new RNObjectType() { TypeName = "FileAttachment" }, GenericFields = gfs.ToArray() } } } }; return(result); }
/// <summary> /// Update the attributes of a match attachment /// </summary> /// <param name="tournament">Tournament ID (e.g. 10230) or URL (e.g. 'single_elim' for /// challonge.com/single_elim). If assigned to a subdomain, URL format must be /// subdomain-tournament_url (e.g. 'test-mytourney' for test.challonge.com/mytourney)</param> /// <param name="matchId">The match's unique id</param> /// <param name="attachmentId">The tournament's unique id</param> /// <param name="url">A web URL</param> /// <param name="description">Text to describe the file or URL attachment, or this can simply be /// standalone text</param> /// <returns>The updated attachment</returns> /// <remarks>At least one of the two optional parameters must be provided</remarks> public async Task <Attachment> UpdateAttachmentAsync(string tournament, int matchId, int attachmentId, string url = null, string description = null) { string request = $"https://api.challonge.com/v1/tournaments/{tournament}/matches/{matchId}/attachments/{attachmentId}.json"; if (url == null && description == null) { throw new ArgumentNullException("At least 1 of the 3 optional parameters must be provided."); } Dictionary <string, string> parameters = new Dictionary <string, string> { ["api_key"] = _apiKey }; if (url != null) { parameters["match_attachment[url]"] = url; } if (description != null) { parameters["match_attachment[description]"] = description; } FormUrlEncodedContent content = new FormUrlEncodedContent(parameters); AttachmentData attachmentData = await PutAsync <AttachmentData>(_httpClient, request, content); return(attachmentData.Attachment); }
public Attachment(AttachmentData obj, bool alreadyEncrypted = false) { Size = obj.Size; BuildDomainModel(this, obj, _map, alreadyEncrypted, new HashSet <string> { "Id", "Url", "SizeName" }); }
protected override void DataPortal_Insert() { using (var dalManager = DataFactoryManager.GetManager()) { var dalFactory = dalManager.GetProvider <IAttachmentDataFactory>(); var data = new AttachmentData(); using (this.BypassPropertyChecks) { this.ModifiedBy = ((IBusinessIdentity)Csla.ApplicationContext.User.Identity).UserId; this.ModifiedDate = DateTime.Now; this.CreatedBy = this.ModifiedBy; this.CreatedDate = this.ModifiedDate; this.Insert(data); data = dalFactory.Insert(data); this.AttachmentId = data.AttachmentId; } // this.FieldManager.UpdateChildren(data); } }
public void AttachmentDataInitsWithNoArgs() { var attachmentData = new AttachmentData(); Assert.NotNull(attachmentData); Assert.IsType <AttachmentData>(attachmentData); }
/// <summary> /// Pushes the attachment to web response. /// </summary> /// <param name="response">The response.</param> /// <param name="EMailMessageId">The E mail message id.</param> /// <param name="AttachementIndex">The attachement id.</param> public static void PushAttachmentToWebResponse(System.Web.HttpResponse response, int EMailMessageId, int AttachementIndex) { EMailMessageRow row = new EMailMessageRow(EMailMessageId); MemoryStream memStream = new MemoryStream(row.EmlMessage.Length); memStream.Write(row.EmlMessage, 0, row.EmlMessage.Length); memStream.Position = 0; Pop3Message message = new Pop3Message(memStream); AttachmentData entry = GetAttachment(message.MimeEntries, ref AttachementIndex); response.ContentType = entry.ContentType; //response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetFileName(entry))); if (Common.OpenInNewWindow(entry.ContentType)) { response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", entry.FileName)); } else { response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", entry.FileName)); } response.OutputStream.Write(entry.Data, 0, entry.Data.Length); response.OutputStream.Flush(); response.End(); }
public Attachment(AttachmentData data) { Id = data.Id; Url = data.Url; FileName = data.FileName != null ? new CipherString(data.FileName) : null; SetSize(data.Size); SizeName = data.SizeName; }
public async Task OnUploadAttachmentAsyncTest() { var sut = CreateSkillHandlerForTesting(); var conversationId = Guid.NewGuid().ToString("N"); var attachmentData = new AttachmentData(); await Assert.ThrowsAsync <NotImplementedException>(() => sut.TestOnUploadAttachmentAsync(_claimsIdentity, conversationId, attachmentData, CancellationToken.None)); }
public async Task <Attachment> GetAttachmentAsync(string tournament, int matchId, int attachmentId) { string request = $" https://api.challonge.com/v1/tournaments/{tournament}/matches/{matchId}/attachments/{attachmentId}.?api_key={apiKey}"; AttachmentData attachmentData = await GetAsync <AttachmentData>(httpClient, request); return(attachmentData.Attachment); }
public void GetAttachmentReturnsNamedAttachment() { var log = new StructuredDocument(); var data = new AttachmentData("foo", MimeTypes.Binary, AttachmentType.Binary, null, new byte[0]); log.Attachments.Add(data); log.Attachments.Add(new AttachmentData("bar", MimeTypes.Binary, AttachmentType.Binary, null, new byte[0])); Assert.AreSame(data, log.GetAttachment("foo")); }
internal static Attachment FetchAttachment(AttachmentData data) { var result = new Attachment(); result.Fetch(data); result.MarkOld(); return(result); }
public void Put(AttachmentData attachmentData) { if (!Directory.Exists(_attachmentLocation)) { Directory.CreateDirectory(_attachmentLocation); } PutAttachment(attachmentData); PutMetadata(attachmentData); }
public void FromAttachmentData_Text() { var attachmentData = new AttachmentData("name", MimeTypes.PlainText, AttachmentType.Text, "content", null); var attachment = (TextAttachment)Attachment.FromAttachmentData(attachmentData); Assert.AreEqual("name", attachment.Name); Assert.AreEqual(MimeTypes.PlainText, attachment.ContentType); Assert.AreEqual("content", attachment.Text); }
public void Save(string uid) { try { if (String.IsNullOrEmpty(uid)) { throw new ArgumentNullException("uid", "User ID is required."); } Dictionary <string, string> ValErrors = Validate(); if (ValErrors.Count > 0) { throw new RequisitionNotValidException("Attachment is not valid", ValErrors); } Attachment Original = null; Enums.HistoryType ChangeType; using (PurchasingContext Context = ContextHelper.GetDBContext()) { AttachmentData data; if (AttachmentID > 0) { data = Context.AttachmentDatas.FirstOrDefault(x => x.attachment_id == AttachmentID); Original = new Attachment(data); ChangeType = Enums.HistoryType.UPDATE; } else { data = new AttachmentData(); ChangeType = Enums.HistoryType.ADD; data.date_created = DateTime.Now; data.created_by = uid; } data.parent_object_type_name = ParentObjectTypeName; data.parent_identifier = ParentIdentifier; data.blob_id = BlobID; data.organization_id = OrganizationID; data.modified_by = uid; data.date_modified = DateTime.Now; data.active = Active; if (AttachmentID <= 0) { Context.AttachmentDatas.InsertOnSubmit(data); } Context.SubmitChanges(); Load(data); } SaveHistory(ChangeType, Original, uid); } catch (Exception ex) { throw new RequisitionException("An error has occurred while saving attachment.", ex); } }
public static AttachmentData Create(MimeEntry entry) { AttachmentData retVal = new AttachmentData(); retVal.ContentType = entry.ContentType; retVal.FileName = EMailMessageInfo.GetFileName(entry); retVal.Data = entry.Body; return(retVal); }
public AttachmentData Update(AttachmentData data) { var attachment = MockDb.Attachments .Where(row => row.AttachmentId == data.AttachmentId) .Single(); Csla.Data.DataMapper.Map(data, attachment); return(data); }
public AttachmentData ToAttachmentData() { var a = new AttachmentData(); a.Size = Size; BuildDataModel(this, a, _map, new HashSet <string> { "Id", "Url", "SizeName" }); return(a); }
public void FromAttachmentData_Binary() { byte[] bytes = new byte[] { 1, 2, 3 }; var attachmentData = new AttachmentData("name", MimeTypes.Binary, AttachmentType.Binary, null, bytes); var attachment = (BinaryAttachment)Attachment.FromAttachmentData(attachmentData); Assert.AreEqual("name", attachment.Name); Assert.AreEqual(MimeTypes.Binary, attachment.ContentType); Assert.AreEqual(bytes, attachment.Bytes); }
public async Task UploadAttachmentWithNullConversationId() { await UseClientFor(async client => { var attachment = new AttachmentData("image/png", "Bot.png", ReadFile("bot.png"), ReadFile("bot_icon.png")); var ex = await Assert.ThrowsAsync <ValidationException>(() => client.Conversations.UploadAttachmentAsync(null, attachment)); Assert.Contains("cannot be null", ex.Message); }); }
/// <summary> /// Upload media data to WeChat. /// </summary> /// <typeparam name="T">The upload result type.</typeparam> /// <param name="attachmentData">The attachment data need to be uploaded.</param> /// <param name="url">The endpoint when upload the data.</param> /// <param name="isTemporaryMedia">If upload media as a temporary media.</param> /// <param name="timeout">Upload media timeout.</param> /// <returns>Uploaded result from WeChat.</returns> private async Task <UploadMediaResult> UploadMediaAsync(AttachmentData attachmentData, string url, bool isTemporaryMedia, int timeout = 30000) { try { // Border break var boundary = "---------------" + DateTime.UtcNow.Ticks.ToString("x", CultureInfo.InvariantCulture); using (var mutipartDataContent = new MultipartFormDataContent(boundary)) { mutipartDataContent.Headers.Remove("Content-Type"); mutipartDataContent.Headers.TryAddWithoutValidation("Content-Type", "multipart/form-data; boundary=" + boundary); // Add attachment content. var contentByte = new ByteArrayContent(attachmentData.OriginalBase64); contentByte.Headers.Remove("Content-Disposition"); var ext = GetMediaExtension(attachmentData.Name, attachmentData.Type); contentByte.Headers.TryAddWithoutValidation("Content-Disposition", $"form-data; name=\"media\";filename=\"{attachmentData.Name + ext}\""); contentByte.Headers.Remove("Content-Type"); contentByte.Headers.TryAddWithoutValidation("Content-Type", attachmentData.Type); mutipartDataContent.Add(contentByte); // Additional form is required when upload a forever video. StringContent stringContent = null; if (isTemporaryMedia == false && attachmentData.Type.Contains(MediaTypes.Video)) { var additionalForm = string.Format(CultureInfo.InvariantCulture, "{{\"title\":\"{0}\", \"introduction\":\"introduction\"}}", attachmentData.Name); // Important! name must be "description" stringContent = new StringContent(additionalForm); mutipartDataContent.Add(stringContent, "\"description\""); } _logger.LogInformation($"Upload {attachmentData.Type} to WeChat", Severity.Information); var response = await SendHttpRequestAsync(HttpMethod.Post, url, mutipartDataContent, null, timeout).ConfigureAwait(false); // Disponse all http content in mutipart form data content before return. contentByte.Dispose(); if (stringContent != null) { stringContent.Dispose(); } if (isTemporaryMedia) { return(ConvertBytesToType <UploadTemporaryMediaResult>(response)); } return(ConvertBytesToType <UploadPersistentMediaResult>(response)); } } catch (Exception ex) { _logger.LogError(ex, $"Failed To Upload Media, Type: {attachmentData.Type}"); throw; } }
private string CallAdobeApi(AttachmentData att, DocumentData currentDocument) { var api = new AdobeSignHelper(_log); var documentId = api.SendDocument(att.Content, Configuration.ApiConfig.TokenValue, $"{att.FileName}.{att.FileExtension}"); var agreementsId = api.SendToSig(documentId, Configuration.ApiConfig.TokenValue, Configuration.MessageContent.MailSubject, Configuration.MessageContent.MailBody, GetMemberInfo(), true, Configuration.RedirectUrl); currentDocument.SetFieldValue(Configuration.AttConfig.AgreementsIdFild, agreementsId); currentDocument.SetFieldValue(Configuration.AttConfig.AttTechnicalFieldID, att.ID); return(api.GetSigningURL(Configuration.ApiConfig.TokenValue, agreementsId)); }
public void ToAttachmentData_Text() { var attachment = new TextAttachment("name", MimeTypes.PlainText, "content"); AttachmentData attachmentData = attachment.ToAttachmentData(); Assert.AreEqual("name", attachmentData.Name); Assert.AreEqual(MimeTypes.PlainText, attachmentData.ContentType); Assert.AreEqual("content", attachmentData.GetText()); Assert.AreEqual(AttachmentContentDisposition.Inline, attachmentData.ContentDisposition); Assert.AreEqual(AttachmentType.Text, attachmentData.Type); }
public async Task GetAttachmentViewWithNullViewIdFails() { await UseClientFor(async client => { var attachment = new AttachmentData("image/png", "Bot.png", ReadFile("bot.png"), ReadFile("bot_icon.png")); var response = await client.Conversations.UploadAttachmentAsync(ConversationId, attachment); var ex = await Assert.ThrowsAsync <ValidationException>(() => client.Attachments.GetAttachmentAsync(response.Id, null)); Assert.Contains("cannot be null", ex.Message); }); }
internal static void Map(AttachmentData source, Attachment destination) { destination.AttachmentId = source.AttachmentId; destination.FileData = source.FileData; destination.FileType = source.FileType; destination.IsArchived = source.IsArchived; destination.Name = source.Name; destination.SourceId = source.SourceId; destination.SourceTypeId = source.SourceTypeId; destination.CreatedBy = source.CreatedBy; destination.CreatedDate = source.CreatedDate; destination.ModifiedBy = source.ModifiedBy; destination.ModifiedDate = source.ModifiedDate; }
public AttachmentData Insert(AttachmentData data) { if (MockDb.Attachments.Count() == 0) { data.AttachmentId = 1; } else { data.AttachmentId = MockDb.Attachments.Select(row => row.AttachmentId).Max() + 1; } MockDb.Attachments.Add(data); return data; }
public AttachmentData Fetch(AttachmentDataCriteria criteria) { using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities> .GetManager(Database.ApplicationConnection, false)) { var attachment = this.Fetch(ctx, criteria) .Single(); var attachmentData = new AttachmentData(); this.Fetch(attachment, attachmentData); return attachmentData; } }
public AttachmentData Fetch(AttachmentData data) { data.Source = MockDb.Sources .Where(row => row.SourceId == data.SourceId) .Single(); data.CreatedByUser = MockDb.Users .Where(row => row.UserId == data.CreatedBy) .Single(); data.ModifiedByUser = MockDb.Users .Where(row => row.UserId == data.ModifiedBy) .Single(); return data; }
public AttachmentData[] FetchLookupInfoList(AttachmentDataCriteria criteria) { using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities> .GetManager(Database.ApplicationConnection, false)) { var attachments = this.Fetch(ctx, criteria) .AsEnumerable(); var attachmentDataList = new List<AttachmentData>(); foreach (var attachment in attachments) { var attachmentData = new AttachmentData(); this.Fetch(attachment, attachmentData); attachmentDataList.Add(attachmentData); } return attachmentDataList.ToArray(); } }
private void Fetch(Attachment attachment, AttachmentData attachmentData) { DataMapper.Map(attachment, attachmentData); attachmentData.Source = new SourceData(); DataMapper.Map(attachment.Source, attachmentData.Source); attachmentData.CreatedByUser = new UserData(); DataMapper.Map(attachment.CreatedByUser, attachmentData.CreatedByUser); attachmentData.ModifiedByUser = new UserData(); DataMapper.Map(attachment.ModifiedByUser, attachmentData.ModifiedByUser); }
public AttachmentData Insert(AttachmentData data) { using (var ctx = Csla.Data.ObjectContextManager<ApplicationEntities> .GetManager(Database.ApplicationConnection, false)) { var attachment = new Attachment(); DataMapper.Map(data, attachment); ctx.ObjectContext.AddToAttachments(attachment); ctx.ObjectContext.SaveChanges(); data.AttachmentId = attachment.AttachmentId; return data; } }
public AttachmentData Update(AttachmentData data) { var attachment = MockDb.Attachments .Where(row => row.AttachmentId == data.AttachmentId) .Single(); Csla.Data.DataMapper.Map(data, attachment); return data; }