Exemplo n.º 1
0
        static void Main(string[] args)
        {
            bool interactive = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/?":
                case "-h":
                case "-help":
                    ShowHelp();
                    return;

                case "-c":
                    Global.config_file = args[++i];
                    break;

                case "-s":
                    Global.webapi_subscriptions_file = args[++i];
                    break;

                case "-i":
                    interactive = true;
                    break;
                }
            }

            if (string.IsNullOrEmpty(Global.config_file))
            {
                Global.config_file = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) +
                                     Path.DirectorySeparatorChar + "OmniLinkBridge.ini";
            }

            if (string.IsNullOrEmpty(Global.webapi_subscriptions_file))
            {
                Global.webapi_subscriptions_file = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) +
                                                   Path.DirectorySeparatorChar + "WebSubscriptions.json";
            }

            log4net.Config.XmlConfigurator.Configure();

            try
            {
                Settings.LoadSettings();
            }
            catch
            {
                // Errors are logged in LoadSettings();
                Environment.Exit(1);
            }

            if (Environment.UserInteractive || interactive)
            {
                Console.TreatControlCAsInput = false;
                Console.CancelKeyPress      += new ConsoleCancelEventHandler(myHandler);

                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

                server = new CoreServer();
            }
            else
            {
                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 ServiceBase[] {new Service1(), new MySecondUserService()};
                //
                ServicesToRun = new ServiceBase[] { new Service() };

                ServiceBase.Run(ServicesToRun);
            }
        }
Exemplo n.º 2
0
 protected override void OnStart(string[] args)
 {
     server = new CoreServer();
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            bool interactive = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/?":
                case "-h":
                case "-help":
                    ShowHelp();
                    return;

                case "-c":
                    Global.config_file = args[++i];
                    break;

                case "-e":
                    Settings.UseEnvironment = true;
                    break;

                case "-d":
                    Settings.ShowDebug = true;
                    break;

                case "-s":
                    Global.webapi_subscriptions_file = args[++i];
                    break;

                case "-i":
                    interactive = true;
                    break;
                }
            }

            if (string.IsNullOrEmpty(Global.config_file))
            {
                Global.config_file = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) +
                                     Path.DirectorySeparatorChar + "OmniLinkBridge.ini";
            }

            if (string.IsNullOrEmpty(Global.webapi_subscriptions_file))
            {
                Global.webapi_subscriptions_file = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) +
                                                   Path.DirectorySeparatorChar + "WebSubscriptions.json";
            }

            log4net.Config.XmlConfigurator.Configure();

            if (Environment.UserInteractive || interactive)
            {
                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            }

            try
            {
                Settings.LoadSettings(Global.config_file);
            }
            catch
            {
                // Errors are logged in LoadSettings();
                Environment.Exit(1);
            }

            if (Environment.UserInteractive || interactive)
            {
                if (IsRunningOnMono())
                {
                    UnixSignal[] signals = new UnixSignal[] {
                        new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
                        new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
                        new UnixSignal(Mono.Unix.Native.Signum.SIGUSR1)
                    };

                    Task.Factory.StartNew(() =>
                    {
                        // Blocking call to wait for any kill signal
                        int index = UnixSignal.WaitAny(signals, -1);

                        server.Shutdown();
                    });
                }

                Console.TreatControlCAsInput = false;
                Console.CancelKeyPress      += new ConsoleCancelEventHandler(myHandler);

                server = new CoreServer();
            }
            else
            {
                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 ServiceBase[] {new Service1(), new MySecondUserService()};
                //
                ServicesToRun = new ServiceBase[] { new Service() };

                ServiceBase.Run(ServicesToRun);
            }
        }
Exemplo n.º 4
0
        static int Main(string[] args)
        {
            bool interactive = false;

            string        config_file = "OmniLinkBridge.ini";
            string        log_file    = "log.txt";
            bool          log_clef    = false;
            LogEventLevel log_level   = LogEventLevel.Information;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "/?":
                case "-h":
                case "-help":
                    ShowHelp();
                    return(0);

                case "-c":
                    config_file = args[++i];
                    break;

                case "-e":
                    Global.UseEnvironment = true;
                    break;

                case "-d":
                    Global.DebugSettings = true;
                    break;

                case "-lf":
                    log_file = args[++i];

                    if (string.Compare(log_file, "disable", true) == 0)
                    {
                        log_file = null;
                    }
                    break;

                case "-lj":
                    log_clef = true;
                    break;

                case "-ll":
                    Enum.TryParse(args[++i], out log_level);
                    break;

                case "-s":
                    Global.webapi_subscriptions_file = args[++i];
                    break;

                case "-i":
                    interactive = true;
                    break;
                }
            }

            config_file = GetFullPath(config_file);

            Global.webapi_subscriptions_file = GetFullPath(Global.webapi_subscriptions_file ?? "WebSubscriptions.json");

            // Use TLS 1.2 as default connection
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            string log_format = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{SourceContext} {Level:u3}] {Message:lj}{NewLine}{Exception}";

            var log_config = new LoggerConfiguration()
                             .MinimumLevel.Verbose()
                             .Enrich.WithProperty("Application", "OmniLinkBridge")
                             .Enrich.WithProperty("Session", Guid.NewGuid())
                             .Enrich.WithProperty("User", (Environment.UserName + Environment.MachineName).GetHashCode())
                             .Enrich.FromLogContext();

            if (log_file != null)
            {
                log_file = GetFullPath(log_file);

                if (log_clef)
                {
                    log_config = log_config.WriteTo.Async(a => a.File(new CompactJsonFormatter(), log_file, log_level,
                                                                      rollingInterval: RollingInterval.Day, retainedFileCountLimit: 15));
                }
                else
                {
                    log_config = log_config.WriteTo.Async(a => a.File(log_file, log_level, log_format,
                                                                      rollingInterval: RollingInterval.Day, retainedFileCountLimit: 15));
                }
            }

            if (UseTelemetry())
            {
                log_config = log_config.WriteTo.Logger(lc => lc
                                                       .Filter.ByIncludingOnly(Matching.WithProperty("Telemetry"))
                                                       .WriteTo.Http("https://telemetry.excalibur-partners.com"));
            }

            if (Environment.UserInteractive || interactive)
            {
                log_config = log_config.WriteTo.Console(outputTemplate: log_format);
            }

            Log.Logger = log_config.CreateLogger();

            try
            {
                Settings.LoadSettings(config_file);
            }
            catch
            {
                // Errors are logged in LoadSettings();
                Log.CloseAndFlush();
                return(-1);
            }

            if (Environment.UserInteractive || interactive)
            {
                if (IsRunningOnMono())
                {
                    UnixSignal[] signals = new UnixSignal[] {
                        new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
                        new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
                        new UnixSignal(Mono.Unix.Native.Signum.SIGUSR1)
                    };

                    Task.Factory.StartNew(() =>
                    {
                        // Blocking call to wait for any kill signal
                        int index = UnixSignal.WaitAny(signals, -1);

                        server.Shutdown();
                    });
                }

                Console.TreatControlCAsInput = false;
                Console.CancelKeyPress      += new ConsoleCancelEventHandler(myHandler);

                server = new CoreServer();
            }
            else
            {
                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 ServiceBase[] {new Service1(), new MySecondUserService()};
                //
                ServicesToRun = new ServiceBase[] { new Service() };

                ServiceBase.Run(ServicesToRun);
            }

            return(0);
        }