Skip to content

Commit b9877e5

Browse files
committed
Add additional informations for periods and add methods to get the color of the code / lesson type by the enums
1 parent 311b7d0 commit b9877e5

4 files changed

Lines changed: 106 additions & 6 deletions

File tree

WebUntisAPI.Client/Converter/StatusDataJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override StatusData ReadJson(JsonReader reader, Type objectType, StatusDa
2424

2525
return new StatusData
2626
{
27-
LessonColors = lessonTypes.First(obj => obj.ContainsKey("ls"))["ls"].ToObject<ForeBackColors>(),
27+
LsColors = lessonTypes.First(obj => obj.ContainsKey("ls"))["ls"].ToObject<ForeBackColors>(),
2828
OhColors = lessonTypes.First(obj => obj.ContainsKey("oh"))["oh"].ToObject<ForeBackColors>(),
2929
SbColors = lessonTypes.First(obj => obj.ContainsKey("sb"))["sb"].ToObject<ForeBackColors>(),
3030
BsColors = lessonTypes.First(obj => obj.ContainsKey("bs"))["bs"].ToObject<ForeBackColors>(),
@@ -42,7 +42,7 @@ public override void WriteJson(JsonWriter writer, StatusData value, JsonSerializ
4242

4343
writer.WriteStartObject();
4444
writer.WritePropertyName("ls");
45-
serializer.Serialize(writer, value.LessonColors);
45+
serializer.Serialize(writer, value.LsColors);
4646
writer.WriteEndObject();
4747

4848
writer.WriteStartObject();

WebUntisAPI.Client/Enums.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -78,4 +79,64 @@ public enum Day
7879
/// </summary>
7980
Saturday = 7,
8081
}
82+
83+
/// <summary>
84+
/// All diefrent types of lesons
85+
/// </summary>
86+
public enum LessonType
87+
{
88+
/// <summary>
89+
/// Lesson
90+
/// </summary>
91+
[JsonProperty("ls")]
92+
Ls = 0,
93+
94+
/// <summary>
95+
/// Office hour
96+
/// </summary>
97+
[JsonProperty("oh")]
98+
Oh = 1,
99+
100+
/// <summary>
101+
/// Standby
102+
/// </summary>
103+
[JsonProperty("sb")]
104+
Sb = 2,
105+
106+
/// <summary>
107+
/// Break supervision
108+
/// </summary>
109+
[JsonProperty("bs")]
110+
Bs = 3,
111+
112+
/// <summary>
113+
/// Examination
114+
/// </summary>
115+
[JsonProperty("ex")]
116+
Ex = 4
117+
}
118+
119+
/// <summary>
120+
/// Various codes for the lessons
121+
/// </summary>
122+
public enum Code
123+
{
124+
/// <summary>
125+
/// No code
126+
/// </summary>
127+
[JsonProperty("")]
128+
None = 0,
129+
130+
/// <summary>
131+
/// A cancelled lesson
132+
/// </summary>
133+
[JsonProperty("cancelled")]
134+
Cancelled = 1,
135+
136+
/// <summary>
137+
/// An irregular lesson
138+
/// </summary>
139+
[JsonProperty("irregular")]
140+
Irregular = 2,
141+
}
81142
}

WebUntisAPI.Client/Models/Period.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace WebUntisAPI.Client.Models
1212
/// <summary>
1313
/// A lesson period
1414
/// </summary>
15-
[DebuggerDisplay("On: {Date.Month, nq}.{Date.Day, nq}.{Date.Year, nq}, From {StartTime.Hour, nq}:{StartTime.Minute, nq} to {EndTime.Hour, nq}:{EndTime.Minute, nq}")]
15+
[DebuggerDisplay("On: {Date.Month, nq}.{Date.Day, nq}.{Date.Year, nq}, From {StartTime.Hour, nq}:{StartTime.Minute, nq} to {EndTime.Hour, nq}:{EndTime.Minute, nq}, Type = {LessonType, nq}")]
1616
public class Period
1717
{
1818
/// <summary>
@@ -72,6 +72,30 @@ public class Period
7272
[JsonProperty("ro")]
7373
public ObjectId[] RoomIds { get; set; }
7474

75+
/// <summary>
76+
/// The type of tghe lesson
77+
/// </summary>
78+
[JsonProperty("lstype")]
79+
public LessonType LessonType { get; set; } = LessonType.Ls;
80+
81+
/// <summary>
82+
/// Code for a the lesson
83+
/// </summary>
84+
[JsonProperty("code")]
85+
public Code Code { get; set; } = Code.None;
86+
87+
/// <summary>
88+
/// Statistical flags of the lesson
89+
/// </summary>
90+
[JsonProperty("statflags")]
91+
public string StatisticalFlags { get; set; } = string.Empty;
92+
93+
/// <summary>
94+
/// Text of the lesson
95+
/// </summary>
96+
[JsonProperty("lstext")]
97+
public string LessonText { get; set; } = string.Empty;
98+
7599
/// <summary>
76100
/// The activity type in the lesson
77101
/// </summary>

WebUntisAPI.Client/Models/StatusData.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class StatusData
1818
/// <summary>
1919
/// Colors for a normal lesson
2020
/// </summary>
21-
public ForeBackColors LessonColors { get; set; }
21+
public ForeBackColors LsColors { get; set; }
2222

2323
/// <summary>
2424
/// Colors for a office hour
@@ -49,6 +49,21 @@ public class StatusData
4949
/// Colors for irregular lessons
5050
/// </summary>
5151
public ForeBackColors IrregularLessonColors { get; set; }
52-
52+
53+
/// <summary>
54+
/// Get the <see cref="ForeBackColors"/> from the lesson type
55+
/// </summary>
56+
/// <param name="lessonType">The lesson type</param>
57+
/// <returns>The colors</returns>
58+
public ForeBackColors GetLessonTypeColor(LessonType lessonType) =>
59+
(ForeBackColors)GetType().GetProperties().First(p => p.Name.ToLower() == (lessonType.ToString() + "Colors").ToLower()).GetValue(this);
60+
61+
/// <summary>
62+
/// Get the <see cref="ForeBackColors"/> from the lesson type
63+
/// </summary>
64+
/// <param name="code">The code</param>
65+
/// <returns>The colors. <see langword="null"/> when the code was <see cref="Code.None"/></returns>
66+
public ForeBackColors? GetCodeColor(Code code) =>
67+
GetType().GetProperties().FirstOrDefault(p => p.Name.ToLower() == (code.ToString() + "LessonColors").ToLower())?.GetValue(this) as ForeBackColors?;
5368
}
5469
}

0 commit comments

Comments
 (0)