Exemplo n.º 1
0
        public async Task <List <ServerInfo> > GetAvailableServers(CancellationToken cancellationToken = default)
        {
            var credentials = await _credentialProvider.GetServerCredentials().ConfigureAwait(false);

            _logger.LogDebug("{0} servers in saved credentials", credentials.Servers.Count);

            if (_networkConnectivity.GetNetworkStatus().GetIsAnyLocalNetworkAvailable())
            {
                foreach (var server in await FindServers(cancellationToken).ConfigureAwait(false))
                {
                    credentials.AddOrUpdateServer(server);
                }
            }

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

            return(credentials.Servers.OrderByDescending(i => i.DateLastAccessed).ToList());
        }
        public async Task<List<ServerInfo>> GetAvailableServers(CancellationToken cancellationToken = default(CancellationToken))
        {
            var credentials = await _credentialProvider.GetServerCredentials().ConfigureAwait(false);

            _logger.Debug("{0} servers in saved credentials", credentials.Servers.Count);

            if (_networkConnectivity.GetNetworkStatus().GetIsAnyLocalNetworkAvailable())
            {
                foreach (var server in await FindServers(cancellationToken).ConfigureAwait(false))
                {
                    credentials.AddOrUpdateServer(server);
                }
            }

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

                var connectServers = await GetConnectServers(credentials.ConnectUserId, credentials.ConnectAccessToken, cancellationToken)
                            .ConfigureAwait(false);

                foreach (var server in connectServers)
                {
                    credentials.AddOrUpdateServer(server);
                }

                // Remove old servers
                var newServerList = credentials.Servers
                    .Where(i => string.IsNullOrWhiteSpace(i.ExchangeToken) ||
                        connectServers.Any(c => string.Equals(c.Id, i.Id, StringComparison.OrdinalIgnoreCase)));

                credentials.Servers = newServerList.ToList();
            }

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

            return credentials.Servers.OrderByDescending(i => i.DateLastAccessed).ToList();
        }