Skip to content

Commit 4e2577c

Browse files
committed
Made the PersonList<T> class.
1 parent a042187 commit 4e2577c

24 files changed

+259
-82
lines changed

bin/MataSharp.XML

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/MataSharp.dll

2 KB
Binary file not shown.

src/MataSharp/Assignment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public partial class Assignment : IComparable<Assignment>
1414
public uint? Grade { get; set; }
1515
public string Class { get; set; }
1616
public ReadOnlyCollection<Attachment> Attachments { get; set; }
17-
public List<MagisterPerson> Teachers { get; set; }
17+
public PersonList<MagisterPerson> Teachers { get; set; }
1818
public int ID { get; set; }
1919
public DateTime HandInTime { get; set; }
2020
public DateTime DeadLine { get; set; }
@@ -138,7 +138,7 @@ public Assignment toAssignment()
138138
{
139139
Grade = this.Beoordeling,
140140
Attachments = this.Bijlagen.ToList(AttachmentType.Assignment_teacher),
141-
Teachers = this.Docenten.ConvertAll(p => p.ToPerson(true)),
141+
Teachers = this.Docenten.ToList(true),
142142
ID = this.Id,
143143
HandInTime = this.IngeleverdOp.ToDateTime(),
144144
DeadLine = this.InleverenVoor.ToDateTime(),

src/MataSharp/Extensions.cs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
11
using System;
2+
using System.Globalization;
23
using System.Collections.Generic;
34
using System.Collections.ObjectModel;
4-
using System.Globalization;
55

66
namespace MataSharp
77
{
88
public static class Extensions
99
{
10-
/// <summary>
11-
/// Converts the current string to a DateTime.
12-
/// </summary>
13-
/// <returns>The string parsed as DateTime</returns>
14-
internal static DateTime ToDateTime(this String original)
10+
#region General
11+
public static void ForEach<T>(this IEnumerable<T> current, Action<T> action)
1512
{
16-
return (!string.IsNullOrWhiteSpace(original)) ? DateTime.Parse(original, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) : new DateTime();
13+
foreach (var item in current) action(item);
1714
}
1815

19-
/// <summary>
20-
/// Convert the current Attachment[] to a List
21-
/// </summary>
22-
/// <param name="AttachmentType">AttachmentType to give every attachment in the array.</param>
23-
/// <returns>The array as list</returns>
24-
internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentArray, AttachmentType AttachmentType)
16+
public static List<Tout> ConvertAll<Tin, Tout>(this IEnumerable<Tin> current, Converter<Tin, Tout> converter)
2517
{
26-
var tmpList = new List<Attachment>(currentArray);
27-
tmpList.ForEach(a => a.Type = AttachmentType);
28-
return new ReadOnlyCollection<Attachment>(tmpList);
18+
var tmpList = new List<Tout>();
19+
foreach (var item in current) tmpList.Add(converter(item));
20+
return tmpList;
2921
}
22+
#endregion
3023

24+
#region DateTime
3125
/// <summary>
3226
/// Converts the current DateTime instance to a string.
3327
/// </summary>
3428
/// <returns>The current DateTime instance as string.</returns>
35-
internal static string ToUTCString(this DateTime original)
36-
{
29+
internal static string ToUTCString(this DateTime original)
30+
{
3731
return original.ToString("yyyy-MM-ddTHH:mm:ss.0000000Z");
3832
}
3933

@@ -43,7 +37,7 @@ internal static string ToUTCString(this DateTime original)
4337
/// <returns>Dutch day of week that represents the day of the current DateTime instance.</returns>
4438
internal static string DayOfWeekDutch(this DateTime Date)
4539
{
46-
switch(Date.DayOfWeek)
40+
switch (Date.DayOfWeek)
4741
{
4842
case DayOfWeek.Monday: return "maandag";
4943
case DayOfWeek.Tuesday: return "dinsdag";
@@ -66,9 +60,42 @@ internal static string ToString(this DateTime Date, bool dutch)
6660
return (dutch) ? (Date.DayOfWeekDutch() + " " + Date.ToString()) : (Date.DayOfWeek + " " + Date.ToString());
6761
}
6862

69-
public static void ForEach<T>(this IEnumerable<T> current, Action<T> action)
63+
/// <summary>
64+
/// Converts the current string to a DateTime.
65+
/// </summary>
66+
/// <returns>The string parsed as DateTime</returns>
67+
internal static DateTime ToDateTime(this String original)
7068
{
71-
foreach (var item in current) action(item);
69+
return (!string.IsNullOrWhiteSpace(original)) ? DateTime.Parse(original, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) : new DateTime();
70+
}
71+
#endregion
72+
73+
#region Attachments
74+
/// <summary>
75+
/// Convert the current Attachment[] to a List
76+
/// </summary>
77+
/// <param name="AttachmentType">AttachmentType to give every attachment in the array.</param>
78+
/// <returns>The array as list</returns>
79+
internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentArray, AttachmentType AttachmentType)
80+
{
81+
var tmpList = new List<Attachment>(currentArray);
82+
tmpList.ForEach(a => a.Type = AttachmentType);
83+
return new ReadOnlyCollection<Attachment>(tmpList);
84+
}
85+
#endregion
86+
87+
#region PersonList
88+
internal static PersonList<MagisterPerson> ToList(this IEnumerable<MagisterStylePerson> collection, bool download, Mata mata = null)
89+
{
90+
var tmpMata = mata ?? _Session.Mata;
91+
return new PersonList<MagisterPerson>(tmpMata, collection, download);
92+
}
93+
94+
public static PersonList<MagisterPerson> ToList(this IEnumerable<MagisterPerson> collection, Mata mata = null)
95+
{
96+
var tmpMata = mata ?? _Session.Mata;
97+
return new PersonList<MagisterPerson>(tmpMata, collection);
7298
}
99+
#endregion
73100
}
74-
}
101+
}

