コード例 #1
0
ファイル: DataAccess.cs プロジェクト: ely-zip1/ESI-ITE
        //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);
            }
        }
コード例 #2
0
 private Deviceoptions(CloneableDictionary <string, DeviceOptionParameter> init)
 {
     foreach (KeyValuePair <string, DeviceOptionParameter> kvp in init)
     {
         this.Add(kvp.Key, kvp.Value);
     }
 }
コード例 #3
0
 /// <summary>
 /// cTor:  Copy - Initializes the tuning options with the given one
 /// </summary>
 /// <param name="init"></param>
 private Tuningoptions(CloneableDictionary <string, OptionTree> init)
 {
     foreach (KeyValuePair <string, OptionTree> kvp in init)
     {
         this.Add(kvp.Key, kvp.Value);
     }
 }
コード例 #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);
    }
コード例 #5
0
ファイル: CloningTest.cs プロジェクト: mayphi/CloneBehave
        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);
        }
コード例 #6
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);
    }
コード例 #7
0
        public void CloneableDictionary_Clone()
        {
            CloneableDictionary<int, string> source
                = new CloneableDictionary<int, string>
                {
                    { 1, "one" },
                    { 2, "two" },
                    { 3, "three" }
                };

            CloneableDictionary<int, string> clone
                = (CloneableDictionary<int, string>) source.Clone();

            Assert.AreEqual(source.Count, clone.Count);
            var keys = source.Keys;
            foreach (int key in keys)
            {
                Assert.AreEqual(source[key], clone[key]);
            }
        }
コード例 #8
0
ファイル: CloningTest.cs プロジェクト: mayphi/CloneBehave
        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);
        }
コード例 #9
0
ファイル: CloningTest.cs プロジェクト: mayphi/CloneBehave
        public void Test_Performance()
        {
            Stopwatch sw = new Stopwatch();
            IDictionary <string, Person> personDict = new Dictionary <string, Person>();

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

            personDict.Clone();
            sw.Start();
            personDict.Clone();
            sw.Stop();

            Console.WriteLine("personDict: " + sw.ElapsedMilliseconds);

            IList <KeyValuePair <string, Person> > personListKeyValue = personDict.ToList();

            personListKeyValue.Clone();
            sw.Restart();
            personListKeyValue.Clone();
            sw.Stop();

            Console.WriteLine("personListKeyValue: " + sw.ElapsedMilliseconds);

            IList <Person> personList = personDict.Values.ToList();

            personList.Clone();
            sw.Restart();
            personList.Clone();
            sw.Stop();

            Console.WriteLine("personList: " + sw.ElapsedMilliseconds);

            IList <Tuple <string, Person> > personTupleList = personDict.Select(p => Tuple.Create(p.Key, p.Value)).ToList();

            personTupleList.Clone();
            sw.Restart();
            personTupleList.Clone();
            sw.Stop();

            Console.WriteLine("personTupleList: " + sw.ElapsedMilliseconds);

            ICollection <Tuple <string, Person> > personTupleCollection = personDict.Select(p => Tuple.Create(p.Key, p.Value)).ToList();

            personTupleCollection.Clone();
            sw.Restart();
            personTupleCollection.Clone();
            sw.Stop();

            Console.WriteLine("personTupleCollection: " + sw.ElapsedMilliseconds);

            CloneableDictionary <string, Person> cDict = new CloneableDictionary <string, Person>(personDict);
            int count = cDict.Count;

            Assert.Equal(10001, count);

            cDict.Clone();
            sw.Restart();
            cDict.Clone();
            sw.Stop();

            Console.WriteLine("CloneableDictionary: " + sw.ElapsedMilliseconds);
        }
コード例 #10
0
 public RepairShip(Ship targetShip, CloneableDictionary <string, object> actionValues)
 {
     this.TargetShip   = targetShip;
     this.ActionValues = actionValues;
 }
コード例 #11
0
ファイル: DataAccess.cs プロジェクト: ely-zip1/ESI-ITE
        //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;
            }

        }
コード例 #12
0
 public RepairPart(BasePart targetPart, CloneableDictionary <string, object> actionValues)
 {
     this.TargetPart   = targetPart;
     this.ActionValues = actionValues;
 }