protected virtual void FromJsonDictionary(IDictionary<string, object> dictionary)
        {
            if (dictionary.ContainsKey("name"))
                Name = dictionary["name"] as string;
            if (dictionary.ContainsKey("label"))
                Label = dictionary["label"] as string;
            if (dictionary.ContainsKey("displayName"))
                DisplayName = dictionary["displayName"] as string;
            if (dictionary.ContainsKey("helpText"))
                HelpText = dictionary["helpText"] as string;
            if (dictionary.ContainsKey("toolTip"))
                ToolTip = dictionary["toolTip"] as string;
            if (dictionary.ContainsKey("type"))
                Type = (GPParameterType)(Enum.Parse(typeof(GPParameterType), dictionary["type"] as string, true));
            if (dictionary.ContainsKey("shownAtRunTime"))
                ShownAtRunTime = Convert.ToBoolean(dictionary["shownAtRunTime"]);
            if (dictionary.ContainsKey("required"))
                Required = Convert.ToBoolean(dictionary["required"]);
            if (dictionary.ContainsKey("input"))
                Input = Convert.ToBoolean(dictionary["input"]);
            #region Default value
            if (dictionary.ContainsKey("defaultValue"))
            {
                object o = dictionary["defaultValue"];
                if (o != null)
                {
                    switch (Type)
                    {
                        case GPParameterType.Boolean:
                        case GPParameterType.Date:
                        case GPParameterType.Double:
                        case GPParameterType.Long:
                        case GPParameterType.String:
                        case GPParameterType.FeatureLayer:
                        case GPParameterType.RecordSet:
                        case GPParameterType.DataFile:
                            DefaultValue = ParameterBase.StringToParameter(Name, Type, o as string, CultureInfo.InvariantCulture);
                            break;
                        case GPParameterType.RasterData:
                        case GPParameterType.RasterDataLayer:
                            IDictionary<string, object> rDic = o as IDictionary<string, object>;
                            if (rDic != null)
                            {
                                string url = null, format = null;
                                if (rDic.ContainsKey("url"))
                                    url = rDic["url"] as string;
                                if (rDic.ContainsKey("format"))
                                    format = rDic["format"] as string;
                                if (url != null || format != null)
                                    DefaultValue = new Client.Tasks.GPRasterData(Name, url, format) { Format = format };//Workaround for slapi bug
                            }
                            break;
                        case GPParameterType.LinearUnit:
                            IDictionary<string, object> lDic = o as IDictionary<string, object>;
                            if (lDic != null)
                            {
                                double distance = double.NaN;
                                ESRI.ArcGIS.Client.Tasks.esriUnits units = Client.Tasks.esriUnits.esriMiles;
                                if (lDic.ContainsKey("distance"))
                                    distance = Convert.ToDouble(lDic["distance"]);
                                if (lDic.ContainsKey("units"))
                                    units = (ESRI.ArcGIS.Client.Tasks.esriUnits)(Enum.Parse(typeof(ESRI.ArcGIS.Client.Tasks.esriUnits),
                                        lDic["units"] as string, true));
                                DefaultValue = new Client.Tasks.GPLinearUnit(Name, units, distance);
                            }
                            break;
                    }
                }
            }
            #endregion

            #region ChoiceList

            if (dictionary.ContainsKey("choiceList"))
            {
                ChoiceList = new List<ParameterSupport.Choice>();
            
                IEnumerable choices = dictionary["choiceList"] as IEnumerable;
                if (choices != null)
                {
                    foreach (Dictionary<string, object> item in choices)
                    {
                        if (item != null)
                        {
                            Choice choice = new Choice();
                            choice.FromJsonDictionary(item, Name);
                            ChoiceList.Add(choice);
                        }
                    }
                }
            }
            #endregion
        }
