protected void Load(string id) { var file = Shell.File.Find(Helpers.CredentialHelper.Path, $"{id}.{LOG.ToLower()}").FirstOrDefault(); if (file == null) { k.Diagnostic.Error(LOG, null, "Cannot possible to load {0} id in {1}", id, Helpers.CredentialHelper.Path); throw new KException(LOG, E.Message.CredentialId_0); } var json = Shell.File.Load(file); if (!R.DebugMode) { json = Security.Decrypt(json, null); } var foo = Newtonsoft.Json.JsonConvert.DeserializeObject(json, this.GetType()); foreach (var p in k.Reflection.GetProperties(foo)) { k.Reflection.SetValue(this, p.Name, p.GetValue(foo)); } if (DueDate != (new DateTime()) && DueDate < DateTime.Now) { k.Shell.File.Delete(file); throw new KException(LOG, E.Message.CredentialExpired_0); } }
/// <summary> /// Save credential and return credential ID /// </summary> /// <returns>ID</returns> public virtual string Save() { var json = ToJson(); var id = Security.Hash(json); var name = $"{id}.{LOG.ToLower()}"; Shell.File.Write(json, name, Helpers.CredentialHelper.Path); return(id); }