public int NumberOfServices(string serverName) { int iCount = 0; IGISServerConnection2 pGISServerConnection = new GISServerConnection() as IGISServerConnection2; pGISServerConnection.Connect(serverName); IServerObjectAdmin4 pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin as IServerObjectAdmin4; IEnumServerObjectConfiguration objConfigs = pServerObjectAdmin.GetConfigurations(); IServerObjectConfiguration3 icfg = objConfigs.Next() as IServerObjectConfiguration3; while (icfg != null) { string stemp = icfg.Name.ToUpper(); iCount++; icfg = objConfigs.Next() as IServerObjectConfiguration3; } COMUtil.ReleaseObject(icfg); COMUtil.ReleaseObject(objConfigs); COMUtil.ReleaseObject(pServerObjectAdmin); COMUtil.ReleaseObject(pGISServerConnection); return(iCount); }
public void Stop(string serverName, string serviceName, bool bDelete) { IGISServerConnection pGISServerConnection = null; IServerObjectAdmin pServerObjectAdmin = null; try { serviceName = CleanServiceName(serviceName); pGISServerConnection = new GISServerConnection(); pGISServerConnection.Connect(serverName); pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin; pServerObjectAdmin.StopConfiguration(serviceName, "MapServer"); if (bDelete == true) { pServerObjectAdmin.DeleteConfiguration(serviceName, "MapServer"); } } catch (Exception ex) { throw ex; } finally { COMUtil.ReleaseObject(pServerObjectAdmin); COMUtil.ReleaseObject(pGISServerConnection); } }
private void SetDataFrameExtents(IFeatureClass pFC) { IPageLayout pPageLayout; IGraphicsContainer pGraphContainer = null; IMapFrame pMapFrame; IElement pElement; IActiveView pActiveView; IGeoDataset pIGeoDataSet = null; try { pPageLayout = _pMapDocument.PageLayout; pGraphContainer = (IGraphicsContainer)pPageLayout; pActiveView = (IActiveView)pPageLayout; pGraphContainer.Reset(); pElement = pGraphContainer.Next(); while (!(pElement == null)) { if (pElement is IMapFrame) { pMapFrame = (IMapFrame)pElement; pIGeoDataSet = pFC as IGeoDataset; pMapFrame.ExtentType = esriExtentTypeEnum.esriExtentBounds; pMapFrame.MapBounds = pIGeoDataSet.Extent; pActiveView.Refresh(); return; } pElement = pGraphContainer.Next(); } } catch (Exception ex) { throw ex; } finally { COMUtil.ReleaseObject(pGraphContainer); } }
public void Start(string serverName, string serviceName) { serviceName = CleanServiceName(serviceName); try { IGISServerConnection pGISServerConnection = new GISServerConnection(); pGISServerConnection.Connect(serverName); IServerObjectAdmin pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin; pServerObjectAdmin.StartConfiguration(serviceName, "MapServer"); COMUtil.ReleaseObject(pServerObjectAdmin); COMUtil.ReleaseObject(pGISServerConnection); } catch (Exception ex) { throw ex; } }
public void Start(string serverName, string serviceName, string sAgsAdminUser, string sAgsAdminPwd) { serviceName = CleanServiceName(serviceName); try { if (!ConnectAGS(serverName, sAgsAdminUser, sAgsAdminPwd)) { throw new ApplicationException("Could not get server connection to " + serverName); } soAdmin.StartConfiguration(serviceName, "MapServer"); COMUtil.ReleaseObject(soAdmin); soAdmin = null; } catch (Exception ex) { throw ex; } }
public void DeleteFeatureDataset(string sFeatureDataset, string sConnectionFile) { IWorkspace pWorkspace = null; IEnumDataset pEnumDataset = null; IDataset pDataset = null; try { pWorkspace = ArcSdeWorkspaceFromFile(sConnectionFile); pEnumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTAny); pDataset = pEnumDataset.Next(); while (pDataset != null) { if (pDataset.Name.Contains(sFeatureDataset)) { if (pDataset.CanDelete()) { pDataset.Delete(); } else { throw new ApplicationException("Cannot delete dataset " + pDataset.Name); } } pDataset = pEnumDataset.Next(); } } catch (Exception ex) { throw ex; } finally { COMUtil.ReleaseObject(pDataset); COMUtil.ReleaseObject(pEnumDataset); COMUtil.ReleaseObject(pWorkspace); } }
public bool Exists(string serverName, string serviceName) { IGISServerConnection2 pGISServerConnection = new GISServerConnection() as IGISServerConnection2; pGISServerConnection.Connect(serverName); IServerObjectConfiguration3 icfg = null; IEnumServerObjectConfiguration objConfigs = null; IServerObjectAdmin4 pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin as IServerObjectAdmin4; try { // Get Configurations from the server objConfigs = pServerObjectAdmin.GetConfigurations(); icfg = objConfigs.Next() as IServerObjectConfiguration3; while (icfg != null) { if (icfg.Name.ToUpper() == serviceName.ToUpper()) { return(true); } icfg = objConfigs.Next() as IServerObjectConfiguration3; } return(false); } catch (Exception ex) { throw ex; } finally { COMUtil.ReleaseObject(icfg); COMUtil.ReleaseObject(objConfigs); COMUtil.ReleaseObject(pServerObjectAdmin); COMUtil.ReleaseObject(pGISServerConnection); } }
public void Create(string serverName, string serviceName, string sFilePath, bool replaceExisting, bool isPooled, string outputDir, string virtualOutputDir, int minInstances, int maxInstances, int waitTimeout, int usageTimeout, int idleTimeout, bool bSde) { IGISServerConnection2 pGISServerConnection = null; IServerObjectAdmin3 pServerObjectAdmin = null; IServerObjectConfiguration3 pConfiguration = null; try { pGISServerConnection = new GISServerConnection() as IGISServerConnection2; pGISServerConnection.Connect(serverName); pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin as IServerObjectAdmin3; // create the new configuration pConfiguration = pServerObjectAdmin.CreateConfiguration() as IServerObjectConfiguration3; pConfiguration.Name = serviceName; pConfiguration.TypeName = "MapServer"; //Convert filepath to a local connection sFilePath = sFilePath.ToUpper().Replace("C$\\", ""); IPropertySet pProps = pConfiguration.Properties; pProps.SetProperty("FilePath", sFilePath); pProps.SetProperty("OutputDir", outputDir); pProps.SetProperty("VirtualOutputDir", virtualOutputDir); pProps.SetProperty("SupportedImageReturnTypes", "URL"); pProps.SetProperty("MaxImageHeight", "2048"); pProps.SetProperty("MaxRecordCount", "500"); pProps.SetProperty("MaxBufferCount", "100"); pProps.SetProperty("MaxImageWidth", "2048"); pProps.SetProperty("IgnoreCache", "false"); pProps.SetProperty("ClientCachingAllowed", "true"); // Tell AGS not to keep an active schema lock on the datasets for this map service pProps.SetProperty("SchemaLockingEnabled", "false"); // Test to enable mobile at publish pProps.SetProperty("MobileDataAccess", "true"); IPropertySet pPropsWeb = pConfiguration.Info; pPropsWeb.SetProperty("WebEnabled", "true"); pPropsWeb.SetProperty("WebCapabilities", "Map,Query,Data"); pConfiguration.IsPooled = isPooled; pConfiguration.MinInstances = minInstances; pConfiguration.MaxInstances = maxInstances; pConfiguration.WaitTimeout = waitTimeout; pConfiguration.UsageTimeout = usageTimeout; pConfiguration.IdleTimeout = idleTimeout; pConfiguration.Description = serviceName; // Set KML extension properties pConfiguration.set_ExtensionEnabled("KMLServer", true); IPropertySet pPropKML = pConfiguration.get_ExtensionInfo("KMLServer"); pPropKML.SetProperty("WebEnabled", "true"); pPropKML.SetProperty("WebCapabilities", "Vectors"); pConfiguration.set_ExtensionInfo("KMLServer", pPropKML); IPropertySet pExtensionPropKML = pConfiguration.get_ExtensionProperties("KMLServer"); pExtensionPropKML.SetProperty("ImageSize", "1024"); pExtensionPropKML.SetProperty("FeatureLimit", "1000000"); pExtensionPropKML.SetProperty("Dpi", "96"); pExtensionPropKML.SetProperty("MinRefreshPeriod", "30"); pExtensionPropKML.SetProperty("UseDefaultSnippets", "false"); // Set FeatureAccess extention if (bSde) { pConfiguration.set_ExtensionEnabled("FeatureServer", true); IPropertySet pPropFeatureAccess = pConfiguration.get_ExtensionInfo("FeatureServer"); pPropFeatureAccess.SetProperty("WebEnabled", "true"); pPropFeatureAccess.SetProperty("Query", "true"); pPropFeatureAccess.SetProperty("Editing", "true"); pPropFeatureAccess.SetProperty("WebCapabilities", "Editing,Query"); } try { pServerObjectAdmin.AddConfiguration(pConfiguration); pServerObjectAdmin.StartConfiguration(pConfiguration.Name, pConfiguration.TypeName); } catch (Exception) { throw new ApplicationException("Service " + serviceName + " already exists"); } } catch (Exception ex) { throw new ApplicationException("Error in MapService.Create: " + ex.Message + " Stack trace: " + ex.StackTrace); } finally { COMUtil.ReleaseObject(pConfiguration); COMUtil.ReleaseObject(pServerObjectAdmin); COMUtil.ReleaseObject(pGISServerConnection); } }
public bool CreateMxd(string sMxdTemplate, string sPathToMXD, string ArcGISServer, string sMxdFile, string sDBConn, string sDataSet, bool bSde) { if (sMxdTemplate.Length > 0) { _sMxdTemplate = sMxdTemplate; } _sPathToMXD = sPathToMXD; _ArcGISServer = ArcGISServer; ESRI.ArcGIS.Carto.IMap pMap = null; IFeatureClass pOldFC = null; string fcName = String.Empty; string sSuffix = String.Empty; IWorkspaceFactory2 wsf = null; IWorkspace2 ws2 = null; IFeatureWorkspace fws = null; IWorkspace ws = null; try { if (bSde) { // Get WS for SDE ws = ArcSdeWorkspaceFromFile(sDBConn); } else { // Get WS from file GDB. wsf = new FileGDBWorkspaceFactoryClass() as IWorkspaceFactory2; //if locks on gdb only path is passed in string fileGdb = sDBConn.Contains(".gdb") ? sDBConn : sDBConn; if (wsf.IsWorkspace(fileGdb)) { ws = wsf.OpenFromFile(fileGdb, 0); } } if (ws == null) { return(false); } // Check if Mxd already exists if (File.Exists(sMxdFile)) { return(false); } // Create a Mxd from Overlays Template pMap = PrivateCreateMxd(sMxdFile); ws2 = (IWorkspace2)ws; fws = (IFeatureWorkspace)ws; // Loop through all layers in MXD and repoint data source to OverlayGDB Features IEnumLayer pEnumLayer = pMap.get_Layers(null, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { if (!(pLayer is IFeatureLayer)) { pLayer = pEnumLayer.Next(); continue; } // Cast pLayer to featurelayer IFeatureLayer pMapFeatureLayer = (IFeatureLayer)pLayer; pOldFC = pMapFeatureLayer.FeatureClass; if (pOldFC == null) { pLayer = pEnumLayer.Next(); continue; } // Get FC name IDataset pDS = (IDataset)pOldFC; fcName = pDS.Name; // Feature Class: <Dataset>_osm_pt, <Dataset>_osm_ln, <Dataset>_osm_ply sSuffix = fcName.Substring(fcName.IndexOf("_osm_")); if (String.IsNullOrEmpty(sSuffix)) { continue; } // Check if feature class exists in GDB if (ws2.get_NameExists(esriDatasetType.esriDTFeatureClass, sDataSet + sSuffix)) { // Get feature class IFeatureClass ipFC = fws.OpenFeatureClass(sDataSet + sSuffix); IFeatureLayer ipFL = (IFeatureLayer)pLayer; // Create IMapAdmin2 from pMap IMapAdmin2 pMapAdmin2 = (IMapAdmin2)pMap; // Change FeatureClass of layer to FC in FGDB ipFL.FeatureClass = ipFC; pMapAdmin2.FireChangeFeatureClass(pOldFC, ipFC); COMUtil.ReleaseObject(ipFC); ipFC = null; COMUtil.ReleaseObject(ipFL); ipFL = null; } else { // Remove layer from map pMap.DeleteLayer(pLayer); } pLayer = pEnumLayer.Next(); } SaveMXD(sMxdFile, pMap); return(true); } catch (System.Runtime.InteropServices.COMException cx) { throw cx; } catch (Exception ex) { throw ex; } finally { COMUtil.ReleaseObject(pOldFC); COMUtil.ReleaseObject(fws); COMUtil.ReleaseObject(ws2); COMUtil.ReleaseObject(ws); COMUtil.ReleaseObject(pMap); COMUtil.ReleaseObject(wsf); pOldFC = null; fws = null; ws2 = null; ws = null; wsf = null; pMap = null; _pMapDocument = null; //Do not make any call to ArcObjects after ShutDownApplication() if (m_AOLicenseInitializer != null) { m_AOLicenseInitializer.ShutdownApplication(); } m_AOLicenseInitializer = null; } }