Exemple #1
0
        /// <summary>
        /// The main application entry point.
        /// </summary>
        protected override void Main()
        {
            // Initialize the environment.

            SysLog.LogProvider = new SwitchLogProvider();

            var assembly = Assembly.GetExecutingAssembly();

            Helper.InitializeApp(assembly);
            Config.SetConfigPath(assembly);
            CorePerf.Initialize();

            CoreApp.InstallPath = Helper.GetAssemblyFolder(Helper.GetEntryAssembly());

            // Initialize the global NeonSwitch related variables.

            Switch.SetGlobal(SwitchGlobal.NeonSwitchVersion, Build.Version);
            Switch.SetGlobal(SwitchGlobal.FreeSwitchVersion, Helper.GetVersionString(Assembly.GetAssembly(typeof(freeswitch))));

            // Load the application configuration settings.

            CoreApp.Config         = new Config("NeonSwitch");
            CoreApp.BkTaskInterval = CoreApp.Config.Get("BkTaskInterval", TimeSpan.FromSeconds(1));

            // Load the switch subcommand handlers.

            Switch.RegisterAssemblySubcommands(assembly);

            // Create a service host for the application service and launch it.

            var logProvider =
                new CompositeSysLogProvider(
                    new NativeSysLogProvider(SwitchConst.NeonSwitchName),
                    new SwitchLogProvider());

            serviceHost = new SwitchServiceHost();
            serviceHost.Initialize(new string[0], new CoreAppService(), logProvider, true);
        }
Exemple #2
0
        /// <summary>
        /// Starts the service, associating it with an <see cref="IServiceHost" /> instance.
        /// </summary>
        /// <param name="serviceHost">The service user interface.</param>
        /// <param name="args">Command line arguments.</param>
        public void Start(IServiceHost serviceHost, string[] args)
        {
            lock (syncLock)
            {
                if (router != null)
                {
                    return;     // Already started
                }
                // Global initialization

                startTime = DateTime.UtcNow;

                NetTrace.Start();
                CoreApp.InstallPerfCounters();

                // Service initialization

                this.serviceHost = serviceHost;

                try
                {
                    SysLog.LogInformation("NeonSwitch v{0} Start", Helper.GetVersionString());

                    router = new LeafRouter();
                    router.Start();

                    state = ServiceState.Running;

                    bkTimer = new GatedTimer(OnBkTimer, null, CoreApp.BkTaskInterval);
                    SpeechEngine.Start(SpeechEngineSettings.LoadConfig("NeonSwitch.Speech"));
#if DEBUG
                    // $todo(jeff.lill): Delete this.

                    SwitchTest.Test();
#endif
                    // Indicate that the switch core service is open for business.  NeonSwitch
                    // application instance loaders will spin, waiting for this to be set before
                    // calling the application's main function.

                    Switch.SetGlobal(SwitchGlobal.NeonSwitchReady, "true");
                }
                catch (Exception e)
                {
                    SpeechEngine.Stop();

                    if (bkTimer != null)
                    {
                        bkTimer.Dispose();
                        bkTimer = null;
                    }

                    if (router != null)
                    {
                        router.Stop();
                        router = null;
                    }

                    SysLog.LogException(e);
                    throw;
                }
            }
        }