private byte[] DownloadAttachmentContent(string downloadPath, Attachment attachment) { Log.Info($"Downloading {downloadPath} ..."); try { using (var httpResponse = Client.Publish.Get <HttpWebResponse>(attachment.Url)) { return(httpResponse.GetResponseStream().ReadFully()); } } catch (WebServiceException exception) { if (!IsAttachmentNotFound(exception)) { throw; } ++MissingAttachmentCount; throw new ExpectedException($"{exception.StatusCode}: {exception.StatusDescription}: {exception.ErrorMessage}"); } }
private void DeleteExistingAttachment(LocationDataServiceResponse locationData, Attachment existingAttachment) { if (!Context.DeleteExistingAttachments) { return; } var match = AttachmentUrlRegex.Match(existingAttachment.Url); if (!match.Success) { throw new ExpectedException($"Can't decode attachment ID from '{existingAttachment.Url}'"); } var attachmentId = match.Groups["attachmentId"].Value; ++DeletedAttachments; LogAction($"Deleting existing attachment '{existingAttachment.FileName}' (uploaded {existingAttachment.DateUploaded:O} from '{locationData.Identifier}' ..."); if (Context.DryRun) { return; } SiteVisit.Delete(new DeleteAttachmentById { Id = attachmentId }); }