public async override Task <bool> InvokeAsync(string paramList)
        {
            var configs = _configBusiness.OpenDatabaseConfig().ToArray();

            if (configs.Length > 1)
            {
                OutputWarning("There are {0} databases configured. When using multiple targets you will have to update the config files manually.", configs.Length);
                return(false);
            }

            var currentConfig = configs.First();
            var config        = new InfluxDatabaseConfig(true, currentConfig.Url, string.Empty, string.Empty, string.Empty, null);

            var index     = 0;
            var logonInfo = await GetUsernameAsync(paramList, index ++, config, "config_database");

            if (logonInfo == null)
            {
                return(false);
            }

            var result = await ServiceCommands.GetServiceStatusAsync();

            if (result != null)
            {
                await ServiceCommands.RestartServiceAsync();
            }

            return(true);
        }
예제 #2
0
        private void ExecuteInsertRSMethod(object obj)
        {
            if (SelectedService == null)
            {
                MessageBox.Show("추가할 서비스를 선택해주세요.");
                return;
            }
            List <ReservedServiceVo> list = _reservedServiceRepository.GetReservedServices(SelectedRes.ResNum);

            if (list.FirstOrDefault(x => (x.SerId == SelectedService.ServiceId)) != null)
            {
                MessageBox.Show("이미 존재하는 서비스입니다.");
                return;
            }
            ReservedServiceVo rv = new ReservedServiceVo();

            rv.ResNum = SelectedRes.ResNum;
            rv.SerId  = SelectedService.ServiceId;
            ServiceVo s           = ServiceList.Single(x => x.ServiceId == rv.SerId);
            ushort    serviceTime = s.ServiceTime;

            if (HasReservations(SelectedRes.StylistId, SelectedRes.EndAt, SelectedRes.EndAt + new TimeSpan(serviceTime / 60, serviceTime % 60, 0)))
            {
                MessageBox.Show("이미 예약이 존재한 시간대입니다.");
                return;
            }
            _reservedServiceRepository.InsertReservedService(rv);
            ServiceCommands.Add(new DataCommandViewModel <ReservedServiceVo>(SelectedService.ServiceName, new Command(RemoveRS), rv));
            TimeSpan ts = new TimeSpan(SelectedService.ServiceTime / 60, SelectedService.ServiceTime % 60, 0);

            SelectedRes.EndAt = SelectedRes.EndAt + ts;
            _reservationRepository.UpdateReservation(SelectedRes);
        }
예제 #3
0
        private void onSelectedResChanged(uint resNum)
        {
            List <ReservedServiceVo> list = _reservedServiceRepository.GetReservedServices(resNum);

            ServiceCommands.Clear();
            foreach (var v in list)
            {
                string serviceName = ServiceList.Single(x => (x.ServiceId == v.SerId)).ServiceName;
                ServiceCommands.Add(new DataCommandViewModel <ReservedServiceVo>(serviceName, new Command(RemoveRS), v));
            }
        }
예제 #4
0
        private void RemoveRS(object obj)
        {
            ReservedServiceVo rsv = (ReservedServiceVo)obj;

            _reservedServiceRepository.RemoveReservedService(rsv.ResNum, rsv.SerId);
            ServiceCommands.Remove(ServiceCommands.Single(x => (x.Data == rsv)));

            ServiceVo     s  = ServiceList.Single(x => x.ServiceId == rsv.SerId);
            ReservationVo r  = ResList.Single(x => x.ResNum == rsv.ResNum);
            TimeSpan      ts = new TimeSpan(s.ServiceTime / 60, s.ServiceTime % 60, 0);

            r.EndAt = r.EndAt - ts;
            _reservationRepository.UpdateReservation(r);
        }
예제 #5
0
        private async Task <bool> StartService()
        {
            OutputInformation("Trying to start the service...");

            var result = await ServiceCommands.GetServiceStatusAsync();

            if (result != null)
            {
                await ServiceCommands.RestartServiceAsync();
            }
            else
            {
                OutputError("The service {0} cannot be found on this machine.", Constants.ServiceName);
                return(false);
            }

            return(true);
        }
