Esempio n. 1
0
        public void ImportInfo(PublicSystemInfo systemInfo)
        {
            Name = systemInfo.ServerName;
            Id = systemInfo.Id;

            if (!string.IsNullOrEmpty(systemInfo.LocalAddress))
            {
                LocalAddress = systemInfo.LocalAddress;
            }

            if (!string.IsNullOrEmpty(systemInfo.WanAddress))
            {
                RemoteAddress = systemInfo.WanAddress;
            }

            var fullSystemInfo = systemInfo as SystemInfo;

            if (fullSystemInfo != null)
            {
                WakeOnLanInfos = new List<WakeOnLanInfo>();

                if (!string.IsNullOrEmpty(fullSystemInfo.MacAddress))
                {
                    WakeOnLanInfos.Add(new WakeOnLanInfo
                    {
                        MacAddress = fullSystemInfo.MacAddress
                    });
                }
            }
        }
        private async Task Login(PublicSystemInfo systemInfo)
        {
            //Check for auto-login credientials
            var config = _appHost.TheaterConfigurationManager.Configuration;

            try
            {
                if (systemInfo != null && string.Equals(systemInfo.Id, config.AutoLoginConfiguration.ServerId))
                {
                    await _appHost.SessionManager.ValidateSavedLogin(config.AutoLoginConfiguration);
                    return;
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                //Login failed, redirect to login page and clear the auto-login
                _logger.ErrorException("Auto-login failed", ex);

                config.AutoLoginConfiguration = new AutoLoginConfiguration();
                _appHost.TheaterConfigurationManager.SaveConfiguration();
            }
            catch (FormatException ex)
            {
                //Login failed, redirect to login page and clear the auto-login
                _logger.ErrorException("Auto-login password hash corrupt", ex);

                config.AutoLoginConfiguration = new AutoLoginConfiguration();
                _appHost.TheaterConfigurationManager.SaveConfiguration();
            }

            await _appHost.NavigationService.NavigateToLoginPage();
        }
        private async Task OnSuccessfulConnection(ServerInfo server,
            ConnectionOptions options,
            PublicSystemInfo systemInfo,
            ConnectionResult result,
            ConnectionMode connectionMode,
            CancellationToken cancellationToken)
        {
            server.ImportInfo(systemInfo);

            var credentials = await _credentialProvider.GetServerCredentials().ConfigureAwait(false);

            if (!string.IsNullOrWhiteSpace(credentials.ConnectAccessToken))
            {
                await EnsureConnectUser(credentials, cancellationToken).ConfigureAwait(false);

                if (!string.IsNullOrWhiteSpace(server.ExchangeToken))
                {
                    await AddAuthenticationInfoFromConnect(server, connectionMode, credentials, cancellationToken).ConfigureAwait(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(server.AccessToken))
            {
                await ValidateAuthentication(server, connectionMode, options, cancellationToken).ConfigureAwait(false);
            }

            credentials.AddOrUpdateServer(server);

            if (options.UpdateDateLastAccessed)
            {
                server.DateLastAccessed = DateTime.UtcNow;
            }
            server.LastConnectionMode = connectionMode;

            await _credentialProvider.SaveServerCredentials(credentials).ConfigureAwait(false);

            result.ApiClient = GetOrAddApiClient(server, connectionMode);
            result.State = string.IsNullOrEmpty(server.AccessToken) ?
                ConnectionState.ServerSignIn :
                ConnectionState.SignedIn;

            ((ApiClient)result.ApiClient).EnableAutomaticNetworking(server, connectionMode, _networkConnectivity);

            if (result.State == ConnectionState.SignedIn)
            {
                AfterConnected(result.ApiClient, options);
            }

            CurrentApiClient = result.ApiClient;

            result.Servers.Add(server);

            if (Connected != null)
            {
                Connected(this, new GenericEventArgs<ConnectionResult>(result));
            }
        }