Ejemplo n.º 1
0
        public static async Task FetchServerDatabasesAsync(ServerRecord server, IAsyncDocumentSession session)
        {
            var client = await ServerHelpers.CreateAsyncServerClient(session, server);

            try
            {
                await StoreDatabaseNames(server, client, session);

                // Mark server as online now, so if one of the later steps throw we'll have this value.
                server.NotifyServerIsOnline();

                await StoreActiveDatabaseNames(server, client, session);
                await CheckReplicationStatusOfEachActiveDatabase(server, client, session);

                // Mark server as online at the LastOnlineTime.
                server.NotifyServerIsOnline();
            }
            catch (HttpRequestException ex)
            {
                Log.ErrorException("Error", ex);

                var webException = ex.InnerException as WebException;
                if (webException != null)
                {
                    var socketException = webException.InnerException as SocketException;
                    if (socketException != null)
                    {
                        server.IsOnline = false;
                    }
                }
            }
            catch (AggregateException ex)
            {
                Log.ErrorException("Error", ex);

                var exception = ex.ExtractSingleInnerException();

                var webException = exception as WebException;
                if (webException != null)
                {
                    var response = webException.Response as HttpWebResponse;
                    if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        server.IsUnauthorized = true;
                    }
                    else
                    {
                        server.IsOnline = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException("Error", ex);
            }
            finally
            {
                server.LastTriedToConnectAt = DateTimeOffset.UtcNow;
            }
        }