コード例 #1
0
        private YamlStream GetYamlStream(bool validate = true)
        {
            var stream = new YamlStream();

            stream.Add(ToYamlDocument(validate));
            return(stream);
        }
コード例 #2
0
        /// <inheritdoc />
        public void SaveMap(MapId mapId, string yamlPath)
        {
            Logger.InfoS("map", $"Saving map {mapId} to {yamlPath}");
            var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager, _componentManager, _prototypeManager);

            foreach (var grid in _mapManager.GetAllMapGrids(mapId))
            {
                context.RegisterGrid(grid);
            }

            var document = new YamlDocument(context.Serialize());

            var resPath = new ResourcePath(yamlPath).ToRootedPath();

            _resMan.UserData.CreateDir(resPath.Directory);

            using (var file = _resMan.UserData.Create(resPath))
            {
                using (var writer = new StreamWriter(file))
                {
                    var stream = new YamlStream();

                    stream.Add(document);
                    stream.Save(new YamlMappingFix(new Emitter(writer)), false);
                }
            }
            Logger.InfoS("map", "Save completed!");
        }
コード例 #3
0
        public void Save(string configurationFilePath)
        {
            if (configurationFilePath == null)
            {
                Log.Error("Configuration cannot be saved as configuration file path was not provided.");
                return;
            }
            if (!File.Exists(configurationFilePath))
            {
                Log.WarnFormat("{0} configuration file does not exists. Creating it.", configurationFilePath);
                Directory.CreateDirectory(Path.GetDirectoryName(configurationFilePath));
                File.Create(configurationFilePath).Close();
            }

            var parser  = new YamlStream();
            var mapping = new YamlMappingNode();

            foreach (Service service in services)
            {
                mapping.Add(new YamlScalarNode(service.Name), service.ToConfig());
            }

            parser.Add(new YamlDocument(mapping));
            var writer = new StreamWriter(configurationFilePath);

            parser.Save(writer);
            writer.Close();
            Log.Info("Services configuration updated.");
        }
コード例 #4
0
#pragma warning restore 649

        /// <inheritdoc />
        public void SaveBlueprint(GridId gridId, string yamlPath)
        {
            var grid = _mapManager.GetGrid(gridId);

            var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager, _componentFactory, _componentManager);

            context.RegisterGrid(grid);
            var root     = context.Serialize();
            var document = new YamlDocument(root);

            var resPath = new ResourcePath(yamlPath).ToRootedPath();

            _resMan.UserData.CreateDir(resPath.Directory);

            using (var file = _resMan.UserData.Open(resPath, FileMode.Create))
            {
                using (var writer = new StreamWriter(file))
                {
                    var stream = new YamlStream();

                    stream.Add(document);
                    stream.Save(new YamlMappingFix(new Emitter(writer)), false);
                }
            }
        }
コード例 #5
0
        /// <inheritdoc />
        public void SaveMap(IMap map, string yamlPath)
        {
            var context = new MapContext();

            foreach (var grid in map.GetAllGrids())
            {
                context.RegisterGrid(grid);
            }

            var document = new YamlDocument(context.Serialize());

            var resPath = new ResourcePath(yamlPath).ToRootedPath();

            _resMan.UserData.CreateDir(resPath.Directory);

            using (var file = _resMan.UserData.Open(resPath, FileMode.Create))
            {
                using (var writer = new StreamWriter(file))
                {
                    var stream = new YamlStream();

                    stream.Add(document);
                    stream.Save(writer, false);
                }
            }
        }
コード例 #6
0
        /// <inheritdoc />
        public void SaveBlueprint(GridId gridId, string yamlPath)
        {
            var grid = _mapManager.GetGrid(gridId);

            var context = new MapContext();

            context.RegisterGrid(grid);
            var root     = context.Serialize();
            var document = new YamlDocument(root);

            var resPath = new ResourcePath(yamlPath).ToRootedPath();

            _resMan.UserData.CreateDir(resPath.Directory);

            using (var file = _resMan.UserData.Open(resPath, FileMode.Create))
            {
                using (var writer = new StreamWriter(file))
                {
                    var stream = new YamlStream();

                    stream.Add(document);
                    stream.Save(writer, false);
                }
            }
        }
コード例 #7
0
        public virtual V Convert <V>(YamlNode node)
        {
            if (node.NodeType == YamlNodeType.Alias)
            {
                return(default(V));
            }

            var deserializer = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention()).Build();

            if (node.NodeType == YamlNodeType.Scalar)
            {
                return(deserializer.Deserialize <V>(((YamlScalarNode)node).Value));
            }

            YamlDocument yamlDocument = new YamlDocument(node);
            YamlStream   yamlStream   = new YamlStream();

            yamlStream.Add(yamlDocument);
            using (MemoryStream stream = new MemoryStream())
            {
                StreamWriter writer = new StreamWriter(stream);
                yamlStream.Save(writer);
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                StreamReader reader = new StreamReader(stream);
                return(deserializer.Deserialize <V>(reader));
            }
        }
