// Parse the chapters in the document, recursively private void ParseBookMapChapters() { List <DitaElement> chapters = RootMap.RootElement.FindChildren(_chapterElements); foreach (DitaElement chapter in chapters) { // What is the href to the chapter? string chapterHref = chapter.Attributes?["href"]; // Try to find this file DitaFile linkedFile = Collection.GetFileByName(chapterHref); List <DitaCollectionLinkJson> children = ParseChaptersFromFile(linkedFile); Chapters.AddRange(children); if (linkedFile is DitaFileTopicAbstract && children.Count > 0) { children[0].Children.AddRange(ParseRefs(chapter.FindChildren(_refElements))); } //if (chapter.Type == "appendices" && children.Count > 0) //{ //} } }
// Build the internal structure based on a map private void ParseMap() { try { // Read the title BookTitle.Add("mainbooktitle", RootMap.Title); // Read the metadata ParseMapMeta(); if (!BookMeta.ContainsKey("document title")) { BookMeta.Add("document title", RootMap.Title); } // Add the chapters Chapters.AddRange(ParseChaptersFromFile(RootMap)); // Removes any blank topics and replaces them with links to their first populate child RemoveBlankPages(); } catch (Exception ex) { Trace.TraceError(ex); } }
/// <inheritdoc /> public void Load(string fileName) { _networkstream = ExtensionProvider.IsNetworkStream(fileName); Log.Info("Loading file: {0}", fileName); if (_decodeChannel != 0 || _mixerChannel != 0) { Stop(); } try { Bass.StreamFree(_decodeChannel); } catch (Exception ex) { Debug.WriteLine(ex); } if (string.IsNullOrEmpty(fileName)) { Log.Error("Filename was null or empty. Aborted load"); return; } var sourceflags = BassFlags.Decode | BassFlags.Loop | BassFlags.Float | BassFlags.Prescan; var mixerflags = BassFlags.MixerDownMix | BassFlags.MixerPositionEx | BassFlags.AutoFree; if (_networkstream) { int r; lock (Lock) { // make sure only 1 thread at a time can do the following // increment the request counter for this request r = ++_req; } var netFlags = BassFlags.StreamDownloadBlocks | sourceflags; Bass.NetProxy = ""; //os default proxy _decodeChannel = Bass.CreateStream(fileName, 0, netFlags, _streamDloadProc, new IntPtr(r)); lock (Lock) { if (r != _req) { if (_decodeChannel != 0) { Bass.StreamFree(_decodeChannel); } return; } } _netadress = fileName; } else { if (ExtensionProvider.IsCdStream(fileName)) { var cd = new CDTrackInfo(fileName); _decodeChannel = BassCd.CreateStream(cd.Drive, cd.Track, sourceflags); Log.Info("Geting track metadata..."); UpdateCDTags(cd.Drive, cd.Track); } else { _decodeChannel = Bass.CreateStream(fileName, 0, 0, sourceflags); Log.Info("Geting track metadata..."); UpdateFileTags(fileName); } } if (_decodeChannel == 0) { Log.Error("Decode chanel creation failed: {0}", Bass.LastError); return; } var channelInfo = Bass.ChannelGetInfo(_decodeChannel); _mixerChannel = BassMix.CreateMixerStream(channelInfo.Frequency, channelInfo.Channels, mixerflags); if (_mixerChannel == 0) { Log.Error("Mixer chanel creation failed: {0}", Bass.LastError); return; } if (!BassMix.MixerAddChannel(_mixerChannel, _decodeChannel, BassFlags.MixerDownMix)) { Log.Error("Failed to route decoded stream to mixer: {0}", Bass.LastError); return; } if (!_networkstream) { Log.Info("Getting track length..."); var len = Bass.ChannelGetLength(_decodeChannel, PositionFlags.Bytes); _length = Bass.ChannelBytes2Seconds(_decodeChannel, len); NotifyChanged(nameof(Length)); Log.Info("Getting Chapters..."); Chapters.Clear(); Chapters.AddRange(ChapterFactory.GetChapters(fileName, _length)); } Volume = _LastVolume; Bass.ChannelSetAttribute(_mixerChannel, ChannelAttribute.Volume, Volume); Log.Info("Loaded file {0}", fileName); }