Esempio n. 1
0
        public async Task <BitmapRepresentation> GetBitmap(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(null);
            }

            var result = _cache.GetOrAdd(url, async s =>
            {
                using (var client = new HttpClient())

                    using (var stream = client.GetStreamAsync(url))
                        using (var bitmap = (Bitmap)Image.FromStream(await stream))

                            return(new BitmapRepresentation(bitmap));
            });

            if (_cache.Count > CacheSize)
            {
                var victim = _cache.Keys.First(v => v != url);
                _cache.TryRemove(victim, out _);
            }

            return((await result).Clone());
        }
Esempio n. 2
0
        private void DeviceOnKeyEvent(object sender, ButtonEventArgs e)
        {
            if (e.IsDown)
            {
                var value = _pressedButtons.AddOrUpdate(e.Location, l =>
                {
                    var result = _globalContext.Services.TimerService.RegisterTimer(_globalContext.Options.LongPressTimeout, () =>
                    {
                        DoButtonPressed(e.Location, ButtonEvent.LongPress);

                        _pressedButtons.TryRemove(l, out _);
                    }, true);

                    result.Start();

                    return(result);
                },
                                                        null);
            }
            else
            {
                if (_pressedButtons.TryRemove(e.Location, out var token))
                {
                    token.Value.Stop();
                }
            }
            DoButtonPressed(e.Location, e.IsDown?ButtonEvent.Down:ButtonEvent.Up);
        }
Esempio n. 3
0
 private void DeleteElement(CompositeLayoutElementInfo elementInfo, bool forever)
 {
     RemoveElement(elementInfo.Location);
     if (forever)
     {
         _initedElements.TryRemove(elementInfo, out _);
     }
 }