Beispiel #1
0
 private static async Task ConvertAsync(TopicData topic, Stream destStream, IDictionary<string, TopicData> name2topic, Paths paths, CancellationToken cancellationToken)
 {
     using (var writer = new StreamWriter(destStream))
     {
         await Writers.TopicWriter.WriteAsync(topic, name2topic, writer, paths, cancellationToken);
     }
 }
Beispiel #2
0
 private static async Task ConvertAsync(TopicData topic, IDictionary<string, TopicData> name2topic, Paths paths, IFile destFile, CancellationToken cancellationToken)
 {
     using (var destStream = await destFile.OpenAsync(FileAccess.ReadAndWrite, cancellationToken))
     {
         await ConvertAsync(topic, destStream, name2topic, paths, cancellationToken);
     }
 }
Beispiel #3
0
 private static string GetTitle(TopicData topic, Block block)
 {
     if (block == null || block.HeaderLevel != 1)
         return topic.Name;
     var title = string.Empty;
     for (var inline = block.InlineContent; inline != null; inline = inline.NextSibling)
         title += inline.LiteralContent;
     return title;
 }
Beispiel #4
0
 /// <summary>
 /// Updates the topic with its ID from content layout.
 /// </summary>
 /// <param name="topic">The topic.</param>
 /// <param name="title2id">Gets the topic ID from the topic title.</param>
 /// <returns>Updated topic.</returns>
 public static TopicData Update(TopicData topic, IDictionary<string, Guid> title2id)
 {
     var block = GetHeaderBlock(topic.ParserResult);
     topic.Title = GetTitle(topic, block);
     Guid id;
     if (!title2id.TryGetValue(topic.Title, out id))
     {
         id = Guid.NewGuid();
         title2id.Add(topic.Title, id);
     }
     topic.Id = id;
     return topic;
 }
Beispiel #5
0
        /// <summary>
        /// Converts the topic to MAML.
        /// </summary>
        /// <param name="topic">Topic data.</param>
        /// <param name="paths">Paths.</param>
        /// <param name="name2topic">Mapping from topic name to data.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <param name="progress">Progress indicator.</param>
        /// <param name="index">Index.</param>
        /// <param name="count">Count.</param>
        /// <returns>Asynchronous task.</returns>
        public static async Task ConvertAsync(TopicData topic, Paths paths, IDictionary<string, TopicData> name2topic,
            CancellationToken cancellationToken, IProgress<Indicator> progress = null, int index = 0, int count = 0)
        {
            var destDir = Path.Combine(paths.Destination, topic.RelativePath);
            var fileName = Path.GetFileName(topic.FileName);
            var destName = Path.ChangeExtension(fileName, ".aml");

            var destFolder = await FileSystem.Current.LocalStorage.CreateFolderAsync(destDir, CreationCollisionOption.OpenIfExists, cancellationToken);
            var destFile = await destFolder.CreateFileAsync(destName, CreationCollisionOption.ReplaceExisting, cancellationToken);

            await ConvertAsync(topic, name2topic, paths, destFile, cancellationToken);

            Indicator.Report(progress, count, index + 1, () => Path.Combine(topic.RelativePath, topic.Name));
        }
Beispiel #6
0
 /// <summary>
 /// Parses the topic.
 /// </summary>
 /// <param name="topic">The topic.</param>
 /// <param name="paths">Paths.</param>
 /// <param name="cancellationToken">Cancellation token.</param>
 /// <param name="progress">Progress indicator.</param>
 /// <param name="index">Index.</param>
 /// <param name="count">Count.</param>
 /// <returns>Parsed topic.</returns>
 public static async Task<TopicParserResult> ParseAsync(TopicData topic, Paths paths, CancellationToken cancellationToken,
     IProgress<Indicator> progress = null, int index = 0, int count = 0)
 {
     var srcFilePath = Path.Combine(paths.Source, topic.RelativePath, topic.FileName);
     var file = await FileSystem.Current.GetFileFromPathAsync(srcFilePath, cancellationToken)
         .ConfigureAwait(false);
     using (var stream = await file.OpenAsync(FileAccess.Read, cancellationToken))
     using (var reader = new StreamReader(stream))
     {
         var parserResult = topic.ParserResult = TopicParser.Parse(reader);
         Indicator.Report(progress, count, index + 1, () => Path.Combine(topic.RelativePath, topic.Name));
         return parserResult;
     }
 }
Beispiel #7
0
 private static async Task<TopicData> MatchAsync(TopicData topic, Paths paths, IDictionary<string, Guid> title2id, CancellationToken cancellationToken,
     IProgress<Indicator> progress, int count, int index)
 {
     await TopicParser.ParseAsync(topic, paths, cancellationToken, progress, index, count);
     return TopicUpdater.Update(topic, title2id);
 }