Exemple #1
0
        async private Task <IServiceMap> FindServiceMap(string name, string alias, IServiceRequestContext context)
        {
            Map map = await FindMap(name, context);

            if (map != null)
            {
                IEnumerable <IMapApplicationModule> modules = null;
                if (_mapServiceDeploymentMananger.MapDocument is IMapDocumentModules)
                {
                    modules = ((IMapDocumentModules)_mapServiceDeploymentMananger.MapDocument).GetMapModules(map);
                }
                return(await ServiceMap.CreateAsync(map, this, modules));
            }

            if (name.Contains(",") /* && _serverLicType == ServerLicType.gdi*/)
            {
                Map newMap = null;

                string[] names = name.Split(',');

                #region Alias Service auflösen...
                StringBuilder sb = new StringBuilder();
                foreach (string n in names)
                {
                    IMapService ms = GetMapService(n.ServiceName(), n.FolderName());
                    if (ms == null)
                    {
                        return(null);
                    }

                    if (sb.Length > 0)
                    {
                        sb.Append(",");
                    }

                    if (ms is MapServiceAlias)
                    {
                        sb.Append(((MapServiceAlias)ms).ServiceName);
                    }
                    else
                    {
                        sb.Append(ms.Name);
                    }
                }
                names = sb.ToString().Split(',');
                #endregion
                Array.Reverse(names);

                //if (names.Length > _maxGDIServices)
                //{
                //    return null;
                //}

                foreach (string n in names)
                {
                    Map m1 = await FindMap(n, context);

                    if (m1.Name == n)
                    {
                        if (newMap == null)
                        {
                            newMap = new Map(m1, true);
                        }
                        else
                        {
                            newMap.Append(m1, true);

                            // SpatialReference von am weitesten unten liegenden Karte übernehmen
                            // ist geschackssache...
                            if (m1.Display != null && m1.Display.SpatialReference != null)
                            {
                                newMap.Display.SpatialReference =
                                    m1.Display.SpatialReference.Clone() as ISpatialReference;
                            }
                        }
                    }
                }
                if (newMap != null)
                {
                    // alle webServiceThemes im TOC vereinigen...
                    if (newMap.TOC != null)
                    {
                        foreach (ITOCElement tocElement in newMap.TOC.Elements)
                        {
                            if (tocElement == null ||
                                tocElement.Layers == null)
                            {
                                continue;
                            }

                            foreach (ILayer layer in tocElement.Layers)
                            {
                                if (layer is IWebServiceLayer)
                                {
                                    newMap.TOC.RenameElement(tocElement, newMap.Name + "_WebThemes");
                                    break;
                                }
                            }
                        }
                    }
                    newMap.Name = alias;
                    if (!_mapServiceDeploymentMananger.MapDocument.AddMap(newMap))
                    {
                        return(null);
                    }

                    bool found = false;
                    foreach (IMapService ms in _mapServiceMananger.MapServices)
                    {
                        if (ms != null &&
                            ms.Name == alias && ms.Type == MapServiceType.GDI)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        _mapServiceMananger.MapServices.Add(new MapService(_mapServiceMananger, name, String.Empty, MapServiceType.GDI));
                    }

                    return(await ServiceMap.CreateAsync(newMap, this, null));
                }
            }

            return(null);
        }