Пример #1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.CheckFileExists  = true;
            dlg.RestoreDirectory = true;
            dlg.Filter           = "*.NotReasonable.json|*.NotReasonable.json";

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }


            List <NotReasonableItem> list = null;

            try {
                string json = System.IO.File.ReadAllText(dlg.FileName, Encoding.UTF8);
                list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <NotReasonableItem> >(json);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "ClownFish.FiddlerPulgin 导入失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (list != null)
            {
                this.listView1.Items.Clear();

                int            index = 1;
                ListViewItem[] items = new ListViewItem[list.Count];

                for (int i = 0; i < list.Count; i++)
                {
                    NotReasonableItem m = list[i];

                    ListViewItem item = new ListViewItem((index++).ToString(), 0);
                    item.SubItems.Add(m.Reason);
                    item.SubItems.Add(m.Url);
                    item.Tag = new RequetItemTag {
                        Request = m.GetRequestText()
                    };
                    items[i] = item;
                }
                listView1.Items.AddRange(items);
            }
        }
Пример #2
0
        private void btnOutput_Click(object sender, EventArgs e)
        {
            if (listView1.Items.Count == 0)
            {
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.CheckPathExists  = true;
            dlg.RestoreDirectory = true;
            dlg.Filter           = "*.NotReasonable.json|*.NotReasonable.json";

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }


            List <NotReasonableItem> list = new List <NotReasonableItem>(this.listView1.Items.Count);

            foreach (ListViewItem item in this.listView1.Items)
            {
                NotReasonableItem m = new NotReasonableItem();
                m.Reason = item.SubItems[1].Text;
                m.Url    = item.SubItems[2].Text;
                m.SetRequestText(item.Tag.ToString());
                list.Add(m);
            }

            try {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented);
                System.IO.File.WriteAllText(dlg.FileName, json, Encoding.UTF8);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "ClownFish.FiddlerPulgin 导出失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }