Ejemplo n.º 1
0
        public bool AddFavorite(string name, string path, Image image)
        {
            try
            {
                RemoveFavorite(name, path);
                FileInfo fi = new FileInfo(ConfigPath);

                XmlStream    stream  = new XmlStream("Favorites");
                FavoriteList favList = new FavoriteList();
                if (fi.Exists)
                {
                    stream.ReadStream(fi.FullName);
                    favList = (FavoriteList)stream.Load("favlist", null, favList);
                    if (favList == null)
                    {
                        favList = new FavoriteList();
                    }
                }
                favList.Add(new Favorite(name, path, image));

                stream = new XmlStream("Favorites");
                stream.Save("favlist", favList);

                stream.WriteStream(fi.FullName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Add Favorite");
            }
            return(false);
        }
Ejemplo n.º 2
0
        public bool LoadMapDocument(string path)
        {
            XmlStream stream = new XmlStream("");

            if (stream.ReadStream(path))
            {
                while (_maps.Count > 0)
                {
                    this.RemoveMap((IMap)_maps[0]);
                }

                stream.Load("MapDocument", null, this);

                if (_maps.Count > 0)
                {
                    FocusMap = _maps[0];
                }
                else
                {
                    FocusMap = null;
                }

                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public bool RemoveFavorite(string name, string path)
        {
            try
            {
                FileInfo fi = new FileInfo(ConfigPath);
                if (!fi.Exists)
                {
                    return(false);
                }

                XmlStream stream = new XmlStream("Favorites");
                stream.ReadStream(fi.FullName);
                FavoriteList favList = (FavoriteList)stream.Load("favlist", null, new FavoriteList());
                if (favList == null)
                {
                    return(false);
                }

                favList.Remove(name, path);

                stream = new XmlStream("Favorites");
                stream.Save("favlist", favList);

                stream.WriteStream(fi.FullName);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error - Remove Favorite");
            }
            return(false);
        }
Ejemplo n.º 4
0
        //-------------------------------------------------------------------------

        public AppManager(InfoCollection infoCollection)
        {
            _infoCollection = infoCollection;

            SetXmlFilePath();

            File.SetAttributes(_xmlFilePath, FileAttributes.Normal);

            _xmlStream.Load(_xmlFilePath);

            _infoCollection.CategoriesInfo.Initialise(_xmlStream.GetElementsWithName("Category"));
            _infoCollection.ManualEntriesInfo.Initialise(_xmlStream.GetElementsWithName("ManualEntry"));
            _infoCollection.RecurringEntriesInfo.Initialise(_xmlStream.GetElementsWithName("RecurringEntry"));
        }
        public static TileServiceMetadata FromService(this TileServiceMetadata metadata, string server, string service)
        {
            var url = server.ToWmtsUrl(service, "GetMetadata");

            using (var client = new HttpClient())
            {
                var response = client.GetAsync(url).Result;
                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"{ url } return with status code { response.StatusCode }");
                }

                var       responseStream = response.Content.ReadAsStreamAsync().Result;
                XmlStream xmlStream      = new XmlStream("WmtsMetadata");
                xmlStream.ReadStream(responseStream);

                return(xmlStream.Load("TileServiceMetadata") as TileServiceMetadata);
            }
        }
Ejemplo n.º 6
0
        internal static IMap LoadMap(string name, IServiceRequestContext context)
        {
            try
            {
                DirectoryInfo di = new DirectoryInfo(ServicesPath);
                if (!di.Exists)
                {
                    di.Create();
                }

                FileInfo fi = new FileInfo(ServicesPath + @"\" + name + ".mxl");
                if (fi.Exists)
                {
                    ServerMapDocument doc = new ServerMapDocument();
                    doc.LoadMapDocument(fi.FullName);

                    if (doc.Maps.Count == 1)
                    {
                        ApplyMetadata(doc.Maps[0] as Map);
                        if (!mapDocument.AddMap(doc.Maps[0]))
                        {
                            return(null);
                        }

                        return(doc.Maps[0]);
                    }
                    return(null);
                }
                fi = new FileInfo(ServicesPath + @"\" + name + ".svc");
                if (fi.Exists)
                {
                    XmlStream stream = new XmlStream("");
                    stream.ReadStream(fi.FullName);
                    IServiceableDataset sds = stream.Load("IServiceableDataset", null) as IServiceableDataset;
                    if (sds != null && sds.Datasets != null)
                    {
                        Map map = new Map();
                        map.Name = name;

                        foreach (IDataset dataset in sds.Datasets)
                        {
                            if (dataset is IRequestDependentDataset)
                            {
                                if (!((IRequestDependentDataset)dataset).Open(context))
                                {
                                    return(null);
                                }
                            }
                            else
                            {
                                if (!dataset.Open())
                                {
                                    return(null);
                                }
                            }
                            //map.AddDataset(dataset, 0);

                            foreach (IDatasetElement element in dataset.Elements)
                            {
                                if (element == null)
                                {
                                    continue;
                                }
                                ILayer layer = LayerFactory.Create(element.Class, element as ILayer);
                                if (layer == null)
                                {
                                    continue;
                                }

                                map.AddLayer(layer);

                                if (element.Class is IWebServiceClass)
                                {
                                    if (map.SpatialReference == null)
                                    {
                                        map.SpatialReference = ((IWebServiceClass)element.Class).SpatialReference;
                                    }

                                    foreach (IWebServiceTheme theme in ((IWebServiceClass)element.Class).Themes)
                                    {
                                        map.SetNewLayerID(theme);
                                    }
                                }
                                else if (element.Class is IFeatureClass && map.SpatialReference == null)
                                {
                                    map.SpatialReference = ((IFeatureClass)element.Class).SpatialReference;
                                }
                                else if (element.Class is IRasterClass && map.SpatialReference == null)
                                {
                                    map.SpatialReference = ((IRasterClass)element.Class).SpatialReference;
                                }
                            }
                        }
                        ApplyMetadata(map);

                        if (!mapDocument.AddMap(map))
                        {
                            return(null);
                        }
                        return(map);
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                if (Functions.log_errors)
                {
                    Logger.Log(loggingMethod.error, "LoadConfig: " + ex.Message);
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        public bool AddMap(string mapName, string MapXML, string usr, string pwd)
        {
            if (String.IsNullOrEmpty(MapXML))
            {
                return(ReloadMap(mapName, usr, pwd));
            }

            if (IMS.acl != null && !IMS.acl.HasAccess(Identity.FromFormattedString(usr), pwd, "admin_addmap"))
            {
                return(false);
            }

            if (IMS.mapServer.Maps.Count >= IMS.mapServer.MaxServices)
            {
                // Überprüfen, ob schon eine Service mit gleiche Namen gibt...
                // wenn ja, ist es nur einem Refresh eines bestehenden Services
                bool found = false;
                foreach (IMapService map in IMS.mapServer.Maps)
                {
                    if (map.Name == mapName)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(false);
                }
            }

            if (MapXML.IndexOf("<IServiceableDataset") == 0)
            {
                XmlStream xmlStream = new XmlStream("");

                StringReader sr = new StringReader("<root>" + MapXML + "</root>");
                if (!xmlStream.ReadStream(sr))
                {
                    return(false);
                }

                IServiceableDataset sds = xmlStream.Load("IServiceableDataset", null) as IServiceableDataset;
                if (sds != null && sds.Datasets != null)
                {
                    IMS.SaveServiceableDataset(sds, mapName);
                    AddMapService(mapName, MapServiceType.SVC);
                }
            }
            else if (MapXML.IndexOf("<ServiceCollection") == 0)
            {
                XmlStream stream = new XmlStream("");

                StringReader sr = new StringReader(MapXML);
                if (!stream.ReadStream(sr))
                {
                    return(false);
                }

                IMS.SaveServiceCollection(mapName, stream);
            }
            else  // Map
            {
                XmlStream xmlStream = new XmlStream("IMap");

                StringReader sr = new StringReader(MapXML);
                if (!xmlStream.ReadStream(sr))
                {
                    return(false);
                }

                Map map = new Map();
                map.Load(xmlStream);
                map.Name = mapName;

                foreach (IMap m in ListOperations <IMap> .Clone(_doc.Maps))
                {
                    if (m.Name == map.Name)
                    {
                        _doc.RemoveMap(m);
                    }
                }

                if (!_doc.AddMap(map))
                {
                    return(false);
                }
                AddMapService(mapName, MapServiceType.MXL);

                IMS.SaveConfig(map);
            }

            /*
             * // Alle Layer sichtbar schalten...
             * IEnum layers = map.MapLayers;
             * IDatasetElement element;
             * while((element=(IDatasetElement)layers.Next)!=null)
             * {
             *  ITOCElement tocElement = map.TOC.GetTOCElement(element);
             *  if (tocElement != null) tocElement.LayerVisible = true;
             * }
             */

            return(true);
        }
Ejemplo n.º 8
0
        static public bool AddMap(string mapName, string MapXML, string usr, string pwd)
        {
            if (String.IsNullOrEmpty(MapXML))
            {
                return(ReloadMap(mapName, usr, pwd));
            }

            if (InternetMapServer.acl != null && !InternetMapServer.acl.HasAccess(Identity.FromFormattedString(usr), pwd, "admin_addmap"))
            {
                return(false);
            }

            if (InternetMapServer.Instance.Maps.Count >= InternetMapServer.Instance.MaxServices)
            {
                // Überprüfen, ob schon eine Service mit gleiche Namen gibt...
                // wenn ja, ist es nur einem Refresh eines bestehenden Services
                bool found = false;
                foreach (IMapService map in InternetMapServer.Instance.Maps)
                {
                    if (map.Name == mapName)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(false);
                }
            }

            if (MapXML.IndexOf("<IServiceableDataset") == 0)
            {
                XmlStream xmlStream = new XmlStream("");

                StringReader sr = new StringReader("<root>" + MapXML + "</root>");
                if (!xmlStream.ReadStream(sr))
                {
                    return(false);
                }

                IServiceableDataset sds = xmlStream.Load("IServiceableDataset", null) as IServiceableDataset;
                if (sds != null && sds.Datasets != null)
                {
                    InternetMapServer.SaveServiceableDataset(sds, mapName);
                    AddMapService(mapName, MapServiceType.SVC);
                }
            }
            else if (MapXML.IndexOf("<ServiceCollection") == 0)
            {
                XmlStream stream = new XmlStream("");

                StringReader sr = new StringReader(MapXML);
                if (!stream.ReadStream(sr))
                {
                    return(false);
                }

                InternetMapServer.SaveServiceCollection(mapName, stream);
            }
            else  // Map
            {
                XmlStream xmlStream = new XmlStream("IMap");

                StringReader sr = new StringReader(MapXML);
                if (!xmlStream.ReadStream(sr))
                {
                    return(false);
                }

                Map map = new Map();
                map.Load(xmlStream);
                map.Name = mapName;

                //foreach (IMap m in ListOperations<IMap>.Clone(_doc.Maps))
                //{
                //    if (m.Name == map.Name) _doc.RemoveMap(m);
                //}

                //if (!_doc.AddMap(map)) return false;
                AddMapService(mapName, MapServiceType.MXL);

                InternetMapServer.SaveConfig(map);
            }

            return(true);
        }
Ejemplo n.º 9
0
        async public Task LoadMapDocument(string filename)
        {
            if (_doc == null || filename == "")
            {
                return;
            }

            _docFilename = filename;

            System.IO.FileInfo fi = new System.IO.FileInfo(filename);
            if (!fi.Exists)
            {
                return;
            }

            if (fi.Extension.ToLower() != ".axl")
            {
                RemoveAllDataViews();
                if (_appWindow != null)
                {
                    _appWindow.RemoveAllToolbars();
                }

                _activeDataView = null;
            }

            XmlStream stream = new XmlStream("");

            if (fi.Extension.ToLower() == ".rdm")
            {
                StreamReader sr    = new StreamReader(filename);
                byte[]       bytes = new byte[fi.Length];
                BinaryReader br    = new BinaryReader(sr.BaseStream);
                br.Read(bytes, 0, bytes.Length);
                sr.Close();

                bytes = Crypto.Decrypt(bytes, _cryptoKey);

                MemoryStream ms = new MemoryStream(bytes);
                stream.ReadStream(ms);
                ms.Close();
            }
            else
            {
                stream.ReadStream(filename);
            }

            while (_doc.Maps.Count() > 0)
            {
                _doc.RemoveMap(_doc.Maps.First());
            }

            _dataViews.Clear();

            await stream.LoadAsync("MapDocument", _doc);

            // Load DataViews...
            DataView dv;

            while ((dv = (DataView)stream.Load("DataView", null, new DataView(_doc.Maps))) != null)
            {
                if (!(dv.Map is Map))
                {
                    continue;
                }

                DataView dataView = _appWindow.AddDataView((Map)dv.Map);
                if (dataView == null)
                {
                    continue;
                }

                dataView.Envelope        = dv.Envelope;
                dataView.TOC             = dv.TOC;
                dataView.DisplayRotation = dv.DisplayRotation;

                if (_activeDataView == null)
                {
                    _activeDataView = dataView;
                }
            }

            if (_dataViews.Count == 0 && _doc.Maps.Count() > 0)
            {
                //_appWindow.AddDataView((Map)_doc.Maps[0]);
                _activeDataView = _dataViews[0];
            }

            if (_activeDataView != null && _activeDataView.MapView != null)
            {
                _activeDataView.MapView.Tool = this.ActiveTool;
            }

            ValidateUI();

            IsDirty = false;

            if (fi.Extension.ToLower() == ".restore")
            {
                IsDirty      = true;
                fi           = new FileInfo(fi.FullName.Substring(0, fi.FullName.Length - ".restore".Length));
                _docFilename = fi.FullName;
            }

            _appWindow.Title = "gView.Carto " + fi.Name;
            _readonly        = (fi.Extension.ToLower() == ".rdm");

            foreach (var map in _doc.Maps)
            {
                if (map.HasErrorMessages)
                {
                    FormToolException.Show($"Loading Map '{ map.Name }'", String.Join(Environment.NewLine, map.ErrorMessages));
                }
            }

            if (AfterLoadMapDocument != null)
            {
                AfterLoadMapDocument(_doc);
            }
        }
Ejemplo n.º 10
0
        public void LoadMapDocument(string filename)
        {
            if (_doc == null || filename == "")
            {
                return;
            }
            _docFilename = filename;

            System.IO.FileInfo fi = new System.IO.FileInfo(filename);
            if (!fi.Exists)
            {
                return;
            }

            if (fi.Extension.ToLower() != ".axl")
            {
                RemoveAllDataViews();
                if (_appWindow != null)
                {
                    _appWindow.RemoveAllToolbars();
                }

                _activeDataView = null;
            }

            XmlStream stream = new XmlStream("");

            if (fi.Extension.ToLower() == ".rdm")
            {
                StreamReader sr    = new StreamReader(filename);
                byte[]       bytes = new byte[fi.Length];
                BinaryReader br    = new BinaryReader(sr.BaseStream);
                br.Read(bytes, 0, bytes.Length);
                sr.Close();

                bytes = Crypto.Decrypt(bytes, _cryptoKey);

                MemoryStream ms = new MemoryStream(bytes);
                stream.ReadStream(ms);
                ms.Close();
            }
            else if (fi.Extension.ToLower() == ".axl")
            {
                IMap          map  = _doc.Maps[0];
                PlugInManager pman = new PlugInManager();

                #region AXL
                XmlDocument axl = new XmlDocument();
                axl.Load(fi.FullName);

                #region Extent
                XmlNode envNode = axl.SelectSingleNode("ARCXML/CONFIG/MAP/PROPERTIES/ENVELOPE[@minx and @maxx and @miny and @miny]");
                if (envNode != null)
                {
                    Envelope env = new Envelope(envNode);
                    map.Display.Limit = new Envelope(env);
                    map.Display.ZoomTo(env);
                }
                #endregion

                #region Workspaces
                Dictionary <string, IDataset> _workspaces = new Dictionary <string, IDataset>();
                foreach (XmlNode workspaceNode in axl.SelectNodes("ARCXML/CONFIG/MAP/WORKSPACES/*"))
                {
                    switch (workspaceNode.Name)
                    {
                    case "SDEWORKSPACE":
                        string connectionString = "server=" + workspaceNode.Attributes["server"].Value;
                        if (workspaceNode.Attributes["instance"] != null)
                        {
                            connectionString += ";instance=" + workspaceNode.Attributes["instance"].Value;
                        }
                        if (workspaceNode.Attributes["database"] != null)
                        {
                            connectionString += ";database=" + workspaceNode.Attributes["database"].Value;
                        }
                        if (workspaceNode.Attributes["user"] != null)
                        {
                            connectionString += ";user="******"user"].Value;
                        }
                        if (workspaceNode.Attributes["password"] != null)
                        {
                            connectionString += ";password="******"password"].Value;
                        }

                        IDataset sdeDataset = pman.CreateInstance(new Guid("CE42218B-6962-48c9-9BAC-39E4C5003AE5")) as IDataset;
                        if (sdeDataset == null)
                        {
                            continue;
                        }
                        sdeDataset.ConnectionString = connectionString;
                        if (!sdeDataset.Open())
                        {
                            continue;
                        }

                        _workspaces.Add(workspaceNode.Attributes["name"].Value, sdeDataset);
                        break;

                    case "SHAPEWORKSPACE":
                        IDataset shapeDataset = pman.CreateInstance(new Guid("80F48262-D412-41fb-BF43-2D611A2ABF42")) as IDataset;
                        if (shapeDataset == null)
                        {
                            continue;
                        }
                        shapeDataset.ConnectionString = workspaceNode.Attributes["directory"].Value;
                        if (!shapeDataset.Open())
                        {
                            continue;
                        }

                        _workspaces.Add(workspaceNode.Attributes["name"].Value, shapeDataset);
                        break;

                    case "IMAGEWORKSPACE":
                        IDataset rasterDataset = pman.CreateInstance(new Guid("43DFABF1-3D19-438c-84DA-F8BA0B266592")) as IDataset;
                        _workspaces.Add(workspaceNode.Attributes["name"].Value, rasterDataset);
                        break;
                    }
                }
                #endregion

                #region Layers
                XmlNodeList layerNodes = axl.SelectNodes("ARCXML/CONFIG/MAP/LAYER[@name and @id and @type]");
                if (layerNodes == null)
                {
                    return;
                }
                for (int i = layerNodes.Count - 1; i >= 0; i--)
                {
                    XmlNode layerNode = layerNodes[i];
                    if (layerNode.Attributes["type"].Value == "featureclass")
                    {
                        XmlNode datasetNode = layerNode.SelectSingleNode("DATASET[@name and @workspace]");
                        if (datasetNode == null)
                        {
                            continue;
                        }
                        if (!_workspaces.ContainsKey(datasetNode.Attributes["workspace"].Value))
                        {
                            continue;
                        }
                        IDataset        dataset   = _workspaces[datasetNode.Attributes["workspace"].Value];
                        IDatasetElement dsElement = dataset[datasetNode.Attributes["name"].Value];
                        if (dsElement == null || dsElement.Class == null)
                        {
                            continue;
                        }

                        IFeatureLayer layer = (IFeatureLayer)LayerFactory.Create(dsElement.Class);
                        if (layerNode.Attributes["visible"] != null)
                        {
                            layer.Visible = layerNode.Attributes["visible"].Value == "true";
                        }
                        layer.SID = layerNode.Attributes["id"].Value;

                        map.AddLayer(layer);

                        SetLayernameAndScales(layerNode, layer);
                        SetRenderers(layerNode, layer);
                        XmlNode queryNode = layerNode.SelectSingleNode("QUERY[@where]");
                        if (queryNode != null)
                        {
                            layer.FilterQuery             = new QueryFilter();
                            layer.FilterQuery.WhereClause = queryNode.Attributes["where"].Value;
                        }
                    }
                    else if (layerNode.Attributes["type"].Value == "image")
                    {
                        XmlNode datasetNode = layerNode.SelectSingleNode("DATASET[@name and @workspace]");
                        if (datasetNode == null)
                        {
                            continue;
                        }
                        if (!_workspaces.ContainsKey(datasetNode.Attributes["workspace"].Value))
                        {
                            continue;
                        }
                        IRasterFileDataset dataset = _workspaces[datasetNode.Attributes["workspace"].Value] as IRasterFileDataset;
                        if (dataset == null)
                        {
                            continue;
                        }

                        XmlNode workspaceNode = axl.SelectSingleNode("ARCXML/CONFIG/MAP/WORKSPACES/IMAGEWORKSPACE[@name='" + datasetNode.Attributes["workspace"].Value + "' and @directory]");
                        if (workspaceNode == null)
                        {
                            continue;
                        }

                        IRasterLayer rLayer = dataset.AddRasterFile(workspaceNode.Attributes["directory"].Value + @"\" + datasetNode.Attributes["name"].Value);
                        if (rLayer == null)
                        {
                            continue;
                        }

                        if (layerNode.Attributes["visible"] != null)
                        {
                            rLayer.Visible = layerNode.Attributes["visible"].Value == "true";
                        }
                        rLayer.SID = layerNode.Attributes["id"].Value;

                        map.AddLayer(rLayer);

                        SetLayernameAndScales(layerNode, rLayer);
                    }
                }
                #endregion

                ValidateUI();
                IsDirty          = false;
                _appWindow.Title = "gView.Carto " + fi.Name;
                if (AfterLoadMapDocument != null)
                {
                    AfterLoadMapDocument(_doc);
                }

                return;

                #endregion
            }
            else
            {
                stream.ReadStream(filename);
            }

            while (_doc.Maps.Count > 0)
            {
                _doc.RemoveMap(_doc.Maps[0]);
            }
            _dataViews.Clear();

            stream.Load("MapDocument", null, _doc);


            // Load DataViews...
            DataView dv;
            while ((dv = (DataView)stream.Load("DataView", null, new DataView(_doc.Maps))) != null)
            {
                if (!(dv.Map is Map))
                {
                    continue;
                }

                DataView dataView = _appWindow.AddDataView((Map)dv.Map);
                if (dataView == null)
                {
                    continue;
                }
                dataView.Envelope        = dv.Envelope;
                dataView.TOC             = dv.TOC;
                dataView.DisplayRotation = dv.DisplayRotation;

                if (_activeDataView == null)
                {
                    _activeDataView = dataView;
                }
            }

            if (_dataViews.Count == 0 && _doc.Maps.Count > 0)
            {
                //_appWindow.AddDataView((Map)_doc.Maps[0]);
                _activeDataView = _dataViews[0];
            }

            if (_activeDataView != null && _activeDataView.MapView != null)
            {
                _activeDataView.MapView.Tool = this.ActiveTool;
            }

            ValidateUI();

            IsDirty = false;

            _appWindow.Title = "gView.Carto " + fi.Name;
            _readonly        = (fi.Extension.ToLower() == ".rdm");

            if (AfterLoadMapDocument != null)
            {
                AfterLoadMapDocument(_doc);
            }
        }