/// <summary> /// Read the package and get its content /// https://github.com/AlenToma/EntityWorker.Core/blob/master/Documentation/Package.md /// </summary> /// <param name="package"></param> /// <returns></returns> public T GetPackage <T>(byte[] package) where T : PackageEntity { try { var uncompressedFile = GzipUtility.Decompress(package); var packageString = System.Text.Encoding.UTF8.GetString(new ByteCipher(GlobalConfiguration.PackageDataEncode_Key, DataCipherKeySize.Key_128).Decrypt(uncompressedFile)); return(packageString.FromJson <T>()); } catch (Exception exception) { throw new EntityException($"Error the package structure is not valid.\n Orginal exception\n{exception.Message}"); } }
/// <summary> /// Read the package and get its content /// https://github.com/AlenToma/EntityWorker.Core/blob/master/Documentation/Package.md /// </summary> /// <param name="package"></param> /// <returns></returns> public T GetPackage <T>(byte[] package) where T : PackageEntity { try { var uncompressedFile = GzipUtility.Decompress(package); using (var msi = new MemoryStream(new ByteCipher(GlobalConfiguration.PackageDataEncode_Key, DataCipherKeySize.Key_128).Decrypt(uncompressedFile))) { // now read the file using (var db = new LiteDB.LiteDatabase(msi)) { var packageCollection = db.GetCollection <T>("Packages"); return(packageCollection.FindOne(x => x.Data != null || x.Files != null)); } } } catch (Exception exception) { throw new EntityException($"Error the package structure is not valid.\n Orginal exception\n{exception.Message}"); } }