/// <summary>
        /// 是否存在key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool Exists(string key)
        {
            try
            {
                if (AllKeys.Contains(key))
                {
                    return(true);
                }
                if (pool != null)
                {
                    using var r = pool.GetClient();
                    if (r != null)
                    {
                        r.SendTimeout = 1000;
                        return(r.ContainsKey(key));
                    }
                }
            }
            catch
            {
                throw new Exception(string.Format("{0}:{1}发生异常!{2}", "cache", "是否存在", key));
            }

            return(false);
        }
Exemplo n.º 2
0
 static string[] GetAllowedNumbers()
 {
     return(AllKeys
            .Where(key => key.StartsWith("Number:"))
            .Select(key => key.Substring("Number:".Length))
            .ToArray());
 }
Exemplo n.º 3
0
        public EncryptionKey CurrentKey => _currentKey ??= AllKeys.First(x => x.IsCurrent); // There must always be 1, so let this throw

        public FoundEncryptionKey GetKeyFromString(string encrypted)
        {
            var key = AllKeys.FirstOrDefault(x => !string.IsNullOrEmpty(x.Id) && encrypted.StartsWith(x.Id, StringComparison.CurrentCulture))
                      ?? VoidKey
                      ?? throw new Exception("Unable to locate matching encryption key");

            return(new FoundEncryptionKey(key, encrypted));
        }
Exemplo n.º 4
0
 public void AddMissing(string key, string value)
 {
     if (AllKeys.Contains(key))
     {
         return;
     }
     Add(key, value);
 }
Exemplo n.º 5
0
        public new void Remove(string key)
        {
            var keys = AllKeys.Where(x => KeyMatches(x, key));

            foreach (var keyName in keys)
            {
                base.Remove(keyName);
            }
        }
Exemplo n.º 6
0
    /*
     *
     * Code below changes the keyboard and input
     *
     */

    private void setKey()
    {
        //Checks the above method for special cases
        if (!SpecialInputCheck.checkSpecialInput(buttonInput, changeText, hoverKeyboard))
        {
            //sets the string to what's pressed on the keyboard
            string setInput  = Input.inputString;
            bool   contained = false;
            foreach (KeyValuePair <string, Inputs> anInput in Inputs.inputDict)
            {
                if (anInput.Value.getInputButton().GetComponentInChildren <Text>().text.ToLower().Equals(setInput.ToLower()))
                {
                    changeText.changedText("This key has already been binded, please choose another one");
                    contained = true;
                    isOn      = false;
                    Debug.Log("This key has already been binded, choose another one.");
                    break;
                }
            }

            if (!setInput.Equals("") && setInput.Length == 1 && !contained)
            {
                foreach (Button aButton in AllKeys.getButtons())
                {
                    //If any button equals the key pressed by user..
                    if (aButton.name.ToLower().Equals(setInput))
                    {
                        changeText.changedText(aButton.name);
                        //TODO RENAME THESE VARS
                        for (int i = 0; i < inputManagerList.Count; i++)
                        {
                            if (inputManagerList[i].Tag.Equals(buttonInput.tag))
                            {
                                Keyboard.setKeyboardBasedOnTags(aButton,
                                                                buttonInput,
                                                                aButton.name,
                                                                inputManagerList[i].Type,
                                                                aButton.name);
                                break;
                            }
                        }
                        AllKeys.setLegendKey(aButton.tag, aButton.name);
                        SaveLoadKeyboard.hasSaved = false;
                        break;
                    }
                }
                buttonInput.tag = "Untagged";
                hoverKeyboard.keyboardKeyboardExit();
                setInput = "";
                isOn     = false;
            }
            else if (setInput.Length > 1)
            {
                Debug.Log("You pressed two keys..");
            }
        }
    }
Exemplo n.º 7
0
        public string Stringify(string resource)
        {
            var pathinfo = AllKeys.Aggregate(resource, (current, key) => Regex.Replace(current, $@"\[{key}\]", Get(key)));

            if (pathinfo.Contains("[") || pathinfo.Contains("]"))
            {
                throw new ClientStateException($"Not all parameters were replaced in request resource: {pathinfo}");
            }
            return(pathinfo);
        }
Exemplo n.º 8
0
    // modify this method as shown
    public MyImmutable Apply(Func <decimal, decimal, decimal> aggFunc, MyImmutable y)
    {
        var aggregated = new Dictionary <ImmutableKey, decimal>(AllKeys.Count());

        foreach (ImmutableKey bt in AllKeys)
        {
            aggregated[bt] = aggFunc(this[bt], y[bt]);
        }
        return(GetNew(aggregated));
    }
