Example #1
0
    public void DeleteService(string sArcGisServer,
                                string sConfigID,
                                string sFeatureDataset,
                                string sServiceName,
                                string sMxdOutput,
                                string sSDEConnection)
    {
      // Check if service name starts with http://
      if (sServiceName.IndexOf("http://") > 1)
      {
        throw new ApplicationException("Service name did not begin with the expected http://! ServiceName: " + sServiceName);
      }

      // Parse out service name
      if (sServiceName.Contains("/"))
      {
        sServiceName = sServiceName.Substring(0, (sServiceName.LastIndexOf("/")));
        sServiceName = sServiceName.Substring(sServiceName.LastIndexOf("/") + 1);
      }

      // Stop and Unpublish
      ServicePublisher.MXD.MapService mapService = null;
      mapService = new MXD.MapService();
      mapService.Stop(sArcGisServer, sServiceName, true);

      // Make sure MXD is deleted
      ServicePublisher.MXD.MxdManager mxdManager = null;
      mxdManager = new MXD.MxdManager();
      mxdManager.DeleteMxd(sMxdOutput, sServiceName);

      // Delete the DataSet from the connection as well
      mxdManager.DeleteFeatureDataset(sFeatureDataset, sSDEConnection);

    }
Example #2
0
        public void DeleteService(string sArcGisServer,
                                  string sConfigID,
                                  string sFeatureDataset,
                                  string sServiceName,
                                  string sMxdOutput,
                                  string sSDEConnection)
        {
            // Check if service name starts with http://
            if (sServiceName.IndexOf("http://") > 1)
            {
                throw new ApplicationException("Service name did not begin with the expected http://! ServiceName: " + sServiceName);
            }

            // Parse out service name
            if (sServiceName.Contains("/"))
            {
                sServiceName = sServiceName.Substring(0, (sServiceName.LastIndexOf("/")));
                sServiceName = sServiceName.Substring(sServiceName.LastIndexOf("/") + 1);
            }

            // Stop and Unpublish
            ServicePublisher.MXD.MapService mapService = null;
            mapService = new MXD.MapService();
            mapService.Stop(sArcGisServer, sServiceName, true);

            // Make sure MXD is deleted
            ServicePublisher.MXD.MxdManager mxdManager = null;
            mxdManager = new MXD.MxdManager();
            mxdManager.DeleteMxd(sMxdOutput, sServiceName);

            // Delete the DataSet from the connection as well
            mxdManager.DeleteFeatureDataset(sFeatureDataset, sSDEConnection);
        }
Example #3
0
        /// <summary>
        /// Publishes a Map Service
        /// </summary>
        /// <param name="minInstances"></param>
        /// <param name="maxInstances"></param>
        /// <param name="waitTimeout"></param>
        /// <param name="usageTimeout"></param>
        /// <param name="idleTimeout"></param>
        /// <param name="sAgsConnFile"></param>
        /// <param name="sPythonScriptFile"></param>
        /// <returns>Published URL or Error as a string</returns>
        public string Publish(int minInstances, int maxInstances, int waitTimeout, int usageTimeout, int idleTimeout, string sAgsConnFile, string sPythonScriptFile)
        {
            string     sURLs            = string.Empty;
            string     sMapServiceName  = string.Empty;
            string     sMxdFile         = string.Empty;
            string     sMxdTemplateName = string.Empty;
            MxdManager pManager         = null;

            try
            {
                if (String.IsNullOrEmpty(_sMXDTemplate))
                {
                    return("Error: No MXD passed.");
                }

                pManager = new MxdManager(_sMXDTemplate);

                if (pManager.IsInitialized)
                {
                    // Set sMapServiceName
                    sMapServiceName = _sMapServiceName;

                    // Set sMxdTemplateName
                    _sMXDTemplate    = _sMXDTemplate.Replace("C:\\\\", "C:\\");
                    sMxdTemplateName = _sMXDTemplate.Substring(_sMXDTemplate.LastIndexOf("\\") + 1);
                    sMxdTemplateName = sMxdTemplateName.Remove(sMxdTemplateName.IndexOf(".mxd"));

                    // Set sMxdFile
                    sMxdFile = Path.Combine(_sOutputDirectory, sMapServiceName + "_" + sMxdTemplateName + ".mxd");

                    if (!(pManager.CreateMxd(_sMXDTemplate, _sOutputDirectory, _ArcGISServer, sMxdFile, _sDBConn, _sDataset, _bSDE)))
                    {
                        sURLs = sURLs + "MxdManager.CreateMxd failed for " + _sMXDTemplate + ". Please see logfile for details.,";
                    }

                    // If sAgsConnFile is empty then publish using ArcGIS Server 10
                    if (string.IsNullOrEmpty(sAgsConnFile))
                    {
                        sURLs = sURLs + pManager.PublishMap(sMapServiceName + "_" + sMxdTemplateName, _ArcGISServer, sMxdFile, _bSDE, minInstances, maxInstances, waitTimeout, usageTimeout, idleTimeout);
                    }
                    else // publish using ArcGIS Server 10.1
                    {
#if _WIN64
                        sURLs = sURLs + pManager.PublishMap10_1(sMapServiceName + "_" + sMxdTemplateName, _ArcGISServer, sMxdFile, _sOutputDirectory, sAgsConnFile, sPythonScriptFile);
#endif
                    }
                }

                return(sURLs.TrimEnd(','));
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error in PublishMXD.Publish: " + ex.Message + " Stack trace: " + ex.StackTrace);
            }
            finally
            {
                pManager = null;
            }
        }
