示例#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));
 }