Пример #1
0
        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);
        }
Пример #2
0
        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));
        }
Пример #3
0
        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;
        }
Пример #4
0
        public void SavePicture(PictureSize pictureSize, string filename, Percent jpegCompressionRate = default(Percent))
        {
            var data = TakePicture(pictureSize, jpegCompressionRate);

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