Пример #1
0
        public static void UnpivotAeisStudent(string filePath, string outPath)
        {
            var sb = new StringBuilder();
            var fileName = Path.GetFileNameWithoutExtension(filePath);
            var outFile = string.Format("{0}/{1} - Parsed.csv", outPath, fileName);
            var emptyList = new[] { "0", "", "." };
            var log = File.CreateText(@"\Parse\log.txt");
            var ctx = new AzureDataContext();
            var campuses = ctx.Campuses.ToList();


            //remove past file if it exists

            if (File.Exists(outFile))
                File.Delete(outFile);


            //read the lines in. First row is headers. save it then remove

            var rows = File.ReadAllLines(filePath).ToList();
            var headers = rows[0].Trim().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
            rows.RemoveAt(0); //pop the top off


            //Find year

            var yearIndex = headers.FindIndex(h => h.ToUpper() == "YEAR");
            var year = yearIndex == -1
                ? DateTime.Now.Year
                : Convert.ToInt32(rows[0].Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)[yearIndex]);


            foreach (var row in rows.Select(row => row.Split(',')))
            {
                if (campuses.FirstOrDefault(c => c.Number == Convert.ToInt64(row[0])) == null)
                {
                    log.WriteLine("{0} - Campus not found", row[0]);
                    continue;
                }

                foreach (var column in row)
                {
                    if (column == "CAMPUS" || column == "YEAR") continue;

                    AeisType type;
                    switch (column[3])
                    {
                        case 'G':
                            type = AeisType.Graduates;
                            break;

                        case 'R':
                            type = AeisType.Retention;
                            break;

                        case 'T':
                            type = AeisType.Student;
                            break;

                        case 'M':
                            type = AeisType.Mobility;
                            break;
                    }
                }
            }


        }
Пример #2
0
 public UnpivotorService()
 {
     _ctx = ApplicationFactory.RetrieveContext();
 }