Esempio n. 1
0
        public static int StopService()
        {
            Log.Write(TraceEventType.Information, "Stop Service");

            if (IISHosted)
            {
                WebSite site = GetInstallWebSite();
                if (site != null)
                {
                    WebsiteState state = IISHelper.StopWebSite(site.Name);
                    switch (state)
                    {
                    case WebsiteState.Stopped:
                        return(1);

                    case WebsiteState.Started:
                        return(4);

                    default:
                        return(0);
                    }
                }
                return(0);
            }
            else
            {
                try
                {
                    System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("Workshare Compare Service");
                    sc.Stop();
                    sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped);

                    return((int)sc.Status);
                }
                catch (Exception ex)
                {
                    Log.Write(TraceEventType.Error, "{0}", ex);
                    return(GetServiceStatus());
                }
            }
        }
Esempio n. 2
0
        public static IEnumerable <WebSite> GetWebSites()
        {
            List <WebSite> result = new List <WebSite>();

            try
            {
                Version iisVer = GetIISVersion();
                if (iisVer.Major == 7)
                {
                    IEnumerable <Site> sites = GetWebSitesIIS7();
                    foreach (Site s in sites)
                    {
                        try
                        {
                            var site = new WebSite();
                            site.Identity = s.Id;
                            site.Name     = s.Name;

                            try
                            {
                                site.State = (WebsiteState)Enum.Parse(typeof(WebsiteState), s.State.ToString());
                            }
                            catch
                            {
                                site.State = WebsiteState.Unknown;
                            }

                            result.Add(site);
                        }
                        catch (Exception ex)
                        {
                            Log.Write(TraceEventType.Error, "GetWebSitesIIS7: Failed to process site. Exception ({0}): '{1}' \n {2}", ex.GetType(), ex.Message, ex.StackTrace);
                        }
                    }
                    return(result);
                }
                else if (iisVer.Major == 6)
                {
                    IEnumerable <DirectoryEntry> entries = GetWebSitesIIS6();
                    foreach (DirectoryEntry entry in entries)
                    {
                        if (entry != null && entry.SchemaClassName == IIS.WebServer)
                        {
                            WebSite site = new WebSite();
                            site.Identity = Convert.ToInt32(entry.Name);
                            site.Name     = entry.InvokeGet("ServerComment").ToString();
                            site.State    = (WebsiteState)entry.InvokeGet("ServerState");
                            result.Add(site);
                        }
                    }
                    return(result);
                }
                else
                {
                    return(new List <WebSite>());
                }
            }
            catch (Exception ex)
            {
                Log.Write(TraceEventType.Error, "{0}", ex);
                return(new List <WebSite>());
            }
        }