static public bool RemoveMap(string mapName, string usr, string pwd)
        {
            if (InternetMapServer.acl != null && !InternetMapServer.acl.HasAccess(Identity.FromFormattedString(usr), pwd, "admin_removemap"))
            {
                return(false);
            }

            bool found = false;

            foreach (IMapService service in ListOperations <IMapService> .Clone(InternetMapServer.mapServices))
            {
                if (service.Name == mapName)
                {
                    InternetMapServer.mapServices.Remove(service);
                    found = true;
                }
            }

            foreach (IMapService m in ListOperations <IMapService> .Clone(InternetMapServer.Instance.Maps))
            {
                if (m.Name == mapName)
                {
                    //_doc.RemoveMap(m);
                    found = true;
                }
            }
            InternetMapServer.RemoveConfig(mapName);

            return(found);
        }
        private Map FindMap(string name, IServiceRequestContext context)
        {
            foreach (IMap map in InternetMapServer.MapDocument.Maps)
            {
                if (map.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) && map is Map)
                {
                    return((Map)map);
                }
            }

            if (name.Contains(","))
            {
                return(null);
            }

            IMap m = InternetMapServer.LoadMap(name, context);

            if (m is Map)
            {
                return((Map)m);
            }

            return(null);
        }
        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);
        }