public void AddFileTest() { FileAttachments fa = new FileAttachments(); Assert.AreEqual(true, fa.AddFile(new UserFile(100000000))); Assert.AreEqual(false, fa.AddFile(new UserFile(10000000))); }
public List <string> GetAttachFiles() { if (FileAttachments.IsNull() || !FileAttachments.Any()) { LoadAttachFile(); } return(FileAttachments); }
public void AddFilesTest() { FileAttachments fa = new FileAttachments(); UserFile[] array = new UserFile[2]; array[0] = new UserFile(100000000); array[1] = new UserFile(10000000); Assert.AreEqual(false, fa.AddFiles(array)); array[1] = new UserFile(1000000); Assert.AreEqual(true, fa.AddFiles(array)); }
/// <summary> /// Get all files/folders at specified folder location /// </summary> /// <param name="folderUrl"></param> /// <returns></returns> /// <see cref="https://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingNetSDK.html"/> /// <seealso cref="https://docs.aws.amazon.com/AmazonS3/latest/dev/ListingObjectKeysUsingNetSDK.html"/> public async Task <FileAttachments> GetFolderContentsAsync(string folderUrl) { var content = new FileAttachments(); string responseBody = ""; try { GetObjectRequest request = new GetObjectRequest { BucketName = _bucketName, Key = folderUrl //ex. folder3/nestedfolder1/ }; using (GetObjectResponse response = await _s3Client.GetObjectAsync(request)) using (Stream responseStream = response.ResponseStream) using (StreamReader reader = new StreamReader(responseStream)) { string title = response.Metadata["x-amz-meta-title"]; // Assume you have "title" as medata added to the object. string contentType = response.Headers["Content-Type"]; Console.WriteLine("Object metadata, Title: {0}", title); Console.WriteLine("Content type: {0}", contentType); responseBody = await reader.ReadToEndAsync(); // Now you process the response body. //TODO; pull out the file data from stream ... content.Files = new List <FileAttachment>(); content.Files.Add(new FileAttachment() { Body = responseBody }); } return(content); } catch (AmazonS3Exception e) { content.ErrorMessage = e.Message; // If bucket or object does not exist Console.WriteLine("Error encountered ***. Message:'{0}' when reading object", e.Message); } catch (Exception e) { content.ErrorMessage = e.Message; Console.WriteLine("Unknown encountered on server. Message:'{0}' when reading object", e.Message); } return(content); }
public void RemoveFileTest() { FileAttachments fa = new FileAttachments(); fa.AddFile(new UserFile(1000)); fa.AddFile(new UserFile(1001)); fa.AddFile(new UserFile(1002)); fa.AddFile(new UserFile(1003)); fa.RemoveFile("test_1000.txt"); Assert.AreEqual(3, fa.Count); fa.RemoveFile("test_1002.txt"); Assert.AreEqual(2, fa.Count); fa.RemoveFile("test_1001.txt"); Assert.AreEqual(1, fa.Count); fa.RemoveFile("test_1003.txt"); Assert.AreEqual(0, fa.Count); }
/// <summary> /// Creates a new mail merge message. /// </summary> /// <param name="subject">Mail message subject.</param> /// <param name="plainText">Plain text part of the mail message.</param> /// <param name="htmlText">HTML message part of the mail message.</param> /// <param name="fileAtt">File attachments of the mail message.</param> public MailMergeMessage(string subject, string plainText, string htmlText, IEnumerable <FileAttachment> fileAtt) : this(subject, plainText, htmlText) { fileAtt.ToList().ForEach(fa => FileAttachments.Add(fa)); }
/// <summary> /// Updates the counters for the file and image attachments /// </summary> public void UpdateAttachmentCounts() { AttachmentFilesCount = FileAttachments.Count(); AttachmentImagesCount = ImageAttachments.Count(); }
public void AttachFile(string fileName) { FileAttachments.Add(fileName); }
/// <summary> /// Gets the MimeMessage representation of the MailMergeMessage for a specific data item. /// </summary> /// <param name="dataItem"> /// The following types are accepted: /// Dictionary<string,object>, ExpandoObject, DataRow, any other class instances, anonymous types, and null. /// For class instances it's allowed to use the name of parameterless methods; use method names WITHOUT parentheses. /// </param> /// <returns>Returns a MailMessage ready to be sent by an SmtpClient.</returns> /// <exception cref="MailMergeMessageException">Throws a general MailMergeMessageException, which contains a list of exceptions giving more details.</exception> public MimeMessage GetMimeMessage(object dataItem = default(object)) { lock (_syncRoot) { // convert DataRow to Dictionary<string, object> if (dataItem is DataRow) { var row = (DataRow)dataItem; dataItem = row.Table.Columns.Cast <DataColumn>().ToDictionary(c => c.ColumnName, c => row[c]); } var mimeMessage = new MimeMessage(); AddSubjectToMailMessage(mimeMessage, dataItem); AddAddressesToMailMessage(mimeMessage, dataItem); AddAttributesToMailMessage(mimeMessage, dataItem); // must be added before subject and addresses BuildTextMessagePart(dataItem); BuildAttachmentPartsForMessage(dataItem); var exceptions = new List <Exception>(); if (mimeMessage.To.Count == 0 && mimeMessage.Cc.Count == 0 && mimeMessage.Bcc.Count == 0) { exceptions.Add(new AddressException("No recipients.", _badMailAddr, null)); } if (string.IsNullOrWhiteSpace(mimeMessage.From.ToString())) { exceptions.Add(new AddressException("No from address.", _badMailAddr, null)); } if (HtmlText.Length == 0 && PlainText.Length == 0 && Subject.Length == 0 && !FileAttachments.Any() && !InlineAttachments.Any() && !StringAttachments.Any() && !StreamAttachments.Any()) { exceptions.Add(new EmtpyContentException("Message is empty.", null)); } if (_badMailAddr.Count > 0) { exceptions.Add( new AddressException($"Bad mail address(es): {string.Join(", ", _badMailAddr.ToArray())}", _badMailAddr, null)); } if (_badInlineFiles.Count > 0) { exceptions.Add( new AttachmentException( $"Inline attachment(s) missing or not readable: {string.Join(", ", _badInlineFiles.ToArray())}", _badInlineFiles, null)); } if (_badAttachmentFiles.Count > 0) { exceptions.Add( new AttachmentException( $"File attachment(s) missing or not readable: {string.Join(", ", _badAttachmentFiles.ToArray())}", _badAttachmentFiles, null)); } if (_badVariableNames.Count > 0) { exceptions.Add( new VariableException( $"Variable(s) for placeholder(s) not found: {string.Join(", ", _badVariableNames.ToArray())}", _badVariableNames, null)); } // Finally throw general exception if (exceptions.Count > 0) { throw new MailMergeMessageException("Building of message failed with one or more exceptions.", exceptions, mimeMessage); } if (_attachmentParts.Any()) { var mixed = new Multipart("mixed"); if (_textMessagePart != null) { mixed.Add(_textMessagePart); } foreach (var att in _attachmentParts) { mixed.Add(att); } mimeMessage.Body = mixed; } if (mimeMessage.Body == null) { mimeMessage.Body = _textMessagePart ?? new TextPart("plain") { Text = string.Empty }; } return(mimeMessage); } }
public virtual int Update(FileAttachments dataSet) { return this.Adapter.Update(dataSet, "DocumentRepository"); }
public virtual int Update(FileAttachments.DocumentRepositoryDataTable dataTable) { return this.Adapter.Update(dataTable); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); FileAttachments ds = new FileAttachments(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "DocumentRepositoryDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { FileAttachments ds = new FileAttachments(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }
/// <summary> /// Add a file attachment that will be attached to the PDF file. /// </summary> /// <param name="attachment">The file attachment as a byte array.</param> /// <param name="fileName">The filename of the file attachment.</param> /// <param name="description">The description of the file attachment.</param> public void AddFileAttachment(byte[] attachment, string fileName, string description) { _resources.Add(attachment); FileAttachments.Add(new FileAttachment( "job-resource:" + (_resources.Count - 1), fileName, description)); }