Beispiel #1
0
        public void KeyExtensions_GivenNextInt_ThenValueIsIncrementedByOne()
        {
            int first  = new Random().Next();
            int second = KeyExtensions.NextInt(first);

            second.Should().Be(first + 1);
        }
Beispiel #2
0
        public void KeyExtensions_GivenPreviousGuid_ThenValueIsDifferent()
        {
            Guid first  = Guid.NewGuid();
            Guid second = KeyExtensions.PreviousGuid();

            second.Should().NotBe(first);
        }
Beispiel #3
0
        private static void SetupShortcut(IKeyboardHook hook, string shortcutId, string shortcutKeys, ShortcutPressed action)
        {
            if (string.IsNullOrEmpty(shortcutKeys))
            {
                hook.UnregisterGlobalShortcut(shortcutId);
                return;
            }

            var keyPress = KeyExtensions.ToKeyPress(shortcutKeys);

            try
            {
                hook.RegisterGlobalShortcut(shortcutId, keyPress.Modifier, keyPress.Key);
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    Application.Current.MainWindow,
                    string.Format("Could not register global shortcut: {0}", e.Message),
                    "WARNING");
                return;
            }
            if (hook[shortcutId] == null)
            {
                hook[shortcutId] += action;
            }
        }
        public ValueExpression GetNormalizedReferenceValue(ValueExpression originalValue, string resourceType)
        {
            if (originalValue == null)
            {
                return(null);
            }
            var value = originalValue.ToString();

            if (string.IsNullOrWhiteSpace(value))
            {
                return(originalValue);
            }
            if (!value.Contains("/") && !string.IsNullOrWhiteSpace(resourceType))
            {
                return(new StringValue($"{resourceType}/{value}"));
            }
            if (Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out var uri))
            {
                var key = KeyExtensions.ExtractKey(uri);
                if (_localhost.GetKeyKind(key) != KeyKind.Foreign) // Don't normalize external references (https://github.com/FirelyTeam/spark/issues/244).
                {
                    var refUri = _localhost.RemoveBase(uri);
                    return(new StringValue(refUri.ToString().TrimStart('/')));
                }
            }
            return(originalValue);
        }
Beispiel #5
0
 private static Func <IFileContextTable> CreateFactory <TKey>(IKey key, IEntityType entityType, bool sensitiveLoggingEnabled, IFileContextScopedOptions options, IServiceProvider serviceProvider)
 => () => new FileContextTable <TKey>(
     // WARNING: The in-memory provider is using EF internal code here. This should not be copied by other providers. See #15096
     KeyExtensions.GetPrincipalKeyValueFactory <TKey>(key),
     sensitiveLoggingEnabled,
     entityType,
     options,
     serviceProvider);
 public Key GetKey(int keyId)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var keyDto = _context.Keys.FirstOrDefault(k => k.Value == keyId);
         Ensure.Any.IsNotNull(keyDto, nameof(keyDto),
                              opt => opt.WithException(new KeyNotFoundException(keyId)));
         var key = KeyExtensions.ParseFromKeyDto(keyDto);
         return(key);
     }
 }
 private void InitializeConfigurableSpecialSingleKeys()
 {
     if (Settings.Default.ShowTabs)
     {
         Keys.Tab.AddToSpecialSingleKeys();
     }
     if (Settings.Default.ShowEnter)
     {
         Keys.Return.AddToSpecialSingleKeys();
         Keys.Enter.AddToSpecialSingleKeys();
     }
     if (Settings.Default.ShowPageUpDown)
     {
         Keys.Next.AddToSpecialSingleKeys();
         Keys.Prior.AddToSpecialSingleKeys();
     }
     if (Settings.Default.ShowOrdinaryKeys)
     {
         KeyExtensions.BuildRemainingKeys();
     }
 }