Exemplo n.º 9
0
        static MouseSelectionAddKey()
        {
            AllKeys = typeof(MouseSelectionAddKey)
                      .GetProperties(BindingFlags.Static | BindingFlags.Public)
                      .Where(o => o.PropertyType == typeof(MouseSelectionAddKey))
                      .Select(o => (MouseSelectionAddKey)o.GetValue(null))
                      .Distinct()
                      .ToList();

            KeysById = AllKeys.ToDictionary(o => o.ID);
        }
Exemplo n.º 10
0
 public void SetAt(Point p, char c)
 {
     Entries[p] = c;
     if (char.IsLower(c) && char.IsLetter(c))
     {
         AllKeys.Add(c);
     }
     if (c == Start)
     {
         StartingPosition = p;
     }
 }
Exemplo n.º 11
0
        public async Task SaveAllAsync()
        {
            var db     = _services.CreateScope().ServiceProvider.GetRequiredService <IKeyValueDbContext>();
            var fromDb = db.KeyValues.ToList();
            var adding = Items.Where(x => !fromDb.Any(d => x.Key == d.Key)).ToList();

            fromDb.RemoveAll(x => !AllKeys.Contains(x.Key));
            fromDb.ForEach(x => x.Value = Get(x.Key));
            db.KeyValues.AddRange(adding);

            await db.Normalize().SaveChangesAsync();
        }
Exemplo n.º 12
0
 public string this[string name]
 {
     get
     {
         if (AllKeys.Contains(name))
         {
             var str = config.GetSection(sectionName)[name];//第一种方法
             return(str);
         }
         return("");
     }
 }
Exemplo n.º 13
0
        void LoadUserSetting(UserSetting userSetting)
        {
            _UserSetting = userSetting;
            if (_UserSetting == null)
            {
                Data = null;
                return;
            }
            MapTypeComboBox.ItemsSource = new List <MapType>()
            {
                MapType.Button, MapType.Axis, MapType.Slider, MapType.POV
            }
            .Select(x => x.ToString()).ToList();
            MapTypeComboBox.SelectedItem     = MapType.Button.ToString();
            MapEventTypeComboBox.ItemsSource = Enum.GetValues(typeof(MapEventType)).Cast <MapEventType>()
                                               .Select(x => x.ToString()).ToList();
            MapEventTypeComboBox.SelectedItem = MapEventType.EnterUpLeaveDown.ToString();
            MapRpmTypeComboBox.ItemsSource    = Enum.GetValues(typeof(MapRpmType)).Cast <MapRpmType>()
                                                .Select(x => x.ToString()).ToList();
            MapRpmTypeComboBox.SelectedItem = MapRpmType.DownIncrease.ToString();
            UserMacrosTabPage.Header        = string.Format("User Macros for {0}", userSetting.InstanceName);

            RefreshList();

            // https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.keys?view=netcore-3.1
            AllKeys = ((Key[])Enum.GetValues(typeof(Key))).ToList();
            AddKeys(Control1KeysComboBox, "Mod", new Key[] {
                Key.Shift, Key.ShiftKey, Key.LShiftKey, Key.RShiftKey,
                Key.Control, Key.ControlKey, Key.LControlKey, Key.RControlKey,
                Key.Alt, Key.Menu, Key.RMenu, Key.LMenu,
                Key.LWin, Key.RWin,
            });
            AddKeys(CharKeysComboBox, "Key", AllKeys.Where(x => x >= Key.A && x <= Key.Z || x == Key.Space));
            AddKeys(NumPadKeysComboBox, "NumPad", AllKeys.Where(x => x >= Key.NumPad0 && x <= Key.NumPad9));
            AddKeys(FKeysComboBox, "F-Key", AllKeys.Where(x => x >= Key.F1 && x <= Key.F24));
            AddKeys(Control2KeysComboBox, "Control", new Key[] {
                Key.Escape, Key.Tab, Key.CapsLock, Key.Back, Key.Enter,
                Key.Insert, Key.Delete, Key.Home, Key.End, Key.PageUp, Key.PageDown, Key.NumLock
            });
            // Add remaining keys
            AddKeys(OtherKeysComboBox, "Other", AllKeys);
            AddKeys(MouseKeysComboBox, "Mouse", new Key[] { Key.LButton, Key.MButton, Key.RButton, Key.XButton1, Key.XButton2 });
            // Add X360CE buttons.
            var xKeys = Enum.GetValues(typeof(MapCode)).Cast <MapCode>()
                        .Where(x => SettingsConverter.IsButtonOrDirection(x));
            var sKeys = xKeys.Select(x => x.ToString()).Distinct().ToList();

            sKeys.Insert(0, "XInput");
            XButtonsComboBox.ItemsSource       = sKeys;
            XButtonsComboBox.SelectedIndex     = alwaysSelectedIndex;
            XButtonsComboBox.SelectionChanged += KeysComboBox_SelectionChanged;
        }
