コード例 #1
0
ファイル: Form1.cs プロジェクト: yushuo1990/NSF2SQL
        private void bSearchServer_Click(object sender, EventArgs ea)
        {
            treeView1.Nodes.Clear();
            onLocalComputer = false;
            InputBox input = InputBox.Show("Domino Server", new InputBoxItem[] { new InputBoxItem("Server", notesServer), new InputBoxItem("Domain", notesDomain), new InputBoxItem("Password", notesPassword, true) }, InputBoxButtons.OKCancel);

            if (input.Result == InputBoxResult.OK)
            {
                notesServer   = input.Items["Server"];
                notesDomain   = input.Items["Domain"];
                notesPassword = input.Items["Password"];

                ProgressDialog pDialog = new ProgressDialog();
                pDialog.Title   = "Get Databases";
                pDialog.Style   = ProgressBarStyle.Marquee;
                pDialog.DoWork += delegate(object dialog, DoWorkEventArgs e)
                {
                    try
                    {
                        NotesSession nSession = initSession(notesPassword);
                        pDialog.ReportProgress(0);
                        NotesDbDirectory directory = nSession.GetDbDirectory(notesServer + "//" + notesDomain);
                        NotesDatabase    db        = directory.GetFirstDatabase(DB_TYPES.DATABASE);
                        int i = 0;
                        while (db != null)
                        {
                            if (pDialog.IsCancelled)
                            {
                                e.Cancel = true;
                                return;
                            }
                            string[] path = db.FilePath.Split(new char[] { '\\' });
                            treeView1.Invoke((MethodInvoker) delegate()
                            {
                                TreeNodeCollection nodes = treeView1.Nodes;
                                for (int n = 0; n < path.Length - 1; n++)
                                {
                                    string folder = path[n].ToUpper();
                                    if (!nodes.ContainsKey(folder))
                                    {
                                        nodes.Add(folder, folder, "folder", "folder");
                                    }
                                    nodes = nodes[folder].Nodes;
                                }
                                nodes.Add(db.FilePath, db.Title, "database", "database");
                            });
                            db = directory.GetNextDatabase();
                            pDialog.ReportProgress(i);
                            i++;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                };
                pDialog.ProgressChanged += delegate(object dialog, ProgressChangedEventArgs e)
                {
                    pDialog.Message = e.ProgressPercentage + " Databases Found";
                };
                pDialog.Completed += delegate(object dialog, RunWorkerCompletedEventArgs e)
                {
                    //treeView1.Invoke((MethodInvoker)delegate()
                    //{
                    if (e.Cancelled)
                    {
                        treeView1.Nodes.Clear();
                    }
                    else
                    {
                        treeView1.Sort();
                    }
                    //});
                };
                pDialog.Run();
            }
        }
コード例 #2
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);
            }
        }