Esempio n. 1
0
 /// <summary>
 /// Read Fb2 file from Stream.
 /// </summary>
 /// <param name="stream">Fb2 file as a stream.</param>
 /// <param name="settings">Settings for reading fb2 file.</param>
 /// <returns></returns>
 public Task<FB2File> ReadAsync(Stream stream, XmlLoadSettings settings)
 {
     return Task.Factory.StartNew(() =>
     {
         var file = new FB2File();
         using (var reader = XmlReader.Create(stream, settings.ReaderSettings))
         {
             var fb2Document = XDocument.Load(reader, settings.Options);
             file.Load(fb2Document, false);
         }
         return file;
     });
 }
Esempio n. 2
0
        /// <summary>
        /// Read Fb2 file from Stream.
        /// </summary>
        /// <param name="stream">Fb2 file as a stream.</param>
        /// <param name="settings">Settings for reading fb2 file.</param>
        /// <returns></returns>
        public Task <FB2File> ReadAsync(Stream stream, XmlLoadSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            return(Task.Factory.StartNew(() =>
            {
                var file = new FB2File();
                using (var reader = XmlReader.Create(stream, settings.ReaderSettings))
                {
                    var fb2Document = XDocument.Load(reader, settings.Options);
                    file.Load(fb2Document, false);
                }
                return file;
            }));
        }
Esempio n. 3
0
		private async Task ReadFB2FileStreamAsync(Stream stream)
		{
			// setup
			var readerSettings = new XmlReaderSettings
			{
				DtdProcessing = DtdProcessing.Ignore
			};
			var loadSettings = new XmlLoadSettings(readerSettings);

			try
			{
				// reading
				FB2File file = await new FB2Reader().ReadAsync(stream, loadSettings);
			}
			catch (Exception ex)
			{
				Debug.WriteLine(string.Format("Error loading file : {0}", ex.Message));
			}
		}