public void SetProviderFields(SIPProvider sipProvider)
        {
            ProviderID            = sipProvider.ID;
            Owner                 = sipProvider.Owner;
            AdminMemberID         = sipProvider.AdminMemberID;
            ProviderName          = sipProvider.ProviderName;
            ProviderAuthUsername  = (!sipProvider.ProviderAuthUsername.IsNullOrBlank()) ? sipProvider.ProviderAuthUsername : sipProvider.ProviderUsername;
            ProviderPassword      = sipProvider.ProviderPassword;
            RegistrarServer       = sipProvider.GetRegistrar();
            RegistrarRealm        = (!sipProvider.RegisterRealm.IsNullOrBlank()) ? sipProvider.RegisterRealm : RegistrarServer.Host;
            ProviderOutboundProxy = sipProvider.ProviderOutboundProxy;

            if (sipProvider.RegisterEnabled)
            {
                BindingExpiry = (sipProvider.RegisterExpiry.HasValue) ? sipProvider.RegisterExpiry.Value : 0;
            }
            else
            {
                BindingExpiry = 0;
            }

            string bindingId = null;
            SIPURI binding   = (!BindingURI.IsNullOrBlank()) ? SIPURI.ParseSIPURIRelaxed(BindingURI) : null;

            if (binding != null && binding.Parameters.Has(REGAGENT_CONTACT_ID_KEY))
            {
                bindingId = binding.Parameters.Get(REGAGENT_CONTACT_ID_KEY);
            }

            if (!sipProvider.RegisterContact.IsNullOrBlank())
            {
                binding = SIPURI.ParseSIPURI(sipProvider.RegisterContact);
                if (!bindingId.IsNullOrBlank())
                {
                    binding.Parameters.Set(REGAGENT_CONTACT_ID_KEY, bindingId);
                }

                if (binding != null)
                {
                    BindingURI = binding.ToString();
                }
                else
                {
                    BindingURI    = null;
                    BindingExpiry = 0;
                }
            }
            else
            {
                // The register contact field on the SIP Provider is empty.
                // This condition needs to be trearted as the binding being disabled and it needs to be removed.
                BindingExpiry = 0;
            }
        }
        public string ToXMLNoParent()
        {
            string lastRegisterTimeStr    = (m_lastRegisterTime != null) ? m_lastRegisterTime.Value.ToString("o") : null;
            string lastRegisterAttemptStr =
                (m_lastRegisterTime != null) ? m_lastRegisterAttempt.Value.ToString("o") : null;
            string nextRegistrationTimeStr = (m_nextRegistrationTime != DateTimeOffset.MaxValue)
                ? m_nextRegistrationTime.ToString("o")
                : null;
            string bindingExpiryStr = (m_bindingExpiry > 0) ? m_bindingExpiry.ToString() : null;
            string bindingURIStr    = (BindingURI != null) ? BindingURI.ToString() : null;
            string contactsListStr  = null;

            if (ContactsList != null)
            {
                foreach (SIPContactHeader contact in ContactsList)
                {
                    contactsListStr += contact.ToString();
                }
            }

            string providerBindingXML =
                "   <id>" + m_id + "</id>" + m_newLine +
                "   <providerid>" + m_providerId + "</providerid>" + m_newLine +
                "   <providername>" + ProviderName + "</providername>" + m_newLine +
                "   <owner>" + m_owner + "</owner>" + m_newLine +
                "   <adminmemberid>" + AdminMemberId + "</adminmemberid>" + m_newLine +
                "   <bindinguri>" + bindingURIStr + "</bindinguri>" + m_newLine +
                "   <cseq>" + CSeq + "</cseq>" + m_newLine +
                "   <contactheader>" + SafeXML.MakeSafeXML(contactsListStr) + "</contactheader>" + m_newLine +
                "   <registrationfailuremessage>" + SafeXML.MakeSafeXML(m_registrationFailureMessage) +
                "</registrationfailuremessage>" + m_newLine +
                "   <lastregistertime>" + lastRegisterTimeStr + "</lastregistertime>" + m_newLine +
                "   <lastregisterattempt>" + lastRegisterAttemptStr + "</lastregisterattempt>" + m_newLine +
                "   <nextregistrationtime>" + nextRegistrationTimeStr + "</nextregistrationtime>" + m_newLine +
                "   <bindingexpiry>" + bindingExpiryStr + "</bindingexpiry>" + m_newLine +
                "   <isregistered>" + m_isRegistered + "</isregistered>" + m_newLine +
                "   <registrarsipsocket>" + RegistrarSIPSocket + "</registrarsipsocket>" + m_newLine;

            return(providerBindingXML);
        }