Пример #1
0
        public static string getAttachmentsNameInSingleLineForm(this Microsoft.Exchange.WebServices.Data.AttachmentCollection attachments)
        {
            string str = string.Empty;

            if (attachments.Count() > 0)
            {
                foreach (Microsoft.Exchange.WebServices.Data.Attachment att in attachments)
                {
                    str += (att.Name + ", ");
                }

                str = str.TrimEnd(' ');
                str = str.TrimEnd(',');
            }

            return(str);
        }
        /// <summary>
        /// Save attachments from collection to files.
        /// </summary>
        /// <param name="attachments">Attachments collection.</param>
        /// <param name="options">Options.</param>
        /// <returns>List of full paths to saved file attachments.</returns>
        private static List <string> SaveAttachments(Microsoft.Exchange.WebServices.Data.AttachmentCollection attachments, ExchangeOptions options)
        {
            List <string> pathList = new List <string> {
            };

            foreach (var attachment in attachments)
            {
                FileAttachment file = attachment as FileAttachment;
                string         path = Path.Combine(
                    options.AttachmentSaveDirectory,
                    options.OverwriteAttachment ? file.Name :
                    String.Concat(
                        Path.GetFileNameWithoutExtension(file.Name), "_",
                        Guid.NewGuid().ToString(),
                        Path.GetExtension(file.Name))
                    );
                file.Load(path);
                pathList.Add(path);
            }

            return(pathList);
        }
Пример #3
0
        public bool SaveAttachmentsToFolder(Microsoft.Exchange.WebServices.Data.AttachmentCollection attachments)
        {
            if (string.IsNullOrEmpty(this.path))
            {
                var argEx = new ArgumentNullException("File Path", "File path must be set prior to calling this method");

                Logger.LoggerAsync.InstanceOf.GeneralLogger.Error(argEx);

                throw argEx;
            }

            var directory = new System.IO.DirectoryInfo(this.path);

            var xmlStorage = new Data.HashStorage(@"..\XmlStorage\hashTable.xml");

            xmlStorage.Read();

            var attachmentList = this.AttachmentFileHash(attachments).Result;

            var result = xmlStorage.MoveToProjectRfiFolder(this.store.ProjectNumber);

            this.SynchronizeHashStorage(directory, xmlStorage);

            if (result == false)
            {
                xmlStorage.MoveToProjectRfiFolder(this.store.ProjectNumber);
            }

            // test names and hashes

            foreach (var item in attachmentList)
            {
                var parser = new Utilities.Parser();

                var isValidName = parser.IsValidRfiAttachmentName(item.Key.Name);

                if (isValidName == false)
                {
                    return(false);
                }

                var comparisonResult = xmlStorage.Comparator(item);

                switch (comparisonResult)
                {
                case Enum.FileComparisonResult.NoMatch:
                    var destination = directory.FullName + @"\" + item.Key.Name;

                    xmlStorage.Write(directory, new List <KeyValuePair <FileInfo, byte[]> > {
                        item
                    }, this.store);

                    var newFile = item.Key.CopyTo(destination);

                    newFile.Refresh();

                    item.Key.Delete();

                    result = newFile.Exists;
                    break;

                case Enum.FileComparisonResult.SameNames:
                case Enum.FileComparisonResult.SameNamesAndData:
                    result = true;

                    break;

                case Enum.FileComparisonResult.SameData:
                    result = false;

                    break;

                default:
                    throw new Exception("Invalid value for FileComparisonResult");
                }
            }


            return(result);
        }
Пример #4
0
        public async System.Threading.Tasks.Task <List <KeyValuePair <FileInfo, byte[]> > > AttachmentFileHash(Microsoft.Exchange.WebServices.Data.AttachmentCollection attachments)
        {
            List <KeyValuePair <FileInfo, byte[]> > hashList = new List <KeyValuePair <FileInfo, byte[]> >();

            foreach (FileAttachment attachment in attachments)
            {
                var tempPath = @"..\" + attachment.Name;

                var item = new FileInfo(tempPath);

                var fileStream = item.OpenWrite();

                attachment.Load(fileStream);

                fileStream.Close();
                fileStream.Dispose();

                var hash = await this.ComputeHash(item);

                hashList.Add(new KeyValuePair <FileInfo, byte[]>(item, hash));
            }

            return(hashList);
        }