Exemplo n.º 14
0
        /// <summary>
        /// When a checkbox state changed, we update the controls list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clbColumns_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            bool isChecked = e.NewValue == CheckState.Checked;

            // Gets the key of the modified column
            string header = (string)clbColumns.Items[e.Index];
            int    key    = AllKeys.First(x => GetHeader(x) == header);

            // Gets the column for this key
            IColumnSettings column = m_columns.First(x => x.Key == key);

            column.Visible = isChecked;
        }
Exemplo n.º 15
0
        private void Mutation(string key)
        {
            Random rand = new Random(i++);
            int    a    = rand.Next(32);
            int    b    = rand.Next(33);

            StringBuilder newKeyBuilder = new StringBuilder(key);
            char          temp          = newKeyBuilder[a];

            newKeyBuilder[a] = newKeyBuilder[b];
            newKeyBuilder[b] = temp;
            string newKey = newKeyBuilder.ToString();

            if (!AllKeys.ContainsKey(newKey))
            {
                AllKeys.Add(newKey, 0.0);
            }
        }
Exemplo n.º 16
0
 public static void AddToList(KeySetting set)
 {
     if (AllKeys == null)
     {
         if (onAwake == null)
         {
             onAwake = () => { };
         }
         onAwake += () =>
         {
             AllKeys.Add(set);
             OnAdd(); //Was basically Instance.OnAdd();
         };
         return;
     }
     AllKeys.Add(set);
     OnAdd();
 }
    public void LoadKeyboard(string aUserName)
    {
        userName = aUserName;
        Keyboard.resetKeyboard();
        AllKeys.removeLegend();
        Debug.Log("Loading Keyboard for " + aUserName);
        if (File.Exists(Application.persistentDataPath + "/" + aUserName + "KeyboardInfo.dat"))
        {
            BinaryFormatter bf      = new BinaryFormatter();
            FileStream      file    = File.Open(Application.persistentDataPath + "/" + aUserName + "KeyboardInfo.dat", FileMode.Open);
            KeyboardDataSer keyData = (KeyboardDataSer)bf.Deserialize(file);
            file.Close();

            InputManager.inputManagerList = new List <InputManager.INPUT_CLASS>();
            Inputs.inputDict   = new Dictionary <string, Inputs>();
            AllKeys.legendList = new List <Button>();

            foreach (InputManager.INPUT_CLASS_FOR_DATA_STORAGE inputClass in keyData.inputManagerList)
            {
                InputManager.INPUT_CLASS tempInputClass = new InputManager.INPUT_CLASS(
                    inputClass.Input, buttonSer.getButtonSer(inputClass.Key.buttonName,
                                                             inputClass.Key.buttonTag), inputClass.Type, inputClass.Tag, inputClass.Name);

                InputManager.inputManagerList.Add(tempInputClass);
            }
            for (int i = 0; i < keyData.inputManagerList.Count; i++)
            {
                inputManager.setKey(InputManager.inputManagerList[i]);
                AllKeys.INITIAL_LIST_LEGEND(keyData.inputManagerList[i].Name, keyData.inputManagerList[i].Tag);
            }

            Keyboard.KeyboardTags.keyboardTagsAndTypes();
            Debug.Log("Keyboard data found for: " + aUserName);
        }
        else
        {
            InputManager.inputManagerList = inputManager.inputManagerList_FROM_INSPECTOR;
            Debug.Log("No Keyboard data found - Using Inspector setup");
            inputManager.CONFIGURE_LAYOUT();
            SaveKeyboard();
        }
    }
