public byte[] GetPicture(string devicePath, PictureSize pictureSize, Percent jpegCompressionRate)
        {
            var cacheKey = new PicturesCacheKey
            {
                DevicePath  = devicePath,
                PictureSize = pictureSize
            };

            if (!cacheValues.ContainsKey(cacheKey))
            {
                return(new byte[0]);
            }

            Console.WriteLine("GetPicture from cache");

            return(cacheValues[cacheKey].Data);
        }
        public bool HasPicture(string devicePath, PictureSize pictureSize, Percent jpegCompressionRate)
        {
            var cacheKey = new PicturesCacheKey
            {
                DevicePath = devicePath, PictureSize = pictureSize
            };

            if (!cacheValues.ContainsKey(cacheKey))
            {
                Console.WriteLine("ContainsKey {0}", false);
                return(false);
            }

            var value = cacheValues[cacheKey];

            return(!IsExpired(value));
        }
        public void AddPicture(string devicePath, PictureSize pictureSize, Percent jpegCompressionRate, byte[] data)
        {
            var cacheKey = new PicturesCacheKey
            {
                DevicePath  = devicePath,
                PictureSize = pictureSize
            };
            var cacheValue = new PicturesCacheValue
            {
                Time = DateTime.UtcNow,
                Data = data
            };

            if (!cacheValues.ContainsKey(cacheKey))
            {
                cacheValues.Add(cacheKey, cacheValue);
                return;
            }

            cacheValues[cacheKey] = cacheValue;
        }
Exemple #4
0
        public void SavePicture(PictureSize pictureSize, string filename, Percent jpegCompressionRate = default(Percent))
        {
            var data = TakePicture(pictureSize, jpegCompressionRate);

            File.WriteAllBytes(filename, data);
        }
Exemple #5
0
 public bool Equals(PictureSize other)
 {
     return(Width == other.Width && Height == other.Height);
 }