public KeyValuePair <string, NotesViewResultSet[]>[] PullNotesView(string[] ViewNames, string server, string database, string password)
 {
     if (ViewNames == null || ViewNames.Length == 0 || ViewNames.ToList().Distinct().Count() != ViewNames.Length)
     {
         throw new ArgumentException();
     }
     else
     {
         List <KeyValuePair <string, NotesViewResultSet[]> > results = new List <KeyValuePair <string, NotesViewResultSet[]> >();
         NotesSession notesSession = new Domino.NotesSession();
         notesSession.Initialize(password);
         NotesDatabase notesDatabase = notesSession.GetDatabase(server, database, false);
         for (int i = 0; i < ViewNames.Length; i++)
         {
             List <NotesViewResultSet> result = new List <NotesViewResultSet>();
             Domino.NotesView          notesView;
             string view = ViewNames[i];
             notesView = notesDatabase.GetView(view);
             NotesViewEntryCollection notesViewCollection = notesView.AllEntries;
             for (int rowCount = 1; rowCount <= notesViewCollection.Count; rowCount++)
             {
                 NotesViewEntry viewEntry   = notesViewCollection.GetNthEntry(rowCount);
                 NotesDocument  document    = viewEntry.Document;
                 Array          notesThings = document.Items as Array;
                 for (int j = 0; j < notesThings.Length; j++)
                 {
                     NotesItem notesItem = (notesThings.GetValue(j) as Domino.NotesItem);
                     result.Add(new NotesViewResultSet()
                     {
                         RecordID = rowCount,
                         Name     = notesItem.Name,
                         Value    = notesItem.Text
                     });
                 }
             }
             results.Add(new KeyValuePair <string, NotesViewResultSet[]>(view, result.ToArray()));
         }
         return(results.ToArray());
     }
 }
Exemplo n.º 2
0
        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);
            }
        }