Example #1
0
        //Select multiple statement
        public List <CloneableDictionary <string, string> > SelectMultiple(string query)
        {
            var lol = new List <CloneableDictionary <string, string> >();

            if (this.OpenConnection() == true)
            {
                MySqlCommand    cmd        = new MySqlCommand(query, connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    var listOfStrings = new CloneableDictionary <string, string>();
                    int columns       = dataReader.FieldCount;
                    for (int x = 0; x < columns; x++)
                    {
                        listOfStrings.Add(dataReader.GetName(x).ToLower(), dataReader[x].ToString());
                    }

                    lol.Add(listOfStrings.Clone());
                }
                dataReader.Close();
                this.CloseConnection();

                return(lol);
            }
            else
            {
                return(lol);
            }
        }
Example #2
0
        private void DictionaryTests(CloneableDictionary <string, Person> dut)
        {
            Assert.True(dut.ContainsKey("2000Horst2000"));
            dut.Add("NEW", new Person(9, "NEWPERSON"));
            Assert.True(dut.ContainsKey("NEW"));
            Assert.Equal(10002, dut.Count);

            dut.Remove("2000Horst2000");
            Assert.Equal(10001, dut.Count);
            Assert.False(dut.ContainsKey("2000Horst2000"));

            Person person = dut.GetValue("NEW", null);

            Assert.Equal("NEWPERSON", person.Name);

            person = dut.GetValue("WTF", new Person(22, "NA"));
            Assert.Equal("NA", person.Name);

            string at100 = dut[100].Item1;

            dut.RemoveAt(100);
            Assert.Equal(10000, dut.Count);
            Assert.Null(dut.GetValue(at100, null));
            Assert.False(dut.ContainsKey(at100));

            dut[500] = Tuple.Create("AT500", new Person(500, "Person500"));
            Assert.True(dut.ContainsKey("AT500"));

            Stopwatch sw = new Stopwatch();

            sw.Start();
            foreach (Tuple <string, Person> dutEntry in dut)
            {
                dut.ContainsKey(dutEntry.Item1);
                dut.GetValue(dutEntry.Item1, null);
            }
            for (int i = 10005; i < 20000; i++)
            {
                dut.Add(i.ToString(), new Person());
            }
            sw.Stop();

            Assert.True(sw.ElapsedMilliseconds < 100);

            dut.Clear();
            Assert.True(dut.Count == 0);
        }
    public IDictionary <TKey, TValue> Clone()
    {
        var clone = new CloneableDictionary <TKey, TValue>();

        foreach (KeyValuePair <TKey, TValue> pair in this)
        {
            ICloneable clonableValue = pair.Value as ICloneable;
            if (clonableValue != null)
            {
                clone.Add(pair.Key, (TValue)clonableValue.Clone());
            }
            else
            {
                clone.Add(pair.Key, pair.Value);
            }
        }
        return(clone);
    }
Example #4
0
    public CloneableDictionary <TKey, TValue> Clone() // shallow copy!
    {
        CloneableDictionary <TKey, TValue> clone = new CloneableDictionary <TKey, TValue>();

        foreach (KeyValuePair <TKey, TValue> kvp in this)
        {
            clone.Add(kvp.Key, kvp.Value);
        }
        return(clone);
    }
Example #5
0
        // ctor
        public OptionTree(DeviceCls device)
        {
            if (m_profileOptions.Count( ) == 0)
            {
                log.Error("cTor OptionTree - profile not yet read");
            }

            // get options for the device class
            var devOpts = m_profileOptions.Where(x => x.DeviceClass == device.DevClass);

            foreach (ProfileOptionRec rec in devOpts)
            {
                m_tuning.Add(rec.OptName, new DeviceTuningParameter(rec.OptName, device));
            }
        }
