Пример #1
0
        private bool ForceStoreToDisk(T e)
        {
            if (e.id == DatabaseElement.ID_INVALID)
            {
                throw new Exception("unable to store element with an invalid identifier");
            }

            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryWriter writer = new BinaryWriter(ms);
                    e.Write(writer);
                    File.WriteAllBytes(MakeFullPath(e.id), DatabaseCryptoService.Encrypt(ms.ToArray(), encryptionKey));
                }
            }
            catch (Exception exc)
            {
                Console.Out.WriteLine(exc.Message);

                return(false);
            }

            return(true);
        }
Пример #2
0
        private T TryGetElementFromDiskByPath(string path)
        {
            try
            {
                T e = new T();

                e.Read(new BinaryReader(new MemoryStream(DatabaseCryptoService.Decrypt(File.ReadAllBytes(path), encryptionKey))));

                return(e);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
            }

            return(null);
        }