public object Read( object data, string masterPassphrase, params KeyValuePair <string, string>[] parameters) { FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType()); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Writing Credential from JSON using serialiser '{0}'.", formatVersion); JObject dataJSON = (JObject)data; String id = JSONHelpers.ReadString(dataJSON, "ID"); String glyphKey = JSONHelpers.ReadString(dataJSON, "GlyphKey"); String glyphColour = JSONHelpers.ReadString(dataJSON, "GlyphColour"); String name = JSONHelpers.ReadString(dataJSON, "Name"); String description = JSONHelpers.ReadString(dataJSON, "Description"); String website = JSONHelpers.ReadString(dataJSON, "Website"); DateTime createdAt = JSONHelpers.ReadDateTime(dataJSON, "CreatedAt"); DateTime lastUpdatedAt = JSONHelpers.ReadDateTime(dataJSON, "LastUpdatedAt"); DateTime passwordLastModifiedAt = JSONHelpers.ReadDateTime(dataJSON, "PasswordLastModifiedAt", createdAt); String username = JSONHelpers.ReadString(dataJSON, "Username"); String password = JSONHelpers.ReadString(dataJSON, "Password"); JArray tagsArray = JSONHelpers.ReadJArray(dataJSON, "Tags", true);; List <String> tags = new List <String>(); foreach (JValue curValue in tagsArray) { tags.Add(curValue.Value <String>()); } String notes = JSONHelpers.ReadString(dataJSON, "Notes"); List <AuditLogEntry> auditLogEntriesList = new List <AuditLogEntry>(); if (dataJSON.ContainsKey("AuditLogEntries")) { ISerialiser auditLogEntrySerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(AuditLogEntry)); JArray auditLogEntries = JSONHelpers.ReadJArray(dataJSON, "AuditLogEntries", true); foreach (JObject curEntry in auditLogEntries) { AuditLogEntry entry = (AuditLogEntry)auditLogEntrySerialiser.Read(curEntry, String.Empty); auditLogEntriesList.Add(entry); } if (auditLogEntriesList.Count > 0) { auditLogEntriesList = auditLogEntriesList.OrderByDescending(ale => ale.DateTime).ToList(); } } return(new Credential(id, glyphKey, glyphColour, name, description, website, createdAt, lastUpdatedAt, passwordLastModifiedAt, username, password, tags.ToArray(), notes, auditLogEntriesList.ToArray())); }
public object Read( object data, string masterPassphrase, params KeyValuePair <string, string>[] parameters) { FormatVersionAttribute formatVersion = FormatVersionAttribute.GetAttributeFromType(this.GetType()); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information, "Reading Vault from JSON using serialiser '{0}'.", formatVersion); JObject dataJSON = (JObject)data; String id = JSONHelpers.ReadString(dataJSON, "ID"); String name = JSONHelpers.ReadString(dataJSON, "Name"); String description = JSONHelpers.ReadString(dataJSON, "Description"); DateTime createdAt = JSONHelpers.ReadDateTime(dataJSON, "CreatedAt"); DateTime lastUpdatedAt = JSONHelpers.ReadDateTime(dataJSON, "LastUpdatedAt"); List <Credential> credentialList = new List <Credential>(); ISerialiser credentialSerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(Credential)); JArray credentials = JSONHelpers.ReadJArray(dataJSON, "Credentials", true); foreach (JObject curCredential in credentials) { Credential credential = (Credential)credentialSerialiser.Read(curCredential, String.Empty); credentialList.Add(credential); } List <AuditLogEntry> auditLogEntriesList = new List <AuditLogEntry>(); if (dataJSON.ContainsKey("AuditLogEntries")) { ISerialiser auditLogEntrySerialiser = FormatVersions.Instance.GetSerialiser(formatVersion.Version, typeof(AuditLogEntry)); JArray auditLogEntries = JSONHelpers.ReadJArray(dataJSON, "AuditLogEntries", true); foreach (JObject curEntry in auditLogEntries) { AuditLogEntry entry = (AuditLogEntry)auditLogEntrySerialiser.Read(curEntry, String.Empty); auditLogEntriesList.Add(entry); } if (auditLogEntriesList.Count > 0) { auditLogEntriesList = auditLogEntriesList.OrderByDescending(ale => ale.DateTime).ToList(); } } return(new Vault(id, name, description, createdAt, lastUpdatedAt, credentialList.ToArray(), auditLogEntriesList.ToArray())); }