/// <summary> /// Set configuration data /// </summary> /// <param name="serviceImplementation">The service with configuration settings.</param> private void ConfigureServiceFromAttributes(IWindowsService serviceImplementation) { var attribute = serviceImplementation.GetType().GetAttribute <WindowsServiceAttribute>(); if (attribute != null) { // wire up the event log source, if provided if (!string.IsNullOrWhiteSpace(attribute.EventLogSource)) { // assign to the base service's EventLog property for auto-log events. EventLog.Source = attribute.EventLogSource; } CanStop = attribute.CanStop; CanPauseAndContinue = attribute.CanPauseAndContinue; CanShutdown = attribute.CanShutdown; // we don't handle: laptop power change event CanHandlePowerEvent = false; // we don't handle: Term Services session event CanHandleSessionChangeEvent = false; // always auto-event-log AutoLog = true; } else { throw new InvalidOperationException( string.Format("IWindowsService implementer {0} must have a WindowsServiceAttribute.", serviceImplementation.GetType().FullName)); } }
// Private input handler for console commands. private static bool HandleConsoleInput(IWindowsService service, string line) { bool canContinue = true; // check input if (line != null) { switch (line.ToUpper()) { case "S": canContinue = false; break; case "P": service.OnPause(); break; case "C": service.OnContinue(); break; default: WriteToConsole(ConsoleColor.Red, "Tecla Invalida. Tente outra vez."); break; } } return(canContinue); }
// Private input handler for console commands. private static bool HandleConsoleInput(IWindowsService service, ConsoleKeyInfo key) { bool canContinue = true; // check input switch (key.Key.ToString()) { case "Q": canContinue = false; break; case "P": service.OnPause(); break; case "R": service.OnContinue(); break; case "S": canContinue = false; shutdown = true; break; default: WriteToConsole(ConsoleColor.Red, "\nDid not understand that input, try again."); break; } return(canContinue); }
// Private input handler for console commands. private static bool HandleConsoleInput(IWindowsService service, string line) { bool canContinue = true; // check input if (line != null) { switch (line.ToUpper()) { case "Q": canContinue = false; break; case "P": service.OnPause(); break; case "R": service.OnContinue(); break; default: WriteToConsole(ConsoleColor.Red, "Did not understand that input, try again."); break; } } return(canContinue); }
/// <summary> /// Runs the service implementation as a service (instead of console app) /// </summary> /// <param name="service">The implementation of the service.</param> public static void Run(IWindowsService service) { using (var serviceHarness = new WindowsServiceHarness(service)) { ServiceBase.Run(serviceHarness); } }
// Run a service from the console given a service implementation internal static void Run(string[] args, IWindowsService service) { string serviceName = service.GetType().Name; bool isRunning = true; // simulate starting the windows service // bypass the system event call via ServiceBase and go straight to our handler if (service.OnStart(args, new EventLog(true))) { // let it run as long as Q is not pressed while (isRunning) { WriteToConsole(ConsoleColor.Yellow, "\nEnter either [P]ause, [R]esume, [Q]uit (stop), [S]hutdown: "); isRunning = HandleConsoleInput(service, WaitForKey(false)); } if (shutdown) { service.OnShutdown(); } else { service.OnStop(); } } WaitForKey(true); }
// Private input handler for console commands. private static bool HandleConsoleInput(IWindowsService service, string line) { bool canContinue = true; // check input if (line != null) { switch (line.ToUpper()) { case "Q": canContinue = false; break; case "P": service.OnPause(); break; case "R": service.OnContinue(); break; default: WriteToConsole(ConsoleColor.Red, "Je n'ai pas compris cette commande, veuillez réessayer."); break; } } return(canContinue); }
public ServiceContainer(IWindowsService[] unitOfCode) { if (unitOfCode == null) throw new ArgumentNullException("unitOfCode"); _unitOfCode = unitOfCode; _components = new System.ComponentModel.Container(); }
// Private input handler for console commands. private static bool HandleConsoleInput(IWindowsService service, string line) { bool canContinue = true; // check input if (line != null) { switch (line.ToUpper()) { case "Q": canContinue = false; break; case "P": service.OnPause(); break; case "R": service.OnContinue(); break; default: service.OnCustomCommand(int.Parse(line)); break; } } return(canContinue); }
public static void Run(IWindowsService service) { var windowsService = new WindowsService(service); if (Environment.UserInteractive) { ConfigureConsole(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" .oOo. .oOo. .oOo. Starting {0} .oOo. .oOo. .oOo. ", windowsService.ServiceName); Console.ForegroundColor = DefaultColor; windowsService.OnStart(null); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" .oOo. .oOo. .oOo. Press ESC to stop .oOo. .oOo. .oOo. "); Console.ForegroundColor = DefaultColor; WairForEscape(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" .oOo. .oOo. .oOo. Stopping {0} .oOo. .oOo. .oOo. ", windowsService.ServiceName); Console.ForegroundColor = DefaultColor; windowsService.Stop(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" .oOo. .oOo. .oOo. Press ESC to exit .oOo. .oOo. .oOo. "); Console.ForegroundColor = DefaultColor; WairForEscape(); } else { Run(windowsService); } }
/// <summary> /// Reads the console input. /// </summary> /// <param name="service">The service.</param> /// <param name="line">The line.</param> /// <returns><c>true</c> if can continue, <c>false</c> otherwise.</returns> private static bool ReadConsoleInput(IWindowsService service, string line) { var canContinue = true; if (line != null) { switch (line.ToUpper()) { case "Q": WriteToConsole(ConsoleColor.Red, "Quitting..."); canContinue = false; break; case "P": WriteToConsole(ConsoleColor.DarkCyan, "Paused..."); service.OnPause(); break; case "R": WriteToConsole(ConsoleColor.Green, "Continuing..."); service.OnContinue(); break; default: WriteToConsole(ConsoleColor.Red, "Please select a a valid option."); break; } } return(canContinue); }
private static bool HandleConsoleInput(IWindowsService service, string line) { bool canContinue = true; // check input if (line != null) { switch (line.ToUpper()) { case "Q": canContinue = false; break; case "P": service.OnPause(); break; case "R": service.OnContinue(); break; default: WriteToConsole(ConsoleColor.Red, "Did not understand that input, try again."); break; } } return canContinue; }
private void ConfigureServiceFromAttributes(IWindowsService ServiceImplementation) { var attribute = ServiceImplementation.GetType().GetAttribute<ServiceAttribute>(); if (attribute != null) { // wire up the event log source, if provided if (!string.IsNullOrWhiteSpace(attribute.EventLogSource)) { // assign to the base service's EventLog property for auto-log events. EventLog.Source = attribute.EventLogSource; } CanStop = attribute.CanStop; CanPauseAndContinue = attribute.CanPauseAndContinue; CanShutdown = attribute.CanShutdown; // we don't handle: laptop power change event CanHandlePowerEvent = false; // we don't handle: Term Services session event CanHandleSessionChangeEvent = false; // always auto-event-log AutoLog = true; } else { throw new InvalidOperationException( string.Format("IWindowsService implementer {0} must have a WindowsServiceAttribute.", ServiceImplementation.GetType().FullName)); } }
public DefaultWindowsServiceStarter(IWindowsService windowsWindowsService, IWindowsServiceConfiguration windowsServiceConfiguration, TClient client) { Client = client; WindowsService = windowsWindowsService; Environment = new Dictionary <string, object> { { Owin.StartParameters, windowsServiceConfiguration.StartParameters } }; }
public SimpleWindowsService(IWindowsService service) { this.service = service; this.CanStop = true; this.CanPauseAndContinue = false; this.AutoLog = true; }
/// <summary> /// Method Run. /// </summary> /// <param name="windowsService">IWindowsService instance.</param> /// <param name="isConsoleMode">true to start in console mode; otherwise, start in windows service mode.</param> /// <param name="args">Command line arguments.</param> public void Run(IWindowsService windowsService, bool isConsoleMode, string[] args) { this._windowsService = windowsService; this.IsConsoleMode = isConsoleMode; this._args = args; this._consoleStatus = ServiceControllerStatus.Stopped; this._setupInfo = windowsService.ServiceSetupInfo.Clone() as WindowsServiceSetup; this.RunWindowsServiceConsole(); }
/// <summary> /// Initializes a new instance of the <see cref="WindowsServiceHarness"/> class. /// </summary> /// <param name="service">A logical Windows service.</param> public WindowsServiceHarness(IWindowsService service) : this() { if (service == null) throw new ArgumentNullException("service", "IWindowsService cannot be null."); _service = service; ConfigureServiceFromAttributes(); }
public MainWindowViewModel(IDialogsService dialogsService, IAppSettings appSettings, IWindowsService windowsService, ISystemService systemService) { this.dialogsService = dialogsService; this.appSettings = appSettings; this.windowsService = windowsService; this.systemService = systemService; XsdExePath = appSettings.XsdExePath; }
public WindowsServiceHarness(IWindowsService service) { if (service == null) { throw new ArgumentNullException("service", "IWindowsService cannot be null in call to GenericWindowsService"); } this.ConfigureServiceFromAttributes(service); this.Service = service; }
public WindowsServiceHarness(IWindowsService serviceImplementation) : this() { if (serviceImplementation == null) { throw new ArgumentNullException(nameof(serviceImplementation), "IWindowsService cannot be null in call to GenericWindowsService"); } ServiceImplementation = serviceImplementation; ConfigureServiceFromAttributes(serviceImplementation); }
public PhoneExplorerService(IWindowsService implementation) : this() { if (implementation == null) { throw new ArgumentNullException("implementation", "implementation cannot be null"); } ServiceImplementation = implementation; //configure service ConfigureServiceFromAttributes(ServiceImplementation); }
/// <summary> /// Initializes a new instance of the <see cref="WindowsServiceConcrete" /> class. /// </summary> /// <param name="windowsService">Instance of IWindowsService.</param> public WindowsServiceConcrete(IWindowsService windowsService) { this.WindowsService = windowsService; this.AutoLog = this.WindowsService.ServiceSetupInfo.AutoLog; this.CanHandlePowerEvent = this.WindowsService.ServiceSetupInfo.CanHandlePowerEvent; this.CanHandleSessionChangeEvent = this.WindowsService.ServiceSetupInfo.CanHandleSessionChangeEvent; this.CanPauseAndContinue = this.WindowsService.ServiceSetupInfo.CanPauseAndContinue; this.CanShutdown = this.WindowsService.ServiceSetupInfo.CanShutdown; this.CanStop = this.WindowsService.ServiceSetupInfo.CanStop; this.ServiceName = this.WindowsService.ServiceSetupInfo.ServiceName; }
public static void Run(string[] args, IWindowsService service) { string serviceName = service.GetType().Name; bool isRunning = true; service.OnStart(args); while (isRunning){ WriteToConsole(ConsoleColor.Yellow, "Enter either [Q]uit, [P]ause, [R]esume : "); isRunning = HandleConsoleInput(service, Console.ReadLine()); } // stop service.OnStop(); }
/// <summary> /// Initializes a new instance of the <see cref="WindowsServiceHarness" /> class. /// Constructor a generic windows service from the given class /// </summary> /// <param name="serviceImplementation"> /// Service implementation. /// </param> public WindowsServiceHarness(IWindowsService serviceImplementation) { // make sure service passed in is valid if (serviceImplementation == null) { throw new ArgumentNullException(nameof(serviceImplementation), "IWindowsService cannot be null in call to GenericWindowsService"); } // set instance and backward instance ServiceImplementation = serviceImplementation; // configure our service ConfigureServiceFromAttributes(serviceImplementation); }
private void Execute(IWindowsService[] services, string[] args) { NotifyApplicationStartup(); try { LaunchInteractiveServices(services, args); LaunchNonInteractiveServices(services); } catch(Exception ex) { _context.Log(ex.ToString()); throw; } }
public NotifyIconManager(IUtilityService utilityService, IWindowsService windowsService) { UtilityService = utilityService; _windowsService = windowsService; _notifyIcon = new NotifyIcon() { ContextMenuStrip = new ContextMenuStrip(), Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location), Text = "Utilities Handler", Visible = true, }; _notifyIcon.MouseClick += new MouseEventHandler(notifyIcon_Click); _notifyIcon.DoubleClick += Double_Click; _notifyIcon.ShowBalloonTip(500, "Utility Handler app is running...", "You can start the utilities here", ToolTipIcon.Info); _notifyIcon.BalloonTipClicked += BalloonTipClicked; }
void ICommandHandler.HandleCommand(ReportCommand command, object[] args) { XRDesignPanel panel = mdiController.ActiveDesignPanel; XRSubreport subreport = (XRSubreport)args[0]; if (subreport.ReportSource == null && String.IsNullOrEmpty(subreport.ReportSourceUrl)) { subreport.ReportSource = CreateReport(); } IWindowsService windowsSvc = panel.GetService(typeof(IWindowsService)) as IWindowsService; windowsSvc.EditSubreport(subreport); subreport.ReportSource = null; }
/// <summary> /// Registers the executable for a service with the Service Control Manager (SCM). /// </summary> /// <param name="windowsService">A <see cref="IWindowsService" /> which indicates a service to start.</param> /// <param name="args">Command line arguments.</param> public static void Run(IWindowsService windowsService, string[] args = null) { if (windowsService == null) { throw new ArgumentNullException("windowsService"); } if (Environment.UserInteractive) { (new WindowsServiceConsole()).Run(windowsService, true, args); } else { Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); ServiceBase.Run(new WindowsServiceConcrete(windowsService)); } }
// Run a service from the console given a service implementation public static void Run(string[] args, IWindowsService service) { bool isRunning = true; // simulate starting the windows service service.OnStart(args); // let it run as long as Q is not pressed while (isRunning) { WriteToConsole(ConsoleColor.Yellow, "Enter either [Q]uit, [P]ause, [R]esume : "); isRunning = HandleConsoleInput(service, Console.ReadLine()); } // stop and shutdown service.OnStop(); service.OnShutdown(); }
/// <summary> /// Registers the executable for a service with the Service Control Manager (SCM). /// </summary> /// <param name="windowsService">A <see cref="IWindowsService" /> which indicates a service to start.</param> /// <param name="serviceArgs">The arguments passed by the service start command.</param> /// <param name="consoleArgs">The arguments for console mode.</param> public static void Run(IWindowsService windowsService, string[] serviceArgs = null, string[] consoleArgs = null) { if (windowsService == null) { throw new ArgumentNullException("windowsService"); } Directory.SetCurrentDirectory(windowsService.ServiceSetupInfo.WorkingDirectory); if (Environment.UserInteractive) { (new WindowsServiceConsole()).Run(windowsService, serviceArgs, true, consoleArgs); } else { ServiceBase.Run(new WindowsServiceConcrete(windowsService, serviceArgs)); } }
// Run a service from the console given a service implementation public static void Run(string[] args, IWindowsService service) { string serviceName = service.GetType().Name; bool isRunning = true; // simulate starting the windows service service.OnStart(args); // let it run as long as Q is not pressed while (isRunning) { WriteToConsole(ConsoleColor.Yellow, "Choisir [Q]uitter, [P]ause, [R]eprendre : "); isRunning = HandleConsoleInput(service, Console.ReadLine()); } // stop and shutdown service.OnStop(); service.OnShutdown(); }
// Run a service from the console given a service implementation public static void Run(string[] args, IWindowsService service) { string serviceName = service.GetType().Name; bool isRunning = true; // simulate starting the windows service service.OnStart(args); // let it run as long as Q is not pressed while (isRunning) { WriteToConsole(ConsoleColor.Yellow, "Enter either [Q]uit, [P]ause, [R]esume : "); isRunning = HandleConsoleInput(service, Console.ReadLine()); } // stop and shutdown service.OnStop(); service.OnShutdown(); }
private static void TryHandleConsoleInput(IWindowsService service, ConsoleKey key, ref ServiceState state) { switch (key) { case ConsoleKey.Q: state = ServiceState.Stopped; break; case ConsoleKey.P: service.OnPause(); state = ServiceState.Paused; break; case ConsoleKey.R: service.OnContinue(); state = ServiceState.Running; break; } }
// Run a service from the console given a service implementation public static void Run(string[] args, IWindowsService service) { string serviceName = service.GetType().Name; bool isRunning = true; // simulate starting the windows service service.OnStart(args); // let it run as long as Q is not pressed while (isRunning) { WriteToConsole(ConsoleColor.Yellow, "MLS Marketing Menu [S + Return] para Sair : "); isRunning = HandleConsoleInput(service, Console.ReadLine()); } // stop and shutdown service.OnStop(); service.OnShutdown(); }
/// <summary> /// Runs the service that implements <see cref="IWindowsService" />. /// </summary> /// <param name="args">The arguments.</param> /// <param name="service">The service.</param> public static void Run(string[] args, IWindowsService service) { var serviceName = service.GetType().Name; WriteToConsole(ConsoleColor.Green, serviceName); WriteToConsole(ConsoleColor.Yellow, "Enter either [Q]uit, [P]ause, [R]esume : "); var running = true; service.OnStart(args); while (running) { running = ReadConsoleInput(service, Console.ReadKey(true).Key.ToString()); } service.OnStop(); service.OnShutdown(); }
public static void Run(string[] args, IWindowsService service) { var serviceName = service.GetType().Name; service.WriteToConsole += OnWriteToConsole; var isRunning = true; AllocConsole(); service.Start(args); while (isRunning) { WriteToConsole(ConsoleColor.Yellow, "Enter either [Q]uit, [P]ause, [R]esume : "); isRunning = HandleConsoleInput(service, Console.ReadLine()); } service.Stop(); service.Shutdown(); }
/// <summary> /// Run a given <see cref="IWindowsService"/> using the console harness. /// </summary> /// <param name="args">Arguments to pass to the service <see cref="IWindowsService.OnStart"/> method.</param> /// <param name="service">The service to run.</param> public static void Run(String[] args, IWindowsService service) { ServiceState state = ServiceState.Running; using (service) { service.OnStart(args); while (state != ServiceState.Stopped) { Console.WriteLine("[muster] Currently {0}: [Q]uit [P]ause [R]esume", state); while (!Console.KeyAvailable) Thread.Sleep(250); TryHandleConsoleInput(service, Console.ReadKey(true).Key, ref state); } service.OnStop(); } }
private void ConfigureServiceFromAttributes(IWindowsService serviceImplementation) { var attribute = serviceImplementation.GetType().GetAttribute <WindowsServiceConfigurationAttribute>(); if (attribute != null) { EventLog.Source = string.IsNullOrEmpty(attribute.EventLogSource) ? "WindowsServiceHarness" : attribute.EventLogSource; CanStop = attribute.CanStop; CanPauseAndContinue = attribute.CanPauseAndContinue; CanShutdown = attribute.CanShutdown; CanHandlePowerEvent = false; CanHandleSessionChangeEvent = false; AutoLog = true; } else { throw new InvalidOperationException( $"IWindowsService implementer {serviceImplementation.GetType().FullName} must have a WindowsServiceAttribute."); } }
IServicesProvider ICoreApplication.Initialize(IServicesProvider servicesProvider) { var assembly = GetType().Assembly; var builder = new ScopeBuilder(servicesProvider); var elementTypeMapping = new ElementTypeMapping(assembly); var appValues = new AppValues(); var conversionService = new ConversionService(assembly); var bindingService = new BindingService(appValues, conversionService); LoadApplicationDefinition(appValues, bindingService, elementTypeMapping, servicesProvider.GetService <IObjectFactory>()); builder .WithInstance(this).As <Application>().As(GetType()) .WithInstance(elementTypeMapping).As <IElementTypeMapping>() .WithInstance(appValues).As <IAppValues>() .WithInstance(bindingService).As <IBindingService>() .WithType <TooltipService>().As <ITooltipService>().AsSingleton() .WithType <UIServices>().As <IUIServices>().AsSingleton() .WithType <XxFileParserImpl>().As <IXxFileParser>().AsSingleton(); BeforeInitServices?.Invoke(servicesProvider, builder); InitServices(servicesProvider, builder); if (!builder.TryResolveInstance <IViewLocator>(out var _)) { builder.WithType <DefaultViewLocator>().As <IViewLocator>().AsSingleton(); } AfterInitServices?.Invoke(servicesProvider, builder); Services = builder.Build(); LoadFonts(Services.GetService <IFontManager>()); WindowsService = Services.GetService <IWindowsService>(); ((WindowService)WindowsService).ObjectFactory = Services.GetService <IObjectFactory>(); return(Services); }
private void ConfigureServiceFromAttributes(IWindowsService service) { var attribute = service.GetType().GetTypeInfo().GetCustomAttribute <WindowsServiceAttribute>(); if (attribute != null) { if (!string.IsNullOrWhiteSpace(attribute.EventLogSource)) { this.EventLog.Source = attribute.EventLogSource; } this.AutoLog = true; this.CanHandlePowerEvent = false; this.CanHandleSessionChangeEvent = false; this.CanPauseAndContinue = attribute.CanPauseAndContinue; this.CanShutdown = attribute.CanShutdown; this.CanStop = attribute.CanStop; } else { throw new InvalidOperationException( string.Format("IWindowsService implementer {0} must have a WindowsServiceAttribute.", service.GetType().FullName)); } }
public void Add(IWindowsService service) { _services.Add(service); }
private ServiceContainer Wrap(IWindowsService[] services) { foreach (var service in services) { _context.Log("Building wrapper for : " + service); service.AppContext = _context; } return new ServiceContainer(services) {AppContext = _context}; }
private void LaunchNonInteractiveServices(IWindowsService[] services) { if (Environment.UserInteractive) { return; } var wrapped = Wrap(services); ServiceBase.Run(wrapped); _context.Log("Listening as a service..."); }
public ServiceViewModel(IWindowsService serviceImpl) { _serviceImpl = serviceImpl; _serviceIsChanging = false; _serviceIsRunning = false; }
public SmcHarness(IWindowsService serverImpl) : this() { _serverImpl = serverImpl; }
public static void Run(IWindowsService serviceToRun) { var app = new Application(); var vm = new ServiceViewModel(serviceToRun); app.Run(new WpfHarnessWindow(vm)); }