Exemple #1
0
    string RunWriter(int initialdepth, object o, int horizontalthreshold, IDictionary <Type, bool> bbt, Func <int, YNode, string> anno)
    {
        var w = new YAMLWriter(new StringWriter(), initialdepth, horizontalthreshold, bbt);

        w.Annotate = anno;
        return(w.Write(o).ToString());
    }
Exemple #2
0
        public void testRoundtrip()
        {
            String yaml1 = "field: 122\ndata:\n  list:\n  - field: 123\n  - doc:\n      name: John\n      doc:\n        list:\n        - 122\n        - 233\n        - 344";
            var    docs1 = YAMLReader.read(yaml1);
            String yaml2 = YAMLWriter.write(docs1);
            var    docs2 = YAMLReader.read(yaml2);

            Assert.IsTrue(docs1.Equals(docs2));
        }
Exemple #3
0
    void TestEscape()
    {
        var yw = new YAMLWriter(Console.Out, 0, 60);

        Is(yw.Escape("\u0087"), "\"\\u0087\"");
        Is(yw.Escape("\ufffe"), "\"\\ufffe\"");
        Is(yw.Escape("\ud900"), "\"\\ud900\"");
        Is(yw.Escape("\u0085\uffff"), "\"\\N\\uffff\"");
    }
Exemple #4
0
 public static void Dump(string name, object o)
 {
     using (new WithInvariantCulture()) {
         lock (WriteLock) {
             Diag("dump of " + name + ": ");
             var yw = new YAMLWriter(Console.Out, 0, TAP.HorizontalThreshold, null);
             yw.Write(o);
         }
     }
 }
 public void Export(IExportContainer container, Object asset, string path)
 {
     using (FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream))
         {
             YAMLWriter   writer = new YAMLWriter();
             YAMLDocument doc    = asset.ExportYAMLDocument(container);
             writer.AddDocument(doc);
             writer.Write(streamWriter);
         }
     }
 }
 public void Export(IExportContainer container, Object asset, string path, Action <IExportContainer, Object, string> callback)
 {
     using (Stream fileStream = FileUtils.CreateVirtualFile(path))
     {
         using (StreamWriter streamWriter = new InvariantStreamWriter(fileStream, new UTF8Encoding(false)))
         {
             YAMLWriter   writer = new YAMLWriter();
             YAMLDocument doc    = asset.ExportYAMLDocument(container);
             writer.AddDocument(doc);
             writer.Write(streamWriter);
         }
     }
     callback?.Invoke(container, asset, path);
 }
Exemple #7
0
 public void Export(IExportContainer container, Object asset, string path, Action <IExportContainer, Object, string> callback)
 {
     using (FileStream fileStream = FileUtils.Open(path, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new InvariantStreamWriter(fileStream, Encoding.UTF8))
         {
             YAMLWriter   writer = new YAMLWriter();
             YAMLDocument doc    = asset.ExportYAMLDocument(container);
             writer.AddDocument(doc);
             writer.Write(streamWriter);
         }
     }
     callback?.Invoke(container, asset, path);
 }
 private void ExportYAML(IAssetsExporter exporter, UtinyRipper.Classes.Object asset, string path)
 {
     using (FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream))
         {
             YAMLWriter writer = new YAMLWriter();
             exporter.File = asset.File;
             YAMLDocument doc = asset.ExportYAMLDocument(exporter);
             writer.AddDocument(doc);
             writer.Write(streamWriter);
         }
     }
 }
 public bool Export(IExportContainer container, Object asset, string path)
 {
     using (Stream fileStream = FileUtils.CreateVirtualFile(path))
     {
         using (StreamWriter streamWriter = new InvariantStreamWriter(fileStream, new UTF8Encoding(false)))
         {
             YAMLWriter   writer = new YAMLWriter();
             YAMLDocument doc    = asset.ExportYAMLDocument(container);
             writer.AddDocument(doc);
             writer.Write(streamWriter);
         }
     }
     return(true);
 }
		public void Export(IExportContainer container, IEnumerable<Object> assets, string path)
		{
			using (FileStream fileStream = FileUtils.Open(path, FileMode.Create, FileAccess.Write))
			{
				using (StreamWriter streamWriter = new InvariantStreamWriter(fileStream, new UTF8Encoding(false)))
				{
					YAMLWriter writer = new YAMLWriter();
					writer.WriteHead(streamWriter);
					foreach (Object asset in assets)
					{
						YAMLDocument doc = asset.ExportYAMLDocument(container);
						writer.WriteDocument(doc);
					}
					writer.WriteTail(streamWriter);
				}
			}
		}
        protected void ExportMeta(ProjectAssetContainer container, Meta meta, string filePath)
        {
            string metaPath = $"{filePath}.meta";

            using (FileStream fileStream = System.IO.File.Open(metaPath, FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter streamWriter = new StreamWriter(fileStream))
                {
                    YAMLWriter   writer = new YAMLWriter();
                    YAMLDocument doc    = meta.ExportYAMLDocument(container);
                    writer.IsWriteDefaultTag = false;
                    writer.IsWriteVersion    = false;
                    writer.AddDocument(doc);
                    writer.Write(streamWriter);
                }
            }
        }
