/sipsorcery-servers/SIPSorcery.SIPAppServer/SIPAppServerProgram.cs
C# | 115 lines | 84 code | 17 blank | 14 comment | 13 complexity | ee51531ddfcd9466bc5a1c29e28aff25 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using SIPSorcery.CRM;
- using SIPSorcery.Net;
- using SIPSorcery.Persistence;
- using SIPSorcery.SIP;
- using SIPSorcery.SIP.App.Entities;
- using SIPSorcery.Sys;
- using log4net;
-
- namespace SIPSorcery.SIPAppServer
- {
- class MainConsole
- {
- private static readonly string m_storageTypeKey = SIPSorceryConfiguration.PERSISTENCE_STORAGETYPE_KEY;
- private static readonly string m_connStrKey = SIPSorceryConfiguration.PERSISTENCE_STORAGECONNSTR_KEY;
-
- private static ILog logger = AppState.logger;
-
- private static ManualResetEvent m_proxyUp = new ManualResetEvent(false);
-
- private static StorageTypes m_serverStorageType;
- private static string m_serverStorageConnStr;
-
- [STAThread]
- 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.");
- }
-
- // Need to force the System.Data.Entity assembly to load before a dialplan instantiation. The assembly will fail to load if
- // requested from the Dynamic Language Runtime which is what happens if the first time it's requested is in an IronRuby dialplan.
- using (SIPSorceryAppEntities appEntities = new SIPSorceryAppEntities())
- {
- logger.Debug("Lookups count=" + (from lookup in appEntities.SIPDialplanLookups select lookup).Count() + ", forcing entity framework assemblies to load.");
- }
-
- //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));
- }
- }
-
- SIPAppServerDaemon daemon = null;
-
- if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank()) {
- daemon = new SIPAppServerDaemon(m_serverStorageType, m_serverStorageConnStr);
- }
- else {
- daemon = new SIPAppServerDaemon(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;
- // SIPAppServerDaemon daemon = new SIPAppServerDaemon(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();
- }
- }
- }
- }
- }