Exemple #1
0
        public async Task CheckUri(UriInfo uriInfo)
        {
            Uri            uri;
            UriEventArgs   args;
            UriStatus      newStatus;
            Exception      error;
            HttpStatusCode httpStatus;

            uri = uriInfo.Uri;

            if (!_settings.Statuses.TryGetValue(uri, out UriStatusInfo status))
            {
                status = new UriStatusInfo
                {
                    LastChange = DateTimeOffset.UtcNow,
                    Status     = UriStatus.Unknown,
                    Uri        = uri
                };

                _settings.Statuses.Add(status);
            }

            args = new UriEventArgs(uri);

            this.OnUriChecking(args);

            (newStatus, httpStatus, error) = await this.GetUriStatus(uriInfo).ConfigureAwait(false);

            if (error != null)
            {
                this.OnUriException(new UriExceptionEventArgs(uri, error));
            }

            this.UpdateStatus(status, httpStatus, newStatus);

            this.OnUriChecked(args);
        }
Exemple #2
0
        private void UpdateStatus(UriStatusInfo status, HttpStatusCode httpStatus, UriStatus newStatus)
        {
            UriStatus previousStatus;

            previousStatus = status.Status;

            if (newStatus == UriStatus.Unstable)
            {
                if (previousStatus == UriStatus.Offline ||
                    (previousStatus == UriStatus.Unstable && status.LastChange + _settings.UnstableInterval < DateTimeOffset.UtcNow))
                {
                    newStatus = UriStatus.Offline;
                }
            }

            if (newStatus != previousStatus)
            {
                status.LastChange = DateTimeOffset.UtcNow;
                status.Status     = newStatus;
                status.HttpStatus = httpStatus;

                this.OnUriStatusChanged(new UriStatusInfoEventArgs(status));
            }
        }
Exemple #3
0
 public UriStatusInfoEventArgs(UriStatusInfo statusInfo)
     : base(statusInfo.Uri)
 {
     _statusInfo = statusInfo;
 }