Example #1
0
        private async void button2_Click(object sender, EventArgs e)
        {
            Task <ListOfArray> task1 = null;
            Task <ListOfArray> task2 = null;

            IRepository repo1 = new Repository();
            IRepository repo2 = new Repository();

            Compare comparator1 = new Compare(repo1);
            Compare comparator2 = new Compare(repo2);


            task1 = Task.Factory.StartNew(() => comparator1.GenerateData(@"c:\tmp\ex.csv"));
            task2 = Task.Factory.StartNew(() => comparator2.GenerateData(@"c:\tmp\ex_1.csv"));

            ListOfArray res1 = await task1;
            ListOfArray res2 = await task2;

            DataTable table1 = comparator1.ConvertListToDataTable(res1);

            dataGridView1.DataSource = table1;

            DataTable table2 = comparator2.ConvertListToDataTable(res2);

            dataGridView2.DataSource = table2;
        }
Example #2
0
        public ListOfArray GenerateData(string path)
        {
            ListOfArray lst = new ListOfArray();

            lst.List = _repository.GetData(path);
            return(lst);
        }
Example #3
0
        public DataTable ConvertListToDataTable(ListOfArray value)
        {
            // New table.
            DataTable table = new DataTable();

            // Get max columns.
            int columns = 0;

            foreach (var array in value.List)
            {
                if (array.Length > columns)
                {
                    columns = array.Length;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                string columnName = "";
                if (i == 0)
                {
                    columnName = "ColumnName";
                }
                else if (i == 1)
                {
                    columnName = "Value in Column with Max Length";
                }
                else if (i == 2)
                {
                    columnName = "Suggested Type";
                }
                else if (i == 3)
                {
                    columnName = "Max Lenght";
                }

                table.Columns.Add(columnName);
            }

            // Add transpond rows.
            for (int i = 0; i < columns; i++)
            {
                table.Rows.Add(value.List[0].ElementAt(i), GetFirstValueFromListOfArrraysByMaxLentgh(value, ColMaxLenght(value, i), i),
                               TryParseStringInListOfArrrays(GetFirstValueFromListOfArrraysByMaxLentgh(value, ColMaxLenght(value, i), i)), ColMaxLenght(value, i));
            }

            return(table);
        }
Example #4
0
 public int ColMaxLenght(ListOfArray arr, int i)
 {
     return(arr.List.Skip(1).Max(p => p[i].Length));
 }
Example #5
0
 public string GetFirstValueFromListOfArrraysByMaxLentgh(ListOfArray array, int maxLentgh, int i)
 {
     return(array.List.Skip(1).First(p => p[i].Length == maxLentgh).ElementAt(i));
 }