示例#1
0
 public Plugin(string path)
 {
     base.Name        = "Service Plugin";
     base.Author      = "Amir Rezaei";
     base.Description = "Show all services.";
     base.Version     = "1.0";
     Entity           = new ServiceEntity(path);
 }
示例#2
0
        public override IEnumerable <Entity> GetEntities()
        {
            var entities = new List <Entity>();

            if (!IsRoot)
            {
                entities.Add(new ServiceEntity(Parent)
                {
                    Name = "[..]", IsDirectory = true, IsParent = true
                });
            }

            try
            {
                if (String.IsNullOrEmpty(Path))
                {
                    IEnumerable <ServiceController> services = ServiceController.GetServices();
                    foreach (ServiceController service in services)
                    {
                        try
                        {
                            Entity serviceEntity = new ServiceEntity(service.ServiceName);
                            serviceEntity.Name        = service.DisplayName;
                            serviceEntity.IsDirectory = service.DependentServices.Length > 0;

                            serviceEntity.Values.Add(nameof(TagNames.CanPauseAndContinue), service.CanPauseAndContinue.ToString());
                            serviceEntity.Values.Add(nameof(TagNames.CanShutdown), service.CanShutdown.ToString());
                            serviceEntity.Values.Add(nameof(TagNames.CanStop), service.CanStop.ToString());
                            entities.Add(serviceEntity);
                        }
                        catch (Exception e)
                        {
                            Logger.Error(e.Message);
                        }
                    }
                }
                else
                {
                    var theService = ServiceController.GetServices().FirstOrDefault(x => x.ServiceName == Path);
                    if (theService != null)
                    {
                        foreach (ServiceController service in theService.DependentServices)
                        {
                            try
                            {
                                Entity serviceEntity = new ServiceEntity(service.ServiceName);
                                serviceEntity.Name        = service.DisplayName;
                                serviceEntity.IsDirectory = service.DependentServices.Length > 0;
                                serviceEntity.Values.Add(nameof(TagNames.CanPauseAndContinue), service.CanPauseAndContinue.ToString());
                                serviceEntity.Values.Add(nameof(TagNames.CanShutdown), service.CanShutdown.ToString());
                                serviceEntity.Values.Add(nameof(TagNames.CanStop), service.CanStop.ToString());
                                entities.Add(serviceEntity);
                            }
                            catch (Exception e)
                            {
                                Logger.Error(e.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
            }

            return(entities);
        }