示例#1
0
        private static List <CourtDecision> getDecisions()
        {
            if (courtDecisions == null)
            {
                //Load Data from Source File and stor it in sourceData
                DataTable sourceData = new DataAccess.CsvHelper.CsvReader(AppDomain.CurrentDomain.BaseDirectory + @"\Data\CourtData.csv")
                {
                    cSeperator = '|', cDelimiter = '"', HasHeaderRow = false
                }.ReadIntoDataTable();

                //Initialize CitationList
                courtDecisions = new List <CourtDecision>();

                //Load Citations to List
                foreach (DataRow row in sourceData.Rows)
                {
                    CourtDecision dec = new CourtDecision();
                    dec.id                    = row[0].ToString();
                    dec.file_number           = row[1].ToString();
                    dec.date                  = row[2].ToString();
                    dec.court                 = new Court();
                    dec.court.level_of_appeal = row[3].ToString();

                    courtDecisions.Add(dec);
                }
            }

            return(courtDecisions);
        }
示例#2
0
        private static void UpdateCitationNetwork()
        {
            //Load Data from Source File and stor it in sourceData
            DataAccess.CsvHelper.CsvReader csvFile = new DataAccess.CsvHelper.CsvReader(AppDomain.CurrentDomain.BaseDirectory + @"\Data\refs.csv")
            {
                cSeperator = ',', cDelimiter = '"', HasHeaderRow = true
            };
            DataTable sourceData = csvFile.ReadIntoDataTable();


            csvFile.Dispose();
            DataTable existingData = con.GetSqlAsDataTable("Select * FROM dbo.citations");
            //Load Citations to List

            int e = 0;

            sourceData.Columns.Add("COMPAREKEY");
            foreach (DataRow r in sourceData.Rows)
            {
                if (e % 50000 == 0)
                {
                    System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString() + " " + e + " keys added (s)");
                }
                r["COMPAREKEY"] = r["from_id"] + "-" + r["to_id"];
                e++;
            }
            e = 0;
            existingData.Columns.Add("COMPAREKEY");
            foreach (DataRow r in existingData.Rows)
            {
                if (e % 50000 == 0)
                {
                    System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString() + " " + e + " keys added (e)");
                }
                r["COMPAREKEY"] = r["from_id"] + "-" + r["to_id"];
                e++;
            }


            var            set          = new HashSet <string>(existingData.AsEnumerable().Select(r => (string)r["COMPAREKEY"]));
            List <DataRow> rowsToInsert = sourceData.AsEnumerable().Where(r => !set.Contains((string)r["COMPAREKEY"])).ToList();

            int i = 0;

            foreach (DataRow row in rowsToInsert)
            {
                if (i % 500 == 0)
                {
                    System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString() + " " + i + " rows checked");
                }
                if (!set.Contains((string)row["COMPAREKEY"]))
                {
                    Citation cit = new Citation(row);
                    cit.UpdateToDatabase(con);
                    set.Add((string)row["COMPAREKEY"]);
                }

                i++;
            }
        }