Beispiel #1
0
        /// <summary>
        /// 得到服务器上下文:AGSServer远程调用AO
        /// </summary>
        /// <returns></returns>
        private IServerContext GetServerContext()
        {
            string serverName = "localhost";    //服务器机器名称
            string mapSvrName = "china";        //空间数据服名称
            IServerObjectManager svrObjMgr = null;

            //获取SOM,并放入session变量中
            if (Session["SOM"] == null)
            {
                //用ADF connection库
                AGSServerConnection agsServerConnection = new AGSServerConnection();
                agsServerConnection.Host = serverName;
                //建立与服务器的连接
                agsServerConnection.Connect();
                svrObjMgr = agsServerConnection.ServerObjectManager;
            }
            else
            {
                svrObjMgr = Session["SOM"] as ServerObjectManager;
            }

            //根据服务名来创建上下文
            IServerContext svrContext = svrObjMgr.CreateServerContext(mapSvrName, "MapServer");

            return(svrContext);
        }
 private static IServerObjectAdmin2 Connect()
 {
     // Must run as an user in the agsadmin group on the SOM
     var agsConn = new AGSServerConnection();
     agsConn.Host = serverName;
     agsConn.Connect();
     return (IServerObjectAdmin2)agsConn.ServerObjectAdmin;
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            AGSServerConnection agsServerConnection = new AGSServerConnection();

            agsServerConnection.Host = "192.171.192.6";
            agsServerConnection.Connect();
            IServerObjectAdmin2 serverObjectAdmin = (IServerObjectAdmin2)agsServerConnection.ServerObjectAdmin;
            // this name must match that defined for property pages
            string extensionName = "WatershedSOE";

            if (args.Length == 1 && args[0] == "/unregister")
            //if(true)
            {
                // check whether the soe is already registered
                if (ExtensionRegistered(serverObjectAdmin, extensionName))
                {
                    // delete the SOE
                    serverObjectAdmin.DeleteExtensionType("MapServer", extensionName);
                    Console.WriteLine(extensionName + " successfully unregistered");
                }
                else
                {
                    Console.WriteLine(extensionName + " is not registered with ArcGIS Server");
                }
            }
            else
            {
                if (!ExtensionRegistered(serverObjectAdmin, extensionName))
                {
                    IServerObjectExtensionType3 serverObjectExtensionType = (IServerObjectExtensionType3)serverObjectAdmin.CreateExtensionType();
                    // must match namespace and classname of the class implementing IServerObjectExtension
                    serverObjectExtensionType.CLSID       = "WatershedSOE.WatershedSOE";
                    serverObjectExtensionType.Description = "Creates watershed above an input location";
                    serverObjectExtensionType.Name        = extensionName;
                    serverObjectExtensionType.DisplayName = "Watershed REST";
                    serverObjectExtensionType.Properties.SetProperty("FlowAccum", "fac");
                    serverObjectExtensionType.Properties.SetProperty("FlowDir", "fdr");
                    serverObjectExtensionType.Info.SetProperty("SupportsREST", "true");
                    serverObjectExtensionType.Info.SetProperty("SupportsMSD", "true");
                    serverObjectAdmin.AddExtensionType("MapServer", serverObjectExtensionType);
                    Console.WriteLine(extensionName + " succesfully registered with ArcGIS Server");
                }
                else
                {
                    Console.WriteLine(extensionName + " is already registered with ArcGIS Server");
                }
            }
            Console.ReadLine();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            AGSServerConnection agsServerConnection = new AGSServerConnection();
            agsServerConnection.Host = "192.171.192.6";
            agsServerConnection.Connect();
            IServerObjectAdmin2 serverObjectAdmin = (IServerObjectAdmin2)agsServerConnection.ServerObjectAdmin;
            // this name must match that defined for property pages
            string extensionName = "WatershedSOE";

            if (args.Length == 1 && args[0] == "/unregister")
            //if(true)
            {
                // check whether the soe is already registered
                if(ExtensionRegistered(serverObjectAdmin,extensionName))
                {
                    // delete the SOE
                    serverObjectAdmin.DeleteExtensionType("MapServer",extensionName);
                    Console.WriteLine(extensionName+" successfully unregistered");
                }
                else
                {
                    Console.WriteLine(extensionName + " is not registered with ArcGIS Server");
                }

            }
            else
            {
                if (!ExtensionRegistered(serverObjectAdmin, extensionName))
                {
                    IServerObjectExtensionType3 serverObjectExtensionType = (IServerObjectExtensionType3)serverObjectAdmin.CreateExtensionType();
                    // must match namespace and classname of the class implementing IServerObjectExtension
                    serverObjectExtensionType.CLSID = "WatershedSOE.WatershedSOE";
                    serverObjectExtensionType.Description = "Creates watershed above an input location";
                    serverObjectExtensionType.Name = extensionName;
                    serverObjectExtensionType.DisplayName = "Watershed REST";
                    serverObjectExtensionType.Properties.SetProperty("FlowAccum", "fac");
                    serverObjectExtensionType.Properties.SetProperty("FlowDir", "fdr");
                    serverObjectExtensionType.Info.SetProperty("SupportsREST", "true");
                    serverObjectExtensionType.Info.SetProperty("SupportsMSD", "true");
                    serverObjectAdmin.AddExtensionType("MapServer", serverObjectExtensionType);
                    Console.WriteLine(extensionName + " succesfully registered with ArcGIS Server");
                }
                else
                {
                    Console.WriteLine(extensionName + " is already registered with ArcGIS Server");
                }
            }
            Console.ReadLine();
        }
