private static void ProcessRequest(FilterInputs filterInputs) { Console.WriteLine("\n### Processing the filter ###"); Console.WriteLine($"Output Directory: " + $"\n\t{GetOutputDirectory(filterInputs.Title)}"); OutputDescriptionToFile(filterInputs); // Filter the Pipe var filterOutputs = FilterHelper.FilterList(Program._Pipe, filterInputs.Pattern); OutputListsToFile(filterOutputs, filterInputs); // update the Pipe if (filterInputs.ReverseFilter) { Program._Pipe = filterOutputs.RemovedList; } else { Program._Pipe = filterOutputs.FilteredList; } ConsoleHelper.RequestAnyInputToProceed(); }
public ActionResult UpdateTemplate(ExportsViewModel model) { var schoolIds = model.SelectedSchools?.Split(',').ToList(); //var schoolYears = model.SelectedSchoolYears?.Split(',').ToList(); //var terms = model.SelectedTerms?.Split(',').ToList(); //var subjects = model.SelectedSubjects?.Split(',').ToList(); //var courses = model.SelectedCourses?.Split(',').ToList(); var teachers = model.SelectedTeachers?.Split(',').ToList(); var sections = model.SelectedSections?.Split(',').ToList(); var inputs = new FilterInputs { Schools = schoolIds, //SchoolYears = schoolYears, //Terms = terms, //Subjects = subjects, //Courses = courses, Teachers = teachers, Sections = sections }; var inputsJson = JsonConvert.SerializeObject(inputs); var template = db.Templates.First(x => x.TemplateId == model.EditTemplateId); template.Filters = inputsJson; template.OneRosterVersion = model.OneRosterVersion; db.SaveChanges(UserName, IpAddress); return(RedirectToAction("Index", "Templates")); }
private async Task <ExportsViewModel> GetDefaultExportsViewModel() { ExportsViewModel result = new ExportsViewModel(); await ApiCalls.PopulateFilterSection1(result); FilterInputs filters = new FilterInputs(); var schools = await ApiCalls.GetSchools(); result.SelectedSchools = string.Join(",", schools.Select(p => p.SchoolId)); return(result); }
private FilterInputs GenerateTestFilterInputs(ExportsViewModel viewModel) { var inputs = new FilterInputs { Schools = viewModel.SchoolsCriteriaSection.FilterCheckboxes.Select(p => p.SchoolId).Distinct().ToList(), //Subjects = viewModel.SubjectsCriteriaSection.FilterCheckboxes.Select(p => p.Subject).Distinct().ToList(), //Courses = viewModel.CoursesCriteriaSection.FilterCheckboxes.Select(p => p.Course).Distinct().ToList(), Teachers = viewModel.TeachersCriteriaSection.FilterCheckboxes.Select(p => p.Teacher).Distinct().ToList() }; return(inputs); }
public ActionResult SaveTemplate(ExportsViewModel model) { var schoolIds = model.SelectedSchools?.Split(',').ToList(); //var schoolYears = model.SelectedSchoolYears?.Split(',').ToList(); //var terms = model.SelectedTerms?.Split(',').ToList(); //var subjects = model.SelectedSubjects?.Split(',').ToList(); //var courses = model.SelectedCourses?.Split(',').ToList(); var teachers = model.SelectedTeachers?.Split(',').ToList(); var sections = model.SelectedSections?.Split(',').ToList(); var inputs = new FilterInputs { Schools = schoolIds, //SchoolYears = schoolYears, //Terms = terms, //Subjects = subjects, //Courses = courses, Teachers = teachers, Sections = sections }; var inputsJson = JsonConvert.SerializeObject(inputs); var template = new Template { TemplateName = model.NewTemplateName, VendorName = model.NewTemplateVendorName, OneRosterVersion = model.OneRosterVersion, Filters = inputsJson }; db.Templates.Add(template); db.SaveChanges(UserName, IpAddress); return(RedirectToAction("Index", "Templates")); }
//http://stackoverflow.com/questions/1179816/best-practices-for-serializing-objects-to-a-custom-string-format-for-use-in-an-ou public async Task <byte[]> GetZipFile(List <string> schoolIds, //List<string> schoolYears, //List<string> terms, //List<string> subjects, //List<string> courses, List <string> teachers, List <string> sections, string oneRosterVersion) { var model = new DataResults(); List <string> schoolYears = new List <string>(); schoolYears.Add("2020"); var inputs = new FilterInputs { Schools = schoolIds, SchoolYears = schoolYears, //Terms = terms, //Subjects = subjects, //Courses = courses, Teachers = teachers, Sections = sections, SchoolIds = new List <string>() }; model = await ApiCalls.GetDataResults(inputs, oneRosterVersion); var csvFilesDirectory = "~/CsvFiles"; var csvDirectoryFullName = CommonUtils.PathProvider.MapPath(csvFilesDirectory); var directoryGuid = Guid.NewGuid().ToString(); var tempDirectory = csvFilesDirectory + "/" + directoryGuid; var tempDirectoryFullName = CommonUtils.PathProvider.MapPath(tempDirectory); Directory.CreateDirectory(tempDirectoryFullName); WriteObjectToCsv(model.Orgs, tempDirectoryFullName, "orgs.csv", oneRosterVersion); WriteObjectToCsv(model.Users, tempDirectoryFullName, "users.csv", oneRosterVersion); WriteObjectToCsv(model.Courses, tempDirectoryFullName, "courses.csv", oneRosterVersion); WriteObjectToCsv(model.Classes, tempDirectoryFullName, "classes.csv", oneRosterVersion); WriteObjectToCsv(model.Enrollments, tempDirectoryFullName, "enrollments.csv", oneRosterVersion); WriteObjectToCsv(model.AcademicSessions, tempDirectoryFullName, "academicSessions.csv", oneRosterVersion); WriteObjectToCsv(model.Demographics, tempDirectoryFullName, "demographics.csv", oneRosterVersion); if (oneRosterVersion == OneRosterVersions.OR_1_1) { WriteObjectToCsv(model.Manifest, tempDirectoryFullName, "manifest.csv", oneRosterVersion); } var zipPath = Path.Combine(csvDirectoryFullName, directoryGuid + ".zip"); var zip = ZipFile.Open(zipPath, ZipArchiveMode.Create); zip.CreateEntryFromFile(tempDirectoryFullName + "\\orgs.csv", "orgs.csv"); zip.CreateEntryFromFile(tempDirectoryFullName + "\\users.csv", "users.csv"); zip.CreateEntryFromFile(tempDirectoryFullName + "\\courses.csv", "courses.csv"); zip.CreateEntryFromFile(tempDirectoryFullName + "\\classes.csv", "classes.csv"); zip.CreateEntryFromFile(tempDirectoryFullName + "\\enrollments.csv", "enrollments.csv"); zip.CreateEntryFromFile(tempDirectoryFullName + "\\academicSessions.csv", "academicSessions.csv"); zip.CreateEntryFromFile(tempDirectoryFullName + "\\demographics.csv", "demographics.csv"); if (oneRosterVersion == OneRosterVersions.OR_1_1) { zip.CreateEntryFromFile(tempDirectoryFullName + "\\manifest.csv", "manifest.csv"); } zip.Dispose(); var bytes = File.ReadAllBytes(zipPath); //if this eats memory there are other options: http://stackoverflow.com/questions/2041717/how-to-delete-file-after-download-with-asp-net-mvc Directory.Delete(tempDirectoryFullName, true); File.Delete(zipPath); return(bytes); }
public async Task <ActionResult> Preview(List <string> schoolIds, //List<string> schoolYears, //List<string> terms, //List<string> subjects, //List<string> courses, List <string> teachers, List <string> sections, string oneRosterVersion) { var model = new ExportsViewModel(); var inputs = new FilterInputs { Schools = schoolIds, //SchoolYears = schoolYears, //Terms = terms, //Subjects = subjects, //Courses = courses, Teachers = teachers, Sections = sections }; model.JsonPreviews = await ApiCalls.GetJsonPreviews(inputs, oneRosterVersion); IEnumerable <string> orgColumnNames; IEnumerable <string> usersColumnNames; IEnumerable <string> coursesColumnNames; IEnumerable <string> classesColumnNames; IEnumerable <string> enrollmentsColumnNames; IEnumerable <string> academicsessionsColumnNames; if (oneRosterVersion == OneRosterVersions.OR_1_0) { orgColumnNames = typeof(CsvOrgs).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR10IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); usersColumnNames = typeof(CsvUsers).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR10IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); coursesColumnNames = typeof(CsvCourses).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR10IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); classesColumnNames = typeof(CsvClasses).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR10IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); enrollmentsColumnNames = typeof(CsvEnrollments).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR10IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); academicsessionsColumnNames = typeof(CsvAcademicSessions).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR10IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); } else { orgColumnNames = typeof(CsvOrgs).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR11IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); usersColumnNames = typeof(CsvUsers).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR11IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); coursesColumnNames = typeof(CsvCourses).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR11IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); classesColumnNames = typeof(CsvClasses).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR11IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); enrollmentsColumnNames = typeof(CsvEnrollments).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR11IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); academicsessionsColumnNames = typeof(CsvAcademicSessions).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR11IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); } model.DataPreviewSections = new List <DataPreviewSection> { new DataPreviewSection { SectionName = "orgs", ColumnNames = orgColumnNames, CurrentPage = 1, TotalPages = model.JsonPreviews.OrgsTotalPages }, new DataPreviewSection { SectionName = "users", ColumnNames = usersColumnNames, CurrentPage = 1, TotalPages = model.JsonPreviews.UsersTotalPages }, new DataPreviewSection { SectionName = "courses", ColumnNames = coursesColumnNames, CurrentPage = 1, TotalPages = model.JsonPreviews.CoursesTotalPages }, new DataPreviewSection { SectionName = "classes", ColumnNames = classesColumnNames, CurrentPage = 1, TotalPages = model.JsonPreviews.ClassesTotalPages }, new DataPreviewSection { SectionName = "enrollments", ColumnNames = enrollmentsColumnNames, CurrentPage = 1, TotalPages = model.JsonPreviews.EnrollmentsTotalPages }, new DataPreviewSection { SectionName = "academicsessions", ColumnNames = academicsessionsColumnNames, CurrentPage = 1, TotalPages = model.JsonPreviews.AcademicSessionsTotalPages } }; if (oneRosterVersion == OneRosterVersions.OR_1_1) { var manifestColumnNames = typeof(CsvManifest).GetProperties().Where(x => Attribute.IsDefined(x, typeof(OR11IncludeFieldAttribute))).Select(x => x.Name.Replace("__", ".")); model.DataPreviewSections.Add(new DataPreviewSection { SectionName = "manifest", ColumnNames = manifestColumnNames }); } return(PartialView("_DataPreview", model)); }