public void Serialize(SchemaFile file, TargetWriter target) { using (target) { var writer = target.GetWriter(); var items = file.GetItems(); Func <int, bool> indentFunction = index => false; for (var i = 0; i < items.Length; i++) { var item = items[i]; var indent = indentFunction.Invoke(i); if (indent) { writer.Write(" "); } if (item.IsComment) { writer.Write("#"); writer.WriteLine(item.Text); } else if (item.IsValue) { writer.WriteLine((item.Text == null) ? "(null)" : item.Text); } else { writer.WriteLine(item.Text); } if (item.IsProperty) { var values = file.GetValues(item.Text); var lastItem = values.LastOrDefault() ?? item; var lastIndex = file.IndexOf(lastItem); indentFunction = index => index <= lastIndex; } } writer.Flush(); } }
public static void Save(Credentials credentials, TargetWriter target) { using (target) { var writer = target.GetWriter(); foreach (var entry in credentials) { var uri = entry.Key; var token = entry.Value; var encryptedData = token.GetEncriptedData(); var line = uri + ' ' + encryptedData; writer.WriteLine(line); } writer.Flush(); } }