Beispiel #1
0
        // Load treeview workspace
        private void openWorkspaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openWS = new OpenFileDialog();

            openWS.Filter = "Workspace Files (*.spamWS)|*.spamWS";
            if (openWS.ShowDialog() == DialogResult.OK)
            {
                StreamReader streamWS = new StreamReader(openWS.OpenFile());
                treeView1.Nodes.Clear();
                tabControl1.TabPages.Clear();
                nodeList.Clear();
                string holdDef = streamWS.ReadLine();
                while (holdDef != null && holdDef != "--EOD")
                {
                    TreeNode holdNode = new TreeNode(holdDef);
                    holdNode.ContextMenuStrip = contextMenuStrip1;
                    treeView1.Nodes.Add(holdNode);
                    holdDef = streamWS.ReadLine();
                }


                string holdRule;
                while ((holdRule = streamWS.ReadLine()) != null)
                {
                    messageNodeInfo newMNI = new messageNodeInfo();
                    TreeNode        nNode  = new TreeNode();
                    Int32           nodeIndex;
                    Int32.TryParse(holdRule, out nodeIndex);
                    nNode.Text        = streamWS.ReadLine();
                    nNode.Name        = streamWS.ReadLine();
                    newMNI.fileName   = nNode.Text;
                    newMNI.filePath   = nNode.Name;
                    newMNI.pNodeIndex = nodeIndex;

                    while (holdRule != "--EON")
                    {
                        newMNI.rulesText = newMNI.rulesText + holdRule;
                        holdRule         = streamWS.ReadLine();
                    }

                    treeView1.Nodes[nodeIndex].Nodes.Add(nNode);
                    nodeList.Add(newMNI);
                }
            }
        }
Beispiel #2
0
        // Each message is opened and a tabpage is created dynamically with a header and body box
        private void load_files(string msgfile, string holder, ref int TabCount, string ruleTxt = "", bool fromNode = false)
        {
            bool rulesFileHere = check_for_rules();

            myTab      = new TabPage(holder);
            myTab.Text = holder;
            TextBox HeaderBox = new TextBox();

            HeaderBox.Multiline        = true;
            HeaderBox.Width            = 550;
            HeaderBox.Height           = 960;
            HeaderBox.Location         = new Point(650, 0);
            HeaderBox.ScrollBars       = ScrollBars.Both;
            HeaderBox.ReadOnly         = true;
            HeaderBox.BackColor        = Color.White;
            HeaderBox.WordWrap         = false;
            headerSizeDec.Enabled      = true;
            headerSizeInc.Enabled      = true;
            HeaderBox.ContextMenuStrip = headerMenu;
            myTab.Controls.Add(HeaderBox);

            TextBox BodyBox = new TextBox();

            BodyBox.Multiline        = true;
            BodyBox.Width            = 650;
            BodyBox.Height           = 960;
            BodyBox.ScrollBars       = ScrollBars.Both;
            BodyBox.ReadOnly         = true;
            BodyBox.BackColor        = Color.White;
            BodyBox.WordWrap         = false;
            bodySizeDec.Enabled      = true;
            bodySizeInc.Enabled      = true;
            BodyBox.ContextMenuStrip = bodyMenu;
            myTab.Controls.Add(BodyBox);

            Regex regex_txt = new Regex(@"\.txt$");
            Regex regex_msg = new Regex(@"\.msg$");
            Regex regex_eml = new Regex(@"\.eml$");
            Match match_txt = regex_txt.Match(msgfile);
            Match match_msg = regex_msg.Match(msgfile);
            Match match_eml = regex_eml.Match(msgfile);

            TabCount = TabCount + 1;

            // What type of file are we trying to open.
            if (match_msg.Success)
            {
                Stream messageStream;
                try { messageStream = File.Open(msgfile, FileMode.Open, FileAccess.Read); }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "File Error", MessageBoxButtons.OK);
                    return;
                }
                OutlookStorage.Message message = new OutlookStorage.Message(messageStream);
                messageStream.Close();


                HeaderBox.Text = message.GetMapiPropertyString("007D");
                BodyBox.Text   = message.BodyText;
                message.Dispose();
            }
            else if (match_eml.Success || match_txt.Success)
            {
                StreamReader mStream;
                try { mStream = new StreamReader(msgfile); }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "File Error", MessageBoxButtons.OK);
                    return;
                }

                bool   reachedBody = false;
                bool   firstLine   = true;
                string header      = "";
                string body        = "";

                while (mStream.Peek() >= 0)
                {
                    string lineTest = mStream.ReadLine();
                    if (lineTest != "" && reachedBody == false)
                    {
                        if (!firstLine)
                        {
                            header = header + "\r\n" + lineTest;
                        }
                        else
                        {
                            header = lineTest; firstLine = false;
                        }
                        reachedBody = false;
                    }

                    else if (lineTest == "" && reachedBody == false)
                    {
                        reachedBody    = true;
                        firstLine      = true;
                        HeaderBox.Text = header;
                    }
                    if (reachedBody)
                    {
                        if (!firstLine)
                        {
                            body = body + "\r\n" + lineTest;
                        }
                        else
                        {
                            body = lineTest; firstLine = false;
                        }
                    }
                }
                BodyBox.Text = body;
            }

            // Add a new node to the tree view for these files
            messageNodeInfo nodeNew = new messageNodeInfo();

            nodeNew.headerText             = HeaderBox.Text;
            nodeNew.bodyText               = BodyBox.Text;
            nodeNew.tNode.Text             = holder;
            nodeNew.tNode.Name             = msgfile;
            nodeNew.filePath               = msgfile;
            nodeNew.fileName               = holder;
            nodeNew.tNode.ContextMenuStrip = contextMenuStrip2;
            nodeList.Add(nodeNew);

            tabControl1.TabPages.Add(myTab);
            //tabControl1.Hide();
            closeBtn.Enabled    = true;
            button1.Enabled     = true;
            closeAllBtn.Enabled = true;

            // If a top level treeview node is already selected add the new files to that node
            // Otherwise create a new toplevel node
            if (treeView1.SelectedNode != null)
            {
                if (treeView1.SelectedNode.Level != 0 && fromNode == false)
                {
                    treeView1.SelectedNode.Parent.Nodes.Add(nodeNew.tNode);
                    nodeNew.pNodeIndex = treeView1.SelectedNode.Parent.Index;
                }
                else if (fromNode == false)
                {
                    treeView1.SelectedNode.Nodes.Add(nodeNew.tNode);
                    nodeNew.pNodeIndex = treeView1.SelectedNode.Index;
                }

                treeView1.SelectedNode.Expand();
            }
            else if (treeView1.SelectedNode == null)
            {
                if (treeView1.Nodes.ContainsKey("Untitled") == false)
                {
                    TreeNode newTopNode = new TreeNode("Untitled");
                    newTopNode.Name             = "Untitled";
                    newTopNode.ContextMenuStrip = contextMenuStrip1;
                    nodeNew.pNodeIndex          = treeView1.Nodes.Count;
                    newTopNode.Nodes.Add(nodeNew.tNode);
                    treeView1.Nodes.Add(newTopNode);
                    treeView1.SelectedNode = treeView1.Nodes[newTopNode.Name];
                }
                else
                {
                    ;
                }
            }
            else
            {
                ;
            }
        }