示例#1
0
        public bool CanParse()
        {
            bool ParseUrl()
            {
                var sp1 = TaskUrl.Split("/tasks/", StringSplitOptions.RemoveEmptyEntries);

                if (sp1.Length != 2)
                {
                    return(false);
                }
                baseUrl = sp1[0];
                var sp2 = baseUrl.Split('/', StringSplitOptions.RemoveEmptyEntries);

                contest = sp2[^ 1];
        private void BuildUI()
        {
            if (ParamContainer == null || ParameterConfigs == null ||
                ParameterConfigs.Count < 1)
            {
                return;
            }
            if ((Results == null || Results.Count < 1) && (Errors == null || Errors.Count < 1))
            {
                return;
            }
            if (!inputLayerInfoAvailable())
            {
                return;
            }
            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) });
            HasSimpleResults       = false;
            layerParamNameIDLookup = InputLayers != null ?
                                     new Dictionary <string, string>(InputLayers) : new Dictionary <string, string>();
            int pendingGPResultImageLayers = 0;

            #region Results
            if (Results != null && Results.Count > 0)
            {
                #region GP mapserver result
                MapServiceLayerParameterConfig mapServiceLayerParameterConfig = ParameterConfigs.FirstOrDefault(p => p.Type == GPParameterType.MapServiceLayer) as MapServiceLayerParameterConfig;
                if (mapServiceLayerParameterConfig != null && mapServiceLayerParameterConfig.SupportsJobResource)
                {
                    string t   = "/rest/services/";
                    string url = string.Format("{0}/{1}/MapServer/jobs/{2}", TaskUrl.Substring(0, TaskUrl.IndexOf(t, StringComparison.OrdinalIgnoreCase) + t.Length - 1), mapServiceLayerParameterConfig.Name, JobID);

                    ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer
                    {
                        Url      = url,
                        ProxyURL = UseProxy ? ProxyUrl : null
                    };
                    layer.SetValue(ESRI.ArcGIS.Mapping.Core.LayerExtensions.ExcludeSerializationProperty, true);
                    addToMap(mapServiceLayerParameterConfig, layer);
                }
                #endregion

                #region display each result
                foreach (ParameterConfig config in ParameterConfigs)
                {
                    MapServiceLayerParameterConfig cfg;
                    if (config.Type == GPParameterType.MapServiceLayer && (cfg = config as MapServiceLayerParameterConfig) != null && !cfg.SupportsJobResource)
                    {
                        pendingGPResultImageLayers++;
                        Geoprocessor gp = new Geoprocessor(TaskUrl);
                        gp.OutputSpatialReference        = Map.SpatialReference.Clone();
                        gp.GetResultImageLayerCompleted += (s, e) =>
                        {
                            GPResultImageLayer gpImageLayer = e.GPResultImageLayer;
                            setLayerProps(cfg, gpImageLayer);
                            gpImageLayer.ProxyUrl = UseProxy ? ProxyUrl : null;
                            Map.Layers.Add(gpImageLayer);
                            layerParamNameIDLookup.Add(cfg.Name, gpImageLayer.ID);
                            pendingGPResultImageLayers--;
                            if (layerParamNameIDLookup.Count > 1 && pendingGPResultImageLayers == 0)
                            {
                                LayerOrderer.OrderLayers(Map, LayerOrder, layerParamNameIDLookup);
                            }
                        };
                        // Initialize proxy
                        gp.ProxyURL = UseProxy ? ProxyUrl : null;
                        gp.GetResultImageLayerAsync(JobID, cfg.Name);
                        continue;
                    }

                    GPParameter param = getParameter(config.Name);
                    if (param == null)
                    {
                        continue;
                    }
                    string value = ParameterBase.ParameterToDisplayString(config.Type, param);

                    switch (config.Type)
                    {
                    case GPParameterType.Boolean:
                    case GPParameterType.Double:
                    case GPParameterType.Long:
                    case GPParameterType.String:
                    case GPParameterType.Date:
                    case GPParameterType.LinearUnit:
                        if (value == null)
                        {
                            value = string.Empty;
                        }
                        addparamUI(config.Label, value, false);
                        break;

                    case GPParameterType.FeatureLayer:
                        addToMap(param as GPFeatureRecordSetLayer, config);
                        break;

                    case GPParameterType.RecordSet:
                        if (string.IsNullOrEmpty(value) && param is GPRecordSet)
                        {
                            GPRecordSet rs = param as GPRecordSet;
                            if (string.IsNullOrEmpty(rs.Url) && rs.FeatureSet != null)
                            {
                                value = ESRI.ArcGIS.Mapping.GP.Resources.Strings.OnlyUrlOutputIsSupportedForRecordsets;
                            }
                            else
                            {
                                value = string.Empty;
                            }
                            addparamUI(config.Label, value, false);
                        }
                        else
                        {
                            addparamUI(config.Label, value, true);
                        }
                        break;

                    case GPParameterType.DataFile:
                    case GPParameterType.RasterData:
                    case GPParameterType.RasterDataLayer:
                        if (value == null)
                        {
                            value = string.Empty;
                        }
                        addparamUI(config.Label, value, true);
                        break;
                    }
                }
                #endregion

                if (layerParamNameIDLookup.Count > 1 && pendingGPResultImageLayers == 0)
                {
                    LayerOrderer.OrderLayers(Map, LayerOrder, layerParamNameIDLookup);
                }
            }
            #endregion

            #region Errors
            if (Errors != null && Errors.Count > 0)
            {
                foreach (Exception error in Errors)
                {
                    addparamUI(ESRI.ArcGIS.Mapping.GP.Resources.Strings.LabelError + " ", error.Message, false);
                    HasSimpleResults = true;
                }
            }
            #endregion
        }