Exemple #12
0
        protected void ExportMeta(IExportContainer container, Meta meta, string filePath)
        {
            string metaPath = $"{filePath}.meta";

            using (Stream fileStream = FileUtils.CreateVirtualFile(metaPath))
            {
                using (StreamWriter streamWriter = new InvariantStreamWriter(fileStream, new UTF8Encoding(false)))
                {
                    YAMLWriter   writer = new YAMLWriter();
                    YAMLDocument doc    = meta.ExportYAMLDocument(container);
                    writer.IsWriteDefaultTag = false;
                    writer.IsWriteVersion    = false;
                    writer.AddDocument(doc);
                    writer.Write(streamWriter);
                }
            }
        }
 public void Export(ProjectAssetContainer container, IEnumerable <Object> assets, string path)
 {
     using (FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream))
         {
             YAMLWriter writer = new YAMLWriter();
             foreach (Object asset in assets)
             {
                 container.File = asset.File;
                 YAMLDocument doc = asset.ExportYAMLDocument(container);
                 writer.AddDocument(doc);
             }
             writer.Write(streamWriter);
         }
     }
 }
 private void ExportYAML(IAssetsExporter exporter, IEnumerable <UtinyRipper.Classes.Object> objects, string path)
 {
     using (FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream))
         {
             YAMLWriter writer = new YAMLWriter();
             foreach (Object @object in objects)
             {
                 exporter.File = @object.File;
                 YAMLDocument doc = @object.ExportYAMLDocument(exporter);
                 writer.AddDocument(doc);
             }
             writer.Write(streamWriter);
         }
     }
 }
Exemple #15
0
        protected static void ExportMeta(IExportContainer container, Meta meta, string filePath)
        {
            string metaPath = $"{filePath}{MetaExtension}";

            using (var fileStream = FileUtils.CreateVirtualFile(metaPath))
                using (var stream = new BufferedStream(fileStream))
                    using (var streamWriter = new InvariantStreamWriter(stream, new UTF8Encoding(false)))
                    {
                        YAMLWriter writer = new YAMLWriter();
                        writer.IsWriteDefaultTag = false;
                        writer.IsWriteVersion    = false;
                        writer.IsFormatKeys      = true;
                        YAMLDocument doc = meta.ExportYAMLDocument(container);
                        writer.AddDocument(doc);
                        writer.Write(streamWriter);
                    }
        }
Exemple #16
0
        public static string SaveToString(DataFormat format, DataNode root)
        {
            switch (format)
            {
            case DataFormat.XML: return(XMLWriter.WriteToString(root));

            case DataFormat.JSON: return(JSONWriter.WriteToString(root));

            case DataFormat.YAML: return(YAMLWriter.WriteToString(root));

            case DataFormat.CSV: return(CSVWriter.WriteToString(root));

            default:
            {
                throw new System.Exception("Format not supported");
            }
            }
        }
Exemple #17
0
        void WriteIsVal(bool leaf, OrderedDictionary dic, string label, string key, List <PathEntry> path, int side)
        {
            var val = dic[key];

            if (leaf)
            {
                Tw.Write("{0}: '{1}'", label, SafeToString(val));
            }
            else
            {
                Tw.WriteLine("  {0}:", label);
                var yw = new YAMLWriter(Tw, 4, TAP.HorizontalThreshold, BBD);
                yw.Annotate = (i, n) => {
                    return(GetAnnotation(i, n, path, side, 0));
                };
                yw.Write(val);
            }
        }
 public bool Export(IExportContainer container, IEnumerable <Object> assets, string path)
 {
     using (Stream fileStream = FileUtils.CreateVirtualFile(path))
     {
         using (StreamWriter streamWriter = new InvariantStreamWriter(fileStream, new UTF8Encoding(false)))
         {
             YAMLWriter writer = new YAMLWriter();
             writer.WriteHead(streamWriter);
             foreach (Object asset in assets)
             {
                 YAMLDocument doc = asset.ExportYAMLDocument(container);
                 writer.WriteDocument(doc);
             }
             writer.WriteTail(streamWriter);
         }
     }
     return(true);
 }
        protected void ExportMeta(IAssetsExporter exporter, IExportCollection collection, string filePath)
        {
            Meta   meta     = new Meta(collection);
            string metaPath = $"{filePath}.meta";

            using (FileStream fileStream = File.Open(metaPath, FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter streamWriter = new StreamWriter(fileStream))
                {
                    YAMLWriter   writer = new YAMLWriter();
                    YAMLDocument doc    = meta.ExportYAMLDocument(exporter);
                    writer.IsWriteDefaultTag = false;
                    writer.IsWriteVersion    = false;
                    writer.AddDocument(doc);
                    writer.Write(streamWriter);
                }
            }
        }
Exemple #20
0
        void WriteIsComment(OrderedDictionary dic, List <PathEntry> path)
        {
            bool leaf = path == null || (YAMLWriter.IsLeafType(dic["actual"]) && YAMLWriter.IsLeafType(dic["expected"]));

            if (!leaf)
            {
                Tw.WriteLine("actual not as expected");
            }
            WriteIsVal(leaf, dic, "got", "actual", path, 0);
            if (leaf)
            {
                Tw.Write(" ");
            }
            WriteIsVal(leaf, dic, "expected", "expected", path, 1);
            if (leaf)
            {
                Tw.WriteLine();
            }
        }
Exemple #21
0
        public override void WriteComment(int nr, OrderedDictionary dic, List <PathEntry> path, string name)
        {
            if (path != null)
            {
                path.Insert(0, new PathEntry(-1));
            }
            var yw      = new YAMLWriter(Tw, 2, TAP.HorizontalThreshold, BBD);
            int rootidx = -1;
            int side    = 0;

            yw.Annotate = (i, n) => {
                int depth = n.Depth;
                if (depth == 1)
                {
                    var k = n.Key as string;
                    if (k != null)
                    {
                        if (k == "actual")
                        {
                            side    = 0;
                            rootidx = i;
                        }
                        else if (k == "expected")
                        {
                            side    = 1;
                            rootidx = i;
                        }
                    }
                    else
                    {
                        rootidx = -1;
                    }
                }
                if (rootidx != -1)
                {
                    return(GetAnnotation(i - rootidx, n, path, side, 1));
                }
                return(null);
            };
            yw.Write(dic);
        }