public RegistrarCore(
            SIPTransport sipTransport,
            SIPRegistrarBindingsManager registrarBindingsManager,
            SIPAssetGetDelegate <SIPAccountAsset> getSIPAccount,
            GetCanonicalDomainDelegate getCanonicalDomain,
            bool mangleUACContact,
            bool strictRealmHandling,
            SIPMonitorLogDelegate proxyLogDelegate,
            SIPUserAgentConfigurationManager userAgentConfigs,
            SIPAuthenticateRequestDelegate sipRequestAuthenticator,
            string switchboarduserAgentPrefix,
            SIPAssetPersistor <Customer> customerPersistor)
        {
            m_sipTransport                   = sipTransport;
            m_registrarBindingsManager       = registrarBindingsManager;
            GetSIPAccount_External           = getSIPAccount;
            GetCanonicalDomain_External      = getCanonicalDomain;
            m_mangleUACContact               = mangleUACContact;
            m_strictRealmHandling            = strictRealmHandling;
            m_registrarLogEvent              = proxyLogDelegate;
            m_userAgentConfigs               = userAgentConfigs;
            SIPRequestAuthenticator_External = sipRequestAuthenticator;
            m_switchboarduserAgentPrefix     = switchboarduserAgentPrefix;
            CustomerPersistor_External       = customerPersistor;

            //try
            //{
            //    if (!switchboardCertificateName.IsNullOrBlank())
            //    {
            //        X509Certificate2 switchboardCertificate = AppState.LoadCertificate(StoreLocation.LocalMachine, switchboardCertificateName, false);
            //        m_switchbboardRSAProvider = (RSACryptoServiceProvider)switchboardCertificate.PrivateKey;
            //        logger.Debug("Switchboard RSA provider successfully loaded from " + switchboardCertificateName + " certificate.");
            //    }
            //}
            //catch (Exception excp)
            //{
            //    logger.Error("Exception loading switchboard certificate using " + switchboardCertificateName + ". " + excp.Message);
            //}
        }
        public RegistrarCore(
            SIPTransport sipTransport,
            SIPRegistrarBindingsManager registrarBindingsManager,
            SIPAssetGetDelegate<SIPAccount> getSIPAccount,
            GetCanonicalDomainDelegate getCanonicalDomain,
            bool mangleUACContact,
            bool strictRealmHandling,
            SIPMonitorLogDelegate proxyLogDelegate,
            SIPUserAgentConfigurationManager userAgentConfigs,
            SIPAuthenticateRequestDelegate sipRequestAuthenticator,
            string switchboardCertificateName)
        {
            m_sipTransport = sipTransport;
            m_registrarBindingsManager = registrarBindingsManager;
            GetSIPAccount_External = getSIPAccount;
            GetCanonicalDomain_External = getCanonicalDomain;
            m_mangleUACContact = mangleUACContact;
            m_strictRealmHandling = strictRealmHandling;
            m_registrarLogEvent = proxyLogDelegate;
            m_userAgentConfigs = userAgentConfigs;
            SIPRequestAuthenticator_External = sipRequestAuthenticator;

            try
            {
                if (!switchboardCertificateName.IsNullOrBlank())
                {
                    X509Certificate2 switchboardCertificate = AppState.LoadCertificate(StoreLocation.LocalMachine, switchboardCertificateName, false);
                    m_switchbboardRSAProvider = (RSACryptoServiceProvider)switchboardCertificate.PrivateKey;
                    logger.Debug("Switchboard RSA provider successfully loaded from " + switchboardCertificateName + " certificate.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception loading switchboard certificate using " + switchboardCertificateName + ". " + excp.Message);
            }
        }
        public void Start() {
            try {
                logger.Debug("SIP Registrar daemon starting...");

                // Pre-flight checks.
                if (m_sipRegistrarSocketsNode == null || m_sipRegistrarSocketsNode.ChildNodes.Count == 0) {
                    throw new ApplicationException("The SIP Registrar cannot start without at least one socket specified to listen on, please check config file.");
                }

                // Send events from this process to the monitoring socket.
                if (m_monitorLoopbackPort != 0) {
                    // Events will be sent by the monitor channel to the loopback interface and this port.
                    m_monitorEventWriter = new SIPMonitorEventWriter(m_monitorLoopbackPort);
                    logger.Debug("Monitor channel initialised for 127.0.0.1:" + m_monitorLoopbackPort + ".");
                }

                // Configure the SIP transport layer.
                m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine(), false);
                m_sipTransport.PerformanceMonitorPrefix = SIPSorceryPerformanceMonitor.REGISTRAR_PREFIX;
                List<SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_sipRegistrarSocketsNode);
                m_sipTransport.AddSIPChannel(sipChannels);

                // Create and configure the SIP Registrar core.
                if (m_natKeepAliveRelaySocket != null) {
                    m_natKeepAliveSender = new UdpClient();
                }

                SIPUserAgentConfigurationManager userAgentConfigManager = new SIPUserAgentConfigurationManager(m_userAgentsConfigNode);
                if (m_userAgentsConfigNode == null) {
                    logger.Warn("The UserAgent config's node was missing.");
                }
                m_registrarBindingsManager = new SIPRegistrarBindingsManager(FireSIPMonitorEvent, m_registrarBindingsPersistor, SendNATKeepAlive, m_maximumAccountBindings, userAgentConfigManager);
                m_registrarBindingsManager.Start();

                m_registrarCore = new RegistrarCore(m_sipTransport, m_registrarBindingsManager, GetSIPAccount_External, GetCanonicalDomain_External, true, true, FireSIPMonitorEvent, userAgentConfigManager, SIPAuthenticateRequest_External, m_switchboardCertificateName);
                m_registrarCore.Start(m_threadCount);
                m_sipTransport.SIPTransportRequestReceived += m_registrarCore.AddRegisterRequest;

                logger.Debug("SIP Registrar successfully started.");
            }
            catch (Exception excp) {
                logger.Error("Exception SIPRegistrarDaemon Start. " + excp.Message);
            }
        }