Exemplo n.º 1
0
        protected new void UpdateHelper(IKey key, IValue value, bool IsAppend)
        {
            if (!value.GetType().Equals(typeof(ValType)))
            {
                throw new InvalidDataException("Invalid IValue Type");
            }

            long ts;  // timestamp

            // check if the entry is present, so that the old file can be deleted
            IValue valueDataFilePathOld = base.Get(key);

            ts = StreamFactory.HighResTick();
            string   dataFilePath         = targetDir + "/" + Convert.ToString(ts) + ".dat";
            StrValue strDataFilePathValue = new StrValue(dataFilePath);

            base.UpdateHelper(key, strDataFilePathValue, IsAppend);

            FileStream fout = new FileStream(dataFilePath,
                                             FileMode.OpenOrCreate,
                                             FileAccess.Write,
                                             FileShare.ReadWrite);

            // write <val> to file
            MemoryStream memStream = value.SerializeToByteStream();

            fout.Write(memStream.GetBuffer(), 0, (int)memStream.Length);
            fout.Close();

            // remove old entry/file if present and update has been called
            if (valueDataFilePathOld != null && !IsAppend)
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(valueDataFilePathOld.ToString());
                try
                {
                    fi.Delete();
                }
                catch (System.IO.IOException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }