private void UploadToDocuments(AttachmentStream file, string contentType, MailBox mailbox, ILogger log) { try { var uploadedFileId = ApiHelper.UploadToDocuments(file.FileStream, file.FileName, contentType, mailbox.EMailInFolder, true); log.Debug("ApiHelper.UploadToDocuments() -> uploadedFileId = {0}", uploadedFileId); } catch (ApiHelperException ex) { if (ex.StatusCode == HttpStatusCode.NotFound || ex.StatusCode == HttpStatusCode.Forbidden) { log.Info("ApiHelper.UploadToDocuments() EMailIN folder '{0}' is unreachable. Try to unlink EMailIN...", mailbox.EMailInFolder); SetMailboxEmailInFolder(mailbox.TenantId, mailbox.UserId, mailbox.MailBoxId, null); mailbox.EMailInFolder = null; CreateUploadToDocumentsFailureAlert(mailbox.TenantId, mailbox.UserId, mailbox.MailBoxId, (ex.StatusCode == HttpStatusCode.NotFound) ? UploadToDocumentsErrorType .FolderNotFound : UploadToDocumentsErrorType .AccessDenied); throw; } log.Error("SaveEmailInData->ApiHelper.UploadToDocuments(fileName: '{0}', folderId: {1}) Exception:\r\n{2}\r\n", file.FileName, mailbox.EMailInFolder, ex.ToString()); } }
static async Task WriteAttachment(AttachmentStream stream) { using var reader = new StreamReader(stream); var contents = await reader.ReadToEndAsync(); Console.WriteLine("Attachment: {0}. Contents:{1}", stream.Name, contents); }
/// <summary> /// Processes an attachment by passing it to <paramref name="action"/>. /// </summary> public virtual async Task ProcessStream(string messageId, string name, SqlConnection connection, SqlTransaction transaction, Func <AttachmentStream, Task> action, CancellationToken cancellation = default) { Guard.AgainstNullOrEmpty(messageId, nameof(messageId)); Guard.AgainstNullOrEmpty(name, nameof(name)); Guard.AgainstLongAttachmentName(name); Guard.AgainstNull(connection, nameof(connection)); Guard.AgainstNull(action, nameof(action)); using (var command = CreateGetDataCommand(messageId, name, connection, transaction)) using (var reader = await command.ExecuteSequentialReader(cancellation).ConfigureAwait(false)) { if (!await reader.ReadAsync(cancellation).ConfigureAwait(false)) { throw ThrowNotFound(messageId, name); } var length = reader.GetInt64(0); var metadata = MetadataSerializer.Deserialize(reader.GetStringOrNull(1)); using (var sqlStream = reader.GetStream(2)) using (var attachmentStream = new AttachmentStream(sqlStream, length, metadata)) { var task = action(attachmentStream); Guard.ThrowIfNullReturned(messageId, name, task); await task.ConfigureAwait(false); } } }
private void btn_GetAttachmentData_Click(object sender, EventArgs e) { try { GetStreamedAttachment(); Functionality.IOFunctionality.WriteStreamToFile(AttachmentStream); AttachmentStream.Close(); } catch (Exception ex) { SetViewedItem(ex, "Error during GetAttachmentData"); } }
public AttachmentStream GetAttachmentStream(MailAttachment attachment) { if (attachment != null) { var storage = GetDataStore(attachment.tenant); var attachment_path = attachment.GerStoredFilePath(); var result = new AttachmentStream { FileStream = storage.GetReadStream("", attachment_path), FileName = attachment.fileName }; return(result); } throw new InvalidOperationException("Attachment not found"); }
/// <summary> /// Processes an attachment by passing it to <paramref name="action"/>. /// </summary> public virtual async Task ProcessStream(string messageId, string name, Func <AttachmentStream, Task> action, CancellationToken cancellation = default) { Guard.AgainstNullOrEmpty(messageId, nameof(messageId)); Guard.AgainstNullOrEmpty(name, nameof(name)); Guard.AgainstNull(action, nameof(action)); var attachmentDirectory = GetAttachmentDirectory(messageId, name); ThrowIfDirectoryNotFound(attachmentDirectory, messageId); cancellation.ThrowIfCancellationRequested(); var dataFile = GetDataFile(attachmentDirectory); ThrowIfFileNotFound(dataFile, messageId, name); var read = FileHelpers.OpenRead(dataFile); var metadata = ReadMetadata(attachmentDirectory); using (var fileStream = new AttachmentStream(read, read.Length, metadata)) { await action(fileStream).ConfigureAwait(false); } }
/// <summary> /// Processes all attachments for <paramref name="messageId"/> by passing them to <paramref name="action"/>. /// </summary> public virtual async Task ProcessStreams(string messageId, Func <string, AttachmentStream, Task> action, CancellationToken cancellation = default) { Guard.AgainstNullOrEmpty(messageId, nameof(messageId)); Guard.AgainstNull(action, nameof(action)); var messageDirectory = GetMessageDirectory(messageId); ThrowIfDirectoryNotFound(messageDirectory, messageId); foreach (var attachmentDirectory in Directory.EnumerateDirectories(messageDirectory)) { cancellation.ThrowIfCancellationRequested(); var dataFile = GetDataFile(attachmentDirectory); var attachmentName = Directory.GetParent(dataFile).Name; var read = FileHelpers.OpenRead(dataFile); var metadata = ReadMetadata(attachmentDirectory); using (var fileStream = new AttachmentStream(read, read.Length, metadata)) { await action(attachmentName, fileStream).ConfigureAwait(false); } } }
/// <summary> /// Processes all attachments for <paramref name="messageId"/> by passing them to <paramref name="action"/>. /// </summary> public virtual async Task ProcessStreams(string messageId, SqlConnection connection, SqlTransaction transaction, Func <string, AttachmentStream, Task> action, CancellationToken cancellation = default) { Guard.AgainstNullOrEmpty(messageId, nameof(messageId)); Guard.AgainstNull(connection, nameof(connection)); Guard.AgainstNull(action, nameof(action)); using (var command = CreateGetDatasCommand(messageId, connection, transaction)) using (var reader = await command.ExecuteSequentialReader(cancellation).ConfigureAwait(false)) { while (await reader.ReadAsync(cancellation).ConfigureAwait(false)) { cancellation.ThrowIfCancellationRequested(); var name = reader.GetString(0); var length = reader.GetInt64(1); var metadata = MetadataSerializer.Deserialize(reader.GetStringOrNull(2)); using (var sqlStream = reader.GetStream(3)) using (var attachmentStream = new AttachmentStream(sqlStream, length, metadata)) { var task = action(name, attachmentStream); Guard.ThrowIfNullReturned(messageId, null, task); await task.ConfigureAwait(false); } } } }
private void GetAttachmentData() { AttachmentStream = soaFunc.GetSOArchiveAttachmentDataStreamed(SystemUsername, SystemPassword, AttachmentId, SelectedEndpointName, SelectedCertificate); Functionality.IOFunctionality.WriteStreamToFile(AttachmentStream); AttachmentStream.Close(); }
public AttachmentStream GetAttachmentStream(MailAttachment attachment) { if (attachment != null) { var storage = GetDataStore(attachment.tenant); var attachment_path = attachment.GerStoredFilePath(); var result = new AttachmentStream { FileStream = storage.GetReadStream("", attachment_path), FileName = attachment.fileName }; return result; } throw new InvalidOperationException("Attachment not found"); }
private MovieInfo ConvertCoreObject(CoreRoot core) { MovieInfo movieInfo = new MovieInfo(); if (core.Streams != null && core.Streams.Any()) { foreach (CoreStream coreStream in core.Streams) { try { BaseStream baseStream = GenerateBaseStream(coreStream); switch (baseStream.StreamType) { case StreamType.None: break; case StreamType.Subtitle: SubtitleStream subtitleStream = new SubtitleStream(baseStream); subtitleStream.Duration = ParseTimeSpan(coreStream.Duration); subtitleStream.DurationTs = coreStream.DurationTs; movieInfo.SubtitleStreams.Add(subtitleStream); break; case StreamType.Audio: AudioStream audioStream = GenerateAudioStream(baseStream, coreStream); movieInfo.AudioStreams.Add(audioStream); break; case StreamType.Video: VideoStream videoStream = GenerateVideoStream(baseStream, coreStream); movieInfo.VideoStreams.Add(videoStream); break; case StreamType.Data: DataStream dataStream = new DataStream(); movieInfo.DataStreams.Add(dataStream); break; case StreamType.Attachment: AttachmentStream attachmentStream = new AttachmentStream(); movieInfo.AttachmentStreams.Add(attachmentStream); break; } } catch (Exception ex) { Console.WriteLine("ERROR: Unhandled Exception while parsing streams:"); Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); } } } if (core.Chapters != null && core.Chapters.Any()) { foreach (CoreChapter coreChapter in core.Chapters) { try { Chapter chapter = new Chapter(); chapter.Id = coreChapter.Id; chapter.End = coreChapter.End; chapter.Start = coreChapter.Start; chapter.TimeBase = coreChapter.TimeBase; chapter.Tags = coreChapter.Tags; chapter.StartTime = ParseTimeSpan(coreChapter.StartTime); chapter.EndTime = ParseTimeSpan(coreChapter.EndTime); if (coreChapter.Tags != null && coreChapter.Tags.Any()) { if (coreChapter.Tags.ContainsKey("title")) { chapter.Title = coreChapter.Tags .FirstOrDefault(x => x.Key.Equals("title", StringComparison.OrdinalIgnoreCase)).Value; } } movieInfo.Chapters.Add(chapter); } catch (Exception ex) { Console.WriteLine("ERROR: Unhandled Exception while parsing streams:"); Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); } } } return(movieInfo); }