Beispiel #1
0
        public void AddMessage(string sType, string command, string headers, string address, string port, string payload, string mimeType)
        {
            TreeNode newNode = currentNode.Nodes.Add("Message");
            newNode.ImageIndex = 2;
            newNode.Tag = "label";
            newNode.SelectedImageIndex = 2;

            TreeNode newChildNode = newNode.Nodes.Add("Type: " + sType);
            newChildNode.Tag = sType;
            newChildNode.ImageIndex = 3;
            newChildNode.SelectedImageIndex = 3;

            newChildNode = newNode.Nodes.Add("Command: " + command);
            newChildNode.Tag = command;
            newChildNode.ImageIndex = 3;
            newChildNode.SelectedImageIndex = 3;

            newChildNode = newNode.Nodes.Add("Headers: " + headers);
            newChildNode.Tag = headers;
            newChildNode.ImageIndex = 3;
            newChildNode.SelectedImageIndex = 3;

            newChildNode = newNode.Nodes.Add("Address: " + address);
            newChildNode.Tag = address;
            newChildNode.ImageIndex = 3;
            newChildNode.SelectedImageIndex = 3;

            newChildNode = newNode.Nodes.Add("Port: " + port);
            newChildNode.Tag = port;
            newChildNode.ImageIndex = 3;
            newChildNode.SelectedImageIndex = 3;

            if (payload == "")
            {
                newChildNode = newNode.Nodes.Add("Payload: {empty}");
            }
            else
            {
                TestTreeNodeTag tag = new TestTreeNodeTag();
                Payload payloadContent = new Payload();
                payloadContent.buffer = Convert.FromBase64String(payload);
                payloadContent.MIMEType = mimeType ;
                string prettyNumber = string.Format("{0:0,0}", payloadContent.buffer.Length);
                newChildNode = newNode.Nodes.Add("Payload: " + mimeType + " {" + prettyNumber + " bytes}");
                tag.userData = payloadContent;
                newChildNode.Tag = tag;
            }
            newChildNode.ImageIndex = 3;
            newChildNode.SelectedImageIndex = 3;
            newChildNode.Parent.Parent.Expand();
        }
Beispiel #2
0
        private void ImportPayloadData()
        {
            Payload payload = new Payload();
            if (openFileDialogPayload.ShowDialog() == DialogResult.OK)
            {
                Mimetype dialog = new Mimetype();
                dialog.LookupType(openFileDialogPayload.FileName);
                dialog.ShowDialog(this);

                string MIMEType = dialog.MIMETypeString;

                // if MIMEType is valid load binary data.
                if (MIMEType != null)
                {
                    try
                    {
                        int bytesRead;
                        byte []buffer = new byte[32000];
                        MemoryStream ms = new MemoryStream();
                        Stream st = File.OpenRead(openFileDialogPayload.FileName);
                        while ((bytesRead = st.Read(buffer, 0, 32000)) > 0)
                        {
                            ms.Write(buffer,0,bytesRead);
                        }
                        payload.MIMEType = MIMEType;
                        payload.buffer = ms.ToArray();
                        st.Close();
                        ms.Close();
                    }
                    catch
                    {
                        MessageBox.Show(this, "File import failed.", "MCWhirlWind",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                if (treeViewXML.SelectedNode != null)
                {
                    string payloadLabel = treeViewXML.SelectedNode.Text;
                    if (payloadLabel.IndexOf("Payload:") != 0)
                    {
                        MessageBox.Show(this, "A 'Payload:' node on the tree view must be selected.", "MCWhirlWind",
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    string prettyNumber = string.Format("{0:0,0}", payload.buffer.Length);
                    treeViewXML.SelectedNode.Text = "Payload: " + payload.MIMEType + " {" + prettyNumber + " bytes}";

                    TestTreeNodeTag tag = new TestTreeNodeTag();
                    tag.label = "payload";
                    tag.userData = payload;
                    treeViewXML.SelectedNode.Tag = tag;
                }
            }
        }