src/MataSharp/Homework.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public bool Done
2222
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
2323
}
2424
}
25-
public List<MagisterPerson> Teachers { get; set; }
25+
public PersonList<MagisterPerson> Teachers { get; set; }
2626
public DateTime End { get; set; }
2727
public int ID { get; set; }
2828
internal int InfoType;
@@ -132,7 +132,7 @@ public Homework ToHomework()
132132
{
133133
Notes = this.AantekeningLeerling,
134134
_Done = this.Afgerond,
135-
Teachers = this.Docenten.ConvertAll(p => p.ToPerson(true)),
135+
Teachers = this.Docenten.ToList(true),
136136
End = this.Einde.ToDateTime(),
137137
ID = this.Id,
138138
InfoType = this.InfoType,

src/MataSharp/MagisterMessage.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public partial class MagisterMessage : IComparable<MagisterMessage>, ICloneable
1616
public string Subject { get; set; }
1717
public MagisterPerson Sender { get; internal set; }
1818
public string Body { get; set; }
19-
public List<MagisterPerson> Recipients { get; set; }
20-
public List<MagisterPerson> CC { get; set; }
19+
public PersonList<MagisterPerson> Recipients { get; set; }
20+
public PersonList<MagisterPerson> CC { get; set; }
2121
public DateTime SentDate { get; set; }
2222
internal bool _IsRead;
2323

@@ -86,8 +86,8 @@ public MagisterMessage()
8686
this.IDKey = 0;
8787
this.SenderGroupID = this.Mata.Person.GroupID;
8888
this.Sender = this.Mata.Person;
89-
this.Recipients = new List<MagisterPerson>();
90-
this.CC = new List<MagisterPerson>();
89+
this.Recipients = new PersonList<MagisterPerson>(this.Mata);
90+
this.CC = new PersonList<MagisterPerson>(this.Mata);
9191
}
9292

