/// <summary> /// Read Fb2 file from string. /// </summary> /// <param name="xml">Fb2 file content as a string.</param> /// <returns></returns> public Task <FB2File> ReadAsync(string xml) { return(Task.Factory.StartNew(() => { var file = new FB2File(); var fb2Document = XDocument.Parse(xml); file.Load(fb2Document, false); return file; })); }
private async void OpenFileTest_OnClick(object sender, RoutedEventArgs e) { FileOpenPicker fp = new FileOpenPicker(); fp.ViewMode = PickerViewMode.Thumbnail; fp.FileTypeFilter.Add(".fb2"); var storageFile = await fp.PickSingleFileAsync(); XDocument fb2 = XDocument.Load(storageFile.Path); FB2File fb = new FB2File(); fb.Load(fb2, false); }
/// <summary> /// Read Fb2 file from string. /// </summary> /// <param name="xml">Fb2 file content as a string.</param> /// <returns></returns> public Task<FB2File> ReadAsync(string xml) { return Task.Factory.StartNew(() => { var file = new FB2File(); var fb2Document = XDocument.Parse(xml); file.Load(fb2Document, false); return file; }); }
private async void TestButton_OnClick(object sender, RoutedEventArgs e) { FileOpenPicker fp = new FileOpenPicker(); fp.ViewMode = PickerViewMode.Thumbnail; fp.FileTypeFilter.Add(".fb2"); var storageFile = await fp.PickSingleFileAsync(); var stream = await storageFile.OpenAsync(FileAccessMode.Read); XDocument fb2 = await Task.Run(() => XDocument.Load(stream.AsStreamForRead())); FB2File fb = new FB2File(); fb.Load(fb2, false); }
/// <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; }); }
/// <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; })); }
protected FB2File ReadFb2FileStream(Stream s) { Logger.Log.Debug("Starting to load FB2 stream"); var settings = new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Prohibit, CheckCharacters = false }; XDocument fb2Document; try { using (XmlReader reader = XmlReader.Create(s, settings)) { fb2Document = XDocument.Load(reader, LoadOptions.PreserveWhitespace); reader.Close(); } } catch (XmlException) // we handle this on top { throw; } catch (Exception ex) { Logger.Log.ErrorFormat("Error loading file : {0}", ex); throw; } var file = new FB2File(); try { file.Load(fb2Document, false); } catch (Exception ex) { Logger.Log.ErrorFormat("Error loading file : {0}", ex); throw; } Logger.Log.Debug("FB2 stream loaded"); return file; }
public void LoadFB2FileFromXML(XDocument fb2Document) { _fb2Files.Clear(); var file = new FB2File(); try { file.Load(fb2Document, false); _fb2Files.Add(file); } catch (Exception ex) { Logger.Log.ErrorFormat("Error loading XML document : {0}", ex); } }
public static Fb2Book Open(Stream inputStream) { try { XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Ignore; using (XmlReader reader = XmlReader.Create(inputStream, settings)) { XDocument fb2Document = XDocument.Load(reader, LoadOptions.PreserveWhitespace); FB2File file = new FB2File(); file.Load(fb2Document, false); List<AbstractTextPart> result = new List<AbstractTextPart>(); List<AbstractTextPart> annotation = new List<AbstractTextPart>(); List<BinaryItem> imgs = new List<BinaryItem>(); BinaryItem logo = new BinaryItem(); foreach (BodyItem bodyItem in file.Bodies) { foreach (SectionItem secionItem in bodyItem.Sections) AppendSectionItem(secionItem, 0, result); } List<Human> authors = new List<Human>(); try { authors = file.TitleInfo.BookAuthors .Select(author => new Human(author.FirstName.Text + " " + author.LastName.Text)) .ToList(); } catch { } if (file.TitleInfo.Annotation != null) { AppendAnnotation(file.TitleInfo.Annotation, 0, annotation); } int count = 0; foreach (var img in file.Images) { if (count++ == 5) break; imgs.Add(img.Value); } if (imgs.Count != 0) logo = imgs[0]; return new Fb2Book(file.TitleInfo.BookTitle.Text, annotation, imgs, authors, result.AsReadOnly(), logo); } } catch (Exception ex) { throw ex; } }
public FB2File ReadFromFile(string path) { var file = new FB2File(); file.Load(XDocument.Load(path), false); return(file); }