private void ReadYamlFile(YamlItemModel yamlObject, string filepath, string fileContents) { if (yamlObject != null & yamlObject?.SharedFields != null) { foreach (var sharedField in yamlObject?.SharedFields) { if ((bool)(sharedField?.Hint.StartsWith("__"))) { continue; } else if (sharedField?.Value != null && (bool)(sharedField?.Value.Contains("stylelabs-content-id"))) { UpdateFile(filepath, GetDamHost(sharedField.Value), new System.Uri(damUrl)?.Host, fileContents); } } } if (yamlObject != null & yamlObject?.Languages != null) { foreach (var language in yamlObject?.Languages) { if (language?.Fields != null) { foreach (var field in language?.Fields) { if ((bool)(field?.Hint.StartsWith("__"))) { continue; } else if (field?.Value != null && (bool)(field?.Value.Contains("stylelabs-content-id"))) { UpdateFile(filepath, GetDamHost(field.Value), new System.Uri(damUrl)?.Host, fileContents); } } } if (language?.Versions != null) { foreach (var version in language?.Versions) { if (version?.Fields != null) { foreach (var field in version?.Fields) { if ((bool)(field?.Hint.StartsWith("__"))) { continue; } else if (field?.Value != null && (bool)(field?.Value.Contains("stylelabs-content-id"))) { UpdateFile(filepath, GetDamHost(field.Value), new System.Uri(damUrl)?.Host, fileContents); } } } } } } } }
private void PerformUpdate(string filepath) { var deserializer = new YamlDotNet.Serialization.Deserializer(); YamlItemModel yamlObject = new YamlItemModel(); string fileContents = String.Empty; using (var reader = new StreamReader(filepath)) { yamlObject = deserializer.Deserialize <YamlItemModel>(reader); reader.DiscardBufferedData(); reader.BaseStream.Seek(0, SeekOrigin.Begin); fileContents = reader.ReadToEnd(); } ReadYamlFile(yamlObject, filepath, fileContents); }