示例#1
0
        private string queryCiiva(string partnumber, string manufacturer, WebClient cli)
        {
            var selectedComponent = new Ciiva.Api.Dto.GetManufacturerComponentsByPartNumber();

            selectedComponent.ManufacturerPartNumber = partnumber;
            selectedComponent.ManufacturerName       = manufacturer;
            selectedComponent.Limit      = 1;
            selectedComponent.ExactMatch = true;
            selectedComponent.ExtraInfo  = true;

            if (selectedComponent == null)
            {
                MessageBox.Show("Please select a method to invoke.");
                this.lsApiMethod.Focus();
                return("error");
            }


            if (cli != null)
            {
                string response = this.ExecuteOnJsonServiceClient(cli, selectedComponent);
                Regex  reg      = new Regex("ManufacturerComponentId\":(.+?),");

                if (reg.IsMatch(response))
                {
                    Match  match       = reg.Match(response);
                    string componentID = match.Groups[1].Value;
                    var    selectParam = new Ciiva.Api.Dto.GetManufacturerComponentById();
                    selectParam.ManufacturerComponentId = Convert.ToInt64(componentID);

                    string responseParam = this.ExecuteOnJsonServiceClient(cli, selectParam);
                    return(responseParam);
                }


                this.UpdateSubscriptionStatus(cli);
            }

            return("error");
        }
示例#2
0
文件: MainForm.cs 项目: ylyxf/Scripts
        private string queryCiiva(string partnumber, string manufacturer, WebClient cli)
        {
//            this.tbResponse.Json = string.Empty;


/*                Guid apiKey = Guid.Empty;
 *              if (!Guid.TryParse(this.tbApiKey.Text, out apiKey))
 *              {
 *                  MessageBox.Show("Please provide API Key.");
 *                  this.tbApiKey.SelectAll();
 *                  this.tbApiKey.Focus();
 *                  return "error";
 *              }
 *
 *              string password = this.tbPassword.Text;
 *              if (string.IsNullOrWhiteSpace(password))
 *              {
 *                  MessageBox.Show("Please enter password.");
 *                  this.tbPassword.SelectAll();
 *                  this.tbPassword.Focus();
 *                  return "error";
 *              }
 *
 *              string serverUrl = this.tbApiServer.Text;
 *              if (string.IsNullOrWhiteSpace(serverUrl))
 *              {
 *                  MessageBox.Show("Please specify API server.");
 *                  this.tbApiServer.SelectAll();
 *                  this.tbApiServer.Focus();
 *                  return "error";
 *              }*/


            var selectedComponent = new Ciiva.Api.Dto.GetManufacturerComponentsByPartNumber();

            selectedComponent.ManufacturerPartNumber = partnumber;
            selectedComponent.ManufacturerName       = manufacturer;
            selectedComponent.Limit      = 1;
            selectedComponent.ExactMatch = true;
            selectedComponent.ExtraInfo  = true;

            if (selectedComponent == null)
            {
                MessageBox.Show("Please select a method to invoke.");
                this.lsApiMethod.Focus();
                return("error");
            }

//                WebClient client = this.GetApiWebClient(serverUrl, apiKey.ToString(), password);
//                if (client != null)
            if (cli != null)
            {
//                    string response = this.ExecuteOnJsonServiceClient(client, selectedParameter);
                string response = this.ExecuteOnJsonServiceClient(cli, selectedComponent);
                Regex  reg      = new Regex("ManufacturerComponentId\":(.+?),");

                if (reg.IsMatch(response))
                {
                    Match  match       = reg.Match(response);
                    string componentID = match.Groups[1].Value;
                    var    selectParam = new Ciiva.Api.Dto.GetManufacturerComponentById();
                    selectParam.ManufacturerComponentId = Convert.ToInt64(componentID);

                    string responseParam = this.ExecuteOnJsonServiceClient(cli, selectParam);
                    return(responseParam);
                }



                //var selectComponet = new Component();
                //selectComponet = fastJSON.JSON.ToObject<Component>(response);

                // var dict = JsonSerializer.DeserializeFromString<Dictionary<string,string>>(response);

                // if (dict.ContainsKey("ManufacturerComponentId"))
                //{

                //    string componentID = dict["ManufacturerComponentId"];
                //    var selectParam = new Ciiva.Api.Dto.GetManufacturerComponentById();
                //    selectParam.ManufacturerComponentId = Convert.ToInt64(componentID);

                //    string responseParam = this.ExecuteOnJsonServiceClient(cli, selectParam);
                //    return responseParam;
                //}



//                    this.UpdateSubscriptionStatus(client);
                this.UpdateSubscriptionStatus(cli);
            }

            return("error");
        }