public static void Main() { System.ServiceProcess.ServiceBase[] ServicesToRun; // Change the following line to match. ServicesToRun = new System.ServiceProcess.ServiceBase[] { new SecurityService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); }
internal static void Main(string[] args) { if (args.Length > 0 && (args[0].ToLower() == "-console" || args[0].ToLower() == "-c")) { System.Console.WriteLine("---------------------------------------------------------------------------"); System.Console.WriteLine("BITS Loader Service"); System.Console.WriteLine("Started at [" + System.DateTime.Now.ToLongTimeString() + "]"); System.Console.WriteLine("---------------------------------------------------------------------------"); _service = new FileManagerService(); _service.Start(args); Console.WriteLine("Waiting for tasks, press enter to stop service..."); Console.ReadLine(); Console.WriteLine("Service stopping..."); _service.StopService(); Console.WriteLine("Service stopped."); } else { // setup the working directory so that edit can find the channels files System.Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory; // kick off the service code System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new FileManagerService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main() { KernelContainer.Kernel = new StandardKernel( new ServiceModule() ); #if SERVICE var ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WindowsTimeService() }; System.ServiceProcess.ServiceBase.Run( ServicesToRun ); #else var service = new WindowsTimeService(); try { service.Start( new string[] {} ); do { } while ( Console.ReadLine() != "q" ); } finally { service.Stop(); } #endif }
/// <summary> /// The main entry point for the application. /// </summary> internal static void Main() { // sets the DEA priority higher. Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (!Environment.UserInteractive) { System.ServiceProcess.ServiceBase[] servicesToRun; servicesToRun = new System.ServiceProcess.ServiceBase[] { new DeaWindowsService() }; System.ServiceProcess.ServiceBase.Run(servicesToRun); } else { using (DeaWindowsService deaService = new DeaWindowsService()) { deaService.Start(); Console.WriteLine(Strings.PressEnterToStopConsoleMessage); Console.ReadLine(); deaService.Stop(); } } }
/// <summary> /// The main entry point for the application. /// </summary> internal static void Main() { Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); if (!Environment.UserInteractive) { System.ServiceProcess.ServiceBase[] servicesToRun; servicesToRun = new System.ServiceProcess.ServiceBase[] { new MSSqlWindowsService() }; System.ServiceProcess.ServiceBase.Run(servicesToRun); } else { using (MSSqlWindowsService sqlService = new MSSqlWindowsService()) { sqlService.Start(); Console.WriteLine(Strings.PressEnterToStopConsoleMessage); Console.ReadLine(); sqlService.Stop(); } } }
// The main entry point for the process static void Main() { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new ProjectKService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); }
static void Main(string[] args) { System.ServiceProcess.ServiceBase[] ServicesToRun; //Thread.Sleep(10000); //调试服务用 ServiceEntryType entryType = ServiceEntryType.Application; if (args.Length > 0 && args[0].Equals("SERVICE", StringComparison.OrdinalIgnoreCase)) { entryType = ServiceEntryType.Service; } MainService.Instance = new MainService(); switch (entryType) { case ServiceEntryType.Application: MainService.Instance.args = args; MainService.Instance.EntryType = ServiceEntryType.Application; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(MainService.Instance)); //Application.Run(new DebugForm()); break; case ServiceEntryType.Service: MainService.Instance.EntryType = ServiceEntryType.Service; ServicesToRun = new System.ServiceProcess.ServiceBase[] { MainService.Instance }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); break; default: break; } //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new MainForm()); }
static void Main(string[] args) { try { if (args != null && args.Length == 1 && args[0].StartsWith("-c")) { Console.WriteLine("SIP Proxy starting"); SIPProxyDaemon daemon = new SIPProxyDaemon(); Thread daemonThread = new Thread(daemon.Start); daemonThread.Start(); m_proxyUp.WaitOne(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp.Message); } }
static void Main(string[] args) { try { logger.Debug("SIP Notifier starting"); m_sipNotifierStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; ; m_sipNotifierStorageConnStr = AppState.GetConfigSetting(m_connStrKey); if (m_sipNotifierStorageType == StorageTypes.Unknown || m_sipNotifierStorageConnStr.IsNullOrBlank()) { throw new ApplicationException("The SIP Notifier cannot start with no persistence settings."); } if (m_sipNotifierStorageType == StorageTypes.XML && !Directory.Exists(m_sipNotifierStorageConnStr)) { throw new ApplicationException("Directory " + m_sipNotifierStorageConnStr + " does not exist for XML persistor."); } SIPAssetPersistor<Customer> customerPersistor = SIPAssetPersistorFactory<Customer>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_customersXMLFilename); SIPAssetPersistor<SIPAccount> sipAccountsPersistor = SIPAssetPersistorFactory<SIPAccount>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_sipAccountsXMLFilename); SIPAssetPersistor<SIPRegistrarBinding> sipRegistrarBindingsPersistor = SIPAssetPersistorFactory<SIPRegistrarBinding>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_registrarBindingsXMLFilename); SIPAssetPersistor<SIPDialogueAsset> sipDialoguePersistor = SIPAssetPersistorFactory<SIPDialogueAsset>.CreateSIPAssetPersistor(m_sipNotifierStorageType, m_sipNotifierStorageConnStr, m_sipDialoguesXMLFilename); SIPDomainManager sipDomainManager = new SIPDomainManager(m_sipNotifierStorageType, m_sipNotifierStorageConnStr); SIPNotifierDaemon daemon = new SIPNotifierDaemon( customerPersistor.Get, sipDialoguePersistor.Get, sipDialoguePersistor.Get, sipDomainManager.GetDomain, sipAccountsPersistor, sipRegistrarBindingsPersistor.Get, sipAccountsPersistor.Get, sipRegistrarBindingsPersistor.Count, SIPRequestAuthenticator.AuthenticateSIPRequest, null); if (args != null && args.Length == 1 && args[0].StartsWith("-c")) { Thread daemonThread = new Thread(daemon.Start); daemonThread.Start(); m_notifierUp.WaitOne(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp.Message); logger.Error("Exception Main. " + excp.Message); } }
static void Main() { #if DEBUG var service = new PushNotificationService(); service.Debug(); #else System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new PushNotificationService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); #endif }
static void MainService(string[] args) { _eventLogSource = Path.GetFileName(Assembly.GetEntryAssembly().Location); if (!EventLog.SourceExists(_eventLogSource)) EventLog.CreateEventSource(_eventLogSource, EVENT_LOG_NAME); System.ServiceProcess.ServiceBase[] ServicesToRun = new System.ServiceProcess.ServiceBase[]{ new JasinskiTimeService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); }
public static void Main(string[] args) { Outils.Excecute("pacman-g2"," -Sy",true); System.ServiceProcess.ServiceBase[] servicesToRun; servicesToRun = new System.ServiceProcess.ServiceBase[] { new Service()}; System.ServiceProcess.ServiceBase.Run(servicesToRun); string strPID = "/tmp/fwmono"; int pid = Mono.Unix.UnixProcess.GetCurrentProcessId(); System.IO.File.Delete(strPID); System.IO.StreamWriter FilePid = new System.IO.StreamWriter(strPID); FilePid.WriteLine("PID="+pid.ToString()); FilePid.Close(); }
/// <summary> /// The main process entry point. /// </summary> static void Main() { System.ServiceProcess.ServiceBase[] ServicesToRun; // More than one user Service may run within the same process. To add // another service to this process, change the following line to // create a second service object. For example, // // ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()}; // ServicesToRun = new System.ServiceProcess.ServiceBase[] { new SocialNetworkingService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); }
static void Main(string[] args) { try { logger.Debug("SIP Registration Agent starting"); m_sipRegAgentStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; m_sipRegAgentStorageConnStr = AppState.GetConfigSetting(m_connStrKey); if (m_sipRegAgentStorageType == StorageTypes.Unknown || m_sipRegAgentStorageConnStr.IsNullOrBlank()) { throw new ApplicationException("The SIP Registration Agent cannot start with no persistence settings."); } if (m_sipRegAgentStorageType == StorageTypes.XML && !Directory.Exists(m_sipRegAgentStorageConnStr)) { throw new ApplicationException("Directory " + m_sipRegAgentStorageConnStr + " does not exist for XML persistor."); } int minWorker, minIOC; ThreadPool.GetMinThreads(out minWorker, out minIOC); ThreadPool.SetMinThreads(MIN_THREADPOOL_WORKERS, minIOC); logger.Debug("ThreadPool minimum idle thread adusted from " + minWorker + " to " + MIN_THREADPOOL_WORKERS + "."); SIPAssetPersistor<SIPProvider> sipProvidersPersistor = SIPAssetPersistorFactory<SIPProvider>.CreateSIPAssetPersistor(m_sipRegAgentStorageType, m_sipRegAgentStorageConnStr, m_sipProvidersXMLFilename); SIPAssetPersistor<SIPProviderBinding> sipProviderBindingsPersistor = SIPAssetPersistorFactory<SIPProviderBinding>.CreateSIPAssetPersistor(m_sipRegAgentStorageType, m_sipRegAgentStorageConnStr, m_sipProviderBindingsXMLFilename); SIPRegAgentDaemon daemon = new SIPRegAgentDaemon(sipProvidersPersistor, sipProviderBindingsPersistor); SIPDNSManager.SIPMonitorLogEvent = daemon.FireSIPMonitorEvent; if (args != null && args.Length == 1 && args[0].StartsWith("-c")) { Thread daemonThread = new Thread(daemon.Start); daemonThread.Start(); m_regAgentUp.WaitOne(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp.Message); logger.Error("Exception Main. " + excp.Message); } }
static void Main(string[] args) { IocInit(); #if !DEBUG var servicesToRun = new System.ServiceProcess.ServiceBase[] { new QuartzService() }; System.ServiceProcess.ServiceBase.Run(servicesToRun); #else new QuartzService().ConsoleDebug(); #endif }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main(string[] args) { #if(DEBUG) // Debug code execution path var service = new FingertipsUploadService(); service.Start(); Logger.Info("Started in Debug"); Thread.Sleep(Timeout.Infinite); #else System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new FingertipsUploadService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); Logger.Info("Started in Normal"); #endif }
// The main entry point for the process static void Main(string[] args) { if(args.Length > 0){ if(args[0].ToLower() == "trayapp"){ System.Windows.Forms.Application.Run(new wfrm_Tray()); } } else{ System.ServiceProcess.ServiceBase[] ServicesToRun; // More than one user Service may run within the same process. To add // another service to this process, change the following line to // create a second service object. For example, // // ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()}; // ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MailServer() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main() { #if SERVICE var ServicesToRun = new System.ServiceProcess.ServiceBase[] { kernel.Get<WindowsTimeService>() }; System.ServiceProcess.ServiceBase.Run( ServicesToRun ); #else var service = new WindowsTimeService(); try { service.Start(new string[] { }); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); } finally { service.Stop(); } #endif }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { var appHost = new AppHost(); //Allow you to debug your Windows Service while you're deleloping it. #if DEBUG "Running WinServiceAppHost in Console mode".Print(); try { appHost.Init(); appHost.Start(ListeningOn); "Press <CTRL>+C to stop.".Print(); Thread.Sleep(Timeout.Infinite); } catch (Exception ex) { "ERROR: {0}: {1}".Print(ex.GetType().Name, ex.Message); throw; } finally { appHost.Stop(); } "WinServiceAppHost has finished".Print(); #else //When in RELEASE mode it will run as a Windows Service with the code below var servicesToRun = new System.ServiceProcess.ServiceBase[] { new WinService(appHost, ListeningOn) }; System.ServiceProcess.ServiceBase.Run(servicesToRun); #endif }
static void Main(string[] args) { try { logger.Debug("RTCC Server starting"); m_rtccStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; ; m_rtccStorageConnStr = AppState.GetConfigSetting(m_connStrKey); if (m_rtccStorageType == StorageTypes.Unknown || m_rtccStorageConnStr.IsNullOrBlank()) { throw new ApplicationException("The RTCC Server cannot start with no persistence settings."); } var sipSorceryPersistor = new SIPSorceryPersistor(m_rtccStorageType, m_rtccStorageConnStr); RTCCDaemon daemon = new RTCCDaemon(sipSorceryPersistor); if (args != null && args.Length == 1 && args[0].StartsWith("-c")) { Thread daemonThread = new Thread(daemon.Start); daemonThread.Start(); m_rtccUp.WaitOne(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp.Message); logger.Error("Exception Main. " + excp.Message); } }
/// <summary> /// Main program entry point /// </summary> public static void Main() { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new ImardaReportService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); }
// The main entry point for the process static void Main(string[] args) { try { Parameters.Initialise(args, new char[] { '-', '/' }, new char[] { ' ', ':' }); System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); if (System.Environment.UserInteractive) { if (Parameters.OptionExists("decrypt")) { string decryptFile = Parameters.GetOption("file", String.Empty); string decryptedFile = Parameters.GetOption("decryptedFile", String.Empty); if (File.Exists(decryptFile)) { string contents = Utilities.FileEncryptedRead(decryptFile, Forms.Configuration.ENCRYPRION_KEY); Utilities.FileWrite(decryptedFile, contents); } return; } if (Parameters.OptionExists("encrypt")) { string decryptedFile = Parameters.GetOption("file", String.Empty); string encryptedFile = Parameters.GetOption("encryptedFile", String.Empty); if (File.Exists(decryptedFile)) { string decryptedContents = Utilities.FileRead(decryptedFile, true); Utilities.FileEncryptedWrite(encryptedFile, decryptedContents, Forms.Configuration.ENCRYPRION_KEY); } return; } Shared.Classes.ThreadManager.Initialise(); try { INSTANCE = new UpdateBackupReplication(); Shared.EventLog.Add("Initializing UserInteractive"); if (Parameters.OptionExists("c")) { Forms.Configuration config = new Forms.Configuration(); try { config.ShowDialog(); } finally { config.Dispose(); config = null; } } else if (Parameters.OptionExists("i")) // install { try { Shared.EventLog.Add("Installing"); ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); } catch (Exception err) { if (!err.Message.Contains("The installation failed, and the rollback has been performed")) { throw; } } } else if (Parameters.OptionExists("u")) // uninstall { Shared.EventLog.Add("Uninstalling"); ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); } else { Shared.EventLog.Add("Run as Application"); Shared.Classes.ThreadManager.ThreadForcedToClose += ThreadManager_ThreadForcedToClose; INSTANCE.RunAsApp(); } } catch (Exception err) { MessageBox.Show(String.Format("{0}\r\n{1}", err.Message, err.StackTrace.ToString())); Shared.EventLog.Add(err.Message); Shared.EventLog.Add(err); } finally { Shared.Classes.ThreadManager.Finalise(); } } else { System.ServiceProcess.ServiceBase[] ServicesToRun; INSTANCE = new UpdateBackupReplication(); ServicesToRun = new System.ServiceProcess.ServiceBase[] { INSTANCE }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception error) { Shared.EventLog.Add(error); } }
static void Main(string[] args) { if (args.Length > 0 && args[0].ToLower() == "/console") { new Program().OnStart(args); Console.ReadLine(); } else { System.ServiceProcess.ServiceBase[] objServicesToRun; objServicesToRun = new System.ServiceProcess.ServiceBase[] { new Program() }; System.ServiceProcess.ServiceBase.Run(objServicesToRun); } }
static void Main(string[] args) { bool isConsole = false; try { // Get DateTime.ToString() to use a format ot ToString("o") instead of ToString("G"). CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"; culture.DateTimeFormat.LongTimePattern = "THH:mm:ss.fffffffzzz"; Thread.CurrentThread.CurrentCulture = culture; m_serverStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; m_serverStorageConnStr = AppState.GetConfigSetting(m_connStrKey); bool monitorCalls = true; if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank()) { throw new ApplicationException("The SIP Application Service cannot start with no persistence settings specified."); } if (args != null && args.Length > 0) { isConsole = true; Console.WriteLine("SIP App Server starting"); logger.Debug("SIP App Server Console starting..."); string sipSocket = null; string callManagerSvcAddress = null; foreach (string arg in args) { if (arg.StartsWith("-sip:")) { sipSocket = arg.Substring(5); } else if (arg.StartsWith("-cms:")) { callManagerSvcAddress = arg.Substring(5); } else if (arg.StartsWith("-hangupcalls:")) { monitorCalls = Convert.ToBoolean(arg.Substring(13)); } } SIPAllInOneDaemon daemon = null; if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank()) { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); } else { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr, SIPEndPoint.ParseSIPEndPoint(sipSocket), callManagerSvcAddress, monitorCalls); } Thread daemonThread = new Thread(new ThreadStart(daemon.Start)); daemonThread.Start(); m_proxyUp.WaitOne(); } else { logger.Debug("SIP App Server Windows Service Starting..."); System.ServiceProcess.ServiceBase[] ServicesToRun; SIPAllInOneDaemon daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception SIP App Server Main. " + excp.Message); if (isConsole) { Console.WriteLine("press any key to exit..."); Console.ReadLine(); } } }
static void Main(string[] args) { System.ServiceProcess.ServiceBase[] ServicesToRun = new System.ServiceProcess.ServiceBase[] { new CWService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); }
static void Main(string[] args) { try { //Windows service has system32 as default working folder, we change the working dir to install dir for file access System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); logger.Debug("Setting current directory to " + System.AppDomain.CurrentDomain.BaseDirectory); var daemon = new WebRTCDaemon(); if (args != null && args.Length == 1 && args[0] == "-i") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Install(state); inst.Commit(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0] == "-u") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Uninstall(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if ((args != null && args.Length == 1 && args[0].StartsWith("-c")) || System.Environment.UserInteractive == true) { Task.Run((Action)daemon.Start); Console.WriteLine("Press q to quit at any time."); while (true) { string option = Console.ReadLine(); if (option?.ToLower() == "q") { Console.WriteLine("User requested quit."); break; } } daemon.Stop(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WebRTCService(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } }
internal static Udbus.Core.Logging.ILog CreateRootLogger(System.ServiceProcess.ServiceBase service) { return(Udbus.Core.Logging.LogCreation.CreateFormatLoggerRoot(defaultRootSourceLevel, assertServiceName(service.ServiceName), defaultFormat, MakeListenersForService(service))); }
} // End Task RunAsPlatformIndependentService // static async System.Threading.Tasks.Task MainTask(string[] args) static async System.Threading.Tasks.Task RunAsWindowsService(string[] args) { Microsoft.Extensions.DependencyInjection.IServiceCollection services = new Microsoft.Extensions.DependencyInjection.ServiceCollection(); // Create configuration builder Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder() .SetBasePath(System.IO.Directory.GetCurrentDirectory()) // .AddIniFile(@"D:\inetpub\LdapService\LdapService.ini") //.AddJsonFile("appsettings.json") ; // Inject configuration services.AddSingleton <Microsoft.Extensions.Configuration.IConfiguration>(provider => { return(configurationBuilder.Build()); }); // Inject Serilog services.AddLogging(options => { options.SetMinimumLevel(LogLevel.Information); options.AddFilter(x => x >= LogLevel.Trace); options.AddConsole(); options.AddDebug(); /* * options.AddSerilog( * new LoggerConfiguration() * .ReadFrom.Configuration(configurationBuilder.Build()) * .CreateLogger() * ); */ }); // Inject common service services.AddSingleton(typeof(ICommonService), typeof(CommonSampleService)); // Inject concrete implementation of the service services.AddSingleton(typeof(System.ServiceProcess.ServiceBase), typeof(GenericService)); // My configuration services.AddSingleton(new MyConfig()); services.Configure <SmtpConfig>( delegate(SmtpConfig config) { config.Server = "hello world"; return; } ); /* * // IConfiguration Configuration = null; * * // services.Configure<SmtpConfig>(Configuration.GetSection("Smtp")); * // IConfiguration iconf = Configuration.GetSection("Smtp"); * Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<SmtpConfig>( * services, iconf * ); */ // Build DI provider Microsoft.Extensions.DependencyInjection.ServiceProvider serviceProvider = services.BuildServiceProvider(); if (System.Diagnostics.Debugger.IsAttached) { // Console Debug mode /* * try * { * IConfiguration confy = serviceProvider.GetService<IConfiguration>(); * System.Console.WriteLine(confy); * // var sec = confy.GetSection("ErrorMail2"); * // https://stackoverflow.com/questions/39169701/how-to-extract-a-list-from-appsettings-json-in-net-core * // foreach (var section in confy.GetChildren()) section.GetChildren(); * * * // Fixes to IniStreamConfigurationProvider.cs:if (separator < 0) * var jobs = confy.GetSection("Jobs").Get<System.Collections.Generic.Dictionary<string, string>>(); * var sec = confy.GetSection("ErrorMail2").Get<System.Collections.Generic.Dictionary<string, string>>(); * * // sec.Keys, sec.Values * * System.Console.WriteLine(sec); * System.Console.WriteLine(jobs); * * * } * catch (System.Exception ex) * { * System.Console.WriteLine(ex.Message); * } */ GenericService svc = serviceProvider.GetService <System.ServiceProcess.ServiceBase>() as GenericService; svc.StartService(args); // System.Console.ReadLine(); System.ConsoleKey cc = default(System.ConsoleKey); do { // THIS IS MADNESS!!! Madness huh? THIS IS SPARTA!!!!!!! while (!System.Console.KeyAvailable) { // System.Threading.Thread.Sleep(100); await System.Threading.Tasks.Task.Delay(100); } cc = System.Console.ReadKey().Key; if (cc == System.ConsoleKey.C) { System.Console.Clear(); } } while (cc != System.ConsoleKey.Enter); svc.Stop(); } else { // Start service System.ServiceProcess.ServiceBase[] servicesToRun; servicesToRun = new System.ServiceProcess.ServiceBase[] { serviceProvider.GetService <System.ServiceProcess.ServiceBase>() }; System.ServiceProcess.ServiceBase.Run(servicesToRun); } // End else of if (System.Diagnostics.Debugger.IsAttached) // await System.Threading.Tasks.Task.CompletedTask; } // End Task RunAsWindowsService
public static int Main(string[] arguments) { // Fix working directory: Services start in System32 // Services can't have arguments, therefore we need to cwd. if (arguments == null || arguments.Length == 0) { Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; } Logging.Configure(); Log.InfoFormat("Starting Zetbox Service with args [{0}] at {1}", String.Join(" ", arguments), Environment.CurrentDirectory); try { var config = ExtractConfig(ref arguments); bool consoleMode = false; if (arguments.Length == 0) { consoleMode = false; Log.InfoFormat("Changed working directory to '{0}'", Environment.CurrentDirectory); } else if (arguments.Length == 1) { switch (arguments[0]) { case "/console": case "-console": case "--console": consoleMode = true; Log.Info("Staying in foreground"); break; case "/help": case "-help": case "--help": Log.Warn("Start with --console to keep the service in the foreground."); Environment.Exit(1); break; } } else { Log.Fatal("Too many parameters. Start with --help to see usage."); Environment.Exit(1); } AssemblyLoader.Bootstrap(AppDomain.CurrentDomain, config); using (var container = CreateMasterContainer(config)) { var service = container.Resolve<WindowsService>(); if (consoleMode) { service.StartService(); Log.Info("Waiting for console input to shutdown"); Console.WriteLine("Services started, press the anykey to exit"); Console.ReadKey(); Log.Info("Shutting down"); service.StopService(); } else { var ServicesToRun = new System.ServiceProcess.ServiceBase[] { service }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } Log.Info("Exiting"); return 0; } catch (Exception ex) { Log.Error("Server Application failed:", ex); return 1; } }
static void Main(string[] args) { bool isConsole = false; try { // Get DateTime.ToString() to use a format ot ToString("o") instead of ToString("G"). CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"; culture.DateTimeFormat.LongTimePattern = "THH:mm:ss.fffffffzzz"; Thread.CurrentThread.CurrentCulture = culture; m_serverStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; m_serverStorageConnStr = AppState.GetConfigSetting(m_connStrKey); bool monitorCalls = true; if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank()) { throw new ApplicationException("The SIP Application Service cannot start with no persistence settings specified."); } SIPAllInOneDaemon daemon = null; if (args != null && args.Length == 1 && args[0] == "-i") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { //if (undo) //{ // inst.Uninstall(state); //} //else //{ inst.Install(state); inst.Commit(state); //} } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0] == "-u") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Uninstall(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0].StartsWith("-c") || System.Environment.UserInteractive == true) { isConsole = true; Console.WriteLine("SIP App Server starting"); logger.Debug("SIP App Server Console starting..."); string sipSocket = null; string callManagerSvcAddress = null; if (args != null && args.Length > 0) { foreach (string arg in args) { if (arg.StartsWith("-sip:")) { sipSocket = arg.Substring(5); } else if (arg.StartsWith("-cms:")) { callManagerSvcAddress = arg.Substring(5); } else if (arg.StartsWith("-hangupcalls:")) { monitorCalls = Convert.ToBoolean(arg.Substring(13)); } } } if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank()) { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); } else { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr, SIPEndPoint.ParseSIPEndPoint(sipSocket), callManagerSvcAddress, monitorCalls); } Thread daemonThread = new Thread(new ThreadStart(daemon.Start)); daemonThread.Start(); Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e) { e.Cancel = true; Console.WriteLine("Ctrl-C, clean up and exit..."); daemon.Stop(); m_proxyUp.Set(); }; m_proxyUp.WaitOne(); } else { logger.Debug("SIP App Server Windows Service Starting..."); System.ServiceProcess.ServiceBase[] ServicesToRun; daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception SIP App Server Main. " + excp.Message); if (isConsole) { Console.WriteLine("press any key to exit..."); Console.ReadLine(); } } }
static void Main(string[] args) { Closing = false; try { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve; Configuration.Initialize(); Parameters.Initialise(args, new char[] { '-', '/' }, new char[] { ' ', ':' }); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); ProcessParams.PreProcessAllParams(); if (Environment.UserInteractive) { ThreadManager.Initialise(); try { INSTANCE = new PrimaryService(); EventLog.Add("Initializing UserInteractive"); if (Parameters.OptionExists("i")) // install { try { EventLog.Add("Installing"); ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location }); } catch (Exception err) { if (!err.Message.Contains("The installation failed, and the rollback has been performed")) { throw; } } } else if (Parameters.OptionExists("u")) // uninstall { EventLog.Add("Uninstalling"); ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location }); } else { EventLog.Add("Run as Application"); ThreadManager.ThreadForcedToClose += ThreadManager_ThreadForcedToClose; INSTANCE.RunAsApplication(); Closing = true; } } catch (Exception err) { MessageBox.Show(String.Format("{0}\r\n{1}", err.Message, err.StackTrace.ToString())); EventLog.Add(err.Message); EventLog.Add(err); } finally { ThreadManager.Finalise(); } } else { System.ServiceProcess.ServiceBase[] ServicesToRun; INSTANCE = new PrimaryService(); ServicesToRun = new System.ServiceProcess.ServiceBase[] { INSTANCE }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception error) { EventLog.Add(error); } }
static void Main(string[] args) { bool isConsole = false; try { // Get DateTime.ToString() to use a format ot ToString("o") instead of ToString("G"). CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"; culture.DateTimeFormat.LongTimePattern = "THH:mm:ss.fffffffzzz"; Thread.CurrentThread.CurrentCulture = culture; m_serverStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; m_serverStorageConnStr = AppState.GetConfigSetting(m_connStrKey); bool monitorCalls = true; if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank()) { throw new ApplicationException("The SIP Application Service cannot start with no persistence settings specified."); } SIPAllInOneDaemon daemon = null; if (args != null && args.Length == 1 && args[0] == "-i") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { //if (undo) //{ // inst.Uninstall(state); //} //else //{ inst.Install(state); inst.Commit(state); //} } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0] == "-u") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Uninstall(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0].StartsWith("-c") || System.Environment.UserInteractive == true) { isConsole = true; Console.WriteLine("SIP App Server starting"); logger.Debug("SIP App Server Console starting..."); string sipSocket = null; string callManagerSvcAddress = null; if (args != null && args.Length > 0) { foreach (string arg in args) { if (arg.StartsWith("-sip:")) { sipSocket = arg.Substring(5); } else if (arg.StartsWith("-cms:")) { callManagerSvcAddress = arg.Substring(5); } else if (arg.StartsWith("-hangupcalls:")) { monitorCalls = Convert.ToBoolean(arg.Substring(13)); } } } if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank()) { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); } else { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr, SIPEndPoint.ParseSIPEndPoint(sipSocket), callManagerSvcAddress, monitorCalls); } Thread daemonThread = new Thread(new ThreadStart(daemon.Start)); daemonThread.Start(); m_proxyUp.WaitOne(); } else { logger.Debug("SIP App Server Windows Service Starting..."); System.ServiceProcess.ServiceBase[] ServicesToRun; daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception SIP App Server Main. " + excp.Message); if (isConsole) { Console.WriteLine("press any key to exit..."); Console.ReadLine(); } } }
// The main entry point for the process public static void Main() { bool isValidProperties = ReadPropertiesFile(); if (isValidProperties) { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WinService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } }
static void Main(string[] args) { try { Console.WriteLine("WebRTC Video Service Console:"); //Windows service has system32 as default working folder, we change the working dir to install dir for file access System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); logger.Debug("Setting current directory to " + System.AppDomain.CurrentDomain.BaseDirectory); var daemon = new WebRTCDaemon(); if (args != null && args.Length == 1 && args[0] == "-i") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Install(state); inst.Commit(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0] == "-u") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Uninstall(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if ((args != null && args.Length == 1 && args[0].StartsWith("-c")) || System.Environment.UserInteractive == true) { Thread daemonThread = new Thread(daemon.Start); daemonThread.Start(); Console.WriteLine("Daemon successfully started."); var mre = new ManualResetEvent(false); mre.WaitOne(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WebRTCService(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } }
private static System.Diagnostics.TraceListener[] MakeListenersForService(System.ServiceProcess.ServiceBase service) { System.Diagnostics.EventLogTraceListener eventListener = new System.Diagnostics.EventLogTraceListener(service.EventLog); System.Diagnostics.ConsoleTraceListener consoleListener = new System.Diagnostics.ConsoleTraceListener(); return(new System.Diagnostics.TraceListener[] { consoleListener, eventListener }); }
public static void Run(System.ServiceProcess.ServiceBase service) { }
internal static Udbus.Core.Logging.ILog ReplaceServiceLogger(System.ServiceProcess.ServiceBase service, Udbus.Core.Logging.ILog log) { return(Udbus.Core.Logging.LogCreation.ReplaceFormatLogger(log, defaultSourceLevel, assertServiceName(service.ServiceName), defaultFormat, MakeListenersForService(service))); }
/// <summary> /// The main entry point for the process /// </summary> static void Main() { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WinService() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); }