Beispiel #1
0
        private void _thumbnailProducer_ThumbnailEvent(ulong videoId, Image thumbnail)
        {
            ThumbnailInfo ti = new ThumbnailInfo()
            {
                VideoId    = getNodeId(videoId),
                Time       = DateTime.Now,
                ImageBytes = getImageBytes(thumbnail)
            };

            InfoItem item = new InfoItem()
            {
                Key       = ti.VideoId,
                IsDeleted = false,
                Info      = StaticInfoSynchronizer <ThumbnailInfo> .SerializeItem(ti)
            };

            string section = $"Thumbnail/{getSection(ti.VideoId)}";

            using (var client = new StaticInfoClient.StaticInfoClient(_baseUri, section))
                client.PutUpdate(new InfoItem[] { item });
        }
        public StaticInfoSynchronizer(string baseAddress, string section, TimeSpan updateInterval, string savePath = null, OnUpdate updateHandler = null)
        {
            if (updateHandler != null)
            {
                UpdateEvent += updateHandler;
            }
            _updateInterval = updateInterval;
            _section        = section;
            _client         = new StaticInfoClient(baseAddress, section);
            if (!string.IsNullOrWhiteSpace(savePath))
            {
                _persistent = new FilePersistent(savePath, section);
                IEnumerable <string> updatedKeys = load();
                if (updatedKeys != null && updatedKeys.Count() > 0)
                {
                    fireUpdateEvent(updatedKeys);
                }
            }

            if (_updateInterval != InfiniteSpan && _updateInterval != TimeSpan.Zero)
            {
                _updateTimer = new Timer(onUpdateTimerTick, null, 10, Timeout.Infinite);
            }
        }