コード例 #1
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
 /// <summary>
 /// Parses this instance.
 /// </summary>
 /// <typeparam name="TFile">The type of the file object expected.</typeparam>
 /// <returns>The parsed file</returns>
 /// <exception cref="ArgumentException">
 /// Could not find file format that returns the specified object type
 /// </exception>
 public async Task <TFile> ParseAsync <TFile>() where TFile : IGenericFile
 {
     if (!(FormatManager?.FindFormat(FullName, Credentials) is IFormat <TFile> Format))
     {
         throw new ArgumentException("Could not find file format that returns the specified object type");
     }
     using var TempStream = new MemoryStream(await ReadBinaryAsync().ConfigureAwait(false));
     return(await Format.ReadAsync(TempStream).ConfigureAwait(false));
 }
コード例 #2
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
 /// <summary>
 /// Parses this instance.
 /// </summary>
 /// <typeparam name="TFile">The type of the file object expected.</typeparam>
 /// <returns>The parsed file</returns>
 /// <exception cref="ArgumentException">
 /// Could not find file format that returns the specified object type
 /// </exception>
 public TFile Parse <TFile>()
     where TFile : IGenericFile
 {
     if (!(FormatManager?.FindFormat(FullName, Credentials) is IFormat <TFile> Format))
     {
         throw new ArgumentException("Could not find file format that returns the specified object type");
     }
     using var TempStream = new MemoryStream(ReadBinary());
     return(Format.Read(TempStream));
 }
コード例 #3
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
        /// <summary>
        /// Parses this instance.
        /// </summary>
        /// <returns>The parsed file</returns>
        /// <exception cref="ArgumentException">
        /// Could not find file format that returns the specified object type
        /// </exception>
        public async Task <IGenericFile> ParseAsync()
        {
            var Format = FormatManager?.FindFormat(FullName, Credentials);

            if (Format is null)
            {
                throw new ArgumentException("Could not find file format that returns the specified object type");
            }
            using var TempStream = new MemoryStream(await ReadBinaryAsync().ConfigureAwait(false));
            return(await Format.ReadBaseAsync(TempStream).ConfigureAwait(false));
        }
コード例 #4
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
        /// <summary>
        /// Parses this instance.
        /// </summary>
        /// <returns>The parsed file</returns>
        /// <exception cref="ArgumentException">
        /// Could not find file format that returns the specified object type
        /// </exception>
        public IGenericFile Parse()
        {
            var Format = FormatManager?.FindFormat(FullName, Credentials);

            if (Format is null)
            {
                throw new ArgumentException("Could not find file format that returns the specified object type");
            }
            using var TempStream = new MemoryStream(ReadBinary());
            return(Format.ReadBase(TempStream));
        }
コード例 #5
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>True if it was written successfully, false otherwise.</returns>
        public bool Write(IGenericFile data, FileMode mode = FileMode.Create)
        {
            var Format = FormatManager?.FindFormat(FullName, Credentials);

            if (Format is null)
            {
                return(false);
            }
            using var TempStream = new MemoryStream();
            var Success = Format.Write(TempStream, data);

            Write(TempStream.ReadAllBinary(), mode);
            return(Success);
        }
コード例 #6
0
ファイル: FileInfo.cs プロジェクト: JaCraig/FileCurator
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>True if it was written successfully, false otherwise.</returns>
        public async Task <bool> WriteAsync(IGenericFile data, FileMode mode = FileMode.Create)
        {
            var Format = FormatManager?.FindFormat(FullName, Credentials);

            if (Format is null)
            {
                return(false);
            }
            using var TempStream = new MemoryStream();
            var Success = await Format.WriteAsync(TempStream, data).ConfigureAwait(false);

            await WriteAsync(await TempStream.ReadAllBinaryAsync().ConfigureAwait(false), mode).ConfigureAwait(false);

            return(Success);
        }