public IActionResult ManifestSnapshot(string sessionId, [FromBody] SendManifestDTO manifestDTO) { if (!Guid.TryParse(sessionId, out Guid sessionGuid)) { this.logger.LogWarning($"Received a request for {nameof(this.ManifestSnapshot)} with an invalid {nameof(sessionId)}."); return(this.NotFound()); } if (!this.ModelState.IsValid) { this.logger.LogWarning($"Received a request for {nameof(this.ManifestSnapshot)} with an invalid DTO. {this.ModelState.ErrorCount} errors."); return(this.BadRequest(this.ModelState)); } return(this.GuardNotFoundException(() => { this.sessionManager.AddManifestSnapshot(sessionGuid, manifestDTO.Manifest); })); }
private async Task Announce() { HttpWebRequest request = GetWebRequest(this.RegistryEndpoint + $"/registrar/{this.SessionId}/manifest"); string manifest = await this.GetManifest(new NAMEContext()).ConfigureAwait(false); string digest = DigestHelper.GetDigestForMessage(manifest); if (this.CurrentDigest != digest && this.settings.RunningMode < SupportedNAMEBehaviours.AnnounceDisabled) { var announceObj = new SendManifestDTO { Manifest = manifest }; var serializer = new DataContractJsonSerializer(typeof(SendManifestDTO)); using (Stream stream = await request.GetRequestStreamAsync().ConfigureAwait(false)) { serializer.WriteObject(stream, announceObj); } HttpWebResponse response = await request.GetResponseAsync().ConfigureAwait(false) as HttpWebResponse; if (response.StatusCode != HttpStatusCode.OK) { var msg = "Unable to send new manifest to the registry. Status code = " + response.StatusCode; LogWarning(msg, true); throw new NAMEException(msg); } else { this.CurrentDigest = digest; } } else { await this.Ping().ConfigureAwait(false); } }