sipsorcery-mono /sipsorcery-servers/SIPSorcery.SIPAppServer/SIPAppServerProgram.cs

Language C# Lines 116
MD5 Hash ee51531ddfcd9466bc5a1c29e28aff25
Repository https://github.com/thecc4re/sipsorcery-mono.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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();
                }
            }
        }
    }
}
Back to Top