Beispiel #5
0
        /// <summary>
        /// 绘制点缓冲
        /// </summary>
        private void DrawBufferByPoint(ESRI.ArcGIS.ADF.Web.Geometry.Point adfPt)
        {
            //1.连接服务器
            AGSServerConnection connection = new AGSServerConnection();

            connection.Host = "localhost";
            connection.Connect();

            //2.获得服务器
            IServerObjectManager pSom      = connection.ServerObjectManager;
            IServerContext       pSc       = pSom.CreateServerContext("china", "MapServer");//服务名和类型
            IMapServer           mapServer = pSc.ServerObject as IMapServer;

            //3.使用服务器对象 几何对象转换
            IMapServerObjects pMso = mapServer as IMapServerObjects;
            //ESRI.ArcGIS.Geometry.IGeometry comPt = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(adfPt, pSc)
            //    as ESRI.ArcGIS.Geometry.IGeometry;////ValueObjectToComObject(pnt, pSC);
            IPoint pt = new ESRI.ArcGIS.Geometry.PointClass();

            pt.X = adfPt.X;
            pt.Y = adfPt.Y;
            ESRI.ArcGIS.Geometry.IGeometry comPt = pt;

            ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
            ISpatialReference pSR = sre.CreateGeographicCoordinateSystem(4326);

            comPt.SpatialReference = pSR;

            //绘制buffer
            ITopologicalOperator pTOPO = comPt as ITopologicalOperator;

            pTOPO.Simplify();//??
            double   bufDis  = Map1.Extent.Width / 2;
            IPolygon bufPoly = pTOPO.Buffer(10) as IPolygon;

            bufPoly.Densify(0, 0);
            ESRI.ArcGIS.ADF.ArcGISServer.PolygonN valuePolyN = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(bufPoly, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)) as ESRI.ArcGIS.ADF.ArcGISServer.PolygonN;
            ESRI.ArcGIS.ADF.Web.Geometry.Polygon  adfPoly    = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(valuePolyN) as ESRI.ArcGIS.ADF.Web.Geometry.Polygon;


            #region Densify
            ////***Densify
            // ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection)bufPoly;
            // ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(com_pointcollection, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.poly));
            //ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
            //for (int i = 0; i < com_pointcollection.PointCount - 1; i++)
            //{
            //    ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_pt = new ESRI.ArcGIS.ADF.Web.Geometry.Point();
            //    new_adf_pt.X = com_pointcollection.get_Point(i).X;
            //    new_adf_pt.Y = com_pointcollection.get_Point(i).Y;
            //    new_adf_pointcollection.Add(new_adf_pt);
            //}
            //ESRI.ArcGIS.ADF.Web.Geometry.Ring new_adf_ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
            //new_adf_ring.Points = new_adf_pointcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.RingCollection new_adf_ringcollection = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
            //new_adf_ringcollection.Add(new_adf_ring);
            //ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
            //new_adf_polygon.Rings = new_adf_ringcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = new_adf_polygon as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            ////*******Densify
            #endregion

            ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = adfPoly as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            GraphicElement geoEle = new GraphicElement(geom, System.Drawing.Color.Red);
            try
            {
                Map1.Zoom(adfPoly);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            geoEle.Symbol.Transparency = 50;

            IEnumerable gfc = Map1.GetFunctionalities();

            MapResource gMap = null;
            foreach (IGISFunctionality gfunc in gfc)
            {
                if (gfunc.Resource.Name == "graph")
                {
                    gMap = (MapResource)gfunc.Resource;
                    break;
                }
            }
            if (gMap == null)
            {
                return;
            }
            ElementGraphicsLayer glayer = null;
            foreach (DataTable dt in gMap.Graphics.Tables)
            {
                if (dt is ElementGraphicsLayer)
                {
                    glayer = dt as ElementGraphicsLayer;
                    break;
                }
            }
            if (glayer == null)
            {
                glayer = new ElementGraphicsLayer();
                gMap.Graphics.Tables.Add(glayer);
            }

            glayer.Clear();//清除数据
            glayer.Add(geoEle);

            //4.释放服务器对象
            pSc.ReleaseContext();

            if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)
            {
                Map1.Refresh();
            }
            else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)
            {
                Map1.RefreshResource(gMap.Name);
            }
            return;
        }
        private static Dictionary <string, List <MapServiceInfo> > CollectMapServerInfo(IEnumerable <string> servers)
        {
            Dictionary <string, List <MapServiceInfo> > output;

            output = new Dictionary <string, List <MapServiceInfo> >();
            AGSServerConnection   connection = null;
            IServerObjectManager4 som        = null;
            IServerContext        ctxt       = null;
            IMapServer            mapServer  = null;

            IEnumServerObjectConfigurationInfo socInfos;
            IServerObjectConfigurationInfo2    socInfo;
            MapServiceInfo mapServiceInfo;

            try
            {
                // Loop through all of the hosts (servers) and create a div for each one containing map service test results.
                foreach (var host in servers)
                {
                    var mapServiceInfos = new List <MapServiceInfo>();
                    output.Add(host, mapServiceInfos);
                    // Create the connection object
                    connection = new AGSServerConnection(host, null, false, true);
                    try
                    {
                        // Attempt to connect to the server.
                        connection.Connect(false);
                        if (connection.IsConnected)
                        {
                            // Get the Server Object Manager (SOM) for the current ArcGIS Server.
                            som = (IServerObjectManager4)connection.ServerObjectManager;
                            // Get a list of the services on the server.
                            socInfos = som.GetConfigurationInfos();
                            // Get the first service from the list.
                            socInfo = socInfos.Next() as IServerObjectConfigurationInfo2;

                            // Loop through the list of services...
                            while (socInfo != null)
                            {
                                mapServiceInfo = new MapServiceInfo {
                                    MapServiceName = socInfo.Name
                                };
                                try
                                {
                                    // Proceed only if the current service is a "MapServer".
                                    if (string.Compare(socInfo.TypeName, "MapServer", true) == 0)
                                    {
                                        // Create a div for the current map service.
                                        Console.Error.WriteLine("{0}", socInfo.Name);
                                        try
                                        {
                                            // Create a server context for the current map service.
                                            ctxt = som.CreateServerContext(socInfo.Name, socInfo.TypeName);
                                            // Cast the context object to an IMapServer.
                                            mapServer = (IMapServer)ctxt.ServerObject;

                                            // Get the document name
                                            IMapServerInit2 msInit = null;
                                            msInit = mapServer as IMapServerInit2;
                                            string sourceDocName = msInit != null ? msInit.FilePath : null;
                                            if (sourceDocName != null)
                                            {
                                                mapServiceInfo.SourceDocumentPath = sourceDocName;
                                            }

                                            // Create a dictionary of the properties for all of the layers in the map service.
                                            mapServiceInfo.ConnectionProperties = mapServer.GetConnectionProperties();
                                        }
                                        catch (COMException comEx)
                                        {
                                            // See if the exception was caused by a stopped service.  Just write the message in this case.
                                            if (comEx.ErrorCode == -2147467259)
                                            {
                                                mapServiceInfo.ErrorMessage = comEx.Message;
                                            }
                                            else
                                            {
                                                mapServiceInfo.ErrorMessage = string.Format("{0}: {1}", comEx.ErrorCode, comEx.Message);
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    mapServiceInfo.ErrorMessage = ex.ToString();
                                }
                                finally
                                {
                                    // Release the server context.
                                    if (ctxt != null)
                                    {
                                        ctxt.ReleaseContext();
                                    }

                                    // Go to the next soc info.
                                    socInfo = socInfos.Next() as IServerObjectConfigurationInfo2;
                                }
                                mapServiceInfos.Add(mapServiceInfo);
                            }
                        }
                    }
                    finally
                    {
                        connection.Dispose();
                    }
                }
            }
            finally
            {
                // Release any COM objects that have been created.
                if (mapServer != null)
                {
                    Marshal.ReleaseComObject(mapServer);
                }
                if (ctxt != null)
                {
                    Marshal.ReleaseComObject(ctxt);
                }
                if (som != null)
                {
                    Marshal.ReleaseComObject(som);
                }
            }
            return(output);
        }
Beispiel #7
0
    /// <summary>
    /// Find map marker points in QueryString parameters or Form data and store them in mapMarkers collection.
    /// </summary>
    /// <example>Saint John: ?markerPoint[0]=2500000,7350000&markerPoint[1]=2550000,7300000</example>
    private IList<GraphicElement> ReadMarkers()
    {
        // clear collection
        List<GraphicElement> mapMarkers = new List<GraphicElement>();

        try
        {
            using (AGSServerConnection connection = new AGSServerConnection())
            {
                connection.Host = Properties.Host;
                connection.Connect();

                string firstService = null;

                IServerContext context = connection
                    .ServerObjectManager
                    .CreateServerContext(Map.PrimaryMapResource, "MapServer");

                // read the marker points from the query string
                IList<Point> markerPoints = new List<Point>();
                //    new MarkerPointReader(HttpContext
                //    .Current
                //    .Request
                //    .QueryString
                //).Read(context, firstService);

                foreach (Point markerPoint in markerPoints)
                {
                    mapMarkers.Add(CreateMarker(markerPoint));
                }

                context.ReleaseContext();
            }
        }
        catch (Exception e)
        {
            Logger.Error("Error while reading markers from query string", e);
        }

        return mapMarkers;
    }