Example #4
0
        /// <summary>
        /// Publishes a Map Service
        /// </summary>
        /// <param name="minInstances"></param>
        /// <param name="maxInstances"></param>
        /// <param name="waitTimeout"></param>
        /// <param name="usageTimeout"></param>
        /// <param name="idleTimeout"></param>
        /// <param name="sAgsConnFile"></param>
        /// <param name="sPythonScriptDir"></param>
        /// <returns>Published URL or Error as a string</returns>
        public string Publish(string sAgsConnFile, string sPythonScriptDir)
        {
            string     sURLs            = string.Empty;
            string     sMapServiceName  = string.Empty;
            string     sMxdFile         = string.Empty;
            string     sMxdTemplateName = string.Empty;
            MxdManager pManager         = null;

            try
            {
                if (String.IsNullOrEmpty(_sMXDTemplate))
                {
                    return("Error: No MXD passed.");
                }

                pManager = new MxdManager(_sMXDTemplate);

                // Set sMapServiceName
                sMapServiceName = _sMapServiceName;

                // Set sMxdTemplateName
                _sMXDTemplate    = _sMXDTemplate.Replace("C:\\\\", "C:\\");
                sMxdTemplateName = _sMXDTemplate.Substring(_sMXDTemplate.LastIndexOf("\\") + 1);
                sMxdTemplateName = sMxdTemplateName.Remove(sMxdTemplateName.IndexOf(".mxd"));

                // Set sMxdFile
                sMxdFile = Path.Combine(_sOutputDirectory, sMapServiceName + "_" + sMxdTemplateName + ".mxd");

                if (!(pManager.CreateMxd(_sMXDTemplate,
                                         _sOutputDirectory,
                                         _ArcGISServer,
                                         sMxdFile,
                                         _sDBConn,
                                         _sDataset,
                                         sPythonScriptDir,
                                         _bSDE)))
                {
                    sURLs = sURLs + "MxdManager.CreateMxd failed for " + _sMXDTemplate + ". Please see logfile for details.,";
                }

                // publish using ArcGIS Server 10.1
                sURLs = sURLs + pManager.PublishMap10_1(sMapServiceName + "_" + sMxdTemplateName,
                                                        _ArcGISServer,
                                                        sMxdFile,
                                                        _sOutputDirectory,
                                                        sAgsConnFile,
                                                        Path.Combine(sPythonScriptDir, PUBLISHMXD_PY));

                return(sURLs.TrimEnd(','));
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error in PublishMXD.Publish: " + ex.Message + " Stack trace: " + ex.StackTrace);
            }
            finally
            {
                pManager = null;
            }
        }
