Inheritance: System.Data.Objects.DataClasses.EntityObject
        public static void SIPProviderDeleted(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderDeleted for " + sipProvider.Owner + " and " + sipProvider.ProviderName + ".");

                using (SIPSorceryEntities sipSorceryEntities = new SIPSorceryEntities())
                {

                    SIPProviderBinding existingBinding = (from binding in sipSorceryEntities.SIPProviderBindings
                                                          where binding.ProviderID == sipProvider.ID
                                                          select binding).FirstOrDefault();

                    if (existingBinding != null)
                    {
                        if (existingBinding.IsRegistered)
                        {
                            // Let the registration agent know the existing binding should be expired.
                            existingBinding.BindingExpiry = 0;
                            existingBinding.NextRegistrationTime = DateTime.UtcNow.ToString("o");
                            sipSorceryEntities.SaveChanges();
                        }
                        else
                        {
                            sipSorceryEntities.SIPProviderBindings.DeleteObject(existingBinding);
                            sipSorceryEntities.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderDeleted. " + excp.Message);
            }
        }
Ejemplo n.º 2
0
        public static void SIPProviderAdded(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderAdded for " + sipProvider.Owner + " and " + sipProvider.ProviderName + " (Provider ID=" + sipProvider.ID + ").");

                if (sipProvider.RegisterEnabled)
                {
                    using (SIPSorceryEntities sipSorceryEntities = new SIPSorceryEntities())
                    {
                        SIPProvider existingProvider = (from provider in sipSorceryEntities.SIPProviders
                                                        where provider.ID == sipProvider.ID
                                                        select provider).FirstOrDefault();

                        if (existingProvider != null)
                        {
                            AddNewBindingForProvider(sipSorceryEntities, existingProvider);
                        }
                        else
                        {
                            logger.Warn("The SIP provider entry was not in the database when attempting to add a provider binding.");
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderAdded. " + excp.Message);
            }
        }
        public static void SIPProviderAdded(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderAdded for " + sipProvider.Owner + " and " + sipProvider.ProviderName + " (Provider ID=" + sipProvider.ID + ").");

                if (sipProvider.RegisterEnabled)
                {
                    using (SIPSorceryEntities sipSorceryEntities = new SIPSorceryEntities())
                    {
                        SIPProvider existingProvider = (from provider in sipSorceryEntities.SIPProviders
                                                        where provider.ID == sipProvider.ID
                                                        select provider).FirstOrDefault();

                        if (existingProvider != null)
                        {
                            AddNewBindingForProvider(sipSorceryEntities, existingProvider);
                        }
                        else
                        {
                            logger.Warn("The SIP provider entry was not in the database when attempting to add a provider binding.");
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderAdded. " + excp.Message);
            }
        }
        public SIPProvider ToSIPProvider()
        {
            var entitySIPProvider = new SIPProvider()
            {
                Owner                 = String.Empty,
                ID                    = ID,
                ProviderName          = ProviderName,
                ProviderUsername      = ProviderUsername,
                ProviderPassword      = ProviderPassword,
                ProviderServer        = ProviderServer,
                ProviderAuthUsername  = ProviderAuthUsername,
                ProviderOutboundProxy = ProviderOutboundProxy,
                ProviderType          = ProviderType,
                ProviderFrom          = ProviderFrom,
                CustomHeaders         = CustomHeaders,
                RegisterEnabled       = RegisterEnabled,
                RegisterContact       = RegisterContact,
                RegisterExpiry        = RegisterExpiry,
                RegisterServer        = RegisterServer,
                RegisterRealm         = RegisterRealm,
                GVCallbackNumber      = GVCallbackNumber,
                GVCallbackPattern     = GVCallbackPattern,
                GVCallbackType        = GVCallbackType
            };

            return(entitySIPProvider);
        }
Ejemplo n.º 5
0
        public static void SIPProviderDeleted(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderDeleted for " + sipProvider.Owner + " and " + sipProvider.ProviderName + ".");

                using (SIPSorceryEntities sipSorceryEntities = new SIPSorceryEntities())
                {
                    SIPProviderBinding existingBinding = (from binding in sipSorceryEntities.SIPProviderBindings
                                                          where binding.ProviderID == sipProvider.ID
                                                          select binding).FirstOrDefault();

                    if (existingBinding != null)
                    {
                        if (existingBinding.IsRegistered)
                        {
                            // Let the registration agent know the existing binding should be expired.
                            existingBinding.BindingExpiry        = 0;
                            existingBinding.NextRegistrationTime = DateTime.UtcNow.ToString("o");
                            sipSorceryEntities.SaveChanges();
                        }
                        else
                        {
                            sipSorceryEntities.SIPProviderBindings.DeleteObject(existingBinding);
                            sipSorceryEntities.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderDeleted. " + excp.Message);
            }
        }
        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 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;
            }
        }
Ejemplo n.º 8
0
        public void SIPProviderInvalidServerValidationTest()
        {
            SIPProvider target = new SIPProvider()
            {
                Owner = "owner",
                ProviderName = "test",
                ProviderUsername = "******",
                ProviderType = "SIP",
                ProviderServer = "somehost"
            };

            string validationResult = SIPProvider.Validate(target);

            Assert.AreEqual("The SIP provider server should contain at least one '.' to be recognised as a valid hostname or IP address.", validationResult);
        }
        public SIPProviderDetailsControl(
            DetailsControlModesEnum mode,
            SIPProvider sipProvider,
            string owner,
            SIPProviderUpdateDelegate sipProviderAdd,
            SIPProviderUpdateDelegate sipProviderUpdate,
            ControlClosedDelegate closed)
        {
            InitializeComponent();

            m_advancedProviderSettings.Visibility = Visibility.Collapsed;
            m_detailsMode = mode;
            m_sipProvider = sipProvider;
            m_owner = owner;
            SIPProviderAdd_External = sipProviderAdd;
            SIPProviderUpdate_External = sipProviderUpdate;
            ControlClosed_External = closed;

            //if (m_disableProviderRegistrations)
            //{
            //    m_providerRegister.IsEnabled = false;
            //    m_providerRegisterContact.IsEnabled = false;
            //    m_providerRegisterExpiry.IsEnabled = false;
            //    m_providerRegisterServer.IsEnabled = false;
            //}

            if (mode == DetailsControlModesEnum.Edit)
            {
                m_providerTypeCanvas.Visibility = Visibility.Collapsed;
                m_gvSettingsPanel.Visibility = System.Windows.Visibility.Collapsed;
                m_applyButton.Content = "Update";
                PopulateDataFields(m_sipProvider);
            }
            else
            {
                m_providerIdCanvas.Visibility = Visibility.Collapsed;
                m_providerTypeNameCanvas.Visibility = Visibility.Collapsed;
                m_gvSettingsPanel.Visibility = System.Windows.Visibility.Collapsed;
                m_applyButton.Content = "Add";
            }
        }
Ejemplo n.º 10
0
        public static string Validate(SIPProvider sipProvider)
        {
            TypeDescriptor.AddProviderTransparent(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(SIPProvider), typeof(SIPProviderMetadata)), typeof(SIPProvider));

            var validationContext = new ValidationContext(sipProvider, null, null);
            var validationResults = new List<ValidationResult>();
            Validator.TryValidateObject(sipProvider, validationContext, validationResults);

            if (validationResults.Count > 0)
            {
                return validationResults.First().ErrorMessage;
            }
            else
            {
                Guid testGuid = Guid.Empty;
                if (!Guid.TryParse(sipProvider.ID, out testGuid))
                {
                    return "The ID was not a valid GUID.";
                }

                if (sipProvider.ProviderType == ProviderTypes.SIP.ToString())
                {
                    if (sipProvider.ProviderServer.IsNullOrBlank())
                    {
                        return "A value for Server must be specified.";
                    }
                    if (sipProvider.RegisterEnabled && sipProvider.RegisterContact == null)
                    {
                        return "A valid contact must be supplied to enable a provider registration.";
                    }
                    //else if (sipProvider.RegisterServer != null && sipProvider.m_registerServer.Host.IndexOf('.') == -1)
                    //{
                    //    return "Your register server entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.";
                    //}
                    //else if (sipProvider.RegisterContact != null && sipProvider.m_registerContact.Host.IndexOf('.') == -1)
                    //{
                    //    return "Your register contact entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.";
                    //}
                    //else if (sipProvider.RegisterContact != null && sipProvider.RegisterContact.User.IsNullOrBlank())
                    //{
                    //    return "Your register contact entry appears to be invalid, the user portion was missing. Contacts must be of the form [email protected], e.g. [email protected].";
                    //}
                    else if (ProhibitedServerPatterns != null && Regex.Match(sipProvider.ProviderServer, ProhibitedServerPatterns).Success)
                    {
                        return "The Provider Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.";
                    }
                    else if (ProhibitedServerPatterns != null && sipProvider.RegisterServer != null && Regex.Match(sipProvider.RegisterServer, ProhibitedServerPatterns).Success)
                    {
                        return "The Provider Register Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.";
                    }
                    else if (!SIPURI.TryParse(sipProvider.ProviderServer))
                    {
                        return "The Provider Server could not be parsed as a valid SIP URI.";
                    }
                    else if (sipProvider.RegisterServer != null && !SIPURI.TryParse(sipProvider.RegisterServer))
                    {
                        return "The Register Server could not be parsed as a valid SIP URI.";
                    }
                }
                else if (sipProvider.ProviderType == ProviderTypes.GoogleVoice.ToString())
                {
                    if (sipProvider.ProviderPassword.IsNullOrBlank())
                    {
                        return "A password is required for Google Voice entries.";
                    }
                    else if (sipProvider.GVCallbackNumber.IsNullOrBlank())
                    {
                        return "A callback number is required for Google Voice entries.";
                    }
                    else if (Regex.Match(sipProvider.GVCallbackNumber, @"\D").Success)
                    {
                        return "The callback number contains an invalid character. Only digits are permitted.";
                    }
                }
            }

            return null;
        }
 private void SIPProvidersPanel_Add()
 {
     m_selectedSIPProvider = null;
     m_addControl = new SIPProviderDetailsControl(DetailsControlModesEnum.Add, m_selectedSIPProvider, m_owner, SIPProviderAdd, null, DetailsControlClosed);
     m_sipProvidersPanel.SetDetailsElement(m_addControl);
 }
 private void UpdateSIPProvider(SIPProvider sipProvider)
 {
     m_riaContext.SubmitChanges(UpdateSIPProviderComplete, sipProvider);
 }
 private void SIPProviderAdd(SIPProvider sipProvider)
 {
     m_riaContext.SIPProviders.Add(sipProvider);
     m_riaContext.SubmitChanges(SIPProviderAddComplete, sipProvider);
 }
        private void SIPProvidersDataGrid_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                if (m_riaContext.SIPProviders.Count() > 0)
                {
                     DataGrid dataGrid = (DataGrid)sender;
                     if (dataGrid.CurrentColumn.Header as string != "Delete")
                     {
                         SIPProvider sipProvider = (SIPProvider)m_sipProvidersDataGrid.SelectedItem;

                         if (m_selectedSIPProvider == null || m_selectedSIPProvider != sipProvider)
                         {
                             m_selectedSIPProvider = sipProvider;
                             m_editControl = new SIPProviderDetailsControl(DetailsControlModesEnum.Edit, m_selectedSIPProvider, m_owner, null, UpdateSIPProvider, DetailsControlClosed);
                             m_sipProvidersPanel.SetDetailsElement(m_editControl);
                         }
                     }
                }
            }
            catch (Exception excp)
            {
                string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
                LogActivityMessage_External(MessageLevelsEnum.Error, "Exception showing SIP Provider details. " + excpMessage);
                m_selectedSIPProvider = null;
            }
        }
Ejemplo n.º 15
0
        public static string Validate(SIPProvider sipProvider)
        {
            TypeDescriptor.AddProviderTransparent(new AssociatedMetadataTypeTypeDescriptionProvider(typeof(SIPProvider), typeof(SIPProviderMetadata)), typeof(SIPProvider));

            var validationContext = new ValidationContext(sipProvider, null, null);
            var validationResults = new List <ValidationResult>();

            Validator.TryValidateObject(sipProvider, validationContext, validationResults);

            if (validationResults.Count > 0)
            {
                return(validationResults.First().ErrorMessage);
            }
            else
            {
                Guid testGuid = Guid.Empty;
                if (!Guid.TryParse(sipProvider.ID, out testGuid))
                {
                    return("The ID was not a valid GUID.");
                }

                if (sipProvider.ProviderType == ProviderTypes.SIP.ToString())
                {
                    if (sipProvider.ProviderServer.IsNullOrBlank())
                    {
                        return("A value for Server must be specified.");
                    }
                    if (sipProvider.RegisterEnabled && sipProvider.RegisterContact == null)
                    {
                        return("A valid contact must be supplied to enable a provider registration.");
                    }
                    //else if (sipProvider.RegisterServer != null && sipProvider.m_registerServer.Host.IndexOf('.') == -1)
                    //{
                    //    return "Your register server entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.";
                    //}
                    //else if (sipProvider.RegisterContact != null && sipProvider.m_registerContact.Host.IndexOf('.') == -1)
                    //{
                    //    return "Your register contact entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.";
                    //}
                    //else if (sipProvider.RegisterContact != null && sipProvider.RegisterContact.User.IsNullOrBlank())
                    //{
                    //    return "Your register contact entry appears to be invalid, the user portion was missing. Contacts must be of the form [email protected], e.g. [email protected].";
                    //}
                    else if (ProhibitedServerPatterns != null && Regex.Match(sipProvider.ProviderServer, ProhibitedServerPatterns).Success)
                    {
                        return("The Provider Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.");
                    }
                    else if (ProhibitedServerPatterns != null && sipProvider.RegisterServer != null && Regex.Match(sipProvider.RegisterServer, ProhibitedServerPatterns).Success)
                    {
                        return("The Provider Register Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.");
                    }
                    else if (!SIPURI.TryParse(sipProvider.ProviderServer))
                    {
                        return("The Provider Server could not be parsed as a valid SIP URI.");
                    }
                    else if (sipProvider.RegisterServer != null && !SIPURI.TryParse(sipProvider.RegisterServer))
                    {
                        return("The Register Server could not be parsed as a valid SIP URI.");
                    }
                }
                else if (sipProvider.ProviderType == ProviderTypes.GoogleVoice.ToString())
                {
                    if (sipProvider.ProviderPassword.IsNullOrBlank())
                    {
                        return("A password is required for Google Voice entries.");
                    }
                    else if (sipProvider.GVCallbackNumber.IsNullOrBlank())
                    {
                        return("A callback number is required for Google Voice entries.");
                    }
                    else if (Regex.Match(sipProvider.GVCallbackNumber, @"\D").Success)
                    {
                        return("The callback number contains an invalid character. Only digits are permitted.");
                    }
                }
            }

            return(null);
        }
 private void DetailsControlClosed()
 {
     m_sipProvidersPanel.CloseDetailsPane();
     m_selectedSIPProvider = null;
 }
Ejemplo n.º 17
0
 public void SIPAccountConstructorTest()
 {
     SIPProvider target = new SIPProvider();
     Assert.IsNotNull(target);
 }
Ejemplo n.º 18
0
        public void InsertSIPProvider(string authUser, SIPProvider sipProvider)
        {
            if (authUser.IsNullOrBlank())
            {
                throw new ArgumentException("An authenticated user is required for InsertSIPProvider.");
            }

            using (var sipSorceryEntities = new SIPSorceryEntities())
            {
                string serviceLevel = (from cust in sipSorceryEntities.Customers where cust.Name == authUser.ToLower() select cust.ServiceLevel).FirstOrDefault();

                if (!serviceLevel.IsNullOrBlank() && serviceLevel.ToLower() == CustomerServiceLevels.Free.ToString().ToLower())
                {
                    // Check the number of SIP providers is within limits.
                    if ((from provider in sipSorceryEntities.SIPProviders
                         where provider.Owner.ToLower() == authUser.ToLower() && !provider.IsReadOnly
                         select provider).Count() >= PROVIDER_COUNT_FREE_SERVICE)
                    {
                        throw new ApplicationException("The SIP Provider cannot be added. You are limited to " + PROVIDER_COUNT_FREE_SERVICE + " SIP Provider on a Free account. Please upgrade to a Premium service if you wish to create additional SIP Providers.");
                    }
                }

                if (sipProvider.RegisterEnabled)
                {
                    FixProviderRegisterDetails(sipProvider, authUser);
                }

                sipProvider.ID = Guid.NewGuid().ToString();
                sipProvider.Owner = authUser.ToLower();
                sipProvider.Inserted = DateTimeOffset.UtcNow.ToString("o");
                sipProvider.LastUpdate = DateTimeOffset.UtcNow.ToString("o");
                sipProvider.RegisterAdminEnabled = true;

                string validationError = SIPProvider.Validate(sipProvider);
                if (validationError != null)
                {
                    throw new ApplicationException(validationError);
                }

                sipSorceryEntities.SIPProviders.AddObject(sipProvider);
                sipSorceryEntities.SaveChanges();
            }

            SIPProviderBindingSynchroniser.SIPProviderAdded(sipProvider);
        }
Ejemplo n.º 19
0
        public void UpdateSIPProvider(string authUser, SIPProvider sipProvider)
        {
            if (authUser.IsNullOrBlank())
            {
                throw new ArgumentException("An authenticated user is required for InsertSIPProvider.");
            }

            SIPProvider existingAccount = null;

            using (var sipSorceryEntities = new SIPSorceryEntities())
            {
                existingAccount = (from sp in sipSorceryEntities.SIPProviders where sp.ID == sipProvider.ID && sp.Owner == authUser.ToLower() select sp).FirstOrDefault();

                if (existingAccount == null)
                {
                    throw new ApplicationException("The SIP provider to update could not be found.");
                }
                else if (existingAccount.Owner.ToLower() != authUser.ToLower())
                {
                    throw new ApplicationException("Not authorised to update the SIP Provider.");
                }
                else if (existingAccount.IsReadOnly)
                {
                    throw new ApplicationException("This SIP Provider is read-only. Please upgrade to a Premium service to enable it.");
                }

                existingAccount.CustomHeaders = sipProvider.CustomHeaders;
                existingAccount.GVCallbackNumber = sipProvider.GVCallbackNumber;
                existingAccount.GVCallbackPattern = sipProvider.GVCallbackPattern;
                existingAccount.GVCallbackType = sipProvider.GVCallbackType;
                existingAccount.LastUpdate = DateTimeOffset.UtcNow.ToString("o");
                existingAccount.ProviderAuthUsername = sipProvider.ProviderAuthUsername;
                existingAccount.ProviderFrom = sipProvider.ProviderFrom;
                existingAccount.ProviderName = sipProvider.ProviderName;
                existingAccount.ProviderOutboundProxy = sipProvider.ProviderOutboundProxy;
                existingAccount.ProviderPassword = sipProvider.ProviderPassword;
                existingAccount.ProviderServer = sipProvider.ProviderServer;
                existingAccount.ProviderUsername = sipProvider.ProviderUsername;
                existingAccount.RegisterContact = sipProvider.RegisterContact;
                existingAccount.RegisterEnabled = sipProvider.RegisterEnabled;
                existingAccount.RegisterExpiry = sipProvider.RegisterExpiry;
                existingAccount.RegisterRealm = sipProvider.RegisterRealm;
                existingAccount.RegisterServer = sipProvider.RegisterServer;
                existingAccount.RegisterDisabledReason = sipProvider.RegisterDisabledReason;
                existingAccount.SendMWISubscribe = sipProvider.SendMWISubscribe;

                if (existingAccount.RegisterEnabled)
                {
                    FixProviderRegisterDetails(existingAccount, authUser);
                }

                string validationError = SIPProvider.Validate(existingAccount);
                if (validationError != null)
                {
                    throw new ApplicationException(validationError);
                }

                sipSorceryEntities.SaveChanges();
            }

            SIPProviderBindingSynchroniser.SIPProviderUpdated(existingAccount);
        }
        private void PopulateDataFields(SIPProvider sipProvider)
        {
            m_providerId.Text = sipProvider.ID.ToString();
            m_providerTypeName.Text = sipProvider.ProviderType.ToString();
            m_providerName.Text = sipProvider.ProviderName;
            m_providerUsername.Text = sipProvider.ProviderUsername;
            m_providerPassword.Text = sipProvider.ProviderPassword;

            if (String.Equals(sipProvider.ProviderType, ProviderTypes.SIP.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                m_providerServer.Text = sipProvider.ProviderServer.ToString();
                m_providerAuthUsername.Text = (sipProvider.ProviderAuthUsername != null) ? sipProvider.ProviderAuthUsername : String.Empty;
                m_providerFromHeader.Text = (sipProvider.ProviderFrom != null) ? sipProvider.ProviderFrom : String.Empty;
                m_providerRegisterRealm.Text = (sipProvider.RegisterRealm != null) ? sipProvider.RegisterRealm : String.Empty;

                //if (!m_disableProviderRegistrations)
                //{
                m_providerRegister.IsChecked = sipProvider.RegisterEnabled;
                m_providerSendMWISubscribe.IsChecked = sipProvider.SendMWISubscribe;
                m_providerRegisterContact.Text = (sipProvider.RegisterContact != null) ? sipProvider.RegisterContact.ToString() : String.Empty;
                m_providerRegisterExpiry.Text = sipProvider.RegisterExpiry.ToString();
                m_providerRegisterServer.Text = (sipProvider.RegisterServer != null) ? sipProvider.RegisterServer.ToString() : String.Empty;

                m_providerRegisterContact.IsEnabled = m_providerRegister.IsChecked.Value;
                m_providerRegisterExpiry.IsEnabled = m_providerRegister.IsChecked.Value;
                m_providerRegisterServer.IsEnabled = m_providerRegister.IsChecked.Value;
                //}

                if (sipProvider.CustomHeaders != null && sipProvider.CustomHeaders.Trim().Length > 0)
                {
                    string[] customHeaders = sipProvider.CustomHeaders.Split(m_customHeadersSeparator);

                    if (customHeaders != null && customHeaders.Length > 0)
                    {
                        foreach (string customHeader in customHeaders)
                        {
                            if (customHeader != null && customHeader.Trim().Length > 0)
                            {
                                m_providerCustomHeaders.Items.Add(customHeader.Trim());
                            }
                        }
                    }
                }
            }
            else
            {
                GoogleVoiceTypeClicked(null, null);

                m_gvCallbackNumber.Text = sipProvider.GVCallbackNumber;
                m_gvCallbackPattern.Text = sipProvider.GVCallbackPattern;

                if (sipProvider.GVCallbackType != null)
                {
                    for (int index = 0; index < m_gvCallbackType.Items.Count; index++)
                    {
                        if (((TextBlock)m_gvCallbackType.Items[index]).Text == sipProvider.GVCallbackType)
                        {
                            m_gvCallbackType.SelectedIndex = index;
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
        private static void AddNewBindingForProvider(SIPSorceryEntities sipSorceryEntities, SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("AddNewBindingForProvider provider ID=" + sipProvider.ID + ".");
                SIPProviderBinding newBinding = sipSorceryEntities.SIPProviderBindings.CreateObject();
                newBinding.SetProviderFields(sipProvider);
                newBinding.ID = Guid.NewGuid().ToString();
                newBinding.NextRegistrationTime = DateTimeOffset.UtcNow.ToString("o");
                newBinding.ProviderID           = sipProvider.ID;
                newBinding.Owner = sipProvider.Owner;

                sipSorceryEntities.SIPProviderBindings.AddObject(newBinding);
                sipSorceryEntities.SaveChanges();
            }
            catch (Exception excp)
            {
                logger.Error("Exception AddNewBindingForProvider. " + excp.Message);
                logger.Error(excp);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Fixes up the register contact and expiry fields on provider records that have the register box checked.
        /// </summary>
        private void FixProviderRegisterDetails(SIPProvider sipProvider, string owner)
        {
            if (!m_disabledRegisterProviderServerPattern.IsNullOrBlank() && Regex.Match(sipProvider.ProviderServer, m_disabledRegisterProviderServerPattern).Success)
            {
                throw new ApplicationException("Registrations are not supported with this provider. Please uncheck the Register box.");
            }

            if (sipProvider.RegisterContact.IsNullOrBlank())
            {
                sipProvider.RegisterContact = "sip:" + sipProvider.ProviderName + "." + owner.ToLower() + "@" + m_domainForProviderContact;
            }

            try
            {
                var registerURI = SIPURI.ParseSIPURIRelaxed(sipProvider.RegisterContact.Trim());
                registerURI.User = SIPEscape.SIPURIUserEscape(registerURI.User);
                sipProvider.RegisterContact = registerURI.ToString();
            }
            catch (Exception sipURIExcp)
            {
                throw new ApplicationException(sipURIExcp.Message);
            }

            if (sipProvider.RegisterExpiry == null || sipProvider.RegisterExpiry < SIPProvider.REGISTER_MINIMUM_EXPIRY || sipProvider.RegisterExpiry > SIPProvider.REGISTER_MAXIMUM_EXPIRY)
            {
                sipProvider.RegisterExpiry = SIPProvider.REGISTER_DEFAULT_EXPIRY;
            }
        }
        private static void AddNewBindingForProvider(SIPSorceryEntities sipSorceryEntities, SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("AddNewBindingForProvider provider ID=" + sipProvider.ID + ".");
                SIPProviderBinding newBinding = sipSorceryEntities.SIPProviderBindings.CreateObject();
                newBinding.SetProviderFields(sipProvider);
                newBinding.ID = Guid.NewGuid().ToString();
                newBinding.NextRegistrationTime = DateTimeOffset.UtcNow.ToString("o");
                newBinding.ProviderID = sipProvider.ID;
                newBinding.Owner = sipProvider.Owner;

                sipSorceryEntities.SIPProviderBindings.AddObject(newBinding);
                sipSorceryEntities.SaveChanges();
            }
            catch (Exception excp)
            {
                logger.Error("Exception AddNewBindingForProvider. " + excp.Message);
                logger.Error(excp);
            }
        }
Ejemplo n.º 24
0
        public SIPProvider ToSIPProvider()
        {
            var entitySIPProvider = new SIPProvider()
            {
                Owner = String.Empty,
                ID = ID,
                ProviderName = ProviderName,
                ProviderUsername = ProviderUsername,
                ProviderPassword = ProviderPassword,
                ProviderServer = ProviderServer,
                ProviderAuthUsername = ProviderAuthUsername,
                ProviderOutboundProxy = ProviderOutboundProxy,
                ProviderType = ProviderType,
                ProviderFrom = ProviderFrom,
                CustomHeaders = CustomHeaders,
                RegisterEnabled = RegisterEnabled,
                RegisterContact = RegisterContact,
                RegisterExpiry = RegisterExpiry,
                RegisterServer = RegisterServer,
                RegisterRealm = RegisterRealm,
                GVCallbackNumber = GVCallbackNumber,
                GVCallbackPattern = GVCallbackPattern,
                GVCallbackType = GVCallbackType
            };

            return entitySIPProvider;
        }
Ejemplo n.º 25
0
        public void SIPProviderInvalidusernameValidationTest()
        {
            SIPProvider target = new SIPProvider()
            {
                Owner = "owner",
                ProviderUsername = "******",
                ProviderName = "my.provider"
            };

            string validationResult = SIPProvider.Validate(target);

            Assert.AreEqual("Provider names cannot contain a full stop '.' in order to avoid ambiguity with DNS host names, please remove the '.'.", validationResult);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Deprecated Method for adding a new object to the SIPProviders EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSIPProviders(SIPProvider sIPProvider)
 {
     base.AddObject("SIPProviders", sIPProvider);
 }
Ejemplo n.º 27
0
        public void DeleteSIPProvider(string authUser, SIPProvider sipProvider)
        {
            using (var sipSorceryEntities = new SIPSorceryEntities())
            {
                SIPProvider existingAccount = (from sp in sipSorceryEntities.SIPProviders where sp.ID == sipProvider.ID && sp.Owner.ToLower() == authUser.ToLower() select sp).FirstOrDefault();

                if (existingAccount == null)
                {
                    throw new ApplicationException("The SIP Provider to delete could not be found.");
                }
                else if (existingAccount.Owner.ToLower() != authUser.ToLower())
                {
                    throw new ApplicationException("Not authorised to delete the SIP Provider.");
                }

                sipSorceryEntities.SIPProviders.DeleteObject(existingAccount);
                sipSorceryEntities.SaveChanges();
            }
        }
Ejemplo n.º 28
0
        public void SIPProviderIsValidTest()
        {
            SIPProvider target = new SIPProvider()
            {
                Owner = "owner",
                ProviderName = "test",
                ProviderUsername = "******"
            };

            string validationResult = SIPProvider.Validate(target);

            Assert.IsNull(validationResult);
        }
Ejemplo n.º 29
0
        public void SIPProviderNoNameValidationTest()
        {
            SIPProvider target = new SIPProvider()
            {
                Owner = "owner"
            };

            string validationResult = SIPProvider.Validate(target);

            Assert.AreEqual("A provider name must be specified.", validationResult);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Create a new SIPProvider object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="inserted">Initial value of the Inserted property.</param>
 /// <param name="lastUpdate">Initial value of the LastUpdate property.</param>
 /// <param name="owner">Initial value of the Owner property.</param>
 /// <param name="providerName">Initial value of the ProviderName property.</param>
 /// <param name="providerType">Initial value of the ProviderType property.</param>
 /// <param name="providerUsername">Initial value of the ProviderUsername property.</param>
 /// <param name="registerAdminEnabled">Initial value of the RegisterAdminEnabled property.</param>
 /// <param name="registerEnabled">Initial value of the RegisterEnabled property.</param>
 /// <param name="isReadOnly">Initial value of the IsReadOnly property.</param>
 /// <param name="sendMWISubscribe">Initial value of the SendMWISubscribe property.</param>
 public static SIPProvider CreateSIPProvider(global::System.String id, global::System.String inserted, global::System.String lastUpdate, global::System.String owner, global::System.String providerName, global::System.String providerType, global::System.String providerUsername, global::System.Boolean registerAdminEnabled, global::System.Boolean registerEnabled, global::System.Boolean isReadOnly, global::System.Boolean sendMWISubscribe)
 {
     SIPProvider sIPProvider = new SIPProvider();
     sIPProvider.ID = id;
     sIPProvider.Inserted = inserted;
     sIPProvider.LastUpdate = lastUpdate;
     sIPProvider.Owner = owner;
     sIPProvider.ProviderName = providerName;
     sIPProvider.ProviderType = providerType;
     sIPProvider.ProviderUsername = providerUsername;
     sIPProvider.RegisterAdminEnabled = registerAdminEnabled;
     sIPProvider.RegisterEnabled = registerEnabled;
     sIPProvider.IsReadOnly = isReadOnly;
     sIPProvider.SendMWISubscribe = sendMWISubscribe;
     return sIPProvider;
 }
        private void Add()
        {
            try
            {
                SIPProvider sipProvider = null;

                ProviderTypes providerType = (m_providerTypeSIPRadio.IsChecked != null && m_providerTypeSIPRadio.IsChecked.Value) ? ProviderTypes.SIP : ProviderTypes.GoogleVoice;
                string providerName = m_providerName.Text.Trim();
                string providerUsername = m_providerUsername.Text.Trim();
                string providerPassword = m_providerPassword.Text.Trim();

                if (providerType == ProviderTypes.SIP)
                {
                    SIPURI providerServer = (!m_providerServer.Text.IsNullOrBlank()) ? SIPURI.ParseSIPURIRelaxed(m_providerServer.Text.Trim()) : null;
                    bool registerEnabled = m_providerRegister.IsChecked.Value;
                    bool sendMWISubscribe = m_providerSendMWISubscribe.IsChecked.Value;
                    SIPURI registerContact = (!m_providerRegisterContact.Text.IsNullOrBlank()) ? SIPURI.ParseSIPURIRelaxed(m_providerRegisterContact.Text.Trim()) : null;
                    string authUsername = m_providerAuthUsername.Text.Trim();
                    string providerFrom = m_providerFromHeader.Text.Trim();
                    string registerRealm = m_providerRegisterRealm.Text.Trim();
                    SIPURI registerServer = (!m_providerRegisterServer.Text.IsNullOrBlank()) ? SIPURI.ParseSIPURIRelaxed(m_providerRegisterServer.Text.Trim()) : null;

                    int registerExpiry = m_defaultRegisterExpiry;
                    Int32.TryParse(m_providerRegisterExpiry.Text, out registerExpiry);

                    string customHeaders = null;
                    if (m_providerCustomHeaders.Items.Count > 0)
                    {
                        foreach (string customHeader in m_providerCustomHeaders.Items)
                        {
                            customHeaders += (m_sipProvider.CustomHeaders != null && m_sipProvider.CustomHeaders.Trim().Length > 0) ? m_customHeadersSeparator.ToString() : null;
                            customHeaders += customHeader;
                        }
                    }

                    sipProvider = new SIPProvider()
                    {
                        ID = Guid.NewGuid().ToString(),
                        ProviderType = ProviderTypes.SIP.ToString(),
                        Owner = m_owner,
                        ProviderName = providerName,
                        ProviderUsername = providerUsername,
                        ProviderPassword = providerPassword,
                        ProviderServer = (providerServer != null) ? providerServer.ToString() : null,
                        ProviderFrom = providerFrom,
                        CustomHeaders = customHeaders,
                        RegisterContact = (registerContact != null) ? registerContact.ToString() : null,
                        RegisterExpiry = registerExpiry,
                        RegisterServer = (registerServer != null) ? registerServer.ToString() : null,
                        ProviderAuthUsername = authUsername,
                        RegisterRealm = registerRealm,
                        RegisterEnabled = registerEnabled,
                        SendMWISubscribe = sendMWISubscribe,
                        RegisterAdminEnabled = true,
                        Inserted = DateTime.Now.ToString("o"),
                        LastUpdate = DateTime.Now.ToString("o")
                    };
                }
                else
                {
                    //string gvCallbackNumber = m_gvCallbackNumber.Text;
                    //string gvCallbackPattern = m_gvCallbackNumber.Text;
                    //GoogleVoiceCallbackTypes callbackType = (GoogleVoiceCallbackTypes)Enum.Parse(typeof(GoogleVoiceCallbackTypes), ((TextBlock)m_gvCallbackType.SelectedValue).Text, true);

                    //sipProvider = new SIPProvider(ProviderTypes.GoogleVoice, m_owner, providerName, providerUsername, providerPassword, null, null, null, null,
                    //    null, 0, null, null, null, false, true, gvCallbackNumber, gvCallbackPattern, callbackType);

                    sipProvider = new SIPProvider()
                    {
                        ID = Guid.NewGuid().ToString(),
                        ProviderType = ProviderTypes.GoogleVoice.ToString(),
                        Owner = m_owner,
                        ProviderName = providerName,
                        ProviderUsername = providerUsername,
                        ProviderPassword = providerPassword,
                        GVCallbackNumber = m_gvCallbackNumber.Text,
                        GVCallbackPattern = m_gvCallbackPattern.Text,
                        GVCallbackType = ((TextBlock)m_gvCallbackType.SelectedValue).Text,
                        Inserted = DateTime.Now.ToString("o"),
                        LastUpdate = DateTime.Now.ToString("o")
                    };
                }

                if (sipProvider.HasValidationErrors)
                {
                    WriteStatusMessage(MessageLevelsEnum.Warn, sipProvider.ValidationErrors.First().ErrorMessage);
                }
                else
                {
                    WriteStatusMessage(MessageLevelsEnum.Info, "Adding SIP Provider please wait...");
                    SIPProviderAdd_External(sipProvider);
                }
            }
            catch (Exception excp)
            {
                WriteStatusMessage(MessageLevelsEnum.Error, "Add SIPProvider Exception. " + excp.Message);
            }
        }