コード例 #1
0
 protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
 {
     using (var writer = new StreamWriter(stream))
         foreach (var line in tree
                  .GetLeafs()
                  .OrderBy(pair => pair.leaf.SourceMark)
                  .SelectMany(pair => FormatEntry(pair.prefix, pair.leaf)))
         {
             await writer.WriteLineAsync(line.ToCharArray(), cancellationToken);
         }
 }
コード例 #2
0
        protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
        {
            var xmlNamespaces = (from pair in tree.GetLeafs()
                                 where pair.leaf.NameString.StartsWith("xmlns:")
                                 select new { Key = pair.leaf.NameString.Substring(6), pair.leaf.Value })
                                .ToDictionary(x => x.Key, x => XNamespace.Get(x.Value));

            using (var writer = new StreamWriter(stream))
                using (var xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings
                {
                    Async = true,
                    Indent = (xmlOptions & XmlOptions.NoIndent) == XmlOptions.None,
                    NewLineOnAttributes = (xmlOptions & XmlOptions.NewLineOnAttributes) == XmlOptions.NewLineOnAttributes
                }))
                    await ApplyOutputPrefix(
                        (XElement)ToXml(tree, new string[0], "", xmlNamespaces)
                        .Single()
                        .node)
                    .WriteToAsync(xmlWriter, cancellationToken);
        }
コード例 #3
0
        protected override async Task DoWrite(ProfileTree tree, Stream stream, CancellationToken cancellationToken)
        {
            using (var memoryStream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                {
                    var parser = new IniStreamParser();
                    var data   = new IniData();

                    foreach (var(prefix, leaf) in tree.GetLeafs())
                    {
                        var names = prefix.Parts
                                    .Select(part => part.Tokens.Cast <TextNameToken>().Single().Text)
                                    .Skip(1);

                        if (outputPrefix != null)
                        {
                            names = outputPrefix.Concat(names);
                        }

                        if (delimiter == ".")
                        {
                            names = names.Select(name => name.Replace(".", "\\."));
                        }

                        data[names.First()][string.Join(delimiter, names.Skip(1))] = leaf.Value;
                    }

                    parser.WriteData(writer, data);

                    await writer.FlushAsync();

                    memoryStream.Seek(0, SeekOrigin.Begin);

                    await memoryStream.CopyToAsync(stream);
                }
        }