9393
/// <summary>
@@ -112,8 +112,8 @@ public MagisterMessage(Mata Mata)
112112
this.IDKey = 0;
113113
this.SenderGroupID = this.Mata.Person.GroupID;
114114
this.Sender = this.Mata.Person;
115-
this.Recipients = new List<MagisterPerson>();
116-
this.CC = new List<MagisterPerson>();
115+
this.Recipients = new PersonList<MagisterPerson>(this.Mata);
116+
this.CC = new PersonList<MagisterPerson>(this.Mata);
117117
}
118118

119119
/// <summary>
@@ -140,7 +140,7 @@ public MagisterMessage CreateForwardMessage()
140140
Deleted = false,
141141
_IsRead = true,
142142
Subject = tmpSubject,
143-
Recipients = new List<MagisterPerson>(),
143+
Recipients = new PersonList<MagisterPerson>(this.Mata),
144144
Ref = null,
145145
State = 0,
146146
SentDate = DateTime.UtcNow,
@@ -172,7 +172,7 @@ public MagisterMessage CreateForwardMessage(string ContentAdd)
172172
Deleted = false,
173173
_IsRead = true,
174174
Subject = tmpSubject,
175-
Recipients = new List<MagisterPerson>(),
175+
Recipients = new PersonList<MagisterPerson>(this.Mata),
176176
Ref = null,
177177
State = 0,
178178
SentDate = DateTime.UtcNow,
@@ -198,7 +198,7 @@ public MagisterMessage CreateReplyToAllMessage(string ContentAdd)
198198
Sender = this.Sender,
199199
_Folder = this._Folder,
200200
Attachments = new ReadOnlyCollection<Attachment>(new List<Attachment>()),
201-
CC = tmpCC,
201+
CC = new PersonList<MagisterPerson>(this.Mata, tmpCC),
202202
IsFlagged = this.IsFlagged,
203203
ID = this.ID,
204204
SenderGroupID = 4,
@@ -209,7 +209,7 @@ public MagisterMessage CreateReplyToAllMessage(string ContentAdd)
209209
Deleted = false,
210210
_IsRead = true,
211211
Subject = tmpSubject,
212-
Recipients = new List<MagisterPerson>() { this.Sender },
212+
Recipients = new PersonList<MagisterPerson>(this.Mata) { this.Sender },
213213
Ref = null,
214214
State = 0,
215215
SentDate = DateTime.UtcNow,
@@ -242,7 +242,7 @@ public MagisterMessage CreateReplyMessage(string ContentAdd)
242242
Deleted = false,
243243
_IsRead = true,
244244
Subject = tmpSubject,
245-
Recipients = new List<MagisterPerson>() { this.Sender },
245+
Recipients = new PersonList<MagisterPerson>(this.Mata) { this.Sender },
246246
Ref = null,
247247
State = 0,
248248
SentDate = DateTime.UtcNow,
@@ -396,10 +396,10 @@ internal partial class MagisterStyleMessage
396396

397397
public MagisterMessage ToMagisterMessage(int index)
398398
{
399-
var tmpReceivers = this.Ontvangers.ConvertAll(p => p.ToPerson(true));
399+
var tmpReceivers = this.Ontvangers.ToList(true);
400400
tmpReceivers.Sort();
401401

402-
var tmpCopiedReceivers = this.KopieOntvangers.ConvertAll(p => p.ToPerson(true));
402+
var tmpCopiedReceivers = this.KopieOntvangers.ToList(true);
403403
tmpCopiedReceivers.Sort();
404404

405405
return new MagisterMessage()

src/MataSharp/MataSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Mata.cs" />
6363
<Compile Include="MagisterSchool.cs" />
6464
<Compile Include="MessageList.cs" />
65+
<Compile Include="PersonList.cs" />
6566
<Compile Include="Properties\AssemblyInfo.cs" />
6667
<Compile Include="StudyGuide.cs" />
6768
</ItemGroup>

0 commit comments

Comments
 (0)