Пример #1
0
        public async Task <long> WriteAsync([CanBeNull] IFileReader reader, CancellationToken token)
        {
            if (reader == null)
            {
                return(-1);
            }
            HandleWriteStart();
            m_SetMaxProcess?.Invoke(-1);

            try
            {
                var sourceAccess = new SourceAccess(m_FullPath, false, recipient: m_Recipient, keepEnencyrpted: m_KeepUnencrypted);
                if (!string.IsNullOrEmpty(m_IdentifierInContainer))
                {
                    sourceAccess.IdentifierInContainer = m_IdentifierInContainer;
                }

                using (var improvedStream = FunctionalDI.OpenStream(sourceAccess))
                    await WriteReaderAsync(reader, improvedStream as Stream, token).ConfigureAwait(false);
            }
            catch (Exception exc)
            {
                Logger.Error(exc, "Could not write file {filename}", FileSystemUtils.GetShortDisplayFileName(m_FullPath));
                throw new FileWriterException($"Could not write file '{FileSystemUtils.GetShortDisplayFileName(m_FullPath)}'\n{exc.SourceExceptionMessage()}",
                                              exc);
            }
            finally
            {
                Logger.Debug("Finished writing {filesetting} Records: {records}", m_FileSettingDisplay, Records);
                WriteFinished?.Invoke(this, null);
            }

            return(Records);
        }
Пример #2
0
 /// <summary>
 ///   Create an improved stream based on another stream
 /// </summary>
 /// <param name="stream">The source stream, the stream must support seek</param>
 /// <param name="isReading"></param>
 /// <param name="type"></param>
 /// <remarks>Make sure the source stream is disposed</remarks>
 // ReSharper disable once NotNullMemberIsNotInitialized
 public ImprovedStream([NotNull] Stream stream, SourceAccess.FileTypeEnum type = SourceAccess.FileTypeEnum.Stream)
 {
     SourceAccess = new SourceAccess(stream, type);
     BaseOpen();
 }
Пример #3
0
 // ReSharper disable once NotNullMemberIsNotInitialized
 public ImprovedStream([NotNull] SourceAccess sourceAccess)
 {
     SourceAccess = sourceAccess;
     BaseOpen();
 }