Exemplo n.º 1
0
 private void Redraw()
 {
     try
     {
         tvJson.BeginUpdate();
         try
         {
             Reset();
             if (!String.IsNullOrEmpty(_json))
             {
                 JsonObjectTree tree = JsonObjectTree.Parse(_json);
                 VisualizeJsonTree(tree);
             }
         }
         finally
         {
             tvJson.EndUpdate();
         }
     }
     catch (JsonParseError e)
     {
         GetParseErrorDetails(e);
     }
     catch (Exception e)
     {
         ShowException(e);
     }
 }
Exemplo n.º 2
0
        private void Redraw()
        {
            if (_pirateXPackage == null)
            {
                return;
            }

            var response = _pirateXPackage;
            var text     = _pirateXPackage.ContentBytes == null?string.Empty: Encoding.UTF8.GetString(_pirateXPackage.ContentBytes);


            var viewitem = listViewIn.Items.Add(DateTime.Now.ToString());

            viewitem.SubItems.Add($"{string.Join("&", response.Headers.AllKeys.Select(a=>a+"="+ response.Headers[a]))}");

            if (string.IsNullOrEmpty(text))
            {
                if (response.Headers.AllKeys.Contains("errorCode") && response.Headers.AllKeys.Contains("errorMsg"))
                {
                    text = $@"
                        {"{"}""errorCode"":""{response.Headers["errorCode"]}"",
                             ""errorMsg"":""{response.Headers["errorMsg"]}""{"}"}";
                }
            }
            viewitem.SubItems.Add(text);
            _json        = text;
            txtJson.Text = text;

            try
            {
                tvJson.BeginUpdate();
                try
                {
                    Reset();
                    if (!String.IsNullOrEmpty(_json))
                    {
                        JsonObjectTree tree = JsonObjectTree.Parse(_json);
                        VisualizeJsonTree(tree);
                    }
                }
                finally
                {
                    tvJson.EndUpdate();
                }
            }
            catch (JsonParseError e)
            {
                GetParseErrorDetails(e);
            }
            catch (Exception e)
            {
                ShowException(e);
            }
        }
Exemplo n.º 3
0
        private void Redraw()
        {
            if (_json == prevText)
            {
                return;
            }
            try
            {
                tvJson.BeginUpdate();
                try
                {
                    Reset();
                    if (!String.IsNullOrEmpty(_json))
                    {
                        JsonObjectTree tree = null;
                        if (hisJsonMap.ContainsKey(_json))
                        {
                            tree = hisJsonMap[_json];
                            int index = hisStringList.BinarySearch(_json);
                            if (index >= 0)
                            {
                                hisListBox1.SetSelected(index, true);
                                lastSelectHisItem = (string)hisListBox1.Items[index];
                            }
                        }
                        else
                        {
                            tree = JsonObjectTree.Parse(_json);
                            hisJsonMap.Add(_json, tree);
                            hisStringList.Add(_json);
                            string title = DateTime.Now.ToLongTimeString() + "→";
                            if (tree.Root.Fields.Count > 0)
                            {
                                title += tree.Root.Fields[0].Text.Replace("\n", " ");
                            }
                            hisListBox1.Items.Add(title, CheckState.Unchecked);
                            hisListBox1.SetSelected(hisListBox1.Items.Count - 1, true);
                            lastSelectHisItem = title;
                            if (hisListBox1.Items.Count > 40)
                            {//超过40条历史记录每多一条删除第一条
                                hisJsonMap.Remove(hisStringList[0]);
                                hisStringList.RemoveAt(0);
                                hisListBox1.Items.RemoveAt(0);
                            }
                        }

                        VisualizeJsonTree(tree);
                    }
                }
                finally
                {
                    tvJson.EndUpdate();
                }
            }
            catch (JsonParseError e)
            {
                GetParseErrorDetails(e);
            }
            catch (Exception e)
            {
                ShowException(e);
            }
            prevText = _json;
        }