コード例 #1
0
        public IEnumerable <string> GetAttachments(NotesDocument doc, string filterName = null)
        {
            bool hasAttachment = false;

            if (doc.HasEmbedded)
            {
                foreach (NotesItem item in (object[])doc.Items)
                {
                    if (item.Name.Equals("$FILE"))
                    {
                        object[] values   = (object[])item.Values;
                        var      filename = values[0].ToString();
                        if (!string.IsNullOrEmpty(filterName) && !filename.Contains(filterName))
                        {
                            continue;
                        }
                        var path   = Path.Combine(Path.GetTempPath(), filename);
                        var attach = doc.GetAttachment(filename);
                        attach.ExtractFile(path);
                        hasAttachment = true;
                        yield return(path);
                    }
                }
                if (!hasAttachment)
                {
                    throw new NoAttachmentException();
                }
                yield break;
            }
            throw new NoAttachmentException();
        }
コード例 #2
0
        public AttachmentModel(NotesDocument document, NotesItem item)
        {
            if (!IsAttachmentItem(item))
            {
                throw new ArgumentException("Item is not an attachment", nameof(item));
            }

            var name = ((IEnumerable)item.Values).Cast <string>().First();

            embeddedObject = document.GetAttachment(name);

            FileSize  = embeddedObject.FileSize;
            Name      = embeddedObject.Name;
            Source    = embeddedObject.Source;
            EmbedType = embeddedObject.type;
        }
コード例 #3
0
        /*
        To begin with, retrieving mail using WCF is not a great idea because of binary attachments.
        It will work perfectly however if if we save all attachments of picked-up mail on server disk
        and return file names with the returned mail.
        Using the web service client we later pick up the attachments using GetEmailAttachments(Email) method,
        at which time these files will also be removed.
        */
        private List<Attachment> ExtractAttachments(NotesDocument lotusNotesEmail)
        {
            List<Attachment> attachmentFileNames = new List<Attachment>();
            List<string> filePathsToDelete = new List<string>();
            object[] items = (object[])lotusNotesEmail.Items;

            foreach (var item in items)
            {
                NotesItem notesItem = (NotesItem)item;

                if (notesItem != null && notesItem.Values != null && !(notesItem.Values is string))
                {
                    object[] itemValues = (object[])notesItem.Values;

                    if (itemValues != null)
                    {
                        if (notesItem.type == Domino.IT_TYPE.ATTACHMENT)
                        {
                            if (itemValues[0] != null && notesItem.Name != null)
                            {
                                string fileNameOriginal = itemValues[0].ToString();
                                string fileNameValid = GetValidFileName(fileNameOriginal);
                                string fileNameDated = GetPrependedDateTime() + fileNameValid;
                                string filePath = Config["FilepathLocalTempFiles"] + fileNameDated;

                                try
                                {
                                    int existingDocumentsWithSameName = (from att in attachmentFileNames where att.FileNameOriginal.Equals(fileNameOriginal) select att).Count(); // Beware of duplicates from Lotus Notes
                                    if (existingDocumentsWithSameName == 0)
                                    {
                                        var attachment = lotusNotesEmail.GetAttachment(fileNameOriginal); // Extracting attachment using the original name (fileNameOriginal)
                                        attachment.ExtractFile(filePath); // Saving file to disk using valid filename (filePath)
                                        attachmentFileNames.Add(new Attachment { FileName = fileNameDated, FilePath = filePath, FileNameOriginal = fileNameOriginal }); // Putting in filepath for now, load byte[] data later
                                    }
                                }
                                catch (Exception e)
                                {
                                    Logger logger = LogManager.GetCurrentClassLogger();
                                    logger.Log(LogLevel.Debug, e);
                                }
                            }
                        }
                    }
                }
            }

            return attachmentFileNames;
        }