コード例 #8
0
ファイル: MapLoader.cs プロジェクト: halworsen/RobustToolbox
        /// <inheritdoc />
        public void SaveMap(MapId mapId, string yamlPath)
        {
            var context = new MapContext(_mapManager, _tileDefinitionManager, _serverEntityManager, _pauseManager);

            foreach (var grid in _mapManager.GetAllMapGrids(mapId))
            {
                context.RegisterGrid(grid);
            }

            var document = new YamlDocument(context.Serialize());

            var resPath = new ResourcePath(yamlPath).ToRootedPath();

            _resMan.UserData.CreateDir(resPath.Directory);

            using (var file = _resMan.UserData.Open(resPath, FileMode.Create))
            {
                using (var writer = new StreamWriter(file))
                {
                    var stream = new YamlStream();

                    stream.Add(document);
                    stream.Save(new YamlMappingFix(new Emitter(writer)), false);
                }
            }
        }
コード例 #9
0
        private void ExportAll_Click(object sender, RoutedEventArgs e)
        {
            // Prep the crate for extraction
            var yaml     = new YamlStream();
            var sequence = new YamlSequenceNode();

            sequence.Style = YamlDotNet.Core.Events.SequenceStyle.Block;
            foreach (var crate in crates)
            {
                sequence.Add(crate.serializeYaml());
                // Adds the crate document to the file stream
            }
            YamlDocument document = new YamlDocument(sequence);

            yaml.Add(document);
            var messageResult = MessageBox.Show("Would you like to save to file?", "Save", MessageBoxButton.YesNoCancel);

            if (messageResult == MessageBoxResult.Yes)
            {
                var dialog = new Microsoft.Win32.SaveFileDialog();
                dialog.Filter = "YML file (*.yml)|*.yml";
                bool?dialogResult = dialog.ShowDialog();
                if (dialogResult == true)
                {
                    string filePath = dialog.FileName;
                    File.Delete(filePath);
                    using (FileStream stream = File.OpenWrite(filePath))
                    {
                        using (var writer = new StreamWriter(stream))
                        {
                            yaml.Save(writer);
                        }
                    }
                }
            }
            else if (messageResult == MessageBoxResult.No)
            {
                if (CratePanel.DataContext is Crate)
                {
                    Crate crate = (Crate)CratePanel.DataContext;
                    // Should probably make a new window to show this in that allows the user to copy+paste it into their config.
                    // Once more developed, I should also add a export all button.
                    MessageBox.Show(crate.ToString());
                }
            }
        }
コード例 #10
0
        public YamlStream GetYamlStream()
        {
            var stream = new YamlStream();
            var root   = new YamlMappingNode();
            var doc    = new YamlDocument(root);

            stream.Add(doc);

            // file info
            root.Add(FileInformation.Name, FileInformation.ToYaml());

            // Logging
            root.Add(Logging.Name, Logging.ToYaml());

            // Plugins
            root.Add(Plugins.Name, Plugins.ToYaml());

            return(stream);
        }
        public static void WriteDefaultConfig(string filePath)
        {
            var stream = new YamlStream();
            var root   = new YamlMappingNode();
            var doc    = new YamlDocument(root);

            stream.Add(doc);

            // Logging
            root.Add("logging", CreateDefaultLoggingConfig());

            // Plugins
            root.Add("plugins", CreateDefaultPluginConfig());

            using (var writer = new StreamWriter(filePath))
            {
                stream.Save(writer, assignAnchors: false);
            }
        }
コード例 #12
0
        /// <inheritdoc />
        public void SaveBlueprint(GridId gridId, string yamlPath)
        {
            var grid = _mapManager.GetGrid(gridId);

            var root = SaveBpNode(grid);

            var document = new YamlDocument(root);

            var resPath = new ResourcePath(yamlPath).ToRootedPath();

            _resMan.UserData.CreateDir(resPath.Directory);

            using (var file = _resMan.UserData.Open(resPath, FileMode.OpenOrCreate))
            {
                using (var writer = new StreamWriter(file))
                {
                    var stream = new YamlStream();

                    stream.Add(document);
                    stream.Save(writer);
                }
            }
        }
コード例 #13
0
        /// <inheritdoc />
        public void SaveMap(IMap map, string yamlPath)
        {
            var root = new YamlMappingNode();

            root.Add("format", MapFormatVersion.ToString());
            root.Add("name", "DemoStation");
            root.Add("author", "Space-Wizards");

            // save grids
            var gridMap = new YamlMappingNode();

            root.Add("grids", gridMap);

            foreach (var grid in map.GetAllGrids())
            {
                var gridBpNode = SaveBpNode(grid);
                gridMap.Add(grid.Index.ToString(), gridBpNode);
            }

            var document = new YamlDocument(root);

            var rootPath = _resMan.ConfigDirectory;
            var path     = Path.Combine(rootPath, "./", yamlPath);
            var fullPath = Path.GetFullPath(path);

            var dir = Path.GetDirectoryName(fullPath);

            Directory.CreateDirectory(dir ?? throw new InvalidOperationException("Full YamlPath was null."));

            using (var writer = new StreamWriter(fullPath))
            {
                var stream = new YamlStream();

                stream.Add(document);
                stream.Save(writer);
            }
        }
