Example #1
0
        protected internal override void Send(string Sequence)
        {
            foreach (var C in Sequence)
            {
                CachedKey Key = LookupKeycode(C);

                // If it is an upper case character, hold the shift key...
                if (char.IsUpper(C) || Key.Shift)
                {
                    Xlib.XTestFakeKeyEvent(XConn.Handle, (uint)XKeys.LeftShift, true, 0);
                }

                // Make sure the key is up before we press it again.
                // If X thinks this key is still down, nothing will happen if we press it.
                // Likewise, if X thinks that the key is up, this will do no harm.
                Xlib.XTestFakeKeyEvent(XConn.Handle, Key.Sym, false, 0);

                // Fake a key event. Note that some programs filter this kind of event.
                Xlib.XTestFakeKeyEvent(XConn.Handle, Key.Sym, true, 0);
                Xlib.XTestFakeKeyEvent(XConn.Handle, Key.Sym, false, 0);

                // ...and release it later on
                if (char.IsUpper(C) || Key.Shift)
                {
                    Xlib.XTestFakeKeyEvent(XConn.Handle, (uint)XKeys.LeftShift, false, 0);
                }
            }
        }
Example #2
0
        public void TestMutability()
        {
            var rsa = new RSACryptoServiceProvider();
            var key = new CachedKey("test", rsa);

            Assert.AreEqual(key.Thumbprint, "test");
            Assert.AreEqual(key.KeyData, rsa);
        }
Example #3
0
 /// <summary>
 /// 添加缓存(键不存在则添加,存在则替换)
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="minutes">缓存时间(分钟)</param>
 /// <returns></returns>
 public static bool AddCache(CachedKey key, object value, int minutes = 10)
 {
     if (!IsUsedCache)
         return false;
     if (minutes <= 0)
         return Mc.Store(StoreMode.Set, key.ToString(), value);
     return Mc.Store(StoreMode.Set, key.ToString(), value, DateTime.Now.AddMinutes(minutes));
 }
Example #4
0
        protected override bool CanVisitAttributeCore(ISymbol symbol, bool wantProtectedMember, IFilterVisitor outer)
        {
            var key = new CachedKey(symbol, wantProtectedMember);

            if (_attributeCache.TryGetValue(key, out bool result))
            {
                return(result);
            }
            result = _attributeCache[key] = Inner.CanVisitAttribute(symbol, wantProtectedMember, outer);
            return(result);
        }
Example #5
0
        public override bool CanVisitAttribute(ISymbol symbol, bool wantProtectedMember = true)
        {
            bool result;
            var  key = new CachedKey(symbol, wantProtectedMember);

            if (_attributeCache.TryGetValue(key, out result))
            {
                return(result);
            }
            result = _attributeCache[key] = Inner.CanVisitAttribute(symbol, wantProtectedMember);
            return(result);
        }
Example #6
0
        CachedKey LookupKeycode(char Code)
        {
            // If we have a cache value, return that
            if (Cache.ContainsKey(Code))
            {
                return(Cache[Code]);
            }

            // First look up the KeySym (XK_* in X11/keysymdef.h)
            uint KeySym = Xlib.XStringToKeysym(Code.ToString());
            // Then look up the appropriate KeyCode
            uint KeyCode = Xlib.XKeysymToKeycode(XConn.Handle, KeySym);

            // Cache for later use
            var Ret = new CachedKey(KeyCode, false);

            Cache.Add(Code, Ret);

            return(Ret);
        }
Example #7
0
        /// <summary>
        /// 是否存在该缓存
        /// </summary>
        /// <param name="key">键</param>
        /// <returns></returns>
        public static bool IsExists(CachedKey key)
        {
            if (!IsUsedCache)
                return false;

            return Mc.Get(key.ToString()) != null;
        }
Example #8
0
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>返回缓存,没有找到则返回null</returns>
        public static object GetCache(CachedKey key)
        {
            if (!IsUsedCache)
                return null;

            try
            {
                return Mc.Get(key.ToString());
            }
            catch (Exception)
            {
                return null;
            }
        }
Example #9
0
        /// <summary>
        /// 删除缓存(如果键不存在,则返回false)
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>成功:true失败:false</returns>
        public static bool DelCache(CachedKey key)
        {
            if (!IsUsedCache)
                return false;

            return Mc.Remove(key.ToString());
        }
Example #10
0
 CachedKey LookupKeycode(char Code)
 {
     // If we have a cache value, return that
     if(Cache.ContainsKey(Code))
         return Cache[Code];
     
     // First look up the KeySym (XK_* in X11/keysymdef.h)
     uint KeySym = Xlib.XStringToKeysym(Code.ToString());
     // Then look up the appropriate KeyCode
     uint KeyCode = Xlib.XKeysymToKeycode(XConn.Handle, KeySym);
     
     // Cache for later use
     var Ret = new CachedKey(KeyCode, false);
     Cache.Add(Code, Ret);
               
     return Ret;
 }            
        public async Task <string> GetCachedImageAsync(Uri url, uint size)
        {
            await this.InitializeCacheFolderAsync();

            CachedAlbumArt cache = await this.cachedAlbumArtsRepository.FindAsync(url, size);

            if (cache == null && this.stateService.IsOffline())
            {
                return(null);
            }

            if (cache == null)
            {
                await this.semaphoreSlim.WaitAsync().ConfigureAwait(continueOnCapturedContext: false);

                try
                {
                    var cachedKey = new CachedKey(url, size);
                    cache = await this.downloadTasks.GetOrAdd(
                        cachedKey,
                        uri => Task.Run(
                            async() =>
                    {
                        CachedAlbumArt downloadedCache = await this.cachedAlbumArtsRepository.FindAsync(url, size);
                        if (downloadedCache == null)
                        {
                            string fileName      = Guid.NewGuid().ToString();
                            string subFolderName = fileName.Substring(0, 1);

                            var folder = await this.cacheFolder.CreateFolderAsync(subFolderName, CreationCollisionOption.OpenIfExists);
                            var file   = await folder.CreateFileAsync(fileName);

                            using (var imageStream = await this.httpClient.GetStreamAsync(url.ChangeSize(size)))
                            {
                                using (var targetStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                                {
                                    using (Stream fileStream = targetStream.AsStreamForWrite())
                                    {
                                        await imageStream.CopyToAsync(fileStream);
                                        await fileStream.FlushAsync();
                                    }
                                }
                            }

                            downloadedCache = new CachedAlbumArt()
                            {
                                AlbumArtUrl = url, Size = size, FileName = fileName
                            };

                            await this.cachedAlbumArtsRepository.AddAsync(downloadedCache);
                        }

                        return(downloadedCache);
                    }));

                    Task <CachedAlbumArt> task;
                    this.downloadTasks.TryRemove(cachedKey, out task);
                }
                finally
                {
                    this.semaphoreSlim.Release(1);
                }
            }

            return(Path.Combine(AlbumArtCacheFolder, cache.FileName.Substring(0, 1), cache.FileName));
        }