Exemplo n.º 1
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="urls">包含多个IP时分号分割,如:http://localhost:8080;http://localhost:8081</param>
        /// <param name="serviceName"></param>
        /// <param name="serviceDisplayName"></param>
        public MicroServiceBase(string urls, string serviceName, string serviceDisplayName)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                var ex = new Exception("ServiceName 不能为空!");
                WriteToLog("启动服务失败", ex);
                throw ex;
            }
            if (!string.IsNullOrWhiteSpace(urls))
            {
                this.runningUrls = urls.Split(';');
            }

            //设置日志记录器
            this.logger = log4net.LogManager.GetLogger(serviceName);

            this.serviceName        = serviceName;
            this.serviceDisplayName = serviceDisplayName ?? this.serviceName;
            this.serviceStatus      = new ServiceStatus(serviceName, string.Join(",", this.RunningUrls));

            this.cancellationTokenSource = new CancellationTokenSource();
            this.cancellationToken       = this.cancellationTokenSource.Token;

            //默认绑定一些事件的处理方法,用于直接在子类中重写达到调用事件的目的
            this.OnServiceStarting       += this.ServiceStartingDefaultAction;
            this.OnServiceStarted        += this.ServiceStartedDefaultAction;
            this.OnServiceStoping        += this.ServiceStopingDefaultAction;
            this.OnServiceStoped         += this.ServiceStopedDefaultAction;
            this.OnServiceStatusUpdating += this.ServiceStatusUpdateDefaultAction;
            this.OnRequestStart          += this.RequestStartDefaultAction;
            this.serviceManager           = new WindowsServiceManager(this);
        }
Exemplo n.º 2
0
    static void Main()
    {
        WindowsServiceManager service = new WindowsServiceManager();

        service.Run("W32Time", 2000);
        service.End("W32Time", 2000);
    }
        public void test01()
        {
            List <WindowsService> lista = WindowsServiceManager.GetWindowsServicesList();

            foreach (WindowsService item in lista)
            {
                Console.WriteLine(item.Name + " " + item.DisplayName + " " + item.Status);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main(string[] args)
        {
            //作为服务运行
            if (args != null && args.Count() > 0 && !string.IsNullOrEmpty(args[0]))
            {
                var cmd = args[0];
                if (cmd.ToLower() == "s")
                {
                    RunService();
                }
                return;
            }

            WindowsServiceManager svrManager = new WindowsServiceManager(HostContext.SvrName);

            svrManager.Manage();
        }
        static void Main(string[] args)
        {
            string arg0 = string.Empty;

            if (args.Length > 0)
            {
                arg0 = (args[0] ?? string.Empty).ToLower();
            }

            if (arg0 == "-service")
            {
                RunService();
                return;
            }
            if (arg0 == "-fakeservice")
            {
                FakeRunService();
                return;
            }
            else if (arg0 == "-installservice" || arg0 == "-i")
            {
                WindowsServiceManager SM = new WindowsServiceManager();
                if (!SM.InstallService(Environment.CurrentDirectory + "\\MarvelPressQueueService.exe -service",
                                       "MarvelPressQueueService", "Marvelpress Workflow Queue Manager Service"))
                {
                    MessageBox.Show("Service install failed.");
                }

                return;
            }
            else if (arg0 == "-uninstallservice" || arg0 == "-u")
            {
                WindowsServiceManager SM = new WindowsServiceManager();
                if (!SM.UnInstallService("MarvelPressQueueService"))
                {
                    MessageBox.Show("Service failed to uninstall.");
                }

                return;
            }

            RunDesktop(args);
        }
Exemplo n.º 6
0
        private void SavePCIDButton_Click(object sender, RoutedEventArgs e)
        {
            UserConfig.PCID = PCIDTextBox.Text;
            ConfigurationSaver configurationSaver = new ConfigurationSaver();

            if (!configurationSaver.SaveUserConfiguration(UserConfig))
            {
                ShowErrorDialog("Error", "Error when save user configuration!");
                EventLogger.WriteLog("CLIENT SAVE CLIENT CONFIG ERROR", "Error when save user configuration!");
            }
            else
            {
                if (WindowsServiceManager.RestartService(SERVICE_NAME))
                {
                    //Get new User Config
                    var userConfigReader = new ConfigurationReader(isService: false, userConfigPath: ServiceConfig.UserConfigPath, userConfigFile: ServiceConfig.UserConfigFileName);
                    UserConfig = userConfigReader.GetUserConfig();
                    string computerName = Environment.MachineName;
                    string currentUser  = Environment.UserName;
                    string macAddr      = MacAddress.GetFirstMacAddress();
                    var    PCID         = UserConfig.PCID.Equals("default") ? $"{computerName}-{currentUser}-{macAddr}" : UserConfig.PCID;

                    if (PCID.Equals(PCIDTextBox.Text))
                    {
                        SavePCIDButton.IsEnabled = false;
                        PCIDTextBox.Text         = UserConfig.PCID;
                    }
                    else
                    {
                        PCIDTextBox.Text = PCID;
                        ShowErrorDialog("Error", "Error when update new PC ID! Check Log for more detail");
                    }
                }
                else
                {
                    SavePCIDButton.IsEnabled = true;
                }
            }
        }
Exemplo n.º 7
0
        public MainWindow()
        {
            _fileManager            = new FileManager();
            _windowsRegistryManager = new WindowsRegistryManager();
            _boFileInfo             = new BoFileInfo();
            _windowsServiceManager  = new WindowsServiceManager();
            _boUserSettings         = new BoUserSettings();
            var args = Environment.GetCommandLineArgs();

            if (args.Length > 1)
            {
                ProcessCommandFromWindowsContextMenu(args[1]);
            }
            InitializeComponent();
            _fileManager.LogDelegate            = LogChanges;
            _windowsRegistryManager.LogDelegate = LogChanges;
            _appConfigurator.LogDelegate        = LogChanges;
            _windowsServiceManager.LogDelegate  = LogChanges;
            AutoUpdater.Start("http://seekurity.com/Appcast.xml");
            var backgroundWorker = new BackgroundWorker();

            SetAllButtonsEnabledState(false);
            _timerTxtServiceUpdater = new Timer {
                Interval = 60000
            };
            _timerTxtServiceUpdater.Tick   += _timerTxtServiceUpdater_Tick;
            _timerTxtServiceUpdater.Enabled = true;
            backgroundWorker.DoWork        += (s, eventArgs) =>
            {
                _appConfigurator.TestAppOnStartUp();
                LoadUserSettingsInfo();

                logList = new ObservableCollection <DtoLog>(_boLog.GetList());
                Dispatcher.Invoke(new Action(() => dataGridLogs.ItemsSource = logList));
            };

            backgroundWorker.RunWorkerAsync();
        }
Exemplo n.º 8
0
 /// <summary>
 /// Runs the services setup.
 /// </summary>
 /// <param name="profile">The profile.</param>
 public static void RunServicesSetup(NetworkProfile profile)
 {
     WindowsServiceManager.Apply(profile.ServiceList);
 }
Exemplo n.º 9
0
        private void tsbForceService_Click(object sender, EventArgs e)
        {
            List <IWindowsServiceInfo> services = Items;

            WindowsServiceManager.Apply(services);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Loads the services.
        /// </summary>
        public void LoadServices()
        {
            List <WindowsService> listaServizi = WindowsServiceManager.GetWindowsServicesList();

            listView.SetObjects(listaServizi);
        }