コード例 #14
0
ファイル: LoadingAYamlStream.cs プロジェクト: wyb314/OAEngine
        public void Main()
        {
            // Setup the input
            var input = new StringReader(Document);

            // Load the stream
            var yaml = new YamlStream();

            yaml.Add(new YamlDocument(new YamlScalarNode("wyb")));
            var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

            mapping.Add(new YamlScalarNode("wyb"), new YamlScalarNode("ht"));
            //mapping.Add(new YamlSequenceNode(""),);

            //yaml.Load(input);

            //// Examine the stream
            //var mapping =
            //    (YamlMappingNode)yaml.Documents[0].RootNode;

            //foreach (var entry in mapping.Children)
            //{
            //    output.WriteLine(((YamlScalarNode)entry.Key).Value);
            //}

            //// List all the items
            var items = (YamlSequenceNode)mapping.Children[new YamlScalarNode("items")];

            foreach (YamlMappingNode item in items)
            {
                output.WriteLine(
                    "{0}\t{1}",
                    item.Children[new YamlScalarNode("part_no")],
                    item.Children[new YamlScalarNode("descrip")]
                    );
            }
        }
コード例 #15
0
        protected override V Convert <K, V>(PropertyConfig <K, V> propertyConfig, object value)
        {
            V v = base.Convert(propertyConfig, value);

            if (!object.Equals(v, default(V)))
            {
                return(v);
            }

            YamlNode node = (YamlNode)value;

            if (node.NodeType == YamlNodeType.Alias)
            {
                return(default(V));
            }

            var deserializer = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention()).Build();

            if (node.NodeType == YamlNodeType.Scalar)
            {
                return(deserializer.Deserialize <V>(((YamlScalarNode)node).Value));
            }

            YamlDocument yamlDocument = new YamlDocument(node);
            YamlStream   yamlStream   = new YamlStream();

            yamlStream.Add(yamlDocument);
            using (MemoryStream stream = new MemoryStream())
            {
                StreamWriter writer = new StreamWriter(stream);
                yamlStream.Save(writer);
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                StreamReader reader = new StreamReader(stream);
                return(deserializer.Deserialize <V>(reader));
            }
        }
コード例 #16
0
        /// <inheritdoc />
        public void SaveBlueprint(GridId gridId, string yamlPath)
        {
            var grid = _mapManager.GetGrid(gridId);

            var root = SaveBpNode(grid);

            var document = new YamlDocument(root);

            var rootPath = _resMan.ConfigDirectory;
            var path     = Path.Combine(rootPath.ToString(), "./", yamlPath);
            var fullPath = Path.GetFullPath(path);

            var dir = Path.GetDirectoryName(fullPath);

            Directory.CreateDirectory(dir ?? throw new InvalidOperationException("Full YamlPath was null."));

            using (var writer = new StreamWriter(fullPath))
            {
                var stream = new YamlStream();

                stream.Add(document);
                stream.Save(writer);
            }
        }
コード例 #17
0
        /// <inheritdoc />
        public void SaveMap(IMap map, string yamlPath)
        {
            var root = new YamlMappingNode();

            root.Add("format", MapFormatVersion.ToString());
            root.Add("name", "DemoStation");
            root.Add("author", "Space-Wizards");

            // save grids
            var gridMap = new YamlMappingNode();

            root.Add("grids", gridMap);

            foreach (var grid in map.GetAllGrids())
            {
                var gridBpNode = SaveBpNode(grid);
                gridMap.Add(grid.Index.ToString(), gridBpNode);
            }

            var document = new YamlDocument(root);

            var resPath = new ResourcePath(yamlPath).ToRootedPath();

            _resMan.UserData.CreateDir(resPath.Directory);

            using (var file = _resMan.UserData.Open(resPath, FileMode.OpenOrCreate))
            {
                using (var writer = new StreamWriter(file))
                {
                    var stream = new YamlStream();

                    stream.Add(document);
                    stream.Save(writer);
                }
            }
        }
コード例 #18
0
ファイル: YamlFileBase.cs プロジェクト: fairyfingers/CKli
 protected YamlMapping GetFirstMapping(IActivityMonitor m, bool autoCreate)
 {
     if (_firstMapping == null)
     {
         var input = TextContent;
         if (input == null && autoCreate)
         {
             input = String.Empty;
         }
         if (input != null)
         {
             _yamlStream = YamlStream.Load(new StringReader(input));
             if (_yamlStream.Count > 0)
             {
                 _doc = _yamlStream[0];
             }
             else
             {
                 _yamlStream.Add((_doc = new YamlDocument()));
             }
             if (_doc.Contents == null)
             {
                 _doc.Contents = (_firstMapping = new YamlMapping());
             }
             else
             {
                 _firstMapping = _doc.Contents as YamlMapping;
                 if (_firstMapping == null)
                 {
                     m.Error($"Unable to parse Yaml file. Missing a first mapping object as the first document content.");
                 }
             }
         }
     }
     return(_firstMapping);
 }