Example #5
0
        // TODO: Add 10.1 method
        public string UnPublish()
        {
            string     sDeleteFgdbResult = "";
            string     sURLs             = "";
            string     sMapServiceName   = "";
            string     sMxdName;
            FileInfo   fiMxd;
            MxdManager manager      = null;
            bool       errorOccured = false;

            try
            {
                if (String.IsNullOrEmpty(_sMXDTemplate))
                {
                    return("Error: No MXD passed.");
                }

                sMxdName = "";
                manager  = new MxdManager("");

                sMapServiceName = _sMXDTemplate;
                if (!(manager.UnPublishMap(sMapServiceName, _ArcGISServer, _sOutputDirectory, _sDataset, _sDBConn)))
                {
                    sURLs        = sURLs + "Error: MxdManager.UnPublishMap failed for " + sMapServiceName + ". Please see logfile for details.,";
                    errorOccured = true;
                }
                else
                {
                    sURLs = sURLs + "Removal of " + sMapServiceName + " was successful.,";
                }

                // Remove trailing ','
                sURLs = sURLs.Remove(sURLs.Length - 1);

                if (!(errorOccured))
                {
                    //if locks exist only path is passed in
                    if (_sDBConn.Contains(".gdb"))
                    {
                        sDeleteFgdbResult = manager.DeleteGdb(_sDBConn);
                        if (sDeleteFgdbResult.Length > 0)
                        {
                            sURLs = sURLs + "," + sDeleteFgdbResult;
                        }
                    }
                }
                return(sURLs);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error in PublishMXD.UnPublish: " + ex.Message + " Stack trace: " + ex.StackTrace);
            }
            finally
            {
                fiMxd   = null;
                manager = null;
            }
        }
        /// <summary>
        /// Publishes a Map Service
        /// </summary>
        /// <param name="minInstances"></param>
        /// <param name="maxInstances"></param>
        /// <param name="waitTimeout"></param>
        /// <param name="usageTimeout"></param>
        /// <param name="idleTimeout"></param>
        /// <param name="sAgsConnFile"></param>
        /// <param name="sPythonScriptFile"></param>
        /// <returns>Published URL or Error as a string</returns>
        public string Publish(int minInstances, int maxInstances, int waitTimeout, int usageTimeout, int idleTimeout, string sAgsConnFile, string sPythonScriptFile)
        {
            string sURLs = string.Empty;
            string sMapServiceName = string.Empty;
            string sMxdFile = string.Empty;
            string sMxdTemplateName = string.Empty;
            MxdManager pManager = null;

            try
            {
                if (String.IsNullOrEmpty(_sMXDTemplate)) return "Error: No MXD passed.";
                
                pManager = new MxdManager(_sMXDTemplate);
                
                if (pManager.IsInitialized)
                {
                    // Set sMapServiceName
                    sMapServiceName = _sMapServiceName;

                    // Set sMxdTemplateName
                    _sMXDTemplate = _sMXDTemplate.Replace("C:\\\\", "C:\\");
                    sMxdTemplateName = _sMXDTemplate.Substring(_sMXDTemplate.LastIndexOf("\\") + 1);
                    sMxdTemplateName = sMxdTemplateName.Remove(sMxdTemplateName.IndexOf(".mxd"));

                    // Set sMxdFile
                    sMxdFile = Path.Combine(_sOutputDirectory, sMapServiceName + "_" + sMxdTemplateName + ".mxd");

                    if (!(pManager.CreateMxd(_sMXDTemplate, _sOutputDirectory, _ArcGISServer, sMxdFile, _sDBConn, _sDataset, _bSDE)))
                    {
                        sURLs = sURLs + "MxdManager.CreateMxd failed for " + _sMXDTemplate + ". Please see logfile for details.,";
                    }

                    // If sAgsConnFile is empty then publish using ArcGIS Server 10
                    if (string.IsNullOrEmpty(sAgsConnFile))
                    {
                        sURLs = sURLs + pManager.PublishMap(sMapServiceName + "_" + sMxdTemplateName, _ArcGISServer, sMxdFile, _bSDE, minInstances, maxInstances, waitTimeout, usageTimeout, idleTimeout);
                    }
                    else // publish using ArcGIS Server 10.1
                    {
#if _WIN64 
                        sURLs = sURLs + pManager.PublishMap10_1(sMapServiceName + "_" + sMxdTemplateName, _ArcGISServer, sMxdFile, _sOutputDirectory, sAgsConnFile, sPythonScriptFile);
#endif
                    }
                }

                return sURLs.TrimEnd(',');
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error in PublishMXD.Publish: " + ex.Message + " Stack trace: " + ex.StackTrace);
            }
            finally
            {
                
                pManager = null;
            }
        }
        /// <summary>
        /// Publishes a Map Service
        /// </summary>
        /// <param name="minInstances"></param>
        /// <param name="maxInstances"></param>
        /// <param name="waitTimeout"></param>
        /// <param name="usageTimeout"></param>
        /// <param name="idleTimeout"></param>
        /// <param name="sAgsConnFile"></param>
        /// <param name="sPythonScriptDir"></param>
        /// <returns>Published URL or Error as a string</returns>
        public string Publish(string sAgsConnFile, string sPythonScriptDir)
        {
            string sURLs = string.Empty;
            string sMapServiceName = string.Empty;
            string sMxdFile = string.Empty;
            string sMxdTemplateName = string.Empty;
            MxdManager pManager = null;

            try
            {
                if (String.IsNullOrEmpty(_sMXDTemplate)) return "Error: No MXD passed.";

                pManager = new MxdManager(_sMXDTemplate);

                // Set sMapServiceName
                sMapServiceName = _sMapServiceName;

                // Set sMxdTemplateName
                _sMXDTemplate = _sMXDTemplate.Replace("C:\\\\", "C:\\");
                sMxdTemplateName = _sMXDTemplate.Substring(_sMXDTemplate.LastIndexOf("\\") + 1);
                sMxdTemplateName = sMxdTemplateName.Remove(sMxdTemplateName.IndexOf(".mxd"));

                // Set sMxdFile
                sMxdFile = Path.Combine(_sOutputDirectory, sMapServiceName + "_" + sMxdTemplateName + ".mxd");

                if (!(pManager.CreateMxd(_sMXDTemplate, 
                                         _sOutputDirectory,
                                         _ArcGISServer, 
                                         sMxdFile,
                                         _sDBConn, 
                                         _sDataset, 
                                         sPythonScriptDir,
                                         _bSDE)))
                {
                    sURLs = sURLs + "MxdManager.CreateMxd failed for " + _sMXDTemplate + ". Please see logfile for details.,";
                }

                // publish using ArcGIS Server 10.1
                sURLs = sURLs + pManager.PublishMap10_1(sMapServiceName + "_" + sMxdTemplateName,
                                                        _ArcGISServer, 
                                                        sMxdFile, 
                                                        _sOutputDirectory, 
                                                        sAgsConnFile, 
                                                        Path.Combine(sPythonScriptDir, PUBLISHMXD_PY));
                
                return sURLs.TrimEnd(',');
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error in PublishMXD.Publish: " + ex.Message + " Stack trace: " + ex.StackTrace);
            }
            finally
            {
                pManager = null;
            }
        }
