public BaseApiMockDialog(Form parentForm, XMLApiItem xmlItem)
 {
     this.parentForm = parentForm;
     this.xmlItem    = xmlItem;
     this.Location   = new Point(parentForm.Location.X + 100, parentForm.Location.Y + 100);
     InitializeComponent();
     initTreeView();
 }
        private void miList_Click(object sender, EventArgs e)
        {
            XMLApiItem        apiItem   = FiddlerExtension.ApiItems[((ToolStripMenuItem)sender).Name];
            BaseApiMockDialog APIDialog = new BaseApiMockDialog(this, apiItem);

            APIDialog.Title  = apiItem.Function;
            APIDialog.ApiUrl = apiItem.Apiurl;
            APIDialog.ShowDialog(this);
        }
Example #3
0
        public static Dictionary <String, XMLApiItem> analyzeXML(FileInfo fi)
        {
            Dictionary <String, XMLApiItem> apiItems = new Dictionary <string, XMLApiItem>();
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(fi.FullName);
            XmlNode root = xmldoc.SelectSingleNode("root");

            XMLApiItem apiItem = new XMLApiItem();

            foreach (XmlNode apiNode in root.SelectNodes("api"))
            {
                //获取product属性
                apiItem.Product = root.Attributes["product"].Value;
                //解析API参数
                apiItem.Name     = apiNode.SelectSingleNode("name").InnerText;
                apiItem.Apiurl   = apiNode.SelectSingleNode("apiulr").InnerText;
                apiItem.Function = apiNode.SelectSingleNode("function").InnerText;
                if (apiNode.SelectSingleNode("scene") != null)
                {
                    apiItem.Scene = apiNode.SelectSingleNode("scene").InnerText;
                }
                apiItem.MenuFolder = apiNode.SelectSingleNode("menuFolder").InnerText;
                apiItem.MenuText   = apiNode.SelectSingleNode("menuText").InnerText;

                //解析Request
                XmlNode xnRequestNode = apiNode.SelectSingleNode("request");
                switch (xnRequestNode.Attributes["type"].Value)
                {
                case "GET":
                    apiItem.Request.Type = RequestType.GET;
                    break;

                case "POST":
                    apiItem.Request.Type = RequestType.POST;
                    break;

                default:
                    break;
                }
                XmlNodeList xnlRequestParams = xnRequestNode.SelectNodes("param");
                foreach (XmlNode xnRequestParam in xnlRequestParams)
                {
                    XMLRequestParam requestParam = new XMLRequestParam();
                    switch (xnRequestParam.Attributes["type"].Value)
                    {
                    case "int":
                        requestParam.Type = RequestParamType.INT;
                        break;

                    case "string":
                        requestParam.Type = RequestParamType.STRING;
                        break;

                    default:
                        break;
                    }
                    requestParam.Compulsory      = xnRequestParam.Attributes["compulsory"].Value == "true" ? true : false;
                    requestParam.ParaName        = xnRequestParam.SelectSingleNode("paraname").InnerText;
                    requestParam.ParaInstruction = xnRequestParam.SelectSingleNode("paraInstruction").InnerText;
                    apiItem.Request.RequestParams.Add(requestParam);
                }

                //解析Response
                XmlNode xnResponseNode = apiNode.SelectSingleNode("response");
                switch (xnResponseNode.Attributes["type"].Value)
                {
                case "json":
                    apiItem.Response.Type = ResponseType.JSON;
                    break;

                case "json_list":
                    apiItem.Response.Type = ResponseType.JSON_LIST;
                    break;

                case "raw":
                    apiItem.Response.Type = ResponseType.RAW;
                    break;

                default:
                    break;
                }
                XmlNodeList xnlSubItems = xnResponseNode.SelectNodes("item");
                if (xnlSubItems.Count > 0)
                {
                    foreach (XmlNode xnSubItem in xnlSubItems)
                    {
                        XMLResponseItem responseItem = getResponseItem(xnSubItem);
                        apiItem.Response.Items.Add(responseItem.ItemName, responseItem);
                    }
                }

                apiItems.Add(apiItem.Apiurl, apiItem);
                apiItem = new XMLApiItem();
            }

            return(apiItems);
        }
 public LotteryList(Form parentForm, XMLApiItem xmlItem)
     : base(parentForm, xmlItem)
 {
     InitializeComponent();
 }