示例#1
0
        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;
        }
示例#2
0
        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);
        }
示例#3
0
 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);
 }
示例#4
0
		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;
		}
示例#5
0
        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);
        }
示例#6
0
		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;
		}
示例#7
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);
                }
            }
        }
示例#8
0
文件: JSONData.cs 项目: devrez/hacs
        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);
        }
示例#9
0
        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)
                {
                }
            }
        }
示例#10
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);
                    }
                }
            }
        }
示例#11
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);
					}
				}
			}
		}
示例#12
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);
				}
            }
        }
示例#13
0
        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;
        }
示例#14
0
        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)
                {
                }
            }
        }
示例#15
0
        public void Write(byte[] Data)
        {
            OnDiscAdress adress = WriteToDatabase(Data);

            WriteToIndex(adress);
        }