Ejemplo n.º 1
0
        public override BugDictionary CreateBugs(string csvfile, Progress progress)
        {
            Dictionary <int, string> Headers;
            DataTable     csvTable;
            BugDictionary bugs;
            Bug           bug;

            #region Pre Condition
            Debug.Assert("" != csvfile);
            #endregion

            Headers  = new Dictionary <int, string>();
            csvTable = CSVParse(csvfile);
            bugs     = new BugDictionary();

            #region Header
            // Use the header row to make a map of where stuff goes
            //string[] csvHeaders = csvTable[0];
            int index = 0;
            foreach (string header in csvTable.Rows[0].ItemArray)
            {
                Headers.Add(index, header);
                index++;
            }
            #endregion

            #region Verification
            // Write code to ensure that we have enough of the fields
            #endregion

            #region Data Row Parse
            DataRow row;

            for (int i = 1; i < csvTable.Rows.Count; i++)
            {
                row = csvTable.Rows[i];
                bug = new Bug();
                for (int j = 0; j < row.ItemArray.Length; j++)
                {
                    if (Headers.ContainsKey(j) && (null != row.ItemArray[j]) && (false == (row.ItemArray[j] is System.DBNull)) && (null != row.ItemArray[j]) && ("" != (string)row.ItemArray[j]))
                    {
                        CSVBugPopulate(bug, Headers[j], (string)row.ItemArray[j]);
                    }
                }

                // This deals with the case of null rows at the end.
                if (0 != bug.Id)
                {
                    bugs.Add(bug.Id, bug);
                }
                if (null != progress)
                {
                    progress.UpdateProgress(1, "Reading " + bug.Id + " from " + csvfile + ".");
                }
            }
            #endregion

            #region Post Condition
            foreach (KeyValuePair <int, Bug> kvp in bugs)
            {
                bug = ((Bug)kvp.Value);
                Debug.Assert(0 != bug.Id);
                Debug.Assert((null != bug.Summary) && ("" != bug.Summary));
            }
            #endregion

            return(bugs);
        }