private static void SetSectionValue(CredentialsSection section, string name, string value) { if (string.Equals(accessKeyName, name, StringComparison.OrdinalIgnoreCase)) { section.AccessKey = value; } else if (string.Equals(secretKeyName, name, StringComparison.OrdinalIgnoreCase)) { section.SecretKey = value; } else if (string.Equals(tokenName, name, StringComparison.OrdinalIgnoreCase)) { section.Token = value; } }
public string Serialize() { var credentialsSection = new CredentialsSection { Username = "******", Password = "******" }; this.credentials = new List <CredentialsSection> { credentialsSection, credentialsSection }; this.logging = "log this"; XmlSerializer s = new XmlSerializer(this.GetType()); StringBuilder sb = new StringBuilder(); TextWriter w = new StringWriter(sb); s.Serialize(w, this); w.Flush(); return(sb.ToString()); }
private void Parse(string[] lines) { Sections = new List <CredentialsSection>(); CredentialsSection currentSection = null; foreach (var l in lines) { var line = l ?? string.Empty; line = line.Trim(); if (string.IsNullOrEmpty(line)) { continue; } if (line.StartsWith(profileNamePrefix, StringComparison.OrdinalIgnoreCase) && line.EndsWith(profileNameSuffix, StringComparison.OrdinalIgnoreCase)) { if (currentSection != null) { Sections.Add(currentSection); } var profileName = GetProfileName(line); currentSection = new CredentialsSection(profileName); } else if (line.StartsWith(dataPrefix, StringComparison.OrdinalIgnoreCase) && currentSection != null) { // split data into key-value pairs, store appropriately var split = SplitData(line); if (split.Count > 0) { var name = split[0]; var value = split.Count > 1 ? split[1] : null; SetSectionValue(currentSection, name, value); } } } if (currentSection != null) { Sections.Add(currentSection); } }
private static void SetSectionValue(CredentialsSection section, string name, string value) { if (string.Equals(accessKeyName, name, StringComparison.OrdinalIgnoreCase)) section.AccessKey = value; else if (string.Equals(secretKeyName, name, StringComparison.OrdinalIgnoreCase)) section.SecretKey = value; else if (string.Equals(tokenName, name, StringComparison.OrdinalIgnoreCase)) section.Token = value; }
private void Parse(string[] lines) { Sections = new List<CredentialsSection>(); CredentialsSection currentSection = null; foreach (var l in lines) { var line = l ?? string.Empty; line = line.Trim(); if (string.IsNullOrEmpty(line)) continue; if (line.StartsWith(profileNamePrefix, StringComparison.OrdinalIgnoreCase) && line.EndsWith(profileNameSuffix, StringComparison.OrdinalIgnoreCase)) { if (currentSection != null) Sections.Add(currentSection); var profileName = GetProfileName(line); currentSection = new CredentialsSection(profileName); } else if (line.StartsWith(dataPrefix, StringComparison.OrdinalIgnoreCase) && currentSection != null) { // split data into key-value pairs, store appropriately var split = SplitData(line); if (split.Count > 0) { var name = split[0]; var value = split.Count > 1 ? split[1] : null; SetSectionValue(currentSection, name, value); } } } if (currentSection != null) Sections.Add(currentSection); }