Example #8
0
        public void DeleteService(string sArcGisServer,
                                  string sAgsInstance,
                                  string sConfigID,
                                  string sFeatureDataset,
                                  string sServiceName,
                                  string sMxdOutput,
                                  string sSDEConnection,
                                  string sAgsUser,
                                  string sAgsPwd,
                                  string sPythonScriptDir)
        {
            // Check if service name starts with http://
            if (sServiceName.IndexOf("http://") > 1)
            {
                throw new ApplicationException("Service name did not begin with the expected http://! ServiceName: " + sServiceName);
            }

            // Parse out service name
            if (sServiceName.Contains("/"))
            {
                sServiceName = sServiceName.Substring(0, (sServiceName.LastIndexOf("/")));
                sServiceName = sServiceName.Substring(sServiceName.LastIndexOf("/") + 1);
            }

            // Set AgsURL
            string sAgsUrl = "http://" + sArcGisServer + ":6080/" + sAgsInstance;

            // Stop and Unpublish
            ServicePublisher.MXD.MapService10_1 mapService = null;
            mapService = new MXD.MapService10_1();
            mapService.UnPublish(sArcGisServer, sAgsUrl, sServiceName, "", sAgsUser, sAgsPwd, System.IO.Path.Combine(sPythonScriptDir, UNPUBLISHSVC_PY));

            // Make sure MXD is deleted
            ServicePublisher.MXD.MxdManager mxdManager = null;
            mxdManager = new MXD.MxdManager();
            mxdManager.DeleteMxd(sMxdOutput, sServiceName);

            // Delete the DataSet from the connection as well
            mxdManager.DeleteFeatureDataset(sFeatureDataset, sSDEConnection, System.IO.Path.Combine(sPythonScriptDir, REMOVEDATA_PY));
        }
    public void DeleteService(string sArcGisServer,
                                string sAgsInstance,
                                string sConfigID,
                                string sFeatureDataset,
                                string sServiceName,
                                string sMxdOutput,
                                string sSDEConnection,
                                string sAgsUser,
                                string sAgsPwd,
                                string sPythonScriptDir)
    {
      // Check if service name starts with http://
      if (sServiceName.IndexOf("http://") > 1)
      {
        throw new ApplicationException("Service name did not begin with the expected http://! ServiceName: " + sServiceName);
      }

      // Parse out service name
      if (sServiceName.Contains("/"))
      {
        sServiceName = sServiceName.Substring(0, (sServiceName.LastIndexOf("/")));
        sServiceName = sServiceName.Substring(sServiceName.LastIndexOf("/") + 1);
      }

        // Set AgsURL
        string sAgsUrl = "http://" + sArcGisServer + ":6080/" + sAgsInstance;
      // Stop and Unpublish
      ServicePublisher.MXD.MapService10_1 mapService = null;
      mapService = new MXD.MapService10_1();
      mapService.UnPublish(sArcGisServer, sAgsUrl, sServiceName, "", sAgsUser, sAgsPwd, System.IO.Path.Combine(sPythonScriptDir, UNPUBLISHSVC_PY));

      // Make sure MXD is deleted
      ServicePublisher.MXD.MxdManager mxdManager = null;
      mxdManager = new MXD.MxdManager();
      mxdManager.DeleteMxd(sMxdOutput, sServiceName);

      // Delete the DataSet from the connection as well
      mxdManager.DeleteFeatureDataset(sFeatureDataset, sSDEConnection, System.IO.Path.Combine(sPythonScriptDir, REMOVEDATA_PY));

    }
        // TODO: Add 10.1 method
        public string UnPublish()
        {
            string sDeleteFgdbResult = "";
            string sURLs = "";
            string sMapServiceName = "";
            string sMxdName;
            FileInfo fiMxd;
            MxdManager manager = null;
            bool errorOccured = false;

            try
            {
                if (String.IsNullOrEmpty(_sMXDTemplate)) 
                    return "Error: No MXD passed.";
                              
                    sMxdName = "";
                    manager = new MxdManager("");

                    sMapServiceName = _sMXDTemplate;
                    if (!(manager.UnPublishMap(sMapServiceName, _ArcGISServer, _sOutputDirectory, _sDataset, _sDBConn)))
                    {
                        sURLs = sURLs + "Error: MxdManager.UnPublishMap failed for " + sMapServiceName + ". Please see logfile for details.,";
                        errorOccured = true;
                    }
                    else
                    {
                        sURLs = sURLs + "Removal of " + sMapServiceName + " was successful.,";
                    }                

                // Remove trailing ','
                sURLs = sURLs.Remove(sURLs.Length - 1);

                if (!(errorOccured))
                {
                    //if locks exist only path is passed in
                    if (_sDBConn.Contains(".gdb"))
                    {
                        sDeleteFgdbResult = manager.DeleteGdb(_sDBConn);
                        if (sDeleteFgdbResult.Length > 0) sURLs = sURLs + "," + sDeleteFgdbResult;
                    }
                }
                return sURLs;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error in PublishMXD.UnPublish: " + ex.Message + " Stack trace: " + ex.StackTrace);
            }
            finally
            {
                fiMxd = null;
                manager = null;
            }
        }