Beispiel #8
0
        private void HandleKeyUp(RawKeyEventArgs args)
        {
            if (KeyExtensions.IsModifierKeys(args.Key))
            {
                lock (this.locker)
                {
                    if (!this.inChordSequence)
                    {
                        if (this.modifiersCombination != ModifierKeys.None)
                        {
                            this.modifiersCombination -= KeyExtensions.ToModifierKeys(args.Key);
                        }

                        if (this.modifiersCombination == ModifierKeys.None)
                        {
                            this.combinationStart = null;
                        }

                        this.window.SetCombinations(this.GetCombinations(this.modifiersCombination));
                    }
                }
            }
        }
 public async Task SetSingleAsync <T>(Guid id, T obj, TimeSpan?expiry = null)
 {
     await SetAsync(KeyExtensions.GetKey <T>(id), obj, expiry);
 }
 public async Task <HashSet <T> > GetHashSetAsync <T>()
 {
     return(await GetAsync <HashSet <T> >(KeyExtensions.GetEnumerableKey <T>()));
 }
 public async Task <IEnumerable <T> > GetCollectionAsync <T>()
 {
     return(await GetAsync <IEnumerable <T> >(KeyExtensions.GetEnumerableKey <T>()));
 }
 public async Task <T> GetSingleOrDefaultAsync <T>(Guid id)
 {
     return(await GetAsync <T>(KeyExtensions.GetKey <T>(id)));
 }
 public async Task DeleteCollectionAsync <T>()
 {
     await DeleteAsync(KeyExtensions.GetEnumerableKey <T>());
 }
 public async Task DeleteSingleAsync <T>(Guid id)
 {
     await DeleteAsync(KeyExtensions.GetKey <T>(id));
 }
 public async Task SetHashSetAsync <T>(HashSet <T> obj, TimeSpan?expiry = null)
 {
     await SetAsync(KeyExtensions.GetEnumerableKey <T>(), obj, expiry);
 }
 public async Task SetCollectionAsync <T>(IEnumerable <T> obj, TimeSpan?expiry = null)
 {
     await SetAsync(KeyExtensions.GetEnumerableKey <T>(), obj, expiry);
 }
Beispiel #17
0
        private void HandleKeyDown(RawKeyEventArgs args)
        {
            lock (this.locker)
            {
                var isModifierKeys = KeyExtensions.IsModifierKeys(args.Key);
                var modifierKeys   = Keyboard.Modifiers;

                // If current key down is modifier key and if we are not in chord sequence
                // we need to find all chord combinations and possible commands for current modifer keys
                if (isModifierKeys && !this.inChordSequence)
                {
                    var fNewModifiersCombination = this.modifiersCombination != modifierKeys;

                    if (fNewModifiersCombination)
                    {
                        this.combinationStart     = DateTime.Now;
                        this.modifiersCombination = modifierKeys;
                    }

                    if ((this.window.IsOpen && fNewModifiersCombination) ||
                        (this.combinationStart.HasValue && (DateTime.Now - this.combinationStart.Value).TotalMilliseconds >= this.keyModifiersCombinationDelay))
                    {
                        this.combinationStart = null;
                        this.window.SetCombinations(this.GetCombinations(modifierKeys));
                    }
                }
                else if (!isModifierKeys && modifierKeys != ModifierKeys.None && !this.inChordSequence)
                {
                    this.DisposeTimer();

                    CurrentCommandsContainer chordCommands = this.GetChordCombinations(modifierKeys, args.Key);

                    this.inChordSequence = chordCommands != null && chordCommands.HasCommands();

                    if (this.inChordSequence && !this.window.IsOpen && this.chordCombinationDelay > 0)
                    {
                        this.showChordKeyTimer = new Timer(
                            (state) =>
                        {
                            lock (this.locker)
                            {
                                if (this.showChordKeyTimer != null)
                                {
                                    this.DisposeTimer();
                                    this.window.SetCombinations(chordCommands);
                                }
                            }
                        },
                            null,
                            this.chordCombinationDelay,
                            Timeout.Infinite);
                    }
                    else
                    {
                        this.window.SetCombinations(chordCommands);
                    }
                }
                else if (!isModifierKeys && (modifierKeys == ModifierKeys.None || this.inChordSequence))
                {
                    this.inChordSequence = false;
                    this.DisposeTimer();

                    // If this is not a modifier keys and user doesn't press any of modifier keys now
                    // or if this is second combination of chord key we need to hide window if it is open.
                    if (this.window.IsOpen)
                    {
                        this.window.SetCombinations(null);
                    }
                }
            }
        }