/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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); }