コード例 #4
0
        public void ExtractGraphicsCafeDocuments()
        {
            var specificCategories = ReadSpecificCategories();

            Console.WriteLine("Initialize the Extract with Cred: Server: " + LotusNotesServer + " Password: "******"Reading file: " + db.FileName);
                    if (db != null && db.FileName.ToLower() == "Graphics Cafe.nsf".ToLower())
                    {
                        Console.WriteLine("Reading file: " + db.FileName);
                        isAlive = false;
                        try
                        {
                            if (!db.IsOpen)
                            {
                                db.Open();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Unable to open database: " + db.FileName);
                            Console.WriteLine("Exception: " + ex);
                            db = d.GetNextDatabase();
                            continue;
                        }
                        NotesDocumentCollection docs = db.AllDocuments;

                        if (docs != null)
                        {
                            Console.WriteLine("Documents Count: " + db.AllDocuments.Count);
                            string rootFolderName    = Path.GetFileNameWithoutExtension(db.FileName);
                            string baseDirectoryPath = BaseDirectoryPath + rootFolderName + "\\";

                            for (int rowCount = 1; rowCount <= docs.Count; rowCount++)
                            {
                                NotesDocument document = docs.GetNthDocument(rowCount);
                                if (document.HasEmbedded && document.HasItem("$File"))
                                {
                                    object[]      AllDocItems   = (object[])document.Items;
                                    string        category      = string.Empty;
                                    List <string> categories    = new List <string>();
                                    string        subCategory   = string.Empty;
                                    List <string> subCategories = new List <string>();
                                    Console.WriteLine("RowIndex: " + rowCount);
                                    string documentDescription = string.Empty;
                                    string documentDate        = string.Empty;
                                    string documentNotes       = string.Empty;
                                    string documentAuthor      = string.Empty;
                                    var    notesItems          = new List <NotesItem>();
                                    foreach (object CurItem in AllDocItems)
                                    {
                                        notesItems.Add((NotesItem)CurItem);
                                    }

                                    var categoryItem = notesItems.FirstOrDefault(x => x.Name == "Category");
                                    if (categoryItem != null && !string.IsNullOrEmpty(categoryItem.Text))
                                    {
                                        category = categoryItem.Text;
                                    }
                                    var subcategoryItem = notesItems.FirstOrDefault(x => x.Name == "SubCategory");

                                    if (subcategoryItem != null && !string.IsNullOrEmpty(subcategoryItem.Text))
                                    {
                                        subCategory = subcategoryItem.Text;
                                    }

                                    var descriptionItem = notesItems.FirstOrDefault(x => x.Name == "Description");
                                    if (descriptionItem != null && !string.IsNullOrEmpty(descriptionItem.Text))
                                    {
                                        documentDescription = descriptionItem.Text;
                                    }

                                    var notesItem = notesItems.FirstOrDefault(x => x.Name == "Notes");
                                    if (notesItem != null && !string.IsNullOrEmpty(notesItem.Text))
                                    {
                                        documentNotes = notesItem.Text;
                                    }

                                    var dateItem = notesItems.FirstOrDefault(x => x.Name == "tmpDate");
                                    if (dateItem != null && !string.IsNullOrEmpty(dateItem.Text))
                                    {
                                        documentDate = dateItem.Text;
                                    }

                                    var authorItem = notesItems.FirstOrDefault(x => x.Name == "tmpAuthor");
                                    if (authorItem != null && !string.IsNullOrEmpty(authorItem.Text))
                                    {
                                        documentAuthor = authorItem.Text;
                                    }

                                    if (!string.IsNullOrEmpty(category))
                                    {
                                        categories = category.Split(';').ToList();
                                    }
                                    if (!string.IsNullOrEmpty(subCategory))
                                    {
                                        subCategories = subCategory.Split(';').ToList();
                                    }

                                    if (specificCategories.Count == 0 || (specificCategories.Count > 0 && (categories.Any(x => specificCategories.Contains(x)) || subCategories.Any(x => specificCategories.Contains(x)))))
                                    {
                                        List <NotesItem> documentItems = notesItems.Where(x => x.type == IT_TYPE.ATTACHMENT).ToList();
                                        if (documentItems != null && documentItems.Count > 0)
                                        {
                                            foreach (var nItem in documentItems)
                                            {
                                                if (IT_TYPE.ATTACHMENT == nItem.type)
                                                {
                                                    var pAttachment = ((object[])nItem.Values)[0].ToString();
                                                    Console.WriteLine("Description: " + documentDescription);
                                                    Console.WriteLine("Date: " + documentDate);
                                                    Console.WriteLine("Notes: " + documentNotes);
                                                    Console.WriteLine("Author: " + documentAuthor);
                                                    foreach (var cat in categories)
                                                    {
                                                        Console.WriteLine("Category: " + cat);
                                                        string destPath = baseDirectoryPath;
                                                        if (!string.IsNullOrEmpty(cat))
                                                        {
                                                            if (!Directory.Exists(baseDirectoryPath + cat))
                                                            {
                                                                Directory.CreateDirectory(baseDirectoryPath + cat);
                                                            }
                                                            destPath = destPath + cat + "\\";
                                                        }

                                                        foreach (var subcat in subCategories)
                                                        {
                                                            Console.WriteLine("SubCategory: " + subcat);

                                                            if (!string.IsNullOrEmpty(subcat))
                                                            {
                                                                if (!Directory.Exists(baseDirectoryPath + cat + "\\" + subcat))
                                                                {
                                                                    Directory.CreateDirectory(baseDirectoryPath + cat + "\\" + subcat);
                                                                }
                                                                destPath = destPath + subcat + "\\";
                                                            }
                                                        }
                                                        Console.WriteLine("Final Destination Path: " + destPath + pAttachment);
                                                        if (!File.Exists(destPath + pAttachment))
                                                        {
                                                            try
                                                            {
                                                                document.GetAttachment(pAttachment).ExtractFile(destPath + pAttachment);
                                                            }
                                                            catch (Exception exe)
                                                            {
                                                                LogDetails("File not extracted: " + destPath + pAttachment);
                                                                LogExceptionDetails("File not extracted: " + destPath + pAttachment, exe);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            Console.WriteLine("File already exists: " + destPath + pAttachment);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (isAlive)
                    {
                        db = d.GetNextDatabase();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Extract Graphics Cafe Documents Exception:" + ex);
            }
        }
コード例 #5
0
ファイル: ReadDomino.cs プロジェクト: namthanhha2/havm
        public static void parseFile(string path, string searchQuery, string type)
        {
            Domino.NotesSession session = null;
            session = new Domino.NotesSession();
            session.Initialize("");
            List <ContentDetail> lstContent  = new List <ContentDetail>();
            List <Resources>     lstResource = new List <Resources>();

            Domino.NotesDatabase db = session.GetDatabase("", path, false);

            Domino.NotesDocumentCollection col = db.Search(searchQuery, null, 0);
            for (int i = 0; i < col.Count; i++)
            {
                NotesDocument nd   = col.GetNthDocument(i);
                Note          note = new Note();
                note.nodeId = nd.NoteID;
                note.fields = new Dictionary <string, object>();
                List <string> ebpath = null;
                foreach (NotesItem item in nd.Items)
                {
                    if (item.Name == "$FILE")
                    {
                        NotesItem           file       = nd.GetFirstItem("$File");
                        string              fileName   = ((object[])item.Values)[0].ToString();
                        NotesEmbeddedObject attachfile = (NotesEmbeddedObject)nd.GetAttachment(fileName);
                        if (attachfile != null)
                        {
                            string p = Settings.Default.saveDirectory + nd.NoteID + "\\" + fileName;
                            System.IO.Directory.CreateDirectory(Settings.Default.saveDirectory + nd.NoteID);
                            if (ebpath == null)
                            {
                                ebpath = new List <string>();
                            }
                            ebpath.Add(p);
                            try
                            {
                                attachfile.ExtractFile(p);
                            } catch (Exception en)
                            {
                                Console.WriteLine(en.Message);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            if (item.type == IT_TYPE.RICHTEXT)
                            {
                                note.fields.Add(item.Name, item.Values);
                            }
                            else
                            {
                                note.fields.Add(item.Name, item.Values[0]);
                            }
                        } catch (Exception en)
                        {
                            Console.WriteLine(en.Message);
                        }
                    }
                }

                if (type == "resource")
                {
                    Resources rs = new Resources(note);
                    if (ebpath != null && ebpath.Count > 0)
                    {
                        foreach (string p in ebpath)
                        {
                            rs.path = rs.path + p + ";";
                        }
                    }
                    lstResource.Add(rs);
                }
                else
                {
                    ContentDetail ct = new ContentDetail(note);
                    lstContent.Add(ct);
                }
            }
            if (lstContent != null && lstContent.Count > 0)
            {
                string json = JsonConvert.SerializeObject(lstContent);
                //write string to file
                System.IO.File.WriteAllText(@Settings.Default.saveDirectory + "cms.txt", json);
            }

            if (lstResource != null && lstResource.Count > 0)
            {
                string json = JsonConvert.SerializeObject(lstResource);
                //write string to file
                System.IO.File.WriteAllText(@Settings.Default.saveDirectory + "resource.txt", json);
            }
        }