/// <summary> /// Returns the model with the given foreignKey from the secureDatacache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="foreignKey"></param> /// <returns></returns> internal bool TryGetSensible <T>(Guid foreignKey, out T model) { CheckDatacache(); if (_secureDatacache.TryGetValue(foreignKey, out var encryptedBytes)) { var decryptedBytes = CryptMemoryProtection.DecryptInMemoryData(encryptedBytes); model = (T)ByteHelper.ByteArrayToObject(decryptedBytes); return(true); } model = (T) new object(); return(false); }
/// <summary> /// Builds models out of one byte array. /// </summary> /// <param name="arr"></param> internal T BuildModelsOutOfBytes <T>(byte[] arr, bool isByteModel = false) where T : Models.Interfaces.ISerializable, IDeletable { if (!isByteModel) { XmlDocument doc = new XmlDocument(); using (var ms = new MemoryStream(arr)) { // doc holds the current xml File doc.Load(ms); var type = _modelTypes.First(t => t.Name == doc.DocumentElement.Name); // Deserialize model var reader = XmlDictionaryReader.CreateTextReader(arr, new XmlDictionaryReaderQuotas()); var dcs = new DataContractSerializer(type); var model = dcs.ReadObject(reader); return((T)model); } } else { var model = ByteHelper.ByteArrayToObject(arr); return((T)model); } }