/// <summary> /// タイマー実行される関数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DispatcherTimer_Tick(object sender, EventArgs e) { if (serviceController != null) { serviceController.Dispose(); } serviceController = new ServiceController("AutoHostsUpdateService"); switch (serviceController.Status) { case ServiceControllerStatus.Stopped: // サービスは実行されていません serviceStatusStatusBarItem.Content = Properties.Resources.StatusStopped; serviceStartStopButton.Content = Properties.Resources.ServiceStartButton; serviceStartStopButton.IsEnabled = true; break; case ServiceControllerStatus.StartPending: // サービスは開始中です serviceStatusStatusBarItem.Content = Properties.Resources.StatusStartPending; break; case ServiceControllerStatus.StopPending: // サービスは停止中です serviceStatusStatusBarItem.Content = Properties.Resources.StatusStopPending; break; case ServiceControllerStatus.Running: // サービスは実行中です serviceStatusStatusBarItem.Content = Properties.Resources.StatusRunning; serviceStartStopButton.Content = Properties.Resources.ServiceStopButton; serviceStartStopButton.IsEnabled = true; break; case ServiceControllerStatus.ContinuePending: // サービスの継続は保留中です serviceStatusStatusBarItem.Content = Properties.Resources.StatusContinuePending; break; case ServiceControllerStatus.PausePending: // サービスは実行されていません serviceStatusStatusBarItem.Content = Properties.Resources.StatusStopped; break; case ServiceControllerStatus.Paused: // サービスの一時中断は保留中です serviceStatusStatusBarItem.Content = Properties.Resources.StatusPausePending; break; default: // それ以外の状態 serviceStatusStatusBarItem.Content = Properties.Resources.StatusUndefined; serviceStartStopButton.IsEnabled = false; break; } }
private void button5_Click(object sender, EventArgs e) { Service = new ServiceController(textBox2.Text); try { Service.Stop(); Service.Dispose(); } catch (Exception E) { Service.Dispose(); MessageBox.Show(E.Message); } }
private bool disposedValue; // To detect redundant calls /// <summary>Clean up objects explicitly</summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!disposedValue) { Logger.Log("Disposing of objects", Logger.MessageLevel.Verbose, AppName); if (disposing) { sc.Dispose(); // Logger.Dispose(); } disposedValue = true; } sc.Dispose(); }
/// <summary>是否已安装</summary> public static bool?IsInstalled(string serviceName) { ServiceController control = null; try { // 取的时候就抛异常,是不知道是否安装的 control = GetService(serviceName); if (control == null) { return(false); } try { //尝试访问一下才知道是否已安装 var b = control.CanShutdown; return(true); } catch { return(false); } } catch { return(null); } finally { control?.Dispose(); } }
/// <summary> /// closes control panel application /// </summary> /// <param name="errorMessage">message to show within message box</param> public static void ExitController(string errorMessage) { notifyIcon.MouseMove -= ShowBalloon; if (timer != null) { timer.Stop(); timer.Dispose(); } if (balloonTimer != null) { balloonTimer.Stop(); balloonTimer.Dispose(); } if (errorMessage != null) { ShowMessageBox(errorMessage); } notifyIcon.Visible = false; notifyIcon.Dispose(); serviceController.Dispose(); ctrlPanel.Dispose(); Application.Exit(); // Application doesn't exit after uninstall if Control Panel Screen is opened Environment.Exit(1); }
// ==================================================================================================================== // WinFCU Show Servcice - Show the WinFCU service information (when installed as service!) // -------------------------------------------------------------------------------------------------------------------- public static void showService() { try { // Get all possible service info ServiceController sc = new ServiceController(ProjectInstaller.SvcServiceName); string svcKey = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\" + ProjectInstaller.SvcServiceName; string startType = "Automatic"; int svc_StartType = (int)Registry.GetValue(svcKey, "Start", -1); if (svc_StartType == (int)ServiceStartMode.Manual) { startType = "Manual"; } if (svc_StartType == (int)ServiceStartMode.Disabled) { startType = "Disabled"; } if ((svc_StartType == (int)ServiceStartMode.Automatic) && ((int)Registry.GetValue(svcKey, "DelayedAutostart", 0) == 1)) { startType = "Automatic (Delayed Start)"; } // Show what we have got..... string svcInfo = String.Format("\r\n WinFCU Service Info\r\n {0}\r\n", new string('-', 100)); svcInfo += String.Format(" - Servicename : {0,-15} - Displayname : {1}\r\n", sc.ServiceName, sc.DisplayName); svcInfo += String.Format(" - Can Stop : {0,-15} - Status : {1}\r\n", sc.CanStop, sc.Status); svcInfo += String.Format(" - Can Shutdown : {0,-15} - Service Type : {1}\r\n", sc.CanShutdown, sc.ServiceType); svcInfo += String.Format(" - Can Pause/Continue : {0,-15} - Startup Type : {1}\r\n", sc.CanPauseAndContinue, startType); Console.WriteLine(svcInfo); sc.Dispose(); } catch (Exception) { Console.WriteLine(ProjectInstaller.SvcServiceName + " is not installed as service"); } return; }
public static bool Stop(string serviceName, string serviceDisplayName) { using (ServiceController serviceController = GetService(serviceName, serviceDisplayName)) { if (serviceController == null || !serviceController.CanStop) { return(false); } try { serviceController.Refresh(); if (serviceController.Status != ServiceControllerStatus.Stopped) { serviceController.Stop(); serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(120)); serviceController.Close(); serviceController.Dispose(); } return(true); } catch { return(false); } } }
/// <summary> /// Dispose /// </summary> public void Dispose() { if (thread != null) { if (thread.ThreadState != ThreadState.Stopped) { thread.Join(); } thread = null; } if (transportServiceStatus != null) { transportServiceStatus.Change(Timeout.Infinite, Timeout.Infinite); transportServiceStatus.Dispose(); transportServiceStatus = null; } if (service != null) { service.Dispose(); service = null; } }
/// <summary>是否已安装</summary> public static Boolean?IsServiceInstalled(String name) { ServiceController control = null; try { // 取的时候就抛异常,是不知道是否安装的 control = GetService(name); if (control == null) { return(false); } try { //尝试访问一下才知道是否已安装 var b = control.CanShutdown; return(true); } catch { return(false); } } catch { return(null); } finally { if (control != null) { control.Dispose(); } } }
public void Dispose() { if (splunkService != null) { splunkService.Dispose(); } }
public static void StartService(string serviceName, string serverName, int timeoutSec) { try { ServiceController service = new ServiceController(serviceName, serverName); if (service.Status == ServiceControllerStatus.Stopped || service.Status == ServiceControllerStatus.StartPending) { try { if (service.Status == ServiceControllerStatus.Stopped) { Log.Info("argustv: service {0} is stopped, so we try start it now...", serviceName); service.Start(); } service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, timeoutSec)); } catch (Exception ex) { Log.Error("argustv: starting service {0} failed, {1}", serviceName, ex.Message); } } Log.Info("argustv: service {0} - current status: {1}", serviceName, service.Status.ToString()); service.Close(); service.Dispose(); } catch { Log.Info("argustv: service {0} not found on {1}", serviceName, serverName); } }
public static bool IsInstalledService(string ServicesName) { ServiceController ctl = null; try { ctl = ServiceController.GetServices().Where(s => s.ServiceName == ServicesName).FirstOrDefault(); if (ctl == null) { return(false); } else { return(true); } } catch { return(false); } finally { if (ctl != null) { ctl.Dispose(); ctl = null; GC.Collect(); GC.WaitForPendingFinalizers(); } } }
public void TestMergeMessageWithParametersCallsMerge() { var merged = false; var service = new ServiceController() { Settings = { ServiceUpdateCore = false }, Packages = new MockServicePackageManager() { PackageInstalled = (sender, uri, packageId) => { merged = true; } } }; service.SignalMessage(new ServiceMessage() { Name = "merge", Arguments = new Dictionary<string, string>() { { "uri", "localhost" }, { "packageid", "id" } } }); Assert.IsTrue(merged); service.Dispose(); }
/// <summary> /// Gets status of service /// </summary> /// <param name="serviceName"></param> /// <returns></returns> private void GetServiceControllerStatus(string serviceName) { try { serviceController = new ServiceController(serviceName); } catch (ArgumentException) { //return "Invalid service name."; // Note that just because a name is valid does not mean the service exists. serviceStatus.text = "Invalid service name"; } using (serviceController) { try { serviceController.Refresh(); Debug.Log("Service status : " + serviceController.Status + " service name : " + serviceName); serviceStatus.text = serviceController.Status + ""; } catch (Exception) { // A Win32Exception will be raised if the service-name does not exist or the running process has insufficient permissions to query service status. // See Win32 QueryServiceStatus()'s documentation. //return "Error: " + ex.Message; serviceStatus.text = "Service-name does not exist or the running process has insufficient permissions to query service status"; } } serviceController.Close(); serviceController.Dispose(); serviceController = null; }
public static void StopService(string serviceName, int timeoutMilliseconds) { ServiceController service = new ServiceController(serviceName); try { if (service.Status == ServiceControllerStatus.Running) { TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds); service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped, timeout); } } catch (Exception ex) { Kaishakanri.Commons.LogMan.Instance.WriteErrorToLog(ex); } finally { if (service != null) { service.Close(); service.Dispose(); service = null; GC.Collect(); GC.WaitForPendingFinalizers(); } } }
public static bool Start(string serviceName, string serviceDisplayName) { try { using (ServiceController serviceController = GetService(serviceName, serviceDisplayName)) { if (serviceController == null) { return(false); } serviceController.Refresh(); if (serviceController.Status != ServiceControllerStatus.Running) { serviceController.Start(); serviceController.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(15)); serviceController.Close(); serviceController.Dispose(); } } } catch { return(false); } return(true); }
public void Dispose() { if (service != null) { service.Dispose(); } }
private void toolStripMenuItem11_Click(object sender, EventArgs e) { if (firewall == 0) { ServiceController sc = new ServiceController("MpsSvc"); try { sc.Start(); } catch { MessageBox.Show("У Вас нет доступа к управлению Брандмауэром", "Отказано в доступе", MessageBoxButtons.OK, MessageBoxIcon.Error); } sc.Dispose(); } else { ServiceController sc = new ServiceController("MpsSvc"); try { sc.Stop(); } catch { MessageBox.Show("У Вас нет доступа к управлению Брандмауэром", "Отказано в доступе", MessageBoxButtons.OK, MessageBoxIcon.Error); } sc.Dispose(); } }
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e) { ServiceController sc = new ServiceController(TaskSchedulerAssistant.TaskSchedulerAssistantService.ServName); sc.Start(); sc.Dispose(); }
//Services 내 이름으로 검색하여 서비스 멈춤 public void StopService(string serviceName, int timeoutMillsec) { ServiceController service = new ServiceController(serviceName); TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMillsec); try { service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped, timeout); if (!CheckServiceStopped(serviceName)) { //logger.Info(" Service Stopped Successfully."); } } catch (Exception e) { //logger.Error(" StopService Error: " + e); throw; } finally { service.Dispose(); } }
private static bool Start(string service) { ServiceController controller = null; try { controller = new ServiceController(service); if (controller.Status == ServiceControllerStatus.Running || controller.Status == ServiceControllerStatus.ContinuePending || controller.Status == ServiceControllerStatus.PausePending || controller.Status == ServiceControllerStatus.StartPending || controller.Status == ServiceControllerStatus.StopPending ) { return(false); } controller.Start(); controller.WaitForStatus(ServiceControllerStatus.Running, ServiceTransitionTimeout); return(controller.Status == ServiceControllerStatus.Running); } catch (System.Exception exc) { //TODO: Log errors return(false); } finally { controller?.Dispose(); } }
private ServiceController CreateServiceController([NotNull] string serviceName) { var serviceController = new ServiceController(serviceName); try { GC.KeepAlive(serviceController.Status); return(serviceController); } catch (InvalidOperationException) { serviceController.Dispose(); return(null); } // List<ServiceController> services = null; // try // { // services = ServiceController.GetServices().ToList(); // // var myService = // services.FirstOrDefault(srv => StringComparer.InvariantCultureIgnoreCase.Equals(srv?.ServiceName, serviceName)); // // if (myService != null) // services.Remove(myService); // // return myService; // } // finally // { // if (services != null) // foreach (var srv in services) // srv.Dispose(); // } }
protected virtual void Dispose(bool disposing) { if (disposing && _serviceController != null) { _serviceController.Dispose(); } }
internal static ServiceControllerStatus GetServiceStatus(string serviceName) { //Program.SystemTrayIconLogger.Log.Info($"{nameof(IsServiceRunning)}: {serviceName}"); if (string.IsNullOrEmpty(serviceName)) { throw new ArgumentNullException(nameof(serviceName), $"{nameof(serviceName)} cannot be a null reference"); } ServiceController service = ServiceController.GetServices().FirstOrDefault(p => p.ServiceName == serviceName); try { if (service != null) { //Program.Log.Info($"Service: {serviceName} status is {service.Status.ToString()}"); return(service.Status); } } catch (Exception ex) { Program.Log.Error("GetServiceStatus", ex); } finally { if (service != null) { service.Dispose(); service = null; } } return(ServiceControllerStatus.Stopped); }
public IconTray() { _sc = new ServiceController("MSSQLSERVER"); _notifyIcon = new NotifyIcon { Icon = GetIcon(), Text = Application.ProductName, Visible = true }; _notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; _notifyIcon.MouseMove += (s, e) => { _notifyIcon.Icon = GetIcon(); }; var exit = new ToolStripMenuItem { Font = new Font("Segoe UI", 9F), Text = _isChinese ? "退出" : "Exit" }; exit.Click += (s, e) => { _notifyIcon.Dispose(); _sc.Dispose(); Application.Exit(); }; var contextMenuStrip = new ContextMenuStrip(); contextMenuStrip.Items.Add(exit); _notifyIcon.ContextMenuStrip = contextMenuStrip; }
/// <summary> /// 停止服务 /// </summary> /// <param name="serviceName">服务名称</param> public static void Stop(string serviceName) { if (!IsExist(serviceName)) { return; } ServiceController service = new ServiceController(serviceName); try { if (service.CanStop && service.Status == ServiceControllerStatus.Running || service.Status == ServiceControllerStatus.Paused || service.Status == ServiceControllerStatus.PausePending || service.Status == ServiceControllerStatus.ContinuePending || service.Status == ServiceControllerStatus.StartPending) { service.Stop(); service.Refresh(); } } catch (Exception ex) { } finally { service.Dispose(); } }
/// <summary> /// 启动服务 /// </summary> /// <param name="serviceName">服务名称</param> public static void Start(string serviceName) { if (!IsExist(serviceName)) { return; } ServiceController service = new ServiceController(serviceName); try { if (service.Status == ServiceControllerStatus.Stopped || service.Status == ServiceControllerStatus.StopPending) { service.Start(); service.Refresh(); } } catch (Exception ex) { } finally { service.Dispose(); } }
/// <summary> /// 暂停服务 /// </summary> /// <param name="serviceName">服务名称</param> public static void Pause(string serviceName) { if (!IsExist(serviceName)) { return; } ServiceController service = new ServiceController(serviceName); try { if (service.CanPauseAndContinue && service.Status == ServiceControllerStatus.Running) { service.Pause(); service.Refresh(); } } catch (Exception ex) { } finally { service.Dispose(); } }
//start the service method private static bool StartService() { bool result = false; ServiceController service = new ServiceController(internalServiceName); try { TimeSpan timeout = TimeSpan.FromMilliseconds(internalLocalTimeout); service.Start(); service.WaitForStatus(ServiceControllerStatus.Running, timeout); var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Info("The: " + internalServiceName + " started successfully"); result = true; } catch (Exception ex) { var logger = NLog.LogManager.GetCurrentClassLogger(); logger.Info(String.Format("{0} {1} {2} {3}", "The windows service:", internalServiceName, "did not start. Esception:", ex.Message)); } finally { service.Dispose(); } return(result); }
private void InstallService() { var dialogResult = MessageBox.Show("尚未安装DDNS服务,该服务将会在开机的时候自动运行,并且每30秒自动更新您的最新IP您的指定记录.在安装之前请确保您正在使用管理员权限运行本程序.是否继续?", "", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { var path = Path.Combine(Directory.GetCurrentDirectory(), "installService.bat"); if (File.Exists(path)) { ShellExecute(IntPtr.Zero, "Open", path, String.Empty, Directory.GetCurrentDirectory(), 0); var task = new Task(() => { System.Threading.Thread.Sleep(5000); try { if (service != null) { service.Dispose(); } service = ServiceControl.GetService(); ServiceStatus = ServiceControl.GetServiceStatus(service); MessageBox.Show("如果左下角的服务状态在1分钟之后还是处于非绿灯状态,请确保您正在使用管理员权限运行本程序,并且程序目录内的文件完整,最后查看程序目录下的DDNSPod.Service.InstallLog和sevice.log日志文件,并向社区求助."); if (service != null) { try { service.Start(); } catch (Exception e) { MessageBox.Show(e.Message); } } } catch (Win32Exception ex) { logger.ErrorException(ex.Message, ex); } }); task.Start(); } else { MessageBox.Show("服务安装脚本丢失,请确保您的DDNSPod的程序目录完整!"); } } }
public void TestServiceProxyType() { var service = new ServiceController(); Assert.AreEqual(typeof(ServiceLoaderProxy), service.ServiceLoaderProxyType); service.Dispose(); }
/// <summary> /// Returns a flag that highlights whether the /// window service with a particular name is /// running. /// </summary> /// <param name="name">Name of the windows service /// to check.</param> /// <returns>True if running, otherwise false.</returns> private static bool Running(string serviceName) { var service = new ServiceController(serviceName); var result = (service.Status == ServiceControllerStatus.Running); service.Dispose(); return(result); }
public void TestInitalServiceStateIsStopped() { var service = new ServiceController(); Assert.AreEqual(ServiceStatusType.Stopped, service.Observer.Status); service.Dispose(); }
public void TestMonitoringIsEnabled() { var service = new ServiceController(); Assert.IsTrue(AppDomain.MonitoringIsEnabled); service.Dispose(); }
public void TestHelpMessageReturnsTrue() { var service = new ServiceController(); Assert.IsTrue(service.SignalMessage(new ServiceMessage() { Name = "help" })); service.Dispose(); }
public void TestJunkMessageReturnsFalse() { var service = new ServiceController(); Assert.IsFalse(service.SignalMessage(new ServiceMessage() { Name = "junk" })); service.Dispose(); }
public void TestNonNullProperties() { var service = new ServiceController(); Assert.IsNotNull(service.Observer); Assert.IsNotNull(service.Polling); Assert.IsNotNull(service.WriteConfig); Assert.IsNotNull(service.Arguments); Assert.IsNotNull(service.Settings); Assert.IsNotNull(service.Packages); service.Dispose(); }
public void TestMergeMessageReturnsTrue() { var service = new ServiceController() { Settings = { ServiceUpdateCore = false } }; Assert.IsTrue(service.SignalMessage(new ServiceMessage() { Name = "merge" })); service.Dispose(); }
public void TestConfigWriteDispatchedEndDelegateCalled() { var end = false; var service = new ServiceController() { ServiceLoaderProxy = new MockServiceLoaderProxy(), WriteServiceConfigEnd = controller => end = true }; service.WriteServiceConfig(); Assert.IsTrue(end); service.Dispose(); }
public void TestConfigWriteDispatchedBeginDelegateCalled() { var begin = false; var service = new ServiceController() { ServiceLoaderProxy = new MockServiceLoaderProxy(), WriteServiceConfigBegin = controller => begin = true }; service.WriteServiceConfig(); Assert.IsTrue(begin); service.Dispose(); }
public void TestMethodCalledExecuteMessage() { var service = new ServiceController() { Packages = new MockServicePackageManager(), Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.ExecuteMessage(new ServiceMessage()); Assert.IsTrue(((MockServiceLoaderProxy)service.ServiceLoaderProxy).OnExecuteMessage); service.Dispose(); }
public void TestObservableStarted() { var service = new ServiceController() { Packages = new MockServicePackageManager(), Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.ExecuteMessage(new ServiceMessage()); Assert.AreEqual(ServiceStatusType.Started, service.Observer.Status); service.Dispose(); }
public void TestFromStoppedEndsAsStarted() { var service = new ServiceController() { Packages = new MockServicePackageManager(), Observer = { Status = ServiceStatusType.Stopped }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.MergePackage("localhost", "id"); Assert.AreEqual(ServiceStatusType.Started, service.Observer.Status); service.Dispose(); }
public void TestExceptionLogged() { var service = new ServiceController() { Packages = new MockServicePackageManager(), Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockNonSerializableServiceLoaderProxy) }; service.Start(); Assert.IsNotEmpty(Defines.ErrorsLogsDirectory.GetFiles()); Assert.Greater(Defines.ErrorsLogsDirectory.GetFiles().First().Length, 0); service.Dispose(); }
public void TestExceptionLogged() { var service = new ServiceController() { ServiceDomain = AppDomain.CreateDomain("Potato.Instance"), UnloadServiceBegin = controller => { throw new Exception("Empty"); }, Process = new MockProcess() }; service.UnloadService(); Assert.IsNotEmpty(Defines.ErrorsLogsDirectory.GetFiles()); Assert.Greater(Defines.ErrorsLogsDirectory.GetFiles().First().Length, 0); service.Dispose(); }
public void TestExceptionKillsProcess() { var process = new MockProcess(); var service = new ServiceController() { ServiceDomain = AppDomain.CreateDomain("Potato.Instance"), UnloadServiceBegin = controller => { throw new Exception("Empty"); }, Process = process }; service.UnloadService(); Assert.IsTrue(process.OnKill); service.Dispose(); }
public void TestSignalBeginCallback() { var signaled = false; var service = new ServiceController() { Settings = { ServiceUpdateCore = false }, SignalBegin = (controller, message) => signaled = true }; service.SignalMessage(new ServiceMessage() { Name = "help" }); Assert.IsTrue(signaled); service.Dispose(); }
public void TestStartedFromStarted() { var service = new ServiceController() { Packages = new MockServicePackageManager(), Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy), Observer = { Status = ServiceStatusType.Started } }; service.Restart(); Assert.AreEqual(ServiceStatusType.Started, service.Observer.Status); service.Dispose(); }
public void TestInstallDispatchedEntryStatusIsStarted() { var merged = false; var service = new ServiceController() { Packages = new MockServicePackageManager() { PackageInstalled = (sender, uri, packageId) => { merged = true; } }, Observer = { Status = ServiceStatusType.Started }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.MergePackage("localhost", "id"); Assert.IsTrue(merged); service.Dispose(); }
public void TestUpdateNotCalledWhenSettingIsFalse() { var merged = false; var service = new ServiceController() { Packages = new MockServicePackageManager() { PackageInstalled = (sender, packageId, version) => { merged = true; } }, Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.UpdateCore(); Assert.IsFalse(merged); service.Dispose(); }
public void TestExceptionLoggedWhenPollingThrowsException() { var service = new ServiceController() { ServiceLoaderProxy = new MockNonSerializableServiceLoaderProxy(), Settings = { ServiceUpdateCore = false }, Observer = { Status = ServiceStatusType.Started }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.Polling_Tick(null); Assert.IsNotEmpty(Defines.ErrorsLogsDirectory.GetFiles()); Assert.Greater(Defines.ErrorsLogsDirectory.GetFiles().First().Length, 0); service.Dispose(); }
public void TestNotWrittenWhenServiceIsStopped() { var signaled = false; var service = new ServiceController() { ServiceLoaderProxy = new MockServiceLoaderProxy(), SignalBegin = (controller, message) => { signaled = true; }, Settings = { ServiceUpdateCore = false }, Observer = { Status = ServiceStatusType.Stopped }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.WriteConfig_Tick(null); Assert.IsFalse(signaled); service.Dispose(); }
public void TestCorruptedServiceInPanicWillOverrideDisabledUpdates() { var merged = false; var service = new ServiceController() { Packages = new MockServicePackageManager() { PackageInstalled = (sender, uri, packageId) => merged = true }, Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockNonSerializableServiceLoaderProxy), Observer = { Status = ServiceStatusType.None } }; service.Panic(); Assert.IsTrue(merged); service.Dispose(); }
public void TestExceptionLoggedOnTimeout() { var service = new ServiceController() { ServiceLoaderProxy = new MockSlowServiceLoaderProxy() { WriteConfigSleep = 500 }, Settings = { WriteServiceConfigTimeout = 10 } }; service.WriteServiceConfig(); Assert.IsNotEmpty(Defines.ErrorsLogsDirectory.GetFiles()); Assert.Greater(Defines.ErrorsLogsDirectory.GetFiles().First().Length, 0); service.Dispose(); }
public void TestCorruptedServiceInPanicWillOverrideDisabledUpdatesAndRecover() { var merged = false; ServiceController service = null; service = new ServiceController() { Packages = new MockServicePackageManager() { PackageInstalled = (sender, uri, packageId) => { merged = true; // ReSharper disable AccessToModifiedClosure // We only do this to keep the test concise. if (service != null) { service.ServiceLoaderProxyType = typeof(MockServiceLoaderProxy); } // ReSharper restore AccessToModifiedClosure } }, Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockNonSerializableServiceLoaderProxy), Observer = { Status = ServiceStatusType.None } }; service.Panic(); Assert.IsTrue(merged); Assert.AreEqual(ServiceStatusType.Started, service.Observer.Status); service.Dispose(); }
public void TestStoppedHealthyServiceInPanicWillRestart() { var service = new ServiceController() { Packages = new MockServicePackageManager(), Settings = { ServiceUpdateCore = true }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy) }; service.Panic(); Assert.AreEqual(ServiceStatusType.Started, service.Observer.Status); service.Dispose(); }
public void TestStoppedHealthyServiceInPanicWillNotUpdateWithUpdatesDisabled() { var merged = false; var service = new ServiceController() { Packages = new MockServicePackageManager() { PackageInstalled = (sender, uri, packageId) => merged = true }, Settings = { ServiceUpdateCore = false }, ServiceLoaderProxyType = typeof(MockServiceLoaderProxy), Observer = { Status = ServiceStatusType.None } }; service.Panic(); Assert.IsFalse(merged); service.Dispose(); }
public void TestExceptionLogged() { var service = new ServiceController() { ServiceLoaderProxy = new MockNonSerializableServiceLoaderProxy() }; service.WriteServiceConfig(); Assert.IsNotEmpty(Defines.ErrorsLogsDirectory.GetFiles()); Assert.Greater(Defines.ErrorsLogsDirectory.GetFiles().First().Length, 0); service.Dispose(); }
public void TestDisposeServiceDispatchedSuccess() { var disposed = false; var service = new ServiceController() { ServiceLoaderProxy = new MockServiceLoaderProxy() { OnDisposeHandler = () => disposed = true } }; service.DisposeService(); Assert.IsTrue(disposed); service.Dispose(); }
public void TestConfigWriteDispatchedSuccess() { var service = new ServiceController() { ServiceLoaderProxy = new MockServiceLoaderProxy() }; service.WriteServiceConfig(); Assert.IsTrue(((MockServiceLoaderProxy)service.ServiceLoaderProxy).OnWriteConfig); service.Dispose(); }