Пример #1
0
        // ***********************************************************************************
        // * ... Get list of chemicals and placards from the gp service
        // ***********************************************************************************
        private ObservableCollection <string> getListOfChemicalsOrPlacards(string serviceType, string serviceURL)
        {
            ObservableCollection <string> list = new ObservableCollection <string>();

            try
            {
                string jsonString = null;

                using (WebClient webClient = new WebClient())
                {
                    webClient.Encoding = Encoding.UTF8;
                    jsonString         = webClient.DownloadString(serviceURL);
                }

                if (jsonString != null)
                {
                    JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

                    dynamic gpServiceInfo = jsSerializer.Deserialize <dynamic>(jsonString);
                    dynamic gpParameters  = gpServiceInfo["parameters"];

                    dynamic gpExecutionType = gpServiceInfo["executionType"];
                    _gpExecutionType = gpExecutionType as string;


                    for (int i = 0; i < gpParameters.Length; i++)
                    {
                        GPParameterInfo gpInfo    = new GPParameterInfo();
                        var             parameter = gpParameters[i];
                        gpInfo.Name          = parameter["name"];
                        gpInfo.ParameterType = parameter["dataType"];

                        if (serviceType == "chemical")
                        {
                            chemicalGPParameters.Add(gpInfo);
                        }
                        else if (serviceType == "placard")
                        {
                            placardGPParameters.Add(gpInfo);
                        }

                        if (parameter["name"] == "material_type" || parameter["name"] == "placard_id")
                        {
                            var choiceList = parameter["choiceList"];
                            _defaultERGName = parameter["defaultValue"];
                            for (int j = 0; j < choiceList.Length; j++) //loop through parameters
                            {
                                list.Add(choiceList[j]);
                            }
                        }
                    }
                }
                else
                {
                    list.Add("Service did not return a list");
                }

                return(list);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                list.Add("Service didn't return list. Check configuration");
                return(list);
            }
        }
        // ***********************************************************************************
        // * ... Get list of chemicals and placards from the gp service 
        // ***********************************************************************************
        private ObservableCollection<string> getListOfChemicalsOrPlacards(string serviceType, string serviceURL)
        {
            ObservableCollection<string> list = new ObservableCollection<string>();
            try
            {
                string jsonString = null;

                using (WebClient webClient = new WebClient())
                {
                    webClient.Encoding = Encoding.UTF8;
                    jsonString = webClient.DownloadString(serviceURL);
                }

                if (jsonString != null)
                {
                    JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

                    dynamic gpServiceInfo = jsSerializer.Deserialize<dynamic>(jsonString);
                    dynamic gpParameters = gpServiceInfo["parameters"];

                    dynamic gpExecutionType = gpServiceInfo["executionType"];
                    _gpExecutionType = gpExecutionType as string; 
        

                    for (int i = 0; i < gpParameters.Length; i++)
                    {
                        GPParameterInfo gpInfo = new GPParameterInfo();
                        var parameter = gpParameters[i];
                        gpInfo.Name = parameter["name"];
                        gpInfo.ParameterType = parameter["dataType"];

                        if (serviceType == "chemical")
                            chemicalGPParameters.Add(gpInfo);
                        else if (serviceType == "placard")
                            placardGPParameters.Add(gpInfo);

                        if (parameter["name"] == "material_type" || parameter["name"] == "placard_id")
                        {
                            var choiceList = parameter["choiceList"];
                            _defaultERGName = parameter["defaultValue"];
                            for (int j = 0; j < choiceList.Length; j++) //loop through parameters
                            {
                                list.Add(choiceList[j]);
                            }
                        }
                    }
                }
                else
                    list.Add("Service did not return a list");

                return list;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                list.Add("Service didn't return list. Check configuration");
                return list; 
            }
        }