Exemple #1
0
 public void Close()
 {
     CancelPreview();
     if (reader != null)
     {
         Reader.Close();
     }
     reader = null;
     bitmapDirty = true;
 }
Exemple #2
0
        public DataBlock FetchDataBlock(OmReader reader, int blockNumber)
        {
            lock (this)
            {
                if (cache.ContainsKey(blockNumber))
                {
                    // Find block in cache
                    LinkedListNode<int> node = lruNodes[blockNumber];

                    // Move to end of LRU
                    lru.Remove(node);
                    lru.AddLast(node);

                    // Return block
                    return cache[blockNumber];
                }
            }

            if (reader == null)
            {
                return null;
            }

            // Read block
            DataBlock dataBlock = DataBlock.FromReader(reader, blockNumber);

            lock (this)
            {
                // Add to cache
                cache[blockNumber] = dataBlock;
                LinkedListNode<int> node = new LinkedListNode<int>(blockNumber);
                lruNodes[blockNumber] = node;
                lru.AddLast(node);

                // Trim cache to maximum size
                while (lru.Count > cacheSize)
                {
                    int evict = lru.First.Value;
                    lru.RemoveFirst();
                    lruNodes.Remove(evict);
                    cache.Remove(evict);
                }

                //// Push in to aggregates
                //int i = ((1 << (levels - 1)) - 1) + blockNumber;
                //for (; ; )
                //{
                //    aggregates[i].Add(dataBlock.Aggregate);
                //    if (i == 0) { break; }
                //    i = ((i - 1) / 2);
                //}

                // Return block
                return dataBlock;
            }
        }
 //TS - TODO - Doesn't check if it is already open or not.
 public static void Close(OmReader reader)
 {
     OmApi.OmReaderClose(reader.Handle);
 }
Exemple #4
0
 public static DataBlock FromReader(OmReader reader, int blockNumber)
 {
     try
     {
         reader.Seek(blockNumber);
         short[] values = reader.ReadBlock();
         if (values == null)
         {
             return null;
         }
         DateTime firstTime = reader.TimeForSample(0);
         DateTime lastTime;
         float light = reader.Light;
         float temp = reader.Temp;
         float battpercent = reader.Batt;
         float battraw = reader.BattRaw;
         if (values.Length == 0) { lastTime = firstTime; }
         else { lastTime = reader.TimeForSample(values.Length - 1); }
         return new DataBlock(firstTime, lastTime, light, temp, battpercent, battraw, values);
     }
     catch (Exception)
     {
         return null;
     }
 }
 //TS - TODO - Doesn't check if it is already open or not.
 public static void Close(OmReader reader)
 {
     OmApi.OmReaderClose(reader.Handle);
 }