Example #1
0
        // Inspector2
        public override int ScoreForSession(Session oS)
        {
#if DEBUG || OUTPUT_PERF_LOG
            FiddlerApp.LogString("ScoreForSession:" + inspectorContext.GetName() + " " + oS.url);
#endif
            int score = base.ScoreForSession(oS);

            // inspectorContext.AssignSession(oS);

            return(FiddlerApp.IsProtobufPacket(inspectorContext.GetHeaders(oS)) ? 100 : 0);
        }
Example #2
0
        public void UpdateData()
#endif
        {
#if DEBUG || OUTPUT_PERF_LOG
            FiddlerApplication.Log.LogString(inspectorContext.GetName() + " UpdateData: " + reason);
#else
            FiddlerApp.LogString(inspectorContext.GetName() + " UpdateData");
#endif

            if (inspectorContext.IsInvalidSession())
            {
#if DEBUG || OUTPUT_PERF_LOG
                FiddlerApp.LogString("UpdateData exits for invalidated session");
#endif
                ClearView();
                return;
            }

            HTTPHeaders headers = inspectorContext.Headers;
            if (!FiddlerApp.IsProtobufPacket(headers))
            {
#if DEBUG || OUTPUT_PERF_LOG
                FiddlerApp.LogString("UpdateData exits for non-protobuf session");
#endif
                ClearView();
                return;
            }

            ClearView(false);
            string messageTypeName  = "";
            string descriptorSetUrl = "";
            if (null != headers && FiddlerApp.ParseMessageTypeNameAndDescriptorSetUrl(headers, out messageTypeName, out descriptorSetUrl))
            {
                this.cmbMessageType.Text    = messageTypeName == null ? "" : messageTypeName;
                this.cmbMessageType.Enabled = (messageTypeName == null || messageTypeName.Length == 0);
            }
            else
            {
                this.cmbMessageType.Enabled = true;
            }

            string protoPath            = this.txtDirectory.Text;
            bool   printEnumAsInteger   = this.chkboxEnumValue.Checked;
            bool   printPrimitiveFields = this.chkboxPrintPrimitiveFields.Checked;

            try
            {
                string jsonString = null;
                byte[] body       = FiddlerApp.DecodeContent(inspectorContext.RawBody, headers);

                if (null != body)
                {
                    string[] protoFiles = FiddlerApp.LoadProtos(protoPath);

                    jsonString = Protobuf2Json.ConvertToJson(protoPath, protoFiles, descriptorSetUrl, messageTypeName, printEnumAsInteger, printPrimitiveFields, false, body);

                    object jsonObject = Fiddler.WebFormats.JSON.JsonDecode(jsonString);
                    Fiddler.WebFormats.JSON.JSONParseResult jsonResult = null;
                    if (!(jsonObject is Fiddler.WebFormats.JSON.JSONParseResult))
                    {
                        tvJson.Nodes.Clear();
                        return;
                    }

                    jsonResult = jsonObject as Fiddler.WebFormats.JSON.JSONParseResult;
                    tvJson.Tag = jsonString;
#if DEBUG || OUTPUT_PERF_LOG
                    FiddlerApplication.Log.LogString(inspectorContext.GetName() + " beginUpdate");
#endif
                    TreeNode rootNode = new TreeNode("Protobuf");

                    Queue <KeyValuePair <object, TreeNode> > queue = new Queue <KeyValuePair <object, TreeNode> >();
                    object   jsonItem   = jsonResult.JSONObject;
                    TreeNode parentNode = rootNode;

                    while (true)
                    {
                        AddNode(jsonItem, parentNode, queue);
                        if (queue.Count == 0)
                        {
                            break;
                        }

                        KeyValuePair <object, TreeNode> kv = queue.Dequeue();
                        jsonItem   = kv.Key;
                        parentNode = kv.Value;
                    }

                    rootNode.ExpandAll();

                    tvJson.BeginUpdate();
                    try
                    {
                        if (tvJson.Nodes.Count > 0)
                        {
                            tvJson.Nodes.Clear();
                        }

                        tvJson.Nodes.Add(rootNode);

                        // tvJson.ExpandAll();
                        // rootNode.EnsureVisible();
                    }
                    finally
                    {
                        tvJson.EndUpdate();
#if DEBUG || OUTPUT_PERF_LOG
                        FiddlerApp.LogString(inspectorContext.GetName() + " EndUpdate: " + tvJson.GetNodeCount(true).ToString());
#endif
                    }
                }
            }
            catch (Exception ex)
            {
                FiddlerApp.LogString(ex.Message);
            }
        }