Exemplo n.º 18
0
        private void Selection()
        {
            BestKeys.Clear();

            foreach (var key in AllKeys.Keys.ToArray())
            {
                Stat.TextAnalysis(Text, key);
                AllKeys[key] = Stat.MeaningfullnessMetric();
            }

            var sortedKeys = (from key in AllKeys
                              orderby key.Value
                              select key).ToList();

            for (int i = 0; i < BestKeysAmount; i++)
            {
                BestKeys.Add(sortedKeys[i].Key, sortedKeys[i].Value);
            }

            AllKeys.Clear();
        }
Exemplo n.º 19
0
    //Called by Default Button
    public void CONFIGURE_LAYOUT()
    {
        Keyboard.resetKeyboard();
        AllKeys.removeLegend();
        Inputs.inputDict   = new Dictionary <string, Inputs>();
        AllKeys.legendList = new List <Button>();

        if (inputManagerList.Count > 0)
        {
            for (int i = 0; i < inputManagerList.Count; i++)
            {
                Keyboard.KeyboardTags.keyboardTagsAndTypes();
                Keyboard.KeyBindings.DISTRIBUTE_KEYS(inputManagerList[i]);
                AllKeys.INITIAL_LIST_LEGEND(inputManagerList[i].Name, inputManagerList[i].Tag);
            }
        }
        else
        {
            Debug.Log("No user input located");
        }
    }
