private static YamlSequenceNode SaveCharacterWidth(CharacterWidthEntry table) { YamlSequenceNode node = new YamlSequenceNode(); node.Style = SharpYaml.YamlStyle.Flow; node.Add(NewMappingNode("CharWidth", table.CharWidth.ToString())); node.Add(NewMappingNode("GlyphWidth", table.GlyphWidth.ToString())); node.Add(NewMappingNode("Left", table.Left.ToString())); return(node); }
private YamlSequenceNode SaveBpNode(IMapGrid grid) { var root = new YamlSequenceNode(); var node = YamlGridSerializer.SerializeGrid(grid); root.Add(node); var ents = new YamlEntitySerializer(); _entityMan.SaveGridEntities(ents, grid.Index); root.Add(ents.GetRootNode()); return(root); }
public YamlScalarNode Visit(ScalarNode node, YamlNode currentRootNode) { if (currentRootNode is YamlMappingNode) { YamlMappingNode rootNode = (YamlMappingNode)currentRootNode; YamlScalarNode child = new YamlScalarNode(node.Value); if (node.Property == "!secret") { child.Tag = "!secret"; } rootNode.Add(node.Key, child); return(child); } else { YamlSequenceNode rootNode = (YamlSequenceNode)currentRootNode; YamlScalarNode child = new YamlScalarNode(node.Value); if (node.Property == "!secret") { child.Tag = "!secret"; } rootNode.Add(child); return(child); } }
public static YamlMappingNode SerializeGrid(IMapGrid mapGrid) { var grid = (IMapGridInternal)mapGrid; var gridn = new YamlMappingNode(); var info = new YamlMappingNode(); var chunkSeq = new YamlSequenceNode(); gridn.Add("settings", info); gridn.Add("chunks", chunkSeq); info.Add("chunksize", grid.ChunkSize.ToString(CultureInfo.InvariantCulture)); info.Add("tilesize", grid.TileSize.ToString(CultureInfo.InvariantCulture)); info.Add("snapsize", grid.SnapSize.ToString(CultureInfo.InvariantCulture)); var chunks = grid.GetMapChunks(); foreach (var chunk in chunks) { var chunkNode = SerializeChunk(chunk.Value); chunkSeq.Add(chunkNode); } return(gridn); }
static void AddSecret(YamlSequenceNode env, string name, string secret, string key) { env.Add(new YamlMappingNode() { { "name", name }, { "valueFrom", new YamlMappingNode() { { "secretKeyRef", new YamlMappingNode() { { "name", new YamlScalarNode(secret) { Style = ScalarStyle.SingleQuoted } }, { "key", new YamlScalarNode(key) { Style = ScalarStyle.SingleQuoted } }, } }, } }, }); }
private static void AddEnvironmentVariablesForComputedBindings(YamlSequenceNode env, ComputedBindings bindings) { foreach (var binding in bindings.Bindings.OfType <EnvironmentVariableInputBinding>()) { env.Add(new YamlMappingNode() { { "name", binding.Name }, { "value", new YamlScalarNode(binding.Value) { Style = ScalarStyle.SingleQuoted, } }, }); } foreach (var binding in bindings.Bindings.OfType <SecretInputBinding>()) { //- name: SECRET_USERNAME // valueFrom: // secretKeyRef: // name: mysecret // key: username if (binding is SecretConnectionStringInputBinding connectionStringBinding) { AddSecret(env, connectionStringBinding.KeyName, binding.Name, "connectionstring"); } else if (binding is SecretUrlInputBinding urlBinding) { AddSecret(env, $"{urlBinding.KeyNameBase}__PROTOCOL", binding.Name, "protocol"); AddSecret(env, $"{urlBinding.KeyNameBase}__HOST", binding.Name, "host"); AddSecret(env, $"{urlBinding.KeyNameBase}__PORT", binding.Name, "port"); } }
public static YamlMappingNode SerializeGrid(IMapGrid grid) { var gridn = new YamlMappingNode(); var info = new YamlMappingNode(); var chunkSeq = new YamlSequenceNode(); gridn.Add("settings", info); gridn.Add("chunks", chunkSeq); info.Add("csz", grid.ChunkSize.ToString(CultureInfo.InvariantCulture)); info.Add("tsz", grid.TileSize.ToString(CultureInfo.InvariantCulture)); info.Add("sgsz", grid.SnapSize.ToString(CultureInfo.InvariantCulture)); var chunks = grid.GetMapChunks(); foreach (var chunk in chunks) { var chunkNode = SerializeChunk(chunk); chunkSeq.Add(chunkNode); } var root = new YamlMappingNode(); root.Add("grid", gridn); return(root); }
private static Tuple<string, YamlNode> GetUpdateAttribute(JProperty prop) { var propValueType = prop.Value.Type; var value = string.Empty; if (propValueType == JTokenType.Object || propValueType == JTokenType.Array) { if (propValueType == JTokenType.Array) { var nodes = new YamlSequenceNode(); foreach(var item in prop.Value as JArray) { var asset = new Asset(item as dynamic); var yamlNode = GetNodes(asset); nodes.Add(yamlNode); } return new Tuple<string, YamlNode>(prop.Name, nodes); } return new Tuple<string, YamlNode>(prop.Name, new YamlScalarNode(string.Empty)); } else { value = (prop.Value as JValue).Value.ToString(); return new Tuple<string, YamlNode>(prop.Name, new YamlScalarNode(value)); } }
/// <summary> /// Converts a view model to yaml /// </summary> /// <param name="model"></param> /// <returns></returns> public static string ToYaml(SearchControlViewModel model) { var root = new YamlMappingNode(); root.Add("app", "filequery"); root.Add("version", Assembly.GetExecutingAssembly().GetName().Version.ToString()); var seq = new YamlSequenceNode(); foreach (var path in model.SearchPaths.Where(x => x.IsValid)) { var map = new YamlMappingNode(); map.Add("type", path.PathType); map.Add("value", path.PathValue); seq.Add(map); } root.Add("paths", seq); seq = new YamlSequenceNode(); foreach (var filter in model.SearchParams.Where(x => x.IsValid)) { var map = new YamlMappingNode(); map.Add("type", filter.ParamType); map.Add("value", filter.ParamValue); map.Add("operator", filter.ParamOperator.Label); seq.Add(map); } root.Add("filters", seq); var yaml = new SerializerBuilder().Build().Serialize(root); return(yaml); }
public static ServiceOutput CreateService(OutputContext output, Application application, ServiceEntry service) { if (output is null) { throw new ArgumentNullException(nameof(output)); } if (application is null) { throw new ArgumentNullException(nameof(application)); } if (service is null) { throw new ArgumentNullException(nameof(service)); } var root = new YamlMappingNode(); root.Add("kind", "Service"); root.Add("apiVersion", "v1"); var metadata = new YamlMappingNode(); root.Add("metadata", metadata); metadata.Add("name", service.Service.Name); var labels = new YamlMappingNode(); metadata.Add("labels", labels); labels.Add("app.kubernetes.io/name", service.Service.Name); labels.Add("app.kubernetes.io/part-of", application.Globals.Name); var spec = new YamlMappingNode(); root.Add("spec", spec); var selector = new YamlMappingNode(); spec.Add("selector", selector); selector.Add("app.kubernetes.io/name", service.Service.Name); spec.Add("type", "ClusterIP"); var ports = new YamlSequenceNode(); spec.Add("ports", ports); var port = new YamlMappingNode(); ports.Add(port); port.Add("name", "web"); port.Add("protocol", "TCP"); port.Add("port", "80"); port.Add("targetPort", "80"); return(new KubernetesServiceOutput(service.Service.Name, new YamlDocument(root))); }
private static void AddProbe(ServiceBuilder service, YamlMappingNode container, ProbeBuilder builder, string name) { var probe = new YamlMappingNode(); container.Add(name, probe); if (builder.Http != null) { var builderHttp = builder.Http; var httpGet = new YamlMappingNode(); probe.Add("httpGet", httpGet); httpGet.Add("path", builderHttp.Path); if (builderHttp.Protocol != null) { httpGet.Add("scheme", builderHttp.Protocol.ToUpper()); } if (builderHttp.Port != null) { httpGet.Add("port", builderHttp.Port.ToString() !); } else { // If port is not given, we pull default port var binding = service.Bindings.First(b => builderHttp.Protocol == null || b.Protocol == builderHttp.Protocol); if (binding.Port != null) { httpGet.Add("port", binding.Port.Value.ToString()); } if (builderHttp.Protocol == null && binding.Protocol != null) { httpGet.Add("scheme", binding.Protocol.ToUpper()); } } if (builderHttp.Headers.Count > 0) { var headers = new YamlSequenceNode(); httpGet.Add("httpHeaders", headers); foreach (var builderHeader in builderHttp.Headers) { var header = new YamlMappingNode(); header.Add("name", builderHeader.Key); header.Add("value", builderHeader.Value.ToString() !); headers.Add(header); } } } probe.Add("initialDelaySeconds", builder.InitialDelay.ToString()); probe.Add("periodSeconds", builder.Period.ToString() !); probe.Add("successThreshold", builder.SuccessThreshold.ToString() !); probe.Add("failureThreshold", builder.FailureThreshold.ToString() !); }
private YamlSequenceNode AddParam(string[] items, YamlSequenceNode node) { node.Style = SequenceStyle.Flow; foreach (string item in items.Where(x => x.Length > 0)) { node.Add(item); } return(node); }
private void CreateYaml(string type) { string str = _mapUpdateInfo.Guid.ToString(); string initialContent = "\nkey: " + str + "\n"; var sr = new StringReader(initialContent); var stream = new YamlStream(); stream.Load(sr); var rootMappingNode = (YamlMappingNode)stream.Documents[0].RootNode; rootMappingNode.Add("map_name", _mapUpdateInfo.MapName); if (type.ToLower() != "_cancel") { string dataKind = _mapUpdateInfo.MapName.Substring(0, 1); rootMappingNode.Add("data_kind", dataKind); rootMappingNode.Add("file_count", _dic_file.Count.ToString()); var seq = new YamlSequenceNode(); foreach (DictionaryEntry dic in _dic_file) { var props = new YamlMappingNode(); string name = Path.GetFileName(dic.Key.ToString()); props.Add("name", name); props.Add("size", dic.Value.ToString()); seq.Add(props); } rootMappingNode.Add("files", seq); } string zipPath = Path.GetDirectoryName(_mapUpdateInfo.ZipPath); string yamlName = _mapUpdateInfo.FileName + type + ".yaml"; string yamlPath = Path.Combine(zipPath, yamlName); try { using (TextWriter writer = File.CreateText(yamlPath)) { stream.Save(writer, false); } if (type.ToLower() != "_cancel") { FileInfo file = new FileInfo(yamlPath); _dic_file.Insert(0, yamlPath, file.Length); //_dic_file.Add(yaml_path, file.Length); } } catch (Exception ex) { } }
private void WriteGridSection() { var grids = new YamlSequenceNode(); RootNode.Add("grids", grids); foreach (var grid in Grids) { var entry = YamlGridSerializer.SerializeGrid(grid); grids.Add(entry); } }
/// <summary> /// Merges a namespace into a TOC node. /// If there is an existing node with the same uid, then it is updated to reflect the data /// in this namespace. /// Otherwise, a new node is added to the sequence. /// </summary> /// <param name="toc">The TOC node to merge into.</param> internal void MergeNamespaceIntoToc(YamlSequenceNode toc) { bool MatchByUid(YamlNode n, string key) { var uid = new YamlScalarNode(this.uid); if (n is YamlMappingNode map) { if (map.Children != null && map.Children.TryGetValue(new YamlScalarNode(Utils.UidKey), out YamlNode node)) { if (node is YamlScalarNode valueNode) { return(valueNode.Equals(uid)); } } } return(false); } var namespaceNode = toc.Children?.SingleOrDefault(c => MatchByUid(c, this.uid)) as YamlMappingNode; YamlSequenceNode itemListNode = null; if (namespaceNode == null) { namespaceNode = new YamlMappingNode(); namespaceNode.AddStringMapping(Utils.UidKey, this.uid); namespaceNode.AddStringMapping(Utils.NameKey, this.name); toc.Add(namespaceNode); } else { YamlNode itemsNode; if (namespaceNode.Children.TryGetValue(new YamlScalarNode(Utils.ItemsKey), out itemsNode)) { itemListNode = itemsNode as YamlSequenceNode; } } if (itemListNode == null) { itemListNode = new YamlSequenceNode(); namespaceNode.Add(Utils.ItemsKey, itemListNode); } foreach (var item in items) { if (!itemListNode.Children.Any(c => MatchByUid(c, item.Uid))) { itemListNode.Add(Utils.BuildMappingNode(Utils.NameKey, item.Name, Utils.UidKey, item.Uid)); } } }
private static YamlSequenceNode SaveCharacterMaps(FINF fontInfo) { YamlSequenceNode node = new YamlSequenceNode(); // node.Style = SharpYaml.YamlStyle.Flow; foreach (var character in fontInfo.CodeMapDictionary.Keys) { YamlMappingNode mapping = new YamlMappingNode(); mapping.Add($"0x{((ushort)character).ToString("X4")}", character.ToString()); node.Add(mapping); } return(node); }
/// <summary> /// Adds a reference to the source item to the target document's 'references' section /// if reference doesn't exist yet. /// </summary> private bool addReference(YamlDocument targetDoc, YamlMappingNode sourceItem) { if (sourceItem?.Children == null) { return(false); } var sourceUid = (sourceItem.Children[new YamlScalarNode("uid")] as YamlScalarNode)?.Value; var targetRoot = targetDoc?.RootNode as YamlMappingNode; YamlSequenceNode references = getSequence(targetRoot, "references", true); if (references?.Children != null) { foreach (var r in references.Children) { var existingRef = r as YamlMappingNode; string uid = (existingRef?.Children?[new YamlScalarNode("uid")] as YamlScalarNode)?.Value; if (uid == sourceUid) { return(false); // reference exists already } } } var reference = new YamlMappingNode(); var sourceCommentId = (sourceItem.Children[new YamlScalarNode("commentId")] as YamlScalarNode)?.Value; var sourceName = (sourceItem.Children[new YamlScalarNode("name")] as YamlScalarNode)?.Value; var sourceFullName = (sourceItem.Children[new YamlScalarNode("fullName")] as YamlScalarNode)?.Value; var sourceNameWithType = (sourceItem.Children[new YamlScalarNode("nameWithType")] as YamlScalarNode)?.Value; reference.Add("uid", sourceUid); reference.Add("commentId", sourceCommentId); reference.Add("name", sourceName); reference.Add("nameWithType", sourceNameWithType); reference.Add("fullName", sourceFullName); var lastDotIndex = sourceUid.LastIndexOf('.'); if (lastDotIndex > 0) // root namespace has no parent... { reference.Add("parent", sourceUid.Substring(0, lastDotIndex)); } references.Add(reference); return(true); }
private static YamlMappingNode CreateNatsPluginNode() { var node = new YamlMappingNode(); node.Add("enabled", "false"); node.Add("max-queued-messages", "100"); node.Add("connect-url", "nats://localhost:4222"); node.Add("connect-retry-seconds", "5"); node.Add("security", new YamlMappingNode( new YamlScalarNode("security-type"), new YamlScalarNode("none"), new YamlScalarNode("ca-trusted-cert-file"), new YamlScalarNode("cert.pem"), new YamlScalarNode("client-private-key-file"), new YamlScalarNode("client_key.pem"), new YamlScalarNode("client-cert-chain-file"), new YamlScalarNode("client_cert.pem"))); var publish = new YamlSequenceNode(); node.Add("publish", publish); publish.Add(new YamlMappingNode( new YamlScalarNode("profile"), new YamlScalarNode("SwitchReadingProfile"), new YamlScalarNode("subject"), new YamlScalarNode("*"))); publish.Add(new YamlMappingNode( new YamlScalarNode("profile"), new YamlScalarNode("SwitchStatusProfile"), new YamlScalarNode("subject"), new YamlScalarNode("*"))); var subscribe = new YamlSequenceNode(); node.Add("subscribe", subscribe); subscribe.Add(new YamlMappingNode( new YamlScalarNode("profile"), new YamlScalarNode("SwitchControlProfile"), new YamlScalarNode("subject"), new YamlScalarNode("*"))); return(node); }
protected override void UpgradeAsset(AssetMigrationContext context, PackageVersion currentVersion, PackageVersion targetVersion, dynamic asset, PackageLoadingAssetFile assetFile) { var entities = asset.Hierarchy.Entities; var designEntities = new YamlSequenceNode(); asset.Hierarchy.Entities = designEntities; foreach (var entity in entities) { var designEntity = new YamlMappingNode(); dynamic dynamicDesignEntity = new DynamicYamlMapping(designEntity); dynamicDesignEntity.Entity = entity; designEntities.Add(designEntity); } }
/// <summary> /// Builds a uid/summary TAML sequence node from a dictionary. /// </summary> /// <param name="pairs">A dictionary mapping uids to summaries</param> /// <returns>A new YAML sequence node containing a list of mapping nodes, /// each with a uid value and a summary value</returns> internal static YamlNode BuildSequenceMappingNode(Dictionary <string, string> pairs) { var seqNode = new YamlSequenceNode(); foreach (var pair in pairs) { var uidKeyNode = BuildStringNode("uid"); var uidValueNode = BuildStringNode(pair.Key); var summaryKeyNode = BuildStringNode("summary"); var summaryValueNode = BuildStringNode(pair.Value); seqNode.Add(new YamlMappingNode(uidKeyNode, uidValueNode, summaryKeyNode, summaryValueNode)); } return(seqNode); }
private static int AddLinks(YamlSequenceNode parent, Link[] links) { int count = 0; foreach (var link in links) { if (link.subfolderitems == null || link.subfolderitems.Length == 0) { // leaf var node = new YamlMappingNode(); node.Add(link.name, GetHref(link)); parent.Children.Add(node); count++; } else { // another sequence. var node = new YamlMappingNode(); var s = new YamlSequenceNode(); var href = GetHref(link); node.Add(link.name, s); parent.Children.Add(node); var overview = new YamlMappingNode(); if (href.EndsWith("Assembly.md")) { overview.Add("Assembly Overview", href); } else if (href.EndsWith("Namespace.md")) { overview.Add("Namespace Overview", href); } else if (href.EndsWith("Type.md")) { overview.Add("Type Overview", href); } else { overview.Add("Overview", href); } s.Add(overview); count += AddLinks(s, link.subfolderitems) + 1; } } return(count); }
public static OamComponentOutput CreateOamComponent(OutputContext output, Application application, ServiceEntry service) { if (output is null) { throw new ArgumentNullException(nameof(output)); } if (application is null) { throw new ArgumentNullException(nameof(application)); } if (service is null) { throw new ArgumentNullException(nameof(service)); } var root = new YamlMappingNode(); root.Add("kind", "ComponentSchematic"); root.Add("apiVersion", "core.oam.dev/v1alpha1"); var metadata = new YamlMappingNode(); root.Add("metadata", metadata); metadata.Add("name", service.Service.Name); var spec = new YamlMappingNode(); root.Add("spec", spec); spec.Add("workloadType", "core.oam.dev/v1alpha1.Server"); var containers = new YamlSequenceNode(); spec.Add("containers", containers); var images = service.Outputs.OfType <DockerImageOutput>(); foreach (var image in images) { var container = new YamlMappingNode(); containers.Add(container); container.Add("name", service.Service.Name); // NOTE: to really support multiple images we'd need to generate unique names. container.Add("image", $"{image.ImageName}:{image.ImageTag}"); } return(new OamComponentOutput(service.Service.Name, new YamlDocument(root))); }
public YamlSequenceNode Visit(SequenceNode node, YamlNode currentRootNode) { if (currentRootNode is YamlMappingNode) { YamlMappingNode rootNode = (YamlMappingNode)currentRootNode; //downcast YamlSequenceNode child = new YamlSequenceNode(); rootNode.Add(node.Value, child); return(child); } else { YamlSequenceNode rootNode = (YamlSequenceNode)currentRootNode; YamlSequenceNode child = new YamlSequenceNode(); rootNode.Add(child); return(child); } }
private void WriteEntitySection() { var entities = new YamlSequenceNode(); RootNode.Add("entities", entities); foreach (var entity in Entities) { CurrentWritingEntity = entity; var mapping = new YamlMappingNode { { "uid", EntityUidMap[entity.Uid].ToString(CultureInfo.InvariantCulture) } }; if (entity.Prototype != null) { mapping.Add("type", entity.Prototype.ID); } var components = new YamlSequenceNode(); // See engine#636 for why the Distinct() call. foreach (var component in entity.GetAllComponents()) { var compMapping = new YamlMappingNode(); CurrentWritingComponent = component.Name; var compSerializer = YamlObjectSerializer.NewWriter(compMapping, this); component.ExposeData(compSerializer); // Don't need to write it if nothing was written! if (compMapping.Children.Count != 0) { // Something actually got written! compMapping.Add("type", component.Name); components.Add(compMapping); } } if (components.Children.Count != 0) { mapping.Add("components", components); } entities.Add(mapping); } }
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()); } } }
private static YamlSequenceNode SaveCharacterWidths(FINF fontInfo) { YamlSequenceNode node = new YamlSequenceNode(); foreach (var character in fontInfo.CodeMapDictionary) { YamlMappingNode mapping = new YamlMappingNode(); mapping.Style = SharpYaml.YamlStyle.Flow; if (character.Value != -1) { var width = fontInfo.GetCharacterWidth(character.Value); mapping.Add($"0x{((ushort)character.Key).ToString("X4")}", SaveCharacterWidth(width)); } node.Add(mapping); } return(node); }
/// <summary> /// Adds a reference from the target item's 'children' section to the source item, /// if reference doesn't exist yet /// </summary> /// <param name="sourceItem"></param> /// <param name="targetItem"></param> /// <returns></returns> private static bool addSourceToChildren(YamlMappingNode sourceItem, YamlMappingNode targetItem) { YamlScalarNode childUid = (sourceItem?.Children?[new YamlScalarNode("uid")] as YamlScalarNode); YamlSequenceNode existingChildren = getSequence(targetItem, "children", true); if (existingChildren == null) { return(false); } if (existingChildren.Children != null && existingChildren.Children.Contains(childUid)) { return(false); } existingChildren.Add(childUid?.Value); return(true); }
static YamlNode reifyDocumentation(EA.Repository Repository, EA.Element e, EA.Connector con, EA.Element client) { logger.log("Reify Documentation:" + e.Name + "-" + e.Version); YamlSequenceNode sn = new YamlSequenceNode(); Dictionary <string, RunState> elementRS = ObjectManager.parseRunState(e.RunState); foreach (string key in elementRS.Keys) { YamlMappingNode docNode = new YamlMappingNode(); sn.Add(docNode); YamlScalarNode docObjectAttribute = new YamlScalarNode(elementRS[key].value); docObjectAttribute.Style = ScalarStyle.Raw; docNode.Add("title", key); docNode.Add("content", docObjectAttribute); } return(sn); }
public YamlNode ToYaml() { var node = new YamlMappingNode( new YamlScalarNode("enabled"), new YamlScalarNode(Enabled.ToString().ToLower()), new YamlScalarNode("thread-pool-size"), new YamlScalarNode(ThreadPoolSize.ToString())); var masters = new YamlSequenceNode(); node.Add(SessionTagName, masters); foreach (var session in Sessions) { var yaml = session.ToYaml(); masters.Add(yaml); } return(node); }
void WriteEntitySection() { var entities = new YamlSequenceNode(); RootNode.Add("entities", entities); foreach (var entity in Entities) { CurrentWritingEntity = entity; var mapping = new YamlMappingNode(); mapping.Add("type", entity.Prototype.ID); if (entity.Name != entity.Prototype.Name) { // TODO: This shouldn't be hardcoded. mapping.Add("name", entity.Prototype.Name); } var components = new YamlSequenceNode(); // See engine#636 for why the Distinct() call. foreach (var component in entity.GetAllComponents().Distinct()) { var compMapping = new YamlMappingNode(); CurrentWritingComponent = component.Name; var compSerializer = YamlObjectSerializer.NewWriter(compMapping, this); component.ExposeData(compSerializer); // Don't need to write it if nothing was written! if (compMapping.Children.Count != 0) { // Something actually got written! compMapping.Add("type", component.Name); components.Add(compMapping); } } if (components.Children.Count != 0) { mapping.Add("components", components); } entities.Add(mapping); } }
public YamlMappingNode ToYaml() { var ss = new YamlMappingNode(); ss.Add(PathKey, FileHelper.ConvertToForwardSlash(RuntimeFilePath)); ss.Add(TemplateFilePathKey, LocalFilePath); ss.Add(SessionNameKey, Name); var overrides = new YamlSequenceNode(); ss.Add(OverridesKey, overrides); foreach (var o in Overrides) { YamlMappingNode dic = new YamlMappingNode(); dic.Add(KeyKey, o.Key); dic.Add(ValueKey, o.Value); overrides.Add(dic); } return(ss); }
protected override void UpgradeAsset(AssetMigrationContext context, int currentVersion, int targetVersion, dynamic asset, PackageLoadingAssetFile assetFile) { var entities = asset.Hierarchy.Entities; var designEntities = new YamlSequenceNode(); asset.Hierarchy.Entities = designEntities; foreach (var entity in entities) { var designEntity = new YamlMappingNode(); dynamic dynamicDesignEntity = new DynamicYamlMapping(designEntity); dynamicDesignEntity.Entity = entity; designEntities.Add(designEntity); } }
protected override void UpgradeAsset(int currentVersion, int targetVersion, ILogger log, dynamic asset) { var entities = asset.Hierarchy.Entities; var designEntities = new YamlSequenceNode(); asset.Hierarchy.Entities = designEntities; foreach (var entity in entities) { var designEntity = new YamlMappingNode(); dynamic dynamicDesignEntity = new DynamicYamlMapping(designEntity); dynamicDesignEntity.Entity = entity; designEntities.Add(designEntity); } }
private YamlNode Build() { var root = new YamlMappingNode(); root.Add("from", _assetType); if (SelectFields.Count > 0) { var select = new YamlSequenceNode(); var attributes = SelectFields.Where(s => s is string); foreach(var attr in attributes) { var val = attr as string; select.Add(val); } var nestedBuilders = SelectFields.Where(s => s is QueryApiQueryBuilder); foreach (var item in nestedBuilders) { var nestedBuilder = item as QueryApiQueryBuilder; select.Add(nestedBuilder.Build()); } root.Add("select", select); } if (WhereCriteria.Count > 0) { var whereNodes = new YamlMappingNode(); foreach (var criterion in WhereCriteria) { whereNodes.Add(criterion.AttributeName, criterion.MatchValue.ToString()); } root.Add("where", whereNodes); } if (FilterCriteria.Count > 0) { var filterNodes = new YamlSequenceNode(); foreach (var criterion in FilterCriteria) { filterNodes.Add($"{criterion.AttributeName}{criterion.Operator.Token}\"{criterion.MatchValue.ToString()}\""); } root.Add("filter", filterNodes); } return root; }