/// <summary> /// Loads a site configuration from a particular path. /// </summary> /// <param name="path">The path to look for _config.yaml file.</param> /// <returns>The loaded or created configuration file.</returns> public static SiteConfig Read(DirectoryInfo path) { SiteConfig configuration = null; try { // Get the configuration file configuration = YamlObject.FromSearch <SiteConfig>(path, SiteConfig.Name, SearchOption.TopDirectoryOnly); } catch { // Unable to read Tracing.Error("Config", "Configuration file " + SiteConfig.Name + " is invalid."); } if (configuration == null) { // Create a new configuration Tracing.Info("Project", "Configuration file not found, creating a new one."); configuration = new SiteConfig(); configuration.ToFile(Path.Combine(path.FullName, SiteConfig.Name)); } return(configuration); }
private static Lexer ParseBlock(Lexer lexer, out YamlObject result) { var indent = CheckIndent(lexer); var block = new Dictionary <string, YamlNode>(); while (lexer.LexerType == LexerType.WhiteSpace && lexer.Length == indent) { lexer = lexer.SkipWhiteSpace(); lexer = ParseKeyValue(lexer, out var keyValue); block[keyValue.key] = keyValue.value; if (lexer.LexerType == LexerType.EndOfFile) { break; } if (lexer.LexerType == LexerType.LineBreak) { lexer = lexer.Skip(LexerType.LineBreak); } } result = new YamlObject(block); return(lexer); }
public static string GetRepoUpdatedDate(string userRepo, out string info) { string lastDate = ""; info = ""; StringBuilder sb = new StringBuilder(); string jsonInfo = DownloadString(giturl + userRepo); lastDate = regexUpdDate.Match(jsonInfo).Groups[1].Value; string jsonCommitsData = DownloadString(giturl + userRepo + "/commits"); YamlObject Commits = YamlParser.Parse(jsonCommitsData); foreach (var commit in Commits.ChildItems) { string date = NormalizeDate(commit[@"commit\author\date"]); string msg = commit[@"commit\message"]; if (date.StartsWith("2015.10")) { break; } if ((msg.IndexOf("README.md") > 0) || (msg.IndexOf("gitignore") > 0)) { continue; } sb.AppendLine("### " + date + " \r\n" + msg + "\r\n"); } info = DownloadString("https://raw.githubusercontent.com/" + userRepo + "/master/README.md"); info += " \r\n## История обновлений и исправлений \r\n" + sb.ToString(); info = MarkdownToHtml(info); return(lastDate); }
public static YamlObject ParseAsset(string path) { if (string.IsNullOrEmpty(path)) { return(null); } YamlObject @object = null; try { var file = new FileInfo(path); var scope = new YamlScope(); using (var input = file.OpenText()) { if (scope.Parse(input)) { @object = new YamlObject(scope); } } } catch (Exception e) { Debug.LogException(e); } return(@object); }
private static Lexer ParseListEntry(Lexer lexer, out YamlObject result) { lexer = lexer.Skip(LexerType.Dash); var dict = new Dictionary <string, YamlNode>(); while (lexer.SkipWhiteSpace().LexerType != LexerType.Dash) { lexer = lexer.SkipWhiteSpace(); lexer = ParseKeyValue(lexer, out var keyValue); dict[keyValue.key] = keyValue.value; if (lexer.LexerType == LexerType.EndOfFile) { break; } if (lexer.LexerType == LexerType.LineBreak) { lexer = lexer.Skip(LexerType.LineBreak); } } result = new YamlObject(dict); return(lexer); }
static void Main(string[] args) { Setting setting = YamlObject.GetFromFile <Setting>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "setting.yml")); var slack = new Slack(setting.Token); Dictionary <string, List <string> > message = setting.GetMessages(); var directroy = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "images")); Parallel.ForEach(directroy.EnumerateFiles("*", SearchOption.TopDirectoryOnly), new ParallelOptions() { MaxDegreeOfParallelism = 5 }, file => { var user = file.Name.Replace(file.Extension, ""); if (!message.ContainsKey(user)) { Console.WriteLine($"message is not found user: {file.Name}"); return; } var binary = ReadImageFile(file); var channel = slack.FileUpload(user, binary).Result; message[user].ForEach(x => slack.MessageSend(user, x, channel).Wait()); }); }
private static Lexer ParseLiteralDictionary(Lexer lexer, out YamlObject result) { lexer = lexer.Skip(LexerType.LeftBrace); var block = new Dictionary <string, YamlNode>(); while (lexer.LexerType != LexerType.RightBrace) { lexer = ParseKeyValue(lexer, out var keyValue); block[keyValue.key] = keyValue.value; if (lexer.LexerType == LexerType.Comma) { lexer = lexer.Skip(LexerType.Comma); if (lexer.LexerType == LexerType.LineBreak) { lexer = lexer.Skip(LexerType.LineBreak); } lexer = lexer.SkipWhiteSpace(); } } lexer = lexer.Skip(LexerType.RightBrace); result = new YamlObject(block); return(lexer); }
public override void OnMlfFormatPre(MlfInstance instance) { foreach (MlfBlock block in instance.Blocks) { if (block.format != "yaml") { continue; } //Detect tabs if (block.Content.Contains("\t")) { Debug.LogError("YAML Does not support tabs."); return; } YamlObject yaml = new YamlObject(block.Content); block.SetFormatData(formatDataKey, yaml); block.OnContentChange += (content) => { yaml.SetContent(content); }; } }
public void YamlString_ProducesCorrect_YamlObject() { var obj = new YamlObject(YamlLine); Assert.AreEqual(level, obj.level, "Level missmatched"); Assert.AreEqual(PropertyName, obj.property, "Property name missmatched"); Assert.AreEqual(PropertyValue.ToString(), obj.value, "Property value missmatched"); }
public static bool ChangeYamlObjects(ref List <string> lines, int startLine, ref int endLine, int currentTabDepth, BetterDict <string, YamlObject> changeDict) { int targetStartingSpaces = currentTabDepth * 2; for (int i = startLine; i <= endLine; i++) { string line = lines[i]; if (!IsKeyValLine(line)) { continue; } int lineStartingSpaces = CountStartingSpaces(line); if (lineStartingSpaces != targetStartingSpaces) { //shouldn't ever leave the targetSection! Console.WriteLine(lineStartingSpaces < targetStartingSpaces ? "ChangeYamlObjects somehow left the target section!" : "ChangeYamlObjects somehow entered a subsection!"); return(false); } int segmentEndLine = GetSegmentEndLineIndex(ref lines, i + 1, currentTabDepth + 1); string lineKey = GetKeyValKey(line); if (!changeDict.ContainsKey(lineKey)) { //go to next segment i = segmentEndLine; continue; } YamlObject targetObject = changeDict[lineKey]; int initialSegmentEndLine = segmentEndLine; if (!targetObject.Save(ref lines, i + 1, ref segmentEndLine, currentTabDepth + 1)) { Console.WriteLine("Failed to save YamlObject: " + lineKey); return(false); } if (segmentEndLine != initialSegmentEndLine) { i = segmentEndLine; int delta = segmentEndLine - initialSegmentEndLine; endLine += delta; } else { i = initialSegmentEndLine; } } return(true); }
private static Style ToStyleFromSettings(YamlObject yo) { string fore = yo["foreground"]; string back = yo["background"]; string font = yo["fontStyle"]; bool bold = (font.IndexOf("bold") >= 0); bool ital = (font.IndexOf("italic") >= 0); bool undl = (font.IndexOf("underline") >= 0); return(ToStyle(fore, back, bold, ital, undl)); }
private void TestLiteralDictionaryImpl(YamlObject block) { var rawLiteralDictionary = block.Values["m_OcclusionCullingData"]; rawLiteralDictionary.YamlNodeType.Should().Be(YamlNodeType.Object); var literalDictionary = (YamlObject)rawLiteralDictionary; literalDictionary.Values.Count.Should().Be(2); (literalDictionary.Values["fileID"] as YamlScalar).Value.Should().Be("0"); (literalDictionary.Values["hoge"] as YamlScalar).Value.Should().Be("2"); }
public void GuidsInYamlObject_ProducesCorrect_ClassObject() { var serializedYamlObject = new YamlObject(0, "Guid", guidObject); var objToWrite = new ObjectWithGuid(); var tree = new TreeNode <YamlObject>(); tree.AddChild(serializedYamlObject); YamlSerializer.DeserializeSimpleProperties(objToWrite, tree); Assert.AreEqual(guidObject, objToWrite.Guid, "Deserialized object should have correct guid value."); }
private void TestNestedObjectImpl(YamlObject block) { var rawNestedObject = block.Values["m_OcclusionBakeSettings"]; rawNestedObject.YamlNodeType.Should().Be(YamlNodeType.Object); var nestedObject = (YamlObject)rawNestedObject; nestedObject.Values.Count.Should().Be(3); (nestedObject.Values["smallestOccluder"] as YamlScalar).Value.Should().Be("5"); (nestedObject.Values["smallestHole"] as YamlScalar).Value.Should().Be("0.25"); (nestedObject.Values["backfaceThreshold"] as YamlScalar).Value.Should().Be("100"); }
private static YamlObject parseArray(XmlNode node) { YamlObject result = new YamlObject(node.Name); result.Type = YamlObjectType.Sequence; int i = 0; foreach (XmlNode child in node.ChildNodes) { YamlObject r = parse(child); r.Name = i.ToString(); result.ChildItems.Add(r); i++; } return result; }
public void GuidsInObject_ProducesCorrect_YamlObject() { var expectedYamlObject = new YamlObject(0, "Guid", guidObject); var obj = new ObjectWithGuid() { Guid = guidObject }; var props = YamlSerializer.SerializeSimpleProperties(obj, 0); Assert.AreEqual(1, props.Count(), "Only one property should have been serialized."); Assert.AreEqual(expectedYamlObject.property, props.First().property, "Property names should be identical."); Assert.AreEqual(expectedYamlObject.value, props.First().value, "Guid values should be identical."); }
private static YamlObject parseArray(XmlNode node) { YamlObject result = new YamlObject(node.Name); result.Type = YamlObjectType.Sequence; int i = 0; foreach (XmlNode child in node.ChildNodes) { YamlObject r = parse(child); r.Name = i.ToString(); result.ChildItems.Add(r); i++; } return(result); }
public static YamlObject LoadFromFile(string file) { YamlObject result = new YamlObject(); if (!File.Exists(file)) file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(file)); if (File.Exists(file)) { XmlDocument xml = new XmlDocument(); xml.XmlResolver = null; try { xml.Load(file); result = readXml(xml); } catch (Exception e) { HMS.LogError("Ошибка загрузки "+file+". Причина: "+ e.Message); } } return result; }
public static YamlObject LoadFromFile(string file) { YamlObject result = new YamlObject(); if (!File.Exists(file)) { file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(file)); } if (File.Exists(file)) { XmlDocument xml = new XmlDocument(); xml.XmlResolver = null; try { xml.Load(file); result = readXml(xml); } catch (Exception e) { HMS.LogError("Ошибка загрузки " + file + ". Причина: " + e.Message); } } return(result); }
private static YamlObject parseDictionary(XmlNode node) { XmlNodeList children = node.ChildNodes; YamlObject result = new YamlObject(node.Name); result.Type = YamlObjectType.Mapping; int count = children.Count; if (count < 2) { return(result); } for (int i = 0; i < count; i += 2) { XmlNode keynode = children[i]; if (keynode.Name == "#comment") { i--; continue; } XmlNode valnode = children[i + 1]; if (valnode.Name == "#comment") { i++; valnode = children[i + 1]; } if (keynode.Name != "key") { continue; } YamlObject r = parse(valnode); r.Name = keynode.InnerText; result.ChildItems.Add(r); } return(result); }
private static YamlObject parseDictionary(XmlNode node) { XmlNodeList children = node.ChildNodes; YamlObject result = new YamlObject(node.Name); result.Type = YamlObjectType.Mapping; int count = children.Count; if (count < 2) return result; for (int i = 0; i < count; i += 2) { XmlNode keynode = children[i]; if (keynode.Name == "#comment") { i--; continue; } XmlNode valnode = children[i + 1]; if (valnode.Name == "#comment") { i++; valnode = children[i + 1]; } if (keynode.Name != "key") continue; YamlObject r = parse(valnode); r.Name = keynode.InnerText; result.ChildItems.Add(r); } return result; }
public void YamlObject_ProducesCorrect_YamlString() { var obj = new YamlObject(level, PropertyName, PropertyValue); Assert.AreEqual(YamlLine, obj.ToString(), "Yaml Lines should be identical"); }
private static Style ToStyleFromSettings(YamlObject yo) { string fore = yo["foreground"]; string back = yo["background"]; string font = yo["fontStyle" ]; bool bold = font.IndexOf("bold" , StringComparison.Ordinal) >= 0; bool ital = font.IndexOf("italic" , StringComparison.Ordinal) >= 0; bool undl = font.IndexOf("underline", StringComparison.Ordinal) >= 0; if ((fore.Length + back.Length == 0) && !bold && !ital && !undl) return null; return ToStyle(fore, back, bold, ital, undl); }
private static Style ToStyleFromSettings(YamlObject yo) { string fore = yo["foreground"]; string back = yo["background"]; string font = yo["fontStyle" ]; bool bold = (font.IndexOf("bold" ) >= 0); bool ital = (font.IndexOf("italic" ) >= 0); bool undl = (font.IndexOf("underline") >= 0); return ToStyle(fore, back, bold, ital, undl); }
public static void LoadFromXml(string file) { Theme t = new Theme(); YamlObject plist = PlistParser.LoadFromFile(file); string themeName = plist["name"]; if (themeName == "") { return; } YamlObject list = plist.GetObject("settings"); foreach (YamlObject item in list) { string name = item["name"]; string[] scope = item["scope"].Split(','); for (int i = 0; i < scope.Length; i++) { scope[i] = scope[i].ToLower().Trim(); } YamlObject settings = item.GetObject("settings"); if ((name == "") && (item["scope"] == "") && (settings.Count > 0)) { t.Background = ToColor(settings["background"]); t.Caret = ToColor(settings["caret"]); t.Foreground = ToColor(settings["foreground"]); t.Invisibles = ToColor(settings["invisibles"]); t.LineHighlight = ToColor(settings["lineHighlight"]); t.Selection = ToColor(settings["selection"]); t.InvisibleStyle = ToStyle(settings["invisibles"]); continue; } if (InScope(scope, "comment")) { t.CommentStyle = ToStyleFromSettings(settings); } if (InScope(scope, "string")) { t.StringStyle = ToStyleFromSettings(settings); } if (InScope(scope, "constant.numeric")) { t.NumberStyle = ToStyleFromSettings(settings); } if (InScope(scope, "keyword")) { t.KeywordStyle = ToStyleFromSettings(settings); } if (InScope(scope, "entity.name.class")) { t.ClassNameStyle = ToStyleFromSettings(settings); } if (InScope(scope, "declaration.class")) { t.ClassNameStyle = ToStyleFromSettings(settings); } if (InScope(scope, "support.class")) { t.ClassNameStyle = ToStyleFromSettings(settings); } if (InScope(scope, "meta.tag")) { t.TagBracketStyle = ToStyleFromSettings(settings); } if (InScope(scope, "entity.name.tag")) { t.TagNameStyle = ToStyleFromSettings(settings); } if (InScope(scope, "variable")) { t.VariableStyle = ToStyleFromSettings(settings); } if (InScope(scope, "attribute-name")) { t.AttributeStyle = ToStyleFromSettings(settings); } if (InScope(scope, "support.function")) { t.FunctionsStyle = ToStyleFromSettings(settings); } if (InScope(scope, "support.constant")) { t.ConstantsStyle = ToStyleFromSettings(settings); } if (InScope(scope, "entity.name.function")) { t.DeclFunctionStyle = ToStyleFromSettings(settings); } } Dict[themeName] = t; }