Exemplo n.º 20
0
        public static KeySignature GetKey(string name)
        {
            name = name.ToUpperInvariant().Replace("-", "").Replace("MAJOR", "")
                   .Replace("MINOR", "m").Replace("FLAT", "♭").Replace("#", "♯")
                   .Replace("SHARP", "♯");

            if (name.StartsWith("BB"))
            {
                name = name.Replace("BB", "B♭");
            }
            else if (name.Substring(1).Contains('B'))
            {
                name = name.Replace('B', '♭');
            }

            if (name.Last() == 'm')
            {
                name = name.Trim('m');
                return(AllKeys.First(k => k.MinorName.ToUpperInvariant().Equals(name.ToUpperInvariant())));
            }

            return(AllKeys.First(k => k.MajorName.ToUpperInvariant().Equals(name.ToUpperInvariant())));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Get all of the data in the requested column of the table.
        /// if an invalid header is given, throws an ArgumentOutOfRangeException.
        /// </summary>
        /// <param name="header">Column Header from this table.</param>
        /// <returns></returns>
        public List <String> GetColumn(String header)
        {
            if (!AllKeys.Contains(header))
            {
                throw new ArgumentOutOfRangeException("Invalid Header Name");
            }

            List <String> column = new List <string>();

            foreach (Dictionary <String, String> row in Data)
            {
                if (!row.ContainsKey(header))
                {
                    column.Add("");
                }
                else
                {
                    column.Add(row[header]);
                }
            }

            return(column);
        }
Exemplo n.º 22
0
 public ConnectionStringSettings this[string name]
 {
     get
     {
         if (AllKeys.Contains(name))
         {
             ConnectionStringSettings rev = new ConnectionStringSettings();
             var item = config.GetSection(sectionName).GetSection(name);//第一种方法
             foreach (var kv in item.AsEnumerable())
             {
                 if (kv.Key == $"ConnectionStrings:{name}:ConnectionString")
                 {
                     rev.ConnectionString = kv.Value;
                 }
                 if (kv.Key == $"ConnectionStrings:{name}:ProviderName")
                 {
                     rev.ProviderName = kv.Value;
                 }
             }
             return(rev);
         }
         return(null);
     }
 }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Delete(string key)
 {
     try
     {
         if (AllKeys.Contains(key))
         {
             Remove(key);
         }
         if (pool != null)
         {
             using var r = pool.GetClient();
             if (r != null)
             {
                 r.SendTimeout = 1000;
                 r.Remove(key);
             }
         }
     }
     catch
     {
         throw new Exception(string.Format("{0}:{1}发生异常!{2}", "cache", "删除", key));
     }
     return(true);
 }
Exemplo n.º 24
0
        public string KeyCodeToString(AllKeys KeyCode)
        {
            string Character = "";

            switch ((int)KeyCode)
            {
                case 0x20:
                    Character = " ";
                    break;
                case 0xDB:
                    Character = "[";
                    break;
                case 0xDD:
                    Character = "]";
                    break;
                case 0xDC:
                    Character = "\\";
                    break;
                case 0xBA:
                    Character = ";";
                    break;
                case 0xDE:
                    Character = "'";
                    break;
                case 0xBF:
                    Character = "/";
                    break;
                case 0xBE:
                    Character = ".";
                    break;
                case 0xBC:
                    Character = ",";
                    break;
                case 0xBD:
                    Character = "-";
                    break;
                case 0xBB:
                    Character = "=";
                    break;
                case 0xC0:
                    Character = "`";
                    break;
                case 0x31:
                    Character = "1";
                    break;
                case 0x32:
                    Character = "2";
                    break;
                case 0x33:
                    Character = "3";
                    break;
                case 0x34:
                    Character = "4";
                    break;
                case 0x35:
                    Character = "5";
                    break;
                case 0x36:
                    Character = "6";
                    break;
                case 0x37:
                    Character = "7";
                    break;
                case 0x38:
                    Character = "8";
                    break;
                case 0x39:
                    Character = "9";
                    break;
                case 0x30:
                    Character = "0";
                    break;
                default:
                    Character = KeyCode.ToString();
                    break;
            }

            if (Character.Length > 1)
            {
                Character = "{" + Character + "}";
            }
            return Character;
        }
Exemplo n.º 25
0
 public bool ContainsKey(string key)
 {
     key = key.ToLowerInvariant();
     return(AllKeys.Any(v => v.ToLowerInvariant() == key));
 }
Exemplo n.º 26
0
 public new IEnumerator <KeyValuePair <string, string> > GetEnumerator()
 {
     return(AllKeys.SelectMany(GetValues, (k, c) => new KeyValuePair <string, string>(k, c)).ToList().GetEnumerator());
 }
Exemplo n.º 27
0
        private void Crossover(string parent1, string parent2)
        {
            Random rand = new Random(i++);

            int a = rand.Next(32);
            int b = rand.Next(a, 34);

            char[] child1 = parent1.ToCharArray();
            char[] child2 = parent2.ToCharArray();

            Dictionary <char, char> accordance1 = new Dictionary <char, char>();
            Dictionary <char, char> accordance2 = new Dictionary <char, char>();

            for (int i = a; i < b; i++)
            {
                child1[i] = parent2[i];
                child2[i] = parent1[i];
                accordance1.Add(parent1[i], parent2[i]);
                accordance2.Add(parent2[i], parent1[i]);
            }

            for (int i = 0; i < a; i++)
            {
                if (accordance1.ContainsKey(child1[i]))
                {
                    child1[i] = accordance1[child1[i]];
                }
                else if (accordance2.ContainsKey(child1[i]))
                {
                    child1[i] = accordance2[child1[i]];
                }

                if (accordance1.ContainsKey(child2[i]))
                {
                    child2[i] = accordance1[child2[i]];
                }
                else if (accordance2.ContainsKey(child2[i]))
                {
                    child2[i] = accordance2[child2[i]];
                }
            }

            for (int i = b; i < 33; i++)
            {
                if (accordance1.ContainsKey(child1[i]))
                {
                    child1[i] = accordance1[child1[i]];
                }
                else if (accordance2.ContainsKey(child1[i]))
                {
                    child1[i] = accordance2[child1[i]];
                }

                if (accordance1.ContainsKey(child2[i]))
                {
                    child2[i] = accordance1[child2[i]];
                }
                else if (accordance2.ContainsKey(child2[i]))
                {
                    child2[i] = accordance2[child2[i]];
                }
            }

            string child1str = new string(child1);
            string child2str = new string(child2);

            if (CheckKey(child1str))
            {
                if (!AllKeys.ContainsKey(child1str))
                {
                    AllKeys.Add(child1str, 0.0);
                }

                if (!AllKeys.ContainsKey(child2str))
                {
                    AllKeys.Add(child2str, 0.0);
                }
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Converts <see cref="ConfigurationSettingsCollection" /> to the dictionary.
 /// </summary>
 /// <returns>The dictionary.</returns>
 public IDictionary <string, string> ToDictionary()
 {
     return(AllKeys.ToDictionary(key => key, key => Get(key)));
 }
Exemplo n.º 29
0
 protected override void RecordKeys()
 {
     base.RecordKeys();
     TrigonometricKeys = new HashSet <Button>(AllKeys.Where(IsTrigonometricKey));
 }
Exemplo n.º 30
0
 public static bool IsAnyKeyPressed()
 {
     return(AllKeys.Any(key => IsKeyPressed(key)));
 }
 public bool HasKeys()
 {
     return(AllKeys.Any());
 }