Пример #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);
        }
Пример #2
0
 /// <summary>
 /// Logs an informational entry.
 /// </summary>
 /// <param name="extension">Extended log entry information (or <c>null</c>).</param>
 /// <param name="message">The message.</param>
 public void LogInformation(ISysLogEntryExtension extension, string message)
 {
     Switch.Log(MapLogLevel(SysLogEntryType.Information), message);
 }
Пример #3
0
 /// <summary>
 /// Logs a warning.
 /// </summary>
 /// <param name="extension">Extended log entry information (or <c>null</c>).</param>
 /// <param name="message">The message.</param>
 public void LogWarning(ISysLogEntryExtension extension, string message)
 {
     Switch.Log(MapLogLevel(SysLogEntryType.Warning), message);
 }
Пример #4
0
 /// <summary>
 /// Logs debugging related information.
 /// </summary>
 /// <param name="extension">Extended log entry information (or <c>null</c>).</param>
 /// <param name="category">Used to group debugging related log entries.</param>
 /// <param name="message">The message.</param>
 public void Trace(ISysLogEntryExtension extension, string category, string message)
 {
     Switch.Log(MapLogLevel(SysLogEntryType.Trace), message);
 }
Пример #5
0
 /// <summary>
 /// Logs a <see cref="SysLogEntry" />
 /// </summary>
 /// <param name="entry">The log entry.</param>
 public void Log(SysLogEntry entry)
 {
     Switch.Log(MapLogLevel(entry.Type), entry.Message);
 }
Пример #6
0
 /// <summary>
 /// Logs an exception with additional information.
 /// </summary>
 /// <param name="extension">Extended log entry information (or <c>null</c>).</param>
 /// <param name="e">The exception being logged.</param>
 /// <param name="message">The message.</param>
 public void LogException(ISysLogEntryExtension extension, Exception e, string message)
 {
     Switch.Log(MapLogLevel(SysLogEntryType.Exception), "Exception [{0}] : {1}", e.GetType().Name, e.Message);
 }
Пример #7
0
 /// <summary>
 /// Logs a failed security related change or access attempt.
 /// </summary>
 /// <param name="extension">Extended log entry information (or <c>null</c>).</param>
 /// <param name="message">The message.</param>
 public void LogSecurityFailure(ISysLogEntryExtension extension, string message)
 {
     Switch.Log(MapLogLevel(SysLogEntryType.SecurityFailure), message);
 }
Пример #8
0
 /// <summary>
 /// Logs an error.
 /// </summary>
 /// <param name="extension">Extended log entry information (or <c>null</c>).</param>
 /// <param name="message">The message.</param>
 public void LogError(ISysLogEntryExtension extension, string message)
 {
     Switch.Log(MapLogLevel(SysLogEntryType.Error), message);
 }
Пример #9
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;
                }
            }
        }
Пример #10
0
 /// <summary>
 /// Called by the <see cref="AppLoader" /> to execute a command asynchronously.
 /// </summary>
 /// <param name="context">The command context.</param>
 internal void OnExecuteBackground(ApiBackgroundContext context)
 {
     Switch.OnExecuteBackground(new ExecuteBackgroundEventArgs(context));
 }
Пример #11
0
 /// <summary>
 /// Called by the <see cref="AppLoader" /> to execute a command synchronously.
 /// </summary>
 /// <param name="context">The command context.</param>
 internal void OnExecute(ApiContext context)
 {
     Switch.OnExecute(new ExecuteEventArgs(context));
 }
Пример #12
0
 /// <summary>
 /// Called by the <see cref="AppLoader" /> when the application has been assigned a new call session.
 /// </summary>
 /// <param name="context">The application context.</param>
 internal void OnNewCallSession(AppContext context)
 {
     Switch.RaiseCallSessionEvent(new CallSessionArgs(new CallSession(context.Session), context.Arguments));
 }