public byte[] Read(OnDiscAdress Adress) { byte[] Readin; lock (DatabaseFile) { // seek to the position DatabaseFile.Seek(Adress.Start, SeekOrigin.Begin); Readin = new byte[Adress.End - Adress.Start]; // read it in DatabaseFile.Read(Readin, 0, Readin.Length); } return Readin; }
public byte[] Read(OnDiscAdress Adress) { byte[] Readin; lock (DatabaseFile) { // seek to the position DatabaseFile.Seek(Adress.Start, SeekOrigin.Begin); Readin = new byte[Adress.End - Adress.Start]; // read it in DatabaseFile.Read(Readin, 0, Readin.Length); } return(Readin); }
public object ReadFromCache(OnDiscAdress adress) { lock (Cache) { if (!Cache.ContainsKey(adress.End)) { // it's not in the cache return(null); } else { return(Cache[adress.End]); } } return(null); }
public object ReadFromCache(OnDiscAdress adress) { lock(Cache) { if (!Cache.ContainsKey(adress.End)) { // it's not in the cache return null; } else { return Cache[adress.End]; } } return null; }
private OnDiscAdress WriteToDatabase(byte[] ToWrite) { OnDiscAdress OutputAdress = new OnDiscAdress(); lock (DatabaseFile) { // seek to the end... DatabaseFile.Seek(DatabaseFile.Length, SeekOrigin.Begin); OutputAdress.Start = DatabaseFile.Position; DatabaseFile.Write(ToWrite, 0, ToWrite.Length); OutputAdress.End = DatabaseFile.Position; DatabaseFile.Flush(); } return(OutputAdress); }
private static XS1_DataObject ReadFromCache(TinyOnDiskStorage sensor_data, OnDiscAdress adress) { XS1_DataObject dataobject = null; object cacheditem = sensor_data.Cache.ReadFromCache(adress); if (cacheditem == null) { // not found in cache, read from disk and add to cache dataobject.Deserialize(sensor_data.Read(adress)); sensor_data.Cache.AddToCache(adress,dataobject); } else { // found in cache, take it... dataobject = (XS1_DataObject)cacheditem; } return dataobject; }
private void WriteToIndex(OnDiscAdress Adresspattern) { lock (DatabaseIndexFile) { // seek to the end... DatabaseIndexFile.Seek(DatabaseIndexFile.Length, SeekOrigin.Begin); byte[] ToWrite = Adresspattern.Serialize(); DatabaseIndexFile.Write(ToWrite, 0, ToWrite.Length); DatabaseIndexFile.Flush(); lock (InMemoryIndex) { // append to the inmemory index InMemoryIndex.Add(Adresspattern); } } }
private XS1_DataObject ReadFromCache(OnDiscAdress adress) { XS1_DataObject dataobject = new XS1_DataObject(); object cacheditem = sensor_data.Cache.ReadFromCache(adress); if (cacheditem == null) { // not found in cache, read from disk and add to cache dataobject.Deserialize(sensor_data.Read(adress)); sensor_data.Cache.AddToCache(adress, dataobject); } else { // found in cache, take it... dataobject = (XS1_DataObject)cacheditem; } return(dataobject); }
public void ReadCompleteIndexFromDiskIntoMemory() { lock (DatabaseIndexFile) { DatabaseIndexFile.Seek(0, SeekOrigin.Begin); long currentPosition = 0; byte[] _SerializedData; OnDiscAdress _deserializedAdress; InMemoryIndex = new List <OnDiscAdress>(); try { while (currentPosition != DatabaseIndexFile.Length) { // read through the index... // one OnDiskAdress is 33 bytes _SerializedData = new byte[33]; DatabaseIndexFile.Read(_SerializedData, 0, 33); _deserializedAdress = new OnDiscAdress(); _deserializedAdress.Deserialize(_SerializedData); InMemoryIndex.Add(_deserializedAdress); currentPosition = currentPosition + 33; /// HACK //if (InMemoryIndex.Count > 50000) // break; } } catch (Exception) { } } }
public void AddToCache(OnDiscAdress adress, object data) { lock (Cache) { if (Cache.ContainsKey(adress.End)) { // update it... Cache.Remove(adress.End); Cache.Add(adress.End, data); } else { // add it Cache.Add(adress.End, data); HouseKeepingList.Add(adress.End); if (HouseKeepingList.Count > MaximumNoOfCacheItems) { Cache.Remove(HouseKeepingList[0]); HouseKeepingList.RemoveAt(0); } } } }
public void AddToCache(OnDiscAdress adress,object data) { lock(Cache) { if (Cache.ContainsKey(adress.End)) { // update it... Cache.Remove(adress.End); Cache.Add(adress.End,data); } else { // add it Cache.Add(adress.End,data); HouseKeepingList.Add(adress.End); if (HouseKeepingList.Count > MaximumNoOfCacheItems) { Cache.Remove(HouseKeepingList[0]); HouseKeepingList.RemoveAt(0); } } } }
private void WriteToIndex(OnDiscAdress Adresspattern) { lock (DatabaseIndexFile) { // seek to the end... DatabaseIndexFile.Seek(DatabaseIndexFile.Length, SeekOrigin.Begin); byte[] ToWrite = Adresspattern.Serialize(); DatabaseIndexFile.Write(ToWrite, 0, ToWrite.Length); DatabaseIndexFile.Flush(); lock(InMemoryIndex) { // append to the inmemory index InMemoryIndex.Add(Adresspattern); } } }
private OnDiscAdress WriteToDatabase(byte[] ToWrite) { OnDiscAdress OutputAdress = new OnDiscAdress(); lock (DatabaseFile) { // seek to the end... DatabaseFile.Seek(DatabaseFile.Length, SeekOrigin.Begin); OutputAdress.Start = DatabaseFile.Position; DatabaseFile.Write(ToWrite, 0, ToWrite.Length); OutputAdress.End = DatabaseFile.Position; DatabaseFile.Flush(); } return OutputAdress; }
public void ReadCompleteIndexFromDiskIntoMemory() { lock (DatabaseIndexFile) { DatabaseIndexFile.Seek(0, SeekOrigin.Begin); long currentPosition = 0; byte[] _SerializedData; OnDiscAdress _deserializedAdress; InMemoryIndex = new List<OnDiscAdress>(); try { while (currentPosition != DatabaseIndexFile.Length) { // read through the index... // one OnDiskAdress is 33 bytes _SerializedData = new byte[33]; DatabaseIndexFile.Read(_SerializedData, 0, 33); _deserializedAdress = new OnDiscAdress(); _deserializedAdress.Deserialize(_SerializedData); InMemoryIndex.Add(_deserializedAdress); currentPosition = currentPosition + 33; /// HACK //if (InMemoryIndex.Count > 50000) // break; } } catch (Exception) { } } }
public void Write(byte[] Data) { OnDiscAdress adress = WriteToDatabase(Data); WriteToIndex(adress); }