Esempio n. 1
0
        public LoginOptions CreateInstance()
        {
            int chatPort = settings.ConnectionSettings.ChatPort;

            if (String.IsNullOrEmpty(settings.ConnectionSettings.BindToIP))
            {
                throw new OperationCanceledException(Translation.Instance.Error_NoNetwork);
            }

            var      localIP          = IPAddress.Parse(settings.ConnectionSettings.BindToIP);
            TimeSpan keepAliveTimeout = settings.ConnectionSettings.KeepAliveTime.Seconds();

            IPAddress presenceAddress;

            if (!NetworkUtility.TryParseAddress(settings.ConnectionSettings.PresenceAddress, out presenceAddress))
            {
                throw new ApplicationException(Translation.Instance.SettingsWindow_Error_InvalidPresenceIP);
            }

            var chatEndPoint             = NetworkUtility.GetFreeEndPoint(new IPEndPoint(localIP, chatPort));
            var presenceServiceEndPoint  = NetworkUtility.GetFreeEndPoint(new IPEndPoint(localIP, settings.ConnectionSettings.PresencePort));
            var multicastEndPoint        = new IPEndPoint(presenceAddress, settings.ConnectionSettings.PresencePort);
            var multicastReceiveEndPoint = NetworkUtility.GetFreeEndPoint(new IPEndPoint(localIP, settings.ConnectionSettings.PresenceCallbackPort));

            string clientID = settings.ConnectionSettings.ClientID;

            string displayName = Environment.ExpandEnvironmentVariables(userInfo.DisplayName.NullIfEmpty() ??
                                                                        signInOptions.DisplayName.NullIfEmpty() ??
                                                                        settings.PersonalSettings.DisplayName);
            var options = new LoginOptions()
            {
                ChatEndPoint             = chatEndPoint,
                MulticastEndPoint        = multicastEndPoint,
                MulticastReceiveEndPoint = multicastReceiveEndPoint,
                PresenceServiceEndPoint  = presenceServiceEndPoint,
                KeepAliveTime            = keepAliveTimeout,
                UserProperties           = CreateProperties(),
                DisplayName = displayName
            };

            return(options);
        }