public override void SaveData(string dataName, byte[] content)
 {
     lock (_filelock)
     {
         using (System.IO.MemoryStream ms = new System.IO.MemoryStream(content))
         {
             EntryInfo en = filedb.Store(dataName, ms);
             filedb.Flush();
             //then replace
             _allFiles[dataName] = en;
         }
     }
 }
Beispiel #2
0
        static void Test3()
        {
            string dbFileName = @"d:\\WImageTest\\testdb3.dat";

#if DEBUG
            if (File.Exists(dbFileName))
            {
                File.Delete(dbFileName);
            }
#endif

            using (var db = new FileDB(dbFileName, FileAccess.ReadWrite))
            {
                byte[] docStream = TestGenLqDocStream();
                //save
                using (var dataStream = new MemoryStream(docStream))
                {
                    db.Store(dbFileName, dataStream);
                    db.Flush();
                }
            }

            //test read file
            //and generate liquid document
            using (var db = new FileDB(dbFileName, FileAccess.ReadWrite))
            {
                EntryInfo[] prevFiles = db.ListFiles();
                //test read file
                using (MemoryStream ms = new MemoryStream())
                {
                    db.Read(prevFiles[0].ID, ms);
                    ms.Position = 0;

                    //convert data to document
                    var docDeser = new LiquidDocumentDeserializer();
                    var reader   = new BinaryReader(ms);
                    docDeser.SetBinaryReader(reader);
                    docDeser.ReadDocument();
                    LiquidDoc result = docDeser.Result;
                    ms.Close();
                }
            }
        }
Beispiel #3
0
        static void Test2()
        {
            //------------------------------------------------------------------------------
            string dbFileName = @"d:\\WImageTest\\testdb2.dat";

            //EntryInfo[] fileList2 = FileDB.ListFiles(dbFileName);
            //var filename1 = fileList2[0].FileUrl;

            //1. open
            byte[] inputBuffer = GenerateTestDataBuffer("hello!...1");
            List <SampleStoreRequest> storeReqs = new List <SampleStoreRequest>()
            {
                new SampleStoreRequest("a01", GenerateTestDataBuffer("hello_a01")),
                new SampleStoreRequest("a02", GenerateTestDataBuffer("hello_a02")),
                new SampleStoreRequest("a03", GenerateTestDataBuffer("hello_a03")),
                new SampleStoreRequest("a04", GenerateTestDataBuffer("hello_a04")),
                new SampleStoreRequest("a05", GenerateTestDataBuffer("hello_a05"))
            };


            using (var db = new FileDB(dbFileName, FileAccess.ReadWrite))
            {
                EntryInfo[] prevFiles = db.ListFiles();
                int         j         = storeReqs.Count;
                for (int i = 0; i < j; ++i)
                {
                    SampleStoreRequest req = storeReqs[i];
                    using (var dataStream = new MemoryStream(req.buffer))
                    {
                        EntryInfo en = db.Store(req.fileName, dataStream);
                        db.Flush();
                    }
                }
            }

            //------------------------------------------------------------------------------
            //test read back
            EntryInfo[] fileList = FileDB.ListFiles(dbFileName);
        }