public void Copy(SipUserAgentSettingsSection section)
 {
     Accounts        = section.Accounts;
     AutoAnswer      = section.AutoAnswer;
     AutoConference  = section.AutoConference;
     SecureMedia     = section.SecureMedia;
     SecureSignaling = section.SecureSignaling;
     NetworkSettings = section.NetworkSettings;
     LogMessages     = section.LogMessages;
     LogLevel        = section.LogLevel;
     TraceAndDebug   = section.TraceAndDebug;
     MediaConfig     = section.MediaConfig;
     Transport       = section.Transport;
 }
        public void Configure(IConfigurationContext context)
        {
            try
            {
                var config = context.Config;
                var mediaConfig = context.MediaConfig;
                var loggingConfig = context.LoggingConfig;
                var cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                _section = (SipUserAgentSettingsSection) cfg.Sections["sipua"];
                if (_section != null)
                {
                    context.RegisterTransport(
                        new Core.Utils.Tuple<TransportType, TransportConfig>(
                            (TransportType) Enum.Parse(typeof (TransportType), _section.Transport.TransportType, true),
                            new TransportConfig(){Port = (uint) _section.Transport.Port,
                                BoundAddress = _section.Transport.BoundAddress,
                                PublicAddress = _section.Transport.PublicAddress
                            }));

                    config.UseSrtp = _section.SecureMedia;
                    config.SecureSignalling = _section.SecureSignaling;

                    if (_section.NetworkSettings != null)
                    {
                        config.NatInSdp = _section.NetworkSettings.NatInSdp;
                        config.ForceLooseRoute = _section.NetworkSettings.ForceLooseRoute;

                        if (_section.NetworkSettings.DnsServers != null)
                            for (int i = 0; i < _section.NetworkSettings.DnsServers.Count; i++)
                                if (!string.IsNullOrEmpty(_section.NetworkSettings.DnsServers[i].Address))
                                    config.DnsServers.Add(_section.NetworkSettings.DnsServers[i].Address);

                        if (_section.NetworkSettings.Proxies != null)
                            for (int i = 0; i < _section.NetworkSettings.Proxies.Count; i++)
                                if (!string.IsNullOrEmpty(_section.NetworkSettings.Proxies[i].Address))
                                    config.OutboundProxies.Add(_section.NetworkSettings.Proxies[i].Address);

                        if (_section.NetworkSettings.StunServers != null)
                            for (int i = 0; i < _section.NetworkSettings.StunServers.Count; i++)
                                if (!string.IsNullOrEmpty(_section.NetworkSettings.StunServers[i].Address))
                                    config.StunServers.Add(_section.NetworkSettings.StunServers[i].Address);

                        if (_section.NetworkSettings.Stun != null)
                        {
                            config.StunHost = _section.NetworkSettings.Stun.Address;
                        }

                        if (_section.NetworkSettings.Turn != null &&
                            _section.NetworkSettings.Turn.Enabled)
                        {
                            mediaConfig.EnableTurn = true;
                            mediaConfig.TurnServer = _section.NetworkSettings.Turn.Server;
                            TransportType tpType = TransportType.Udp;
                            switch (_section.NetworkSettings.Turn.TransportType)
                            {
                                case "udp":
                                    tpType = TransportType.Udp;
                                    break;
                                case "tcp":
                                    tpType = TransportType.Tcp;
                                    break;
                                case "tls":
                                    tpType = TransportType.Tls;
                                    break;
                            }
                            mediaConfig.TurnConnectionType = tpType;
                            mediaConfig.TurnAuthentication = new NetworkCredential
                                                                 {
                                                                     UserName = _section.NetworkSettings.Turn.UserName,
                                                                     Password = _section.NetworkSettings.Turn.Password,
                                                                     Domain = _section.NetworkSettings.Turn.Realm
                                                                 };
                        }

                        if (_section.NetworkSettings.ICE != null)
                        {
                            mediaConfig.EnableICE = _section.NetworkSettings.ICE.Enabled;
                            //mediaConfig.ICENoHostCandidates = _section.NetworkSettings.ICE.NoHostCandidates;
                            mediaConfig.ICENoRtcp = _section.NetworkSettings.ICE.NoRtcp;
                        }
                    }

                    mediaConfig.IsVadEnabled = _section.MediaConfig.IsVadEnabled;

                    config.AutoAnswer = _section.AutoAnswer;
                    config.AutoRecord = _section.AutoRecording;
                    config.AutoConference = _section.AutoConference;
                    config.MaxCalls = (uint) _section.MaxCalls;

                    loggingConfig.LogMessages = _section.LogMessages;
                    loggingConfig.LogLevel = (uint) _section.LogLevel;
                    loggingConfig.TraceAndDebug = _section.TraceAndDebug;

                    mediaConfig.CaptureDeviceId = _section.MediaConfig.CaptureDeviceId;
                    mediaConfig.PlaybackDeviceId = _section.MediaConfig.PlaybackDeviceId;

                    context.RegisterAccounts(
                        _section.Accounts.Cast<AccountElement>()
                            .Select(ae =>
                                        {
                                            var accCfg = new AccountConfig()
                                                             {
                                                                 Id = ae.AccountId,
                                                                 RegUri = ae.RegistrarUri,
                                                                 IsPublishEnabled = ae.PublishPresence,
                                                                 IsDefault = ae.IsDefault
                                                             };
                                            accCfg.Credentials.Add(new NetworkCredential(ae.UserName, ae.Password,
                                                                                         ae.Realm));
                                            return accCfg;
                                        }));
                }
            }
            catch (ConfigurationErrorsException) //error in config using default settings
            {
            }
        }
        public void Configure(IConfigurationContext context)
        {
            try
            {
                var config        = context.Config;
                var mediaConfig   = context.MediaConfig;
                var loggingConfig = context.LoggingConfig;
                var cfg           = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                _section = (SipUserAgentSettingsSection)cfg.Sections["sipua"];
                if (_section != null)
                {
                    context.RegisterTransport(
                        new Core.Utils.Tuple <TransportType, TransportConfig>(
                            (TransportType)Enum.Parse(typeof(TransportType), _section.Transport.TransportType, true),
                            new TransportConfig()
                    {
                        Port          = (uint)_section.Transport.Port,
                        BoundAddress  = _section.Transport.BoundAddress,
                        PublicAddress = _section.Transport.PublicAddress
                    }));

                    config.UseSrtp          = _section.SecureMedia;
                    config.SecureSignalling = _section.SecureSignaling;

                    if (_section.NetworkSettings != null)
                    {
                        config.NatInSdp        = _section.NetworkSettings.NatInSdp;
                        config.ForceLooseRoute = _section.NetworkSettings.ForceLooseRoute;

                        if (_section.NetworkSettings.DnsServers != null)
                        {
                            for (int i = 0; i < _section.NetworkSettings.DnsServers.Count; i++)
                            {
                                if (!string.IsNullOrEmpty(_section.NetworkSettings.DnsServers[i].Address))
                                {
                                    config.DnsServers.Add(_section.NetworkSettings.DnsServers[i].Address);
                                }
                            }
                        }

                        if (_section.NetworkSettings.Proxies != null)
                        {
                            for (int i = 0; i < _section.NetworkSettings.Proxies.Count; i++)
                            {
                                if (!string.IsNullOrEmpty(_section.NetworkSettings.Proxies[i].Address))
                                {
                                    config.OutboundProxies.Add(_section.NetworkSettings.Proxies[i].Address);
                                }
                            }
                        }

                        if (_section.NetworkSettings.StunServers != null)
                        {
                            for (int i = 0; i < _section.NetworkSettings.StunServers.Count; i++)
                            {
                                if (!string.IsNullOrEmpty(_section.NetworkSettings.StunServers[i].Address))
                                {
                                    config.StunServers.Add(_section.NetworkSettings.StunServers[i].Address);
                                }
                            }
                        }

                        if (_section.NetworkSettings.Stun != null)
                        {
                            config.StunHost = _section.NetworkSettings.Stun.Address;
                        }

                        if (_section.NetworkSettings.Turn != null &&
                            _section.NetworkSettings.Turn.Enabled)
                        {
                            mediaConfig.EnableTurn = true;
                            mediaConfig.TurnServer = _section.NetworkSettings.Turn.Server;
                            TransportType tpType = TransportType.Udp;
                            switch (_section.NetworkSettings.Turn.TransportType)
                            {
                            case "udp":
                                tpType = TransportType.Udp;
                                break;

                            case "tcp":
                                tpType = TransportType.Tcp;
                                break;

                            case "tls":
                                tpType = TransportType.Tls;
                                break;
                            }
                            mediaConfig.TurnConnectionType = tpType;
                            mediaConfig.TurnAuthentication = new NetworkCredential
                            {
                                UserName = _section.NetworkSettings.Turn.UserName,
                                Password = _section.NetworkSettings.Turn.Password,
                                Domain   = _section.NetworkSettings.Turn.Realm
                            };
                        }

                        if (_section.NetworkSettings.ICE != null)
                        {
                            mediaConfig.EnableICE = _section.NetworkSettings.ICE.Enabled;
                            //mediaConfig.ICENoHostCandidates = _section.NetworkSettings.ICE.NoHostCandidates;
                            mediaConfig.ICENoRtcp = _section.NetworkSettings.ICE.NoRtcp;
                        }
                    }

                    mediaConfig.IsVadEnabled = _section.MediaConfig.IsVadEnabled;

                    config.AutoAnswer     = _section.AutoAnswer;
                    config.AutoRecord     = _section.AutoRecording;
                    config.AutoConference = _section.AutoConference;
                    config.MaxCalls       = (uint)_section.MaxCalls;

                    loggingConfig.LogMessages   = _section.LogMessages;
                    loggingConfig.LogLevel      = (uint)_section.LogLevel;
                    loggingConfig.TraceAndDebug = _section.TraceAndDebug;

                    mediaConfig.CaptureDeviceId  = _section.MediaConfig.CaptureDeviceId;
                    mediaConfig.PlaybackDeviceId = _section.MediaConfig.PlaybackDeviceId;

                    context.RegisterAccounts(
                        _section.Accounts.Cast <AccountElement>()
                        .Select(ae =>
                    {
                        var accCfg = new AccountConfig()
                        {
                            Id               = ae.AccountId,
                            RegUri           = ae.RegistrarUri,
                            IsPublishEnabled = ae.PublishPresence,
                            IsDefault        = ae.IsDefault
                        };
                        accCfg.Credentials.Add(new NetworkCredential(ae.UserName, ae.Password,
                                                                     ae.Realm));
                        return(accCfg);
                    }));
                }
            }
            catch (ConfigurationErrorsException) //error in config using default settings
            {
            }
        }
 public void Copy(SipUserAgentSettingsSection section)
 {
     Accounts = section.Accounts;
     AutoAnswer = section.AutoAnswer;
     AutoRecording = section.AutoRecording;
     AutoConference = section.AutoConference;
     SecureMedia = section.SecureMedia;
     SecureSignaling = section.SecureSignaling;
     NetworkSettings = section.NetworkSettings;
     LogMessages = section.LogMessages;
     LogLevel = section.LogLevel;
     TraceAndDebug = section.TraceAndDebug;
     MediaConfig = section.MediaConfig;
     Transport = section.Transport;
 }