Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8ed79de

Browse files
[csharp] [courses_steps_csv] [03_split_parsing_phase] Extract method for the ParseCsv phase 🌈
VS Code is my new best friend. It can extract method ✨
1 parent 78123d8 commit 8ed79de

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

‎examples/csharp/csharp-courses_steps_csv-03_split_parsing_phase/src/CoursesStepsCsv/CourseStepsGetController.cs‎

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,19 @@ public CourseStepsGetController(Platform platform)
2424

2525
public string Get(string courseId)
2626
{
27-
var csv = platform.FindCourseSteps(courseId);
28-
29-
var csvSteps = new List<CsvStep>();
30-
31-
var lines = csv.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
32-
33-
for (int i = 0; i < lines.Length; i++)
34-
{
35-
var row = lines[i].Split(',');
36-
37-
var id = row[0];
38-
var type = row[1];
39-
int? quizTotalQuestions = string.IsNullOrEmpty(row[2]) ? null : int.Parse(row[2]);
40-
int? videoDuration = string.IsNullOrEmpty(row[3]) ? null : int.Parse(row[3]);
41-
42-
if (type != STEP_TYPE_VIDEO && type != STEP_TYPE_QUIZ)
43-
{
44-
continue;
45-
}
46-
47-
var csvStep = new CsvStep(id, type, quizTotalQuestions, videoDuration);
48-
49-
csvSteps.Add(csvStep);
50-
}
27+
List<CsvStep> csvSteps = ParseCsv(courseId);
5128

5229
var results = "[";
5330

54-
lines = csv.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
55-
5631
for (int i = 0; i < csvSteps.Count; i++)
5732
{
58-
var row = lines[i].Split(',');
59-
6033
var csvStep = csvSteps.ElementAt(i);
34+
6135
var id = csvStep.StepId;
6236
var type = csvStep.Type;
6337
var quizTotalQuestions = csvStep.QuizTotalQuestions;
6438
var videoDuration = csvStep.VideoDuration;
65-
39+
6640
var stepDurationInMinutes = 0.0;
6741
var points = 0.0;
6842

@@ -93,7 +67,7 @@ public string Get(string courseId)
9367
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
9468
});
9569

96-
if (i != lines.Length - 1)
70+
if (i != csvSteps.Count - 1)
9771
{
9872
results += ",";
9973
}
@@ -102,5 +76,35 @@ public string Get(string courseId)
10276

10377
return results;
10478
}
79+
80+
private List<CsvStep> ParseCsv(string courseId)
81+
{
82+
var csv = platform.FindCourseSteps(courseId);
83+
84+
var csvSteps = new List<CsvStep>();
85+
86+
var lines = csv.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
87+
88+
for (int i = 0; i < lines.Length; i++)
89+
{
90+
var row = lines[i].Split(',');
91+
92+
var id = row[0];
93+
var type = row[1];
94+
int? quizTotalQuestions = string.IsNullOrEmpty(row[2]) ? null : int.Parse(row[2]);
95+
int? videoDuration = string.IsNullOrEmpty(row[3]) ? null : int.Parse(row[3]);
96+
97+
if (type != STEP_TYPE_VIDEO && type != STEP_TYPE_QUIZ)
98+
{
99+
continue;
100+
}
101+
102+
var csvStep = new CsvStep(id, type, quizTotalQuestions, videoDuration);
103+
104+
csvSteps.Add(csvStep);
105+
}
106+
107+
return csvSteps;
108+
}
105109
}
106110
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /