Esempio n. 1
0
        async static public Task <ArcIMSThemeFeatureClass> CreateAsync(IDataset dataset, string id)
        {
            var fc = new ArcIMSThemeFeatureClass(dataset, id);

            if (dataset is IFeatureDataset)
            {
                fc.Envelope         = await((IFeatureDataset)dataset).Envelope();
                fc.SpatialReference = await((IFeatureDataset)dataset).GetSpatialReference();
            }

            return(fc);
        }
Esempio n. 2
0
        async public Task <bool> Open(IServiceRequestContext context)
        {
            if (_class == null)
            {
                _class = new ArcIMSClass(this);
            }

            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;
            //}

            dotNETConnector connector = new dotNETConnector();

            if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd))
            {
                connector.setAuthentification(user, pwd);
            }

            try
            {
                _themes.Clear();

                string axl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\"><REQUEST><GET_SERVICE_INFO fields=\"true\" envelope=\"true\" renderer=\"true\" extensions=\"true\" /></REQUEST></ARCXML>";
                //string axl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\"><REQUEST><GET_SERVICE_INFO dpi=\"96\" toc=\"true\" /></REQUEST></ARCXML>";

                await ArcIMSClass.LogAsync(context, "GetServiceInfo Response", server, service, axl);

                axl = connector.SendRequest(axl, server, service);
                await ArcIMSClass.LogAsync(context, "GetServiceInfo Response", server, service, axl);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(axl);

                double  dpi    = 96.0;
                XmlNode screen = doc.SelectSingleNode("//ENVIRONMENT/SCREEN");
                if (screen != null)
                {
                    if (screen.Attributes["dpi"] != null)
                    {
                        dpi = Convert.ToDouble(screen.Attributes["dpi"].Value.Replace(".", ","));
                    }
                }
                double dpm = (dpi / 0.0254);

                XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS");
                _sRef = ArcXMLGeometry.AXL2SpatialReference(FeatureCoordSysNode);

                foreach (XmlNode envelopeNode in doc.SelectNodes("//ENVELOPE"))
                {
                    if (_envelope == null)
                    {
                        _envelope = new Envelope(envelopeNode);
                    }
                    else
                    {
                        _envelope.Union(new Envelope(envelopeNode));
                    }
                }
                foreach (XmlNode layerNode in doc.SelectNodes("//LAYERINFO[@id]"))
                {
                    bool visible = true;

                    if (layerNode.Attributes["visible"] != null)
                    {
                        bool.TryParse(layerNode.Attributes["visible"].Value, out visible);
                    }

                    XmlNode tocNode = layerNode.SelectSingleNode("TOC");
                    if (tocNode != null)
                    {
                        ReadTocNode(tocNode);
                    }
                    IClass           themeClass = null;
                    IWebServiceTheme theme;
                    if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "featureclass")
                    {
                        themeClass = await ArcIMSThemeFeatureClass.CreateAsync(this, layerNode.Attributes["id"].Value);

                        ((ArcIMSThemeFeatureClass)themeClass).Name             = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value;
                        ((ArcIMSThemeFeatureClass)themeClass).fieldsFromAXL    = layerNode.InnerXml;
                        ((ArcIMSThemeFeatureClass)themeClass).SpatialReference = _sRef;

                        XmlNode FCLASS = layerNode.SelectSingleNode("FCLASS[@type]");
                        if (FCLASS != null)
                        {
                            ((ArcIMSThemeFeatureClass)themeClass).fClassTypeString = FCLASS.Attributes["type"].Value;
                        }
                        foreach (XmlNode child in layerNode.ChildNodes)
                        {
                            switch (child.Name)
                            {
                            case "SIMPLERENDERER":
                            case "SIMPLELABELRENDERER":
                            case "VALUEMAPRENDERER":
                            case "SCALEDEPENDENTRENDERER":
                            case "VALUEMAPLABELRENDERER":
                            case "GROUPRENDERER":
                                ((ArcIMSThemeFeatureClass)themeClass).OriginalRendererNode = child;
                                break;
                            }
                        }
                        theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme;
                        if (theme == null)
                        {
                            continue;
                        }
                        theme.Visible = visible;
                    }
                    else if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "image")
                    {
                        //themeClass = new ArcIMSThemeRasterClass(this,
                        //    layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value);
                        themeClass = new ArcIMSThemeRasterClass(this, layerNode.Attributes["id"].Value);
                        ((ArcIMSThemeRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value;

                        theme = new WebServiceTheme(
                            themeClass,
                            themeClass.Name,
                            layerNode.Attributes["id"].Value,
                            visible,
                            _class as IWebServiceClass);
                    }
                    else
                    {
                        continue;
                    }

                    try
                    {
                        if (layerNode.Attributes["minscale"] != null)
                        {
                            theme.MinimumScale = Convert.ToDouble(layerNode.Attributes["minscale"].Value.Replace(".", ",")) * dpm;
                        }
                        if (layerNode.Attributes["maxscale"] != null)
                        {
                            theme.MaximumScale = Convert.ToDouble(layerNode.Attributes["maxscale"].Value.Replace(".", ",")) * dpm;
                        }
                    }
                    catch { }
                    _themes.Add(theme);
                }
                _state = DatasetState.opened;

                ((ArcIMSClass)_class).SpatialReference = await this.GetSpatialReference();

                return(true);
            }
            catch (Exception ex)
            {
                _state  = DatasetState.unknown;
                _errMsg = ex.Message;
                await ArcIMSClass.ErrorLog(context, "Open Dataset", server, service, ex);

                return(false);
            }
        }