public void TestMultiMapRemove()
        {
            MultiMapList <string, string> multiMapList = new MultiMapList <string, string>();
            string key  = nameof(key);
            string val  = nameof(val);
            string val2 = nameof(val2);

            Assert.IsTrue(multiMapList.TryToAddMapping(key, val));
            Assert.IsTrue(multiMapList.TryToAddMapping(key, val));
            Assert.IsTrue(multiMapList.TryToAddMapping(key, val2));
            Assert.IsTrue(multiMapList.TryToAddMapping(key, val2));
            Assert.AreEqual(2, multiMapList.ContainsMapping(key, val));
            Assert.AreEqual(2, multiMapList.ContainsMapping(key, val2));

            Assert.IsTrue(multiMapList.TryToRemoveMapping(key, val));
            Assert.AreEqual(1, multiMapList.ContainsMapping(key, val));
            Assert.IsTrue(multiMapList.TryToRemoveMapping(key, val));
            Assert.IsFalse(multiMapList.TryToRemoveMapping(key, val));
            Assert.AreEqual(0, multiMapList.ContainsMapping(key, val));
            Assert.AreEqual(1, multiMapList.Keys.Count);
            Assert.AreEqual(1, multiMapList.Values.Count);


            Assert.IsTrue(multiMapList.TryToRemoveMapping(key, val2));
            Assert.AreEqual(1, multiMapList.ContainsMapping(key, val2));
            Assert.IsTrue(multiMapList.TryToRemoveMapping(key, val2));
            Assert.IsFalse(multiMapList.TryToRemoveMapping(key, val2));
            Assert.AreEqual(0, multiMapList.ContainsMapping(key, val2));

            Assert.AreEqual(0, multiMapList.Keys.Count);
            Assert.AreEqual(0, multiMapList.Values.Count);
        }
        public void MultiMapList_duplicates()
        {
            var personnesParVille = new MultiMapList <string, string>();

            //Lookup<string, string> personnesParVille = (Lookup<string, string>)new List<Person>().ToLookup(k => k.Ville, v => v.Nom);
            personnesParVille.Add("Paris", "Arthur");
            personnesParVille.Add("Paris", "Arthur");
            personnesParVille.Add("Paris", "Laurent");
            personnesParVille.Add("Paris", "David");
            personnesParVille.Add("Versailles", "Arthur");
            Check.That(personnesParVille.Count).IsEqualTo(2);
            Check.That(personnesParVille["Paris"].Count).IsEqualTo(4);
            Check.That(personnesParVille["Versailles"].Count).IsEqualTo(1);

            personnesParVille.Add("Versailles", "Arthur");
            Check.That(personnesParVille["Versailles"].Count).IsEqualTo(2);
            Check.That(personnesParVille.Count).IsEqualTo(2);

            personnesParVille.Add("Versailles", "Annabelle");
            Check.That(personnesParVille["Versailles"].Count).IsEqualTo(3);
            Check.That(personnesParVille.Count).IsEqualTo(2);

            personnesParVille.Add("Aix", "Françoise");
            Check.That(personnesParVille.Count).IsEqualTo(3);
        }
        public void TestMultiMapAdd()
        {
            MultiMapList <string, string> multiMapList = new MultiMapList <string, string>();
            string key  = nameof(key);
            string val  = nameof(val);
            string val2 = nameof(val2);

            Assert.IsTrue(multiMapList.TryToAddMapping(key, val));
            Assert.IsTrue(multiMapList.TryToAddMapping(key, val));
            Assert.IsTrue(multiMapList.TryToAddMapping(key, val2));
            Assert.IsTrue(multiMapList.TryToAddMapping(key, val2));
            Assert.AreEqual(2, multiMapList.ContainsMapping(key, val));
            Assert.AreEqual(2, multiMapList.ContainsMapping(key, val2));
        }
