List() public method

Retrieves a list of all services
public List ( ) : IList
return IList
        public void ListTest()
        {
            ServiceManager target = new ServiceManager();

            var actual = target.List();
            Assert.IsTrue(actual.Count > 0, "No Services?");
        }
Example #2
0
        public ActionResult ServersStatus(string serverName)
        {
            var authres = CheckAuthorizationAndLog(Audit.AuditTypeEnum.View, false, serverName, "Get server service status","","");
            if (authres != null)
                return authres;

            ServiceManager sm = new ServiceManager(serverName, Session["Username"] as string, Session["Password"] as string);
            var services = sm.List();

            var service = services.FirstOrDefault(i => i.Name == "DNS");
            if (service == null)
                return Content("Not installed");
            return Content(service.State.ToString());
        }
Example #3
0
        public ActionResult ServerServiceAction(string serverName, string serviceName, string action)
        {
            var authres = CheckAuthorizationAndLog(Audit.AuditTypeEnum.Change, true, serverName,"","", "change service state");
            if (authres != null)
                return authres;

            //Check service name is in allowed list
            if (!AllowedServiceControlNames.Contains(serviceName))
            {
                Audit.Log(Audit.AuditTypeEnum.UnauthorizedAccess, serverName, (Session["Domain"] as string) + "\\" + (Session["Username"] as string), NetworkHelper.ClientIPAddress(HttpContext), "Attempted to change service state for an unauthorized service","","");
                return new HttpUnauthorizedResult();
            }

            ServiceManager sm = new ServiceManager(serverName, Session["Username"] as string, Session["Password"] as string);
            var service = sm.List().Where(i => i.Name == serviceName).FirstOrDefault();
            if (service != null)
            {
                switch (action.ToLower())
                {
                    case "stop": service.StopService();
                        break;
                    case "start": service.StartService();
                        break;
                    case "pause": service.PauseService();
                        break;
                    case "resume": service.ResumeService();
                        break;
                    case "restart":
                        service.StopService();
                        service.StartService();
                        break;
                }
            }

            return Content(true.ToString());
        }