예제 #6
0
        public bool ExecuteCommand(string serviceName, ServiceCommands command)
        {
            try
            {
                var services = ServiceController.GetServices();
                var service  = services.Where(s => s.ServiceName == serviceName).FirstOrDefault();
                if (service != null)
                {
                    service.ExecuteCommand((int)command);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.Write(MethodInfo.GetCurrentMethod(), ex);
            }

            return(false);
        }
        public async override Task <bool> InvokeAsync(string paramList)
        {
            var index = 0;
            var flushSecondsInterval = QueryParam <int>("Flush Seconds Interval", GetParam(paramList, index++));
            var debugMode            = QueryParam("Debug Mode", GetParam(paramList, index++), new Dictionary <bool, string> {
                { false, "No" }, { true, "Yes" }
            });

            _configBusiness.SaveApplicationConfig(flushSecondsInterval, debugMode, true, 20000);

            var result = await ServiceCommands.GetServiceStatusAsync();

            if (result != null)
            {
                await ServiceCommands.RestartServiceAsync();
            }

            return(true);
        }
        private bool InvokeServiceMethod(ServiceCommands command)
        {
            var  success         = false;
            Type serviceBaseType = _service.GetType();

            object[] parameters = null;
            if (command == ServiceCommands.Start)
            {
                parameters = new object[] { null };
            }

            string method = "OnStart";

            switch (command)
            {
            case ServiceCommands.Stop:
                method = "OnStop";
                break;

            case ServiceCommands.Pause:
                method = "OnPause";
                break;

            case ServiceCommands.Start:
            default:
                method = "OnStart";
                break;
            }

            try
            {
                serviceBaseType.InvokeMember(method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, _service, parameters);
                success = true;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("An exception was thrown while trying to call the {0} of the {1} service.  Examine the inner exception for more information.", method, _service.ServiceName), ex.InnerException);
            }
            return(success);
        }
예제 #9
0
        private void ExecuteServiceCommand(ServiceCommands ServiceCommand)
        {
            log.Info($"Will execute {ServiceCommand} for {ServiceInfos.Count()} service(s): {string.Join(", ", ServiceInfos.Select(SI => SI.ServiceName))}");


            object[] Arguments = null;
            string   ServiceCommandName;

            switch (ServiceCommand)
            {
            case ServiceCommands.Start:
                ServiceCommandName = "OnStart";
                Arguments          = new object[] { new string[] { "" } };
                break;

            case ServiceCommands.Stop:
                ServiceCommandName = "OnStop";
                Arguments          = null;

                break;

            default:

                Exception ex = new Exception($"Unknown {nameof(ServiceCommand)} {ServiceCommand}. Cant get name of method to invoke.");
                log.Error(ex.Message, ex);
                throw ex;
            }


            foreach (ServiceInfo ServiceInfo in ServiceInfos)
            {
                log.Debug($"Trying to {ServiceCommand.ToString().ToLowerInvariant()} service {ServiceInfo.ServiceName}");

                if (ServiceInfo.LastCommand != ServiceCommand)
                {
                    Type ServiceType = ServiceInfo.Service.GetType();

                    ServiceInfo.LastCommand       = ServiceCommand;
                    ServiceInfo.LastCommandResult = null;
                    try
                    {
                        ServiceType.InvokeMember(
                            ServiceCommandName,
                            System.Reflection.BindingFlags.Instance
                            | System.Reflection.BindingFlags.InvokeMethod
                            | System.Reflection.BindingFlags.NonPublic
                            | System.Reflection.BindingFlags.Public,
                            null,
                            ServiceInfo.Service,
                            Arguments
                            );
                    }
                    catch (Exception E)
                    {
                        ServiceInfo.LastCommandResult = $"{E.GetType().Name}: {E.Message}";
                        log.Warn($"A exception occured while trying to {ServiceCommand.ToString().ToLowerInvariant()} service {ServiceInfo.ServiceName}. {E.Message}", E);
                    }
                }
                else
                {
                    log.Warn($"Command {ServiceCommand.ToString().ToLowerInvariant()} not executed from service {ServiceInfo.ServiceName} since the same command has been executed last.");
                    ServiceInfo.LastCommandResult = "Command not executed. Same command was the last command";
                }
            }
            if (ServiceInfos.Any(SI => SI.LastCommandResult != null))
            {
                log.Warn($"Executed {ServiceCommand.ToString().ToLowerInvariant()} for {ServiceInfos.Count()} service(s). Failed for {ServiceInfos.Where(SI => SI.LastCommandResult != null).Count()} service(s):\n {string.Join("\n", ServiceInfos.Where(SI => SI.LastCommandResult != null).Select(SI => $"{SI.ServiceName} -> {SI.LastCommandResult}"))}");
            }
            else
            {
                log.Info($"Executed {ServiceCommand.ToString().ToLowerInvariant()} for {ServiceInfos.Count()} service(s): {string.Join(", ", ServiceInfos.Select(SI => SI.ServiceName))}");
            }

            ServiceInfos.ForEach(SI => SI.LastCommandResult = SI.LastCommandResult ?? $"{ServiceCommand} executed");
        }