Esempio n. 1
0
        protected virtual void AddToJsonDictionary(ref Dictionary <string, object> dictionary)
        {
            addString(ref dictionary, Name, "name");
            addString(ref dictionary, Label, "label");
            addString(ref dictionary, DisplayName, "displayName");
            addString(ref dictionary, HelpText, "helpText");
            addString(ref dictionary, ToolTip, "toolTip");
            dictionary.Add("type", Type);
            dictionary.Add("shownAtRunTime", ShownAtRunTime);
            dictionary.Add("required", Required);
            dictionary.Add("input", Input);
            string defaultValue = null;

            switch (Type)
            {
            case GPParameterType.LinearUnit:     //handled in ToJson
            case GPParameterType.RasterData:
            case GPParameterType.RasterDataLayer:
                dictionary.Add("defaultValue", DefaultValue);
                break;

            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.ParameterToString(Type, DefaultValue, CultureInfo.InvariantCulture);
                if (!string.IsNullOrEmpty(defaultValue))
                {
                    dictionary.Add("defaultValue", defaultValue);
                }
                break;
            }
        }
Esempio n. 2
0
        private void BuildUI()
        {
            if (ParamContainer == null)
            {
                return;
            }
            if (ServiceInfo != null && Configuration == null)
            {
                Configuration = new GPConfiguration();
                Configuration.LoadConfiguration(ServiceInfo, ServiceEndpoint);
                return;
            }
            else if (Configuration != null && ServiceEndpoint == null)
            {
                ServiceEndpoint = Configuration.TaskEndPoint;
            }
            paramsScroller.IsEnabled = true;
            if (isLoading)
            {
                ParamContainer.Children.Clear();
                ParamContainer.Children.Add(new TextBlock()
                {
                    Text = ESRI.ArcGIS.Mapping.GP.Resources.Strings.Loading, FontWeight = System.Windows.FontWeights.Bold
                });
            }
            else if (Configuration != null)
            {
                double size = ViewUtility.GetViewHeight() - 325;
                paramsScroller.MaxHeight = size < 100 ? 100 : size;
                size = ViewUtility.GetViewWidth() - 200;
                paramsScroller.MaxWidth = size < 100 ? 100 : size;
                if (paramsScroller.MaxWidth > 500)
                {
                    paramsScroller.MaxWidth = 500;
                }
                ParamContainer.Children.Clear();
                ParamContainer.ColumnDefinitions.Clear();
                ParamContainer.RowDefinitions.Clear();
                ParamContainer.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                ParamContainer.ColumnDefinitions.Add(new ColumnDefinition());// { Width = new GridLength(0, GridUnitType.Star) });
                InputParameters.Clear();

                foreach (ParameterSupport.ParameterConfig config in Configuration.InputParameters)
                {
                    ParameterSupport.ParameterBase parameter = ParameterSupport.ParameterFactory.Create(config, Map);
                    if (parameter != null)
                    {
                        parameter.CanExecuteChanged += parameter_CanExecuteChanged;
                        InputParameters.Add(parameter);
                        if (config.ShownAtRunTime)
                        {
                            ParamContainer.RowDefinitions.Add(new RowDefinition());
                            TextBlock label = new TextBlock()
                            {
                                Text = config.Label,
                                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                                Padding           = new Thickness(2, 0, 2, 0)
                            };
                            label.SetValue(Grid.RowProperty, ParamContainer.RowDefinitions.Count - 1);
                            //if (config.Required)
                            //    label.Text += "*";
                            ParamContainer.Children.Add(label);
                            parameter.AddUI(ParamContainer);
                        }
                    }
                }
            }
        }
        public override void AddConfigUI(Grid grid)
        {
            TextBlock label;

            #region Header
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            Grid g = new Grid();
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            label = new TextBlock()
            {
                Text = DisplayName ?? Name,
                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                Margin            = new Thickness(2),
                FontWeight        = FontWeights.Bold,
                TextTrimming      = TextTrimming.WordEllipsis
            };
            g.Children.Add(label);

            if (Required)
            {
                label = new TextBlock()
                {
                    Text = Resources.Strings.Required,
                    VerticalAlignment   = System.Windows.VerticalAlignment.Center,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
                    Margin     = new Thickness(2),
                    FontWeight = FontWeights.Light,
                    FontStyle  = FontStyles.Italic
                };
                label.SetValue(Grid.ColumnProperty, 1);
                g.Children.Add(label);
            }
            g.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            g.SetValue(Grid.ColumnSpanProperty, 2);
            grid.Children.Add(g);
            #endregion

            #region Type
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            label = new TextBlock()
            {
                Text              = Resources.Strings.LabelType,
                Margin            = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            label = new TextBlock()
            {
                Text              = Type.ToString(),
                Margin            = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            label.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(label);
            #endregion

            #region Label
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            label = new TextBlock()
            {
                Text              = Resources.Strings.LabelLabel,
                Margin            = new Thickness(2),
                VerticalAlignment = System.Windows.VerticalAlignment.Center
            };
            label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            grid.Children.Add(label);
            TextBox labelTextBox = new TextBox()
            {
                Text   = Label == null ? string.Empty : Label,
                Margin = new Thickness(2),
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
            };
            labelTextBox.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
            labelTextBox.SetValue(Grid.ColumnProperty, 1);
            grid.Children.Add(labelTextBox);
            labelTextBox.TextChanged += (s, e) =>
            {
                Label = labelTextBox.Text;
            };
            #endregion

            if (Input)
            {
                #region Tooltip
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelTooltip,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                TextBox tbToolTip = new TextBox()
                {
                    Margin = new Thickness(2),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                };
                if (!string.IsNullOrEmpty(ToolTip))
                {
                    tbToolTip.Text = ToolTip;
                }
                tbToolTip.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                tbToolTip.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(tbToolTip);
                tbToolTip.TextChanged += (s, e) =>
                {
                    ToolTip = tbToolTip.Text;
                };
                #endregion

                #region Format Tooltip
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelFormatTooltip,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                TextBox tbFormatToolTip = new TextBox()
                {
                    Margin = new Thickness(2),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                };
                if (!string.IsNullOrEmpty(FormatToolTip))
                {
                    tbFormatToolTip.Text = FormatToolTip;
                }
                tbFormatToolTip.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                tbFormatToolTip.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(tbFormatToolTip);
                tbFormatToolTip.TextChanged += (s, e) =>
                {
                    FormatToolTip = tbFormatToolTip.Text;
                };
                #endregion

                #region ShownAtRuntime
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelShowParameter,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                CheckBox chb = new CheckBox()
                {
                    IsChecked = ShownAtRunTime, Margin = new Thickness(2)
                };
                chb.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                chb.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(chb);
                chb.Checked   += (s, e) => { ShownAtRunTime = true; };
                chb.Unchecked += (s, e) => { ShownAtRunTime = false; };
                #endregion

                #region Default Value
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                label = new TextBlock()
                {
                    Text              = Resources.Strings.LabelDefaultValue,
                    Margin            = new Thickness(2),
                    VerticalAlignment = System.Windows.VerticalAlignment.Center
                };
                label.SetValue(Grid.RowProperty, grid.RowDefinitions.Count - 1);
                grid.Children.Add(label);
                ParameterBase paramUI = ParameterFactory.Create(this, null);
                paramUI.AddUI(grid);
                paramUI.CanExecuteChanged += (a, b) =>
                {
                    this.DefaultValue = paramUI.Value;
                };
                #endregion
            }
        }
Esempio n. 4
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
        }