public CollectionChangedTestViewModel() { HeaderText.Value = "Section1"; FooterText.Value = "FooterText1"; var headers = new string[] { "Hoge", "Fuga", "Piyo" }; var footers = new string[] { "Fumufumu", "Houhou", "Naninai" }; var idxH = 0; var idxF = 0; SectionCommand.Subscribe(p => { if (p == "Header") { HeaderText.Value = headers[idxH++]; if (idxH >= 3) { idxH = 0; } } else { FooterText.Value = footers[idxF++]; if (idxF >= 3) { idxF = 0; } } }); }
public CollectionChangedTestViewModel() { HeaderText.Value = "Section1"; FooterText.Value = "FooterText1"; var headers = new string[] { "Hoge", "Fuga", "Piyo" }; var footers = new string[] { "Fumufumu", "Houhou", "Naninai" }; var idxH = 0; var idxF = 0; SectionCommand.Subscribe(p => { if (p == "Header") { HeaderText.Value = headers[idxH++]; if (idxH >= 3) { idxH = 0; } } else { FooterText.Value = footers[idxF++]; if (idxF >= 3) { idxF = 0; } } }); CellIconSize.Subscribe(x => { Debug.WriteLine($"CellIconSizeChange {x.Width} {x.Height}"); }); }
/// <summary> /// Loads and parses ini file. /// </summary> public void ParseIniFile(FileReference Filename) { String[] IniLines = null; List <Command> Commands = null; if (!FileCache.ContainsKey(Filename.FullName)) { try { IniLines = File.ReadAllLines(Filename.FullName); Commands = new List <Command>(); FileCache.Add(Filename.FullName, Commands); } catch (Exception ex) { Console.WriteLine("Error reading ini file: " + Filename + " Exception: " + ex.Message); } } else { Commands = FileCache[Filename.FullName]; } if (IniLines != null) { IniSection CurrentSection = null; // Line Index for exceptions var LineIndex = 1; var bMultiLine = false; var SingleValue = ""; var Key = ""; var LastAction = ParseAction.None; // Parse each line foreach (var Line in IniLines) { var TrimmedLine = Line.Trim(); // Multiline value support bool bWasMultiLine = bMultiLine; bMultiLine = TrimmedLine.EndsWith("\\"); if (bMultiLine) { TrimmedLine = TrimmedLine.Substring(0, TrimmedLine.Length - 1).TrimEnd(); } if (!bWasMultiLine) { if (TrimmedLine.StartsWith("[")) { CurrentSection = FindOrAddSection(TrimmedLine, Filename, LineIndex); LastAction = ParseAction.None; if (CurrentSection != null) { SectionCommand Command = new SectionCommand(); Command.Filename = Filename; Command.LineIndex = LineIndex; Command.TrimmedLine = TrimmedLine; Commands.Add(Command); } } else { if (LastAction != ParseAction.None) { throw new IniParsingException("Parsing new key/value pair when the previous one has not yet been processed ({0}, {1}) in {2}, line {3}: {4}", Key, SingleValue, Filename, LineIndex, TrimmedLine); } // Check if the line is empty or a comment, also remove any +/- markers LastAction = GetActionForLine(ref TrimmedLine); if (LastAction != ParseAction.None) { /* if (CurrentSection == null) * { * throw new IniParsingException("Trying to parse key/value pair that doesn't belong to any section in {0}, line {1}: {2}", Filename, LineIndex, TrimmedLine); * }*/ ParseKeyValuePair(TrimmedLine, Filename, LineIndex, out Key, out SingleValue); } } } if (bWasMultiLine) { SingleValue += TrimmedLine; } if (!bMultiLine && LastAction != ParseAction.None && CurrentSection != null) { ProcessKeyValuePair(CurrentSection, Key, SingleValue, LastAction); KeyValueCommand Command = new KeyValueCommand(); Command.Key = Key; Command.Value = SingleValue; Command.LastAction = LastAction; Commands.Add(Command); LastAction = ParseAction.None; SingleValue = ""; Key = ""; } else if (CurrentSection == null) { LastAction = ParseAction.None; } LineIndex++; } } else if (Commands != null) { IniSection CurrentSection = null; // run each command for (int Idx = 0; Idx < Commands.Count; ++Idx) { var Command = Commands[Idx]; if (Command is SectionCommand) { CurrentSection = FindOrAddSection((Command as SectionCommand).TrimmedLine, (Command as SectionCommand).Filename, (Command as SectionCommand).LineIndex); } else if (Command is KeyValueCommand) { ProcessKeyValuePair(CurrentSection, (Command as KeyValueCommand).Key, (Command as KeyValueCommand).Value, (Command as KeyValueCommand).LastAction); } } } }