Exemplo n.º 2
0
        protected virtual void FromJsonDictionary(IDictionary <string, object> dictionary)
        {
            if (dictionary.ContainsKey("name"))
            {
                Name = dictionary["name"] as string;
            }
            if (dictionary.ContainsKey("label"))
            {
                Label = dictionary["label"] as string;
            }
            if (dictionary.ContainsKey("displayName"))
            {
                DisplayName = dictionary["displayName"] as string;
            }
            if (dictionary.ContainsKey("helpText"))
            {
                HelpText = dictionary["helpText"] as string;
            }
            if (dictionary.ContainsKey("toolTip"))
            {
                ToolTip = dictionary["toolTip"] as string;
            }
            if (dictionary.ContainsKey("type"))
            {
                Type = (GPParameterType)(Enum.Parse(typeof(GPParameterType), dictionary["type"] as string, true));
            }
            if (dictionary.ContainsKey("shownAtRunTime"))
            {
                ShownAtRunTime = Convert.ToBoolean(dictionary["shownAtRunTime"]);
            }
            if (dictionary.ContainsKey("required"))
            {
                Required = Convert.ToBoolean(dictionary["required"]);
            }
            if (dictionary.ContainsKey("input"))
            {
                Input = Convert.ToBoolean(dictionary["input"]);
            }
            #region Default value
            if (dictionary.ContainsKey("defaultValue"))
            {
                object o = dictionary["defaultValue"];
                if (o != null)
                {
                    switch (Type)
                    {
                    case GPParameterType.Boolean:
                    case GPParameterType.Date:
                    case GPParameterType.Double:
                    case GPParameterType.Long:
                    case GPParameterType.String:
                    case GPParameterType.FeatureLayer:
                    case GPParameterType.RecordSet:
                    case GPParameterType.DataFile:
                        DefaultValue = ParameterBase.StringToParameter(Name, Type, o as string, CultureInfo.InvariantCulture);
                        break;

                    case GPParameterType.RasterData:
                    case GPParameterType.RasterDataLayer:
                        IDictionary <string, object> rDic = o as IDictionary <string, object>;
                        if (rDic != null)
                        {
                            string url = null, format = null;
                            if (rDic.ContainsKey("url"))
                            {
                                url = rDic["url"] as string;
                            }
                            if (rDic.ContainsKey("format"))
                            {
                                format = rDic["format"] as string;
                            }
                            if (url != null || format != null)
                            {
                                DefaultValue = new Client.Tasks.GPRasterData(Name, url, format)
                                {
                                    Format = format
                                }
                            }
                            ;                                                                                           //Workaround for slapi bug
                        }
                        break;

                    case GPParameterType.LinearUnit:
                        IDictionary <string, object> lDic = o as IDictionary <string, object>;
                        if (lDic != null)
                        {
                            double distance = double.NaN;
                            ESRI.ArcGIS.Client.Tasks.esriUnits units = Client.Tasks.esriUnits.esriMiles;
                            if (lDic.ContainsKey("distance"))
                            {
                                distance = Convert.ToDouble(lDic["distance"]);
                            }
                            if (lDic.ContainsKey("units"))
                            {
                                units = (ESRI.ArcGIS.Client.Tasks.esriUnits)(Enum.Parse(typeof(ESRI.ArcGIS.Client.Tasks.esriUnits),
                                                                                        lDic["units"] as string, true));
                            }
                            DefaultValue = new Client.Tasks.GPLinearUnit(Name, units, distance);
                        }
                        break;
                    }
                }
            }
            #endregion

            #region ChoiceList

            if (dictionary.ContainsKey("choiceList"))
            {
                ChoiceList = new List <ParameterSupport.Choice>();

                IEnumerable choices = dictionary["choiceList"] as IEnumerable;
                if (choices != null)
                {
                    foreach (Dictionary <string, object> item in choices)
                    {
                        if (item != null)
                        {
                            Choice choice = new Choice();
                            choice.FromJsonDictionary(item, Name);
                            ChoiceList.Add(choice);
                        }
                    }
                }
            }
            #endregion
        }