コード例 #1
0
ファイル: DataObjectOnDisk.cs プロジェクト: pereritob/hacs
        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
ファイル: ObjectCache.cs プロジェクト: palortoff/hacs
 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
ファイル: ObjectCache.cs プロジェクト: pereritob/hacs
		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
ファイル: GenerateSwimlane.cs プロジェクト: pereritob/hacs
		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
ファイル: ObjectCache.cs プロジェクト: palortoff/hacs
        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
ファイル: ObjectCache.cs プロジェクト: pereritob/hacs
		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
ファイル: DataObjectOnDisk.cs プロジェクト: pereritob/hacs
        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
ファイル: DataObjectOnDisk.cs プロジェクト: pereritob/hacs
        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
ファイル: DataObjectOnDisk.cs プロジェクト: pereritob/hacs
        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);
        }