public IHttpActionResult PutKeyPosition(int id, KeyPosition keyPosition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != keyPosition.ID)
            {
                return(BadRequest());
            }

            db.Entry(keyPosition).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KeyPositionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        private static bool Import(string exportedString, bool throwExceptions, out FingerPositions outputInstance)
        {
            outputInstance = null;
            var positionsDict = new Dictionary <KeyPosition, Finger>();

            var iRow  = -1;
            var lines = exportedString.Split(new[] { NewLine }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var line in lines)
            {
                ++iRow;

                var iKey          = -1;
                var fingerStrings = line.Split(new[] { KeySeparator }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var fingerString in fingerStrings)
                {
                    iKey++;

                    if (!GetFinger(throwExceptions, fingerString, out Finger finger))
                    {
                        return(false);
                    }

                    var pos = new KeyPosition(iRow, iKey);
                    positionsDict.Add(pos, finger);
                }
            }


            outputInstance = new FingerPositions(positionsDict);
            return(true);
        }
Beispiel #3
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (KeyPosition != null ? KeyPosition.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Distance;
         hashCode = (hashCode * 397) ^ DoorMask;
         return(hashCode);
     }
 }
        public IHttpActionResult GetKeyPosition(int id)
        {
            KeyPosition keyPosition = db.KeyPositions.Find(id);

            if (keyPosition == null)
            {
                return(NotFound());
            }

            return(Ok(keyPosition));
        }
        public Finger this[KeyPosition keyPosition]
        {
            get
            {
                if (ContainsKey(keyPosition))
                {
                    return(_positionsDictionary[keyPosition]);
                }

                throw new KeyNotFoundException($"No finger is associated with position '{keyPosition}'!");
            }
        }
        public IHttpActionResult PostKeyPosition(KeyPosition keyPosition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.KeyPositions.Add(keyPosition);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = keyPosition.ID }, keyPosition));
        }
        public IHttpActionResult DeleteKeyPosition(int id)
        {
            KeyPosition keyPosition = db.KeyPositions.Find(id);

            if (keyPosition == null)
            {
                return(NotFound());
            }

            db.KeyPositions.Remove(keyPosition);
            db.SaveChanges();

            return(Ok(keyPosition));
        }
Beispiel #8
0
        private static bool Import(string exportString, bool throwExceptions, out MechanicalKeyboardLayout outputLayout)
        {
            outputLayout = null;
            var sizefactorsDict = new Dictionary <KeyPosition, float?>();

            exportString = exportString.Trim();
            var lines = exportString.Split(new[] { NewLine }, StringSplitOptions.RemoveEmptyEntries);

            var iRow = -1;

            foreach (var line in lines)
            {
                iRow++;
                var keyStrings = line.Trim().Split(new[] { KeySeparator }, StringSplitOptions.RemoveEmptyEntries);

                var iKey = -1;
                foreach (var keyString in keyStrings)
                {
                    iKey++;
                    var position = new KeyPosition(iRow, iKey);

                    if (keyString == RegularKey)
                    {
                        sizefactorsDict.Add(position, null);
                    }
                    else if (keyString.StartsWith(ProportionalKey))
                    {
                        var sizefactorString = keyString.Replace(ProportionalKey, "");

                        if (!GetSizefactor(throwExceptions, sizefactorString, out float size))
                        {
                            return(false);
                        }

                        sizefactorsDict.Add(position, size);
                    }
                    else
                    {
                        throw new FormatException($"Couldn't parse '{keyString}'! Must either be '{RegularKey}' or "
                                                  + $"'{ProportionalKey}{1.234f.ToString(FloatFormat)}'!");
                    }
                }
            }

            outputLayout = new MechanicalKeyboardLayout(sizefactorsDict);
            return(true);
        }
        private void BuildKeySizesDict(IReadOnlyList <IList <float?> > keySizefactors)
        {
            _keySizefactorsDict.Clear();

            for (var iRow = 1; iRow <= keySizefactors.Count; iRow++)
            {
                var keySizesInRow = keySizefactors[iRow];

                for (var iKey = 1; iKey <= keySizesInRow.Count; iKey++)
                {
                    var size = keySizesInRow[iKey];
                    var pos  = new KeyPosition(iRow, iKey);

                    _keySizefactorsDict.Add(pos, size);
                }
            }

            SetNumbers();
        }
        static KeyCodes()
        {
            Keypositions = new List<KeyPosition> { };
            var lines = File.ReadAllLines("keymap.txt");

            foreach (var line in lines)
            {
                if (!line.StartsWith("key,"))
                {
                    var ele = line.Split(new char[] { ',' });
                    //KeyCodes.ScanCode code = (KeyCodes.ScanCode)Enum.Parse(typeof(KeyCodes.ScanCode), ele[0]);
                    var k = new KeyPosition();
                    //k.keyCode = (int)code;
                    k.KeyName = ele[0];
                    k.X = Convert.ToSingle(ele[1]);
                    k.Y = Convert.ToSingle(ele[2]);
                    k.Width = Convert.ToSingle(ele[3]);
                    k.Height = Convert.ToSingle(ele[4]);
                    k.KeyCode = Convert.ToInt16(ele[5], 16);
                    Keypositions.Add(k);
                }
            }
        }
Beispiel #11
0
 void AddKeyPosition(KeyPosition kp)
 {
     KeyPositions.Add(kp.KeyPositionType, kp);
     KeyPositionsChanged.Invoke(this, kp);
 }
 public bool ContainsKey(KeyPosition keyPosition)
 => _positionsDictionary.ContainsKey(keyPosition);
        public float?GetSizefactor(KeyPosition position)
        {
            var keyPosition = _keySizefactorsDict.Keys.First(keyPos => keyPos.Equals(position));

            return(_keySizefactorsDict[keyPosition]);
        }
Beispiel #14
0
 private void applyKeyPosition(int key, KeyPosition pos)
 {
     applyLightState(key, 0, pos.blue);
     applyLightState(key, 1, pos.red);
 }
Beispiel #15
0
 internal void KeyPositionsChanged(object sender, KeyPosition e)
 {
     Debug.LogWarning(e.KeyPositionType + "   " + keyPositions.Count);
     //keyPositions.Add(e.KeyPositionType,e);
 }