예제 #1
0
        async public Task <bool> Open(gView.MapServer.IServiceRequestContext context)
        {
            string url = String.Empty;

            try
            {
                _isOpened = true;
                bool ret = true;

                if (_wfsDataset != null)
                {
                    ret = _wfsDataset.Open();
                }
                if (_class != null)
                {
                    string param = "REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";

                    url = Append2Url(_connection, param);
                    string response = WebFunctions.HttpSendRequest(url, "GET", null,
                                                                   ConfigTextStream.ExtractValue(_connectionString, "usr"),
                                                                   ConfigTextStream.ExtractValue(_connectionString, "pwd"));

                    response = RemoveDOCTYPE(response);

                    _class.Init(response, _wfsDataset);
                }

                _state = (ret) ? DatasetState.opened : DatasetState.unknown;

                return(ret);
            }
            catch (Exception ex)
            {
                await WMSClass.ErrorLogAsync(context, "GetCapabilities", url, ex);

                _class      = null;
                _wfsDataset = null;

                return(false);
            }
        }
예제 #2
0
        public bool Open(gView.MapServer.IServiceRequestContext context)
        {
            if (_class == null)
            {
                _class = new AGSClass(this);
            }

            #region Parameters
            string server  = ConfigTextStream.ExtractValue(ConnectionString, "server");
            string service = ConfigTextStream.ExtractValue(ConnectionString, "service");
            string user    = ConfigTextStream.ExtractValue(ConnectionString, "user");
            string pwd     = ConfigTextStream.ExtractValue(ConnectionString, "pwd");

            if ((user == "#" || user == "$") &&
                context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null)
            {
                string roles = String.Empty;
                if (user == "#" && context.ServiceRequest.Identity.UserRoles != null)
                {
                    foreach (string role in context.ServiceRequest.Identity.UserRoles)
                    {
                        if (String.IsNullOrEmpty(role))
                        {
                            continue;
                        }
                        roles += "|" + role;
                    }
                }
                user = context.ServiceRequest.Identity.UserName + roles;
                pwd  = context.ServiceRequest.Identity.HashedPassword;
            }
            #endregion

            try
            {
                _proxy = ProxySettings.Proxy(server);

                _themes.Clear();
                _parentIds.Clear();

                _mapServer       = new gView.Interoperability.AGS.Proxy.MapServer(service);
                _mapServer.Proxy = gView.Framework.Web.ProxySettings.Proxy(service);
                MapServerInfo msi = _mapServer.GetServerInfo(_mapServer.GetDefaultMapName());
                _mapDescription = msi.DefaultMapDescription;

                MapLayerInfo[] mapLayerInfos = msi.MapLayerInfos;
                foreach (MapLayerInfo layerInfo in mapLayerInfos)
                {
                    if (layerInfo.Extent is EnvelopeN)
                    {
                        EnvelopeN env = (EnvelopeN)layerInfo.Extent;
                        if (_envelope == null)
                        {
                            _envelope = new gView.Framework.Geometry.Envelope(env.XMin, env.YMin, env.XMax, env.YMax);
                        }
                        else
                        {
                            _envelope.Union(new gView.Framework.Geometry.Envelope(env.XMin, env.YMin, env.XMax, env.YMax));
                        }
                    }

                    CalcParentLayerIds(mapLayerInfos, layerInfo.LayerID);
                    IClass           themeClass = null;
                    IWebServiceTheme theme      = null;
                    LayerDescription ld         = LayerDescriptionById(layerInfo.LayerID);
                    if (ld == null)
                    {
                        continue;
                    }

                    if (layerInfo.LayerType == "Feature Layer")
                    {
                        #region Geometry Type (Point, Line, Polygon)
                        geometryType geomType = geometryType.Unknown;
                        if (layerInfo.Fields != null)
                        {
                            foreach (Proxy.Field fieldInfo in layerInfo.Fields.FieldArray)
                            {
                                if (fieldInfo.Type == esriFieldType.esriFieldTypeGeometry &&
                                    fieldInfo.GeometryDef != null)
                                {
                                    switch (fieldInfo.GeometryDef.GeometryType)
                                    {
                                    case esriGeometryType.esriGeometryMultipoint:
                                    case esriGeometryType.esriGeometryPoint:
                                        geomType = geometryType.Point;
                                        break;

                                    case esriGeometryType.esriGeometryPolyline:
                                        geomType = geometryType.Polyline;
                                        break;

                                    case esriGeometryType.esriGeometryPolygon:
                                        geomType = geometryType.Polygon;
                                        break;

                                    case esriGeometryType.esriGeometryMultiPatch:
                                        break;
                                    }
                                }
                            }
                        }
                        #endregion

                        themeClass = new AGSThemeFeatureClass(this, layerInfo, geomType);
                        theme      = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme;
                        if (theme == null)
                        {
                            continue;
                        }
                    }
                    else if (layerInfo.LayerType == "Raster Layer" ||
                             layerInfo.LayerType == "Raster Catalog Layer")
                    {
                        themeClass = new AGSThemeRasterClass(this, layerInfo);
                        theme      = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme;
                        if (theme == null)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        MapLayerInfo parentLayer = MapLayerInfoById(mapLayerInfos, layerInfo.ParentLayerID);
                        if (parentLayer != null && parentLayer.LayerType == "Annotation Layer")
                        {
                            themeClass = new AGSThemeFeatureClass(this, layerInfo, geometryType.Polygon);
                            theme      = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme;
                            if (theme == null)
                            {
                                continue;
                            }
                        }
                    }
                    if (theme != null)
                    {
                        theme.MinimumScale = layerInfo.MaxScale;
                        theme.MaximumScale = layerInfo.MinScale;
                        theme.Visible      = ld.Visible;
                        _themes.Add(theme);
                    }
                }

                _state = DatasetState.opened;
                return(true);
            }
            catch (Exception ex)
            {
                _state  = DatasetState.unknown;
                _errMsg = ex.Message;
                return(false);
            }
        }