Beispiel #4
0
        public static bool GetTypeColumn(System.Data.DataTable rawDataTable,
                                         string typeName, string columnName,
                                         out Tuple <string, string, string> typeColumnInitialValues)
        {
            string columnKey   = string.Empty;
            string columnValue = string.Empty;

            {
                Regex regex = new Regex("(\\w+)_(\\d+)");
                Match m     = regex.Match(columnName);
                if (!m.Success)
                {
                    string initialValue = GetServerDefaultInitializeValue(typeName);
                    typeColumnInitialValues =
                        new Tuple <string, string, string>(typeName, columnName, initialValue);

                    return(true);
                }

                columnKey   = m.Groups[1].Value;
                columnValue = m.Groups[2].Value;

                int columnValueToInt = Convert.ToInt32(columnValue);
                if (columnValueToInt > 1)
                {
                    Trace.Assert(columnValueToInt != 0);

                    typeColumnInitialValues =
                        new Tuple <string, string, string>(string.Empty, string.Empty, string.Empty);
                    return(false);
                }
            }

            MultiMapList <string, string> multiMapList = new MultiMapList <string, string>();

            {
                int columnCount = rawDataTable.Columns.Count;
                for (int i = 0; i < columnCount; ++i)
                {
                    string rawDataColumnName = rawDataTable.Columns[i].ColumnName;

                    Regex regex = new Regex("(\\w+)_(\\d+)");
                    Match m     = regex.Match(rawDataColumnName);
                    if (m.Success)
                    {
                        string key   = m.Groups[1].Value;
                        string value = m.Groups[2].Value;

                        multiMapList.TryToAddMapping(key, value);
                    }
                }
            }

            List <string> columnValues = new List <string>();

            if (!multiMapList.TryGetValue(columnKey, out columnValues))
            {
                typeColumnInitialValues =
                    new Tuple <string, string, string>(string.Empty, string.Empty, string.Empty);
                return(false);
            }

            int    columnKeyCount = columnValues.Count;
            string arrayTypeName  = string.Format("std::array<{0}, {1}>", typeName, columnKeyCount);

            string initialValues = string.Empty;

            for (int i = 0; i < columnKeyCount; ++i)
            {
                if (initialValues.Length != 0)
                {
                    initialValues += ", ";
                }

                initialValues += string.Format("{{{0}}}", GetServerDefaultInitializeValue(typeName));
            }

            initialValues = string.Format("{{ {{{0}}} }}", initialValues);

            typeColumnInitialValues =
                new Tuple <string, string, string>(arrayTypeName, columnKey + "s", initialValues);
            return(true);
        }
Beispiel #5
0
        public bool Execute(ref System.Data.DataSet rawDataSet)
        {
            using (System.Data.DataSet mergedRawDataSet = new System.Data.DataSet())
            {
                MultiMapList <string, string> multimapList = new MultiMapList <string, string>();

                foreach (System.Data.DataTable rawDataTable in rawDataSet.Tables)
                {
                    string tableName = rawDataTable.TableName;

                    if (tableName.Contains("_"))
                    {
                        string[] splitedTableName = tableName.Split('_');

                        if (splitedTableName.Length != 2)
                        {
                            Log.ErrorFormat("Error. Table's name has twice underbar('_'). {0}",
                                            tableName);
                            Trace.Assert(false);
                            return(false);
                        }

                        if (!multimapList.TryToAddMapping(splitedTableName[0], tableName))
                        {
                            Log.ErrorFormat("Fail to add. {0}, {1}",
                                            splitedTableName[0], tableName);
                            return(false);
                        }
                    }
                    else
                    {
                        if (!multimapList.TryToAddMapping(tableName, tableName))
                        {
                            Log.ErrorFormat("Fail to add. {0}, {1}",
                                            tableName, tableName);
                            return(false);
                        }
                    }
                }

                foreach (var kvp in multimapList)
                {
                    string        key    = kvp.Key;
                    List <string> values = kvp.Value;

                    foreach (string value in values)
                    {
                        string tableName = value;
                        System.Data.DataTable rawDataTable = rawDataSet.Tables[tableName];
                        if (rawDataTable != null)
                        {
                            System.Data.DataTable addOrMergeTable = rawDataTable.Copy();
                            addOrMergeTable.TableName = key;

                            if (!mergedRawDataSet.Tables.Contains(key))
                            {
                                mergedRawDataSet.Tables.Add(addOrMergeTable);
                            }
                            else
                            {
                                var compareSourceRow =
                                    mergedRawDataSet.Tables[key].Rows[0].ItemArray
                                    .Aggregate((lhs, rhs) => lhs + ", " + rhs);
                                var compareDestRow = addOrMergeTable.Rows[0].ItemArray
                                                     .Aggregate((lhs, rhs) => lhs + ", " + rhs);

                                if (!compareSourceRow.Equals(compareDestRow))
                                {
                                    Log.ErrorFormat("Table Schema is not matched." +
                                                    " {0}, source: {1}, dest: {2}",
                                                    key, compareSourceRow, compareDestRow);
                                    return(false);
                                }

                                addOrMergeTable.Rows.RemoveAt(0);
                                mergedRawDataSet.Tables[key].Merge(addOrMergeTable);
                            }
                        }
                    }
                }

                rawDataSet = mergedRawDataSet;
            }

            return(true);
        }