Example #6
0
        public void Test_Cloneable_Dictionary()
        {
            Stopwatch sw = new Stopwatch();
            CloneableDictionary <string, Person> cDict = new CloneableDictionary <string, Person>();

            for (int i = 0; i <= 10000; i++)
            {
                Person p = new Person(i, "Horst" + i);
                cDict.Add(i + p.Name, p);
            }

            Assert.Equal(10001, cDict.Count);
            CloneableDictionary <string, Person> clonedDict = cDict.Clone();

            Assert.NotEqual(clonedDict[100].Item2, cDict[100].Item2);
            Assert.Equal(clonedDict[100].Item2.ID, cDict[100].Item2.ID);
            Assert.Equal(clonedDict[100].Item2.Name, cDict[100].Item2.Name);
            Assert.Equal(clonedDict[100].Item2.Adress, cDict[100].Item2.Adress);

            DictionaryTests(cDict);
            DictionaryTests(clonedDict);
        }
Example #7
0
        // ctor
        public OptionTree(DeviceCls device)
        {
            m_tuning.Add("flight_move_pitch", new DeviceTuningParameter("flight_move_pitch", device));
            m_tuning.Add("flight_move_yaw", new DeviceTuningParameter("flight_move_yaw", device));
            m_tuning.Add("flight_move_roll", new DeviceTuningParameter("flight_move_roll", device));
            m_tuning.Add("flight_move_strafe_vertical", new DeviceTuningParameter("flight_move_strafe_vertical", device));
            m_tuning.Add("flight_move_strafe_lateral", new DeviceTuningParameter("flight_move_strafe_lateral", device));
            m_tuning.Add("flight_move_strafe_longitudinal", new DeviceTuningParameter("flight_move_strafe_longitudinal", device));

            m_tuning.Add("flight_throttle_abs", new DeviceTuningParameter("flight_throttle_abs", device));
            m_tuning.Add("flight_throttle_rel", new DeviceTuningParameter("flight_throttle_rel", device));

            m_tuning.Add("flight_aim_pitch", new DeviceTuningParameter("flight_aim_pitch", device));
            m_tuning.Add("flight_aim_yaw", new DeviceTuningParameter("flight_aim_yaw", device));

            m_tuning.Add("flight_view_pitch", new DeviceTuningParameter("flight_view_pitch", device));
            m_tuning.Add("flight_view_yaw", new DeviceTuningParameter("flight_view_yaw", device));

            m_tuning.Add("turret_aim_pitch", new DeviceTuningParameter("turret_aim_pitch", device));
            m_tuning.Add("turret_aim_yaw", new DeviceTuningParameter("turret_aim_yaw", device));

            // Gamepad specific
            if (Gamepad.GamepadCls.IsDeviceClass(device.DevClass))
            {
                m_tuning.Add("fps_view_pitch", new DeviceTuningParameter("fps_view_pitch", device));
                m_tuning.Add("fps_view_yaw", new DeviceTuningParameter("fps_view_yaw", device));

                m_tuning.Add("fps_move_lateral", new DeviceTuningParameter("fps_move_lateral", device));
                m_tuning.Add("fps_move_longitudinal", new DeviceTuningParameter("fps_move_longitudinal", device));

                m_tuning.Add("mgv_view_pitch", new DeviceTuningParameter("mgv_view_pitch", device));
                m_tuning.Add("mgv_view_yaw", new DeviceTuningParameter("mgv_view_yaw", device));
            }
        }
Example #8
0
        //Select multiple statement
        public List<CloneableDictionary<string, string>> SelectMultiple(string query)
        {
            var lol = new List<CloneableDictionary<string, string>>();

            if (this.OpenConnection() == true)
            {
                MySqlCommand cmd = new MySqlCommand(query, connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    var listOfStrings = new CloneableDictionary<string, string>();
                    int columns = dataReader.FieldCount;
                    for (int x = 0; x < columns; x++)
                    {
                        listOfStrings.Add(dataReader.GetName(x).ToLower(), dataReader[x].ToString());
                    }

                    lol.Add(listOfStrings.Clone());

                }
                dataReader.Close();
                this.CloseConnection();

                return lol;
            }
            else
            {
                return lol;
            }

        }