Skip to content

Commit c22c138

Browse files
committed
Combine MagisterMessageFolder and MessageList.
1 parent 729fb9a commit c22c138

21 files changed

+421
-465
lines changed

bin/MataSharp.XML

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

bin/MataSharp.dll

-1 KB
Binary file not shown.

src/MataSharp/Attachment.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ namespace MataSharp
77
public partial class Attachment : IComparable<Attachment>
88
{
99
[JsonProperty("Id")]
10-
public int ID { get; internal set; }
10+
public int ID { get; private set; }
1111
[JsonProperty("Ref")]
12-
public object Ref { get; internal set; } // Even Schoolmaster doesn't know what this is, it's mysterious. Just keep it in case.
12+
public object Ref { get; private set; } // Even Schoolmaster doesn't know what this is, it's mysterious. Just keep it in case.
1313
[JsonProperty("Naam")]
14-
public string Name { get; internal set; }
14+
public string Name { get; private set; }
1515
[JsonProperty("Datum")]
1616
internal DateTime _Date { get; set; }
1717
[JsonIgnore]
1818
public DateTime Date { get { return this._Date.Date; } }
1919
[JsonProperty("Grootte")]
20-
public int Size { get; internal set; }
20+
public int Size { get; private set; }
2121

2222
[JsonIgnore]
2323
internal AttachmentType Type { get; set; }

src/MataSharp/MagisterMessage.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public bool IsRead
3030

3131
this._IsRead = value;
3232

33-
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
33+
_Session.HttpClient.Put(this.URL, JsonConvert.SerializeObject(this.ToMagisterStyle()));
3434
}
3535
}
3636

@@ -62,7 +62,7 @@ public bool CanSend
6262
private Mata Mata { get; set; }
6363
#endregion
6464

65-
private string URL() { return "https://" + this.Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + this._Folder + "/berichten/" + this.ID; }
65+
private string URL { get { return "https://" + this.Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + this._Folder + "/berichten/" + this.ID; } }
6666

6767
/// <summary>
6868
/// Returns new MagisterMessage.
@@ -274,7 +274,7 @@ public void Move(int FolderID)
274274

275275
this._Folder = FolderID;
276276

277-
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
277+
_Session.HttpClient.Put(this.URL, JsonConvert.SerializeObject(this.ToMagisterStyle()));
278278
thisCopied.Delete();
279279
}
280280

@@ -286,7 +286,7 @@ public void Delete()
286286
if (this.Deleted) return;
287287

288288
this.Deleted = true;
289-
_Session.HttpClient.Delete(this.URL(), "SESSION_ID=" + this.Mata.SessionID + "&fileDownload=true");
289+
_Session.HttpClient.Delete(this.URL, "SESSION_ID=" + this.Mata.SessionID + "&fileDownload=true");
290290
}
291291

292292
/// <summary>

src/MataSharp/Mata.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void ComposeAndSendMessage(string Subject, string Body, IEnumerable<Magis
7979
{
8080
Subject = Subject,
8181
Body = Body,
82-
Recipients = Recipients.ToList()
82+
Recipients = Recipients.ToList(this)
8383
}.Send();
8484
}
8585

@@ -111,7 +111,7 @@ public bool ComposeAndTrySendMessage(string Subject, string Body, IEnumerable<Ma
111111
{
112112
Subject = Subject,
113113
Body = Body,
114-
Recipients = Recipients.ToList()
114+
Recipients = Recipients.ToList(this)
115115
}.TrySend();
116116
}
117117

@@ -141,7 +141,7 @@ public List<MagisterMessageFolder> GetMessageFolders()
141141
string MessageFoldersRAW = _Session.HttpClient.DownloadString(url);
142142
var MessageFolders = JsonConvert.DeserializeObject<MagisterStyleMessageFolderListItem[]>(MessageFoldersRAW);
143143

144-
List<MagisterMessageFolder> tmplst = new List<MagisterMessageFolder>();
144+
var tmplst = new List<MagisterMessageFolder>();
145145
foreach (var messageFolder in MessageFolders)
146146
{
147147
tmplst.Add(new MagisterMessageFolder()

src/MataSharp/MessageFolder.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace MataSharp
77
{
8-
public partial class MagisterMessageFolder
8+
public partial class MagisterMessageFolder : IEnumerable<MagisterMessage>
99
{
1010
public string Name { get; set; }
1111
public uint UnreadMessagesCount { get; set; }
@@ -17,17 +17,6 @@ public partial class MagisterMessageFolder
1717

1818
internal Mata Mata { get; set; }
1919
internal MagisterSchool School { get { return this.Mata.School; } }
20-
21-
public MessageList<MagisterMessage> Messages { get { return new MessageList<MagisterMessage>(this); } }
22-
/// <summary>
23-
/// Gets the MagisterMessage on the given index.
24-
/// </summary>
25-
/// <param name="index">The zero-based index of the MagisterMessage to get.</param>
26-
/// <returns>The MagisterMessage on the given index.</returns>
27-
public MagisterMessage this[int index]
28-
{
29-
get { return this.Messages[index]; }
30-
}
3120
}
3221

3322
public enum MessageFolder : int

src/MataSharp/MessageList.cs

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,36 @@
55

66
namespace MataSharp
77
{
8-
public class MessageList<Message> : IEnumerable<Message> where Message : MagisterMessage
8+
public partial class MagisterMessageFolder : IEnumerable<MagisterMessage>
99
{
10-
private MagisterMessageFolder Sender { get; set; }
11-
12-
public MessageList() { throw new Exception("MessageLists are only able to be internally created."); }
13-
14-
internal MessageList(MagisterMessageFolder Sender)
15-
{
16-
this.Sender = Sender;
17-
}
18-
1910
/// <summary>
2011
/// Gets the item on the given index.
2112
/// </summary>
2213
/// <param name="index">The zero-based index of the item to get.</param>
2314
/// <returns>The item on the given index.</returns>
24-
public Message this[int index] { get { return this.GetSpecificEnumerator().GetAt(index); } }
15+
public MagisterMessage this[int index] { get { return this.GetSpecificEnumerator().GetAt(index); } }
2516

26-
public IEnumerator<Message> GetEnumerator()
17+
public IEnumerator<MagisterMessage> GetEnumerator()
2718
{
28-
return new Enumerator<Message>(this.Sender.Mata, this.Sender);
19+
return new Enumerator<MagisterMessage>(this);
2920
}
3021

3122
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
3223
{
3324
return GetEnumerator();
3425
}
3526

36-
private Enumerator<Message> GetSpecificEnumerator()
27+
private Enumerator<MagisterMessage> GetSpecificEnumerator()
3728
{
38-
return new Enumerator<Message>(this.Sender.Mata, this.Sender);
29+
return new Enumerator<MagisterMessage>(this);
3930
}
4031

41-
public Message ElementAt(int index)
32+
public MagisterMessage ElementAt(int index)
4233
{
4334
return this[index];
4435
}
4536

46-
public List<Message> Take(int count)
37+
public List<MagisterMessage> Take(int count)
4738
{
4839
return this.GetRange(0, count);
4940
}
@@ -54,7 +45,7 @@ public List<Message> Take(int count)
5445
/// <param name="Ammount">Ammount to ask for on the server.</param>
5546
/// <param name="Skip">Ammount of messages to skip | Default = 0</param>
5647
/// <returns>List of unread MagisterMessages.</returns>
57-
public List<Message> WhereUnread(uint Ammount, uint Skip = 0)
48+
public List<MagisterMessage> WhereUnread(uint Ammount, uint Skip = 0)
5849
{
5950
return this.GetSpecificEnumerator().GetUnread(Ammount, Skip);
6051
}
@@ -63,7 +54,7 @@ public List<Message> WhereUnread(uint Ammount, uint Skip = 0)
6354
/// Gets ALL the new messages on the parent's mata server.
6455
/// </summary>
6556
/// <returns>List of unread MagisterMessages.</returns>
66-
public List<Message> WhereUnread()
57+
public List<MagisterMessage> WhereUnread()
6758
{
6859
return this.GetSpecificEnumerator().GetUnread();
6960
}
@@ -93,7 +84,7 @@ public void RemoveRange(int index, int count)
9384
/// <param name="index">The zero-based index at which the range starts.</param>
9485
/// <param name="count">The number of elements in the range.</param>
9586
/// <returns>The given range of MagisterMessages as a List</returns>
96-
public List<Message> GetRange(int index, int count)
87+
public List<MagisterMessage> GetRange(int index, int count)
9788
{
9889
return this.GetSpecificEnumerator().GetRange(count, index);
9990
}
@@ -103,10 +94,10 @@ public List<Message> GetRange(int index, int count)
10394
/// </summary>
10495
/// <param name="item">The item to get its position from.</param>
10596
/// <returns>A zero-based index of the position of the given item.</returns>
106-
public int IndexOf(Message item)
97+
public int IndexOf(MagisterMessage item)
10798
{
10899
var enumerator = this.GetSpecificEnumerator();
109-
Message currentItem = null;
100+
MagisterMessage currentItem = null;
110101
int pos = -1;
111102
do
112103
{
@@ -122,7 +113,7 @@ public int IndexOf(Message item)
122113
/// </summary>
123114
/// <param name="max">The ammount of messages to check for on the server.</param>
124115
/// <param name="predicate">The predicate the messages must match to.</param>
125-
public void RemoveAll(int max, Predicate<Message> predicate)
116+
public void RemoveAll(int max, Predicate<MagisterMessage> predicate)
126117
{
127118
this.GetSpecificEnumerator().GetRange(max, 0).Where(m => predicate(m)).ToList().ForEach(m => m.Delete());
128119
}
@@ -133,7 +124,7 @@ public void RemoveAll(int max, Predicate<Message> predicate)
133124
/// <param name="max">The max value to check for on the server.</param>
134125
/// <param name="predicate">The predicate the messages must match</param>
135126
/// <returns>A List containing the messages that matched the predicate.</returns>
136-
public List<Message> Where(int max, Func<Message,bool> predicate)
127+
public List<MagisterMessage> Where(int max, Func<MagisterMessage, bool> predicate)
137128
{
138129
return this.GetSpecificEnumerator().GetRange(max, 0).Where(m => predicate(m)).ToList();
139130
}
@@ -144,7 +135,7 @@ public List<Message> Where(int max, Func<Message,bool> predicate)
144135
/// <param name="max">The max value to check for on the server.</param>
145136
/// <param name="predicate">The predicate the message must match.</param>
146137
/// <returns>The first message on the server that matches the predicate.</returns>
147-
public Message First(int max, Func<Message,bool> predicate)
138+
public MagisterMessage First(int max, Func<MagisterMessage, bool> predicate)
148139
{
149140
var enumerator = this.GetSpecificEnumerator();
150141
for (int i = 0; i < max; i++)
@@ -161,7 +152,7 @@ public Message First(int max, Func<Message,bool> predicate)
161152
/// <param name="max">The max value to check for on the server.</param>
162153
/// <param name="predicate">The predicate the message must match.</param>
163154
/// <returns>The last message on the server that matches the predicate.</returns>
164-
public Message Last(int max, Func<Message,bool> predicate)
155+
public MagisterMessage Last(int max, Func<MagisterMessage, bool> predicate)
165156
{
166157
return this.GetSpecificEnumerator().GetRange(max, 0).Last(m => predicate(m));
167158
}
@@ -172,15 +163,15 @@ public Message Last(int max, Func<Message,bool> predicate)
172163
/// <param name="max">The max value to check for on the server.</param>
173164
/// <param name="predicate">The predicate the message must match.</param>
174165
/// <returns>The first message on the server that matches the predicate.</returns>
175-
public Message FirstOrDefault(int max, Func<Message, bool> predicate)
166+
public MagisterMessage FirstOrDefault(int max, Func<MagisterMessage, bool> predicate)
176167
{
177168
var enumerator = this.GetSpecificEnumerator();
178169
for (int i = 0; i < max; i++)
179170
{
180171
var msg = enumerator.GetAt(i);
181172
if (predicate(msg)) return msg;
182-
}
183-
return default(Message);
173+
}
174+
return default(MagisterMessage);
184175
}
185176

186177
/// <summary>
@@ -189,17 +180,17 @@ public Message FirstOrDefault(int max, Func<Message, bool> predicate)
189180
/// <param name="max">The max value to check for on the server.</param>
190181
/// <param name="predicate">The predicate the message must match.</param>
191182
/// <returns>The last message on the server that matches the predicate.</returns>
192-
public Message LastOrDefault(int max, Func<Message, bool> predicate)
183+
public MagisterMessage LastOrDefault(int max, Func<MagisterMessage, bool> predicate)
193184
{
194185
var enumerator = this.GetSpecificEnumerator();
195-
Message msg = null;
186+
MagisterMessage msg = null;
196187
for(int i = 0; i < max; i++)
197188
{
198189
var tmpMsg = enumerator.GetAt(i);
199190
if (predicate(tmpMsg)) msg = tmpMsg;
200191
}
201192
if (msg != null) return msg;
202-
else return default(Message);
193+
else return default(MagisterMessage);
203194
}
204195

205196
/// <summary>
@@ -208,7 +199,7 @@ public Message LastOrDefault(int max, Func<Message, bool> predicate)
208199
/// <param name="max">The max value to check for on the server.</param>
209200
/// <param name="predicate">The predicate the message must match.</param>
210201
/// <returns>A boolean value that tells if there is a message matching the given predicate.</returns>
211-
public bool Any(int max, Func<Message, bool> predicate)
202+
public bool Any(int max, Func<MagisterMessage, bool> predicate)
212203
{
213204
var enumerator = this.GetSpecificEnumerator();
214205
for(int i = 0; i < max; i++)
@@ -225,10 +216,10 @@ public bool Any(int max, Func<Message, bool> predicate)
225216
/// <param name="predicate">The predicate that the message must match to.</param>
226217
/// <param name="max">The max ammount of messages to get from the server.</param>
227218
/// <returns>A single MagisterMessage matching the given predicate.</returns>
228-
public Message Single(int max, Func<Message, bool> predicate)
219+
public MagisterMessage Single(int max, Func<MagisterMessage, bool> predicate)
229220
{
230221
var enumerator = this.GetSpecificEnumerator();
231-
Message msg = null;
222+
MagisterMessage msg = null;
232223
for(int i = 0; i <= max; i++)
233224
{
234225
var tmpMsg = enumerator.GetAt(i);
@@ -249,10 +240,10 @@ public Message Single(int max, Func<Message, bool> predicate)
249240
/// <param name="max">The max ammount of messages to get from the server.</param>
250241
/// <param name="predicate">The predicate that the message must match to.</param>
251242
/// <returns>A single MagisterMessage matching the given predicate.</returns>
252-
public Message SingleOrDefault(int max, Func<Message, bool> predicate)
243+
public MagisterMessage SingleOrDefault(int max, Func<MagisterMessage, bool> predicate)
253244
{
254245
var enumerator = this.GetSpecificEnumerator();
255-
Message msg = null;
246+
MagisterMessage msg = null;
256247
for (int i = 0; i <= max; i++)
257248
{
258249
var tmpMsg = enumerator.GetAt(i);
@@ -263,30 +254,29 @@ public Message SingleOrDefault(int max, Func<Message, bool> predicate)
263254
}
264255
}
265256
if (msg != null) return msg;
266-
else return default(Message);
257+
else return default(MagisterMessage);
267258
}
268259

269260
/// <summary>
270261
/// Checks if the given messages exist on the servers.
271262
/// </summary>
272263
/// <param name="item">The item to check if it exists.</param>
273264
/// <returns>A boolean value telling if the given message exists.</returns>
274-
public bool Contains(Message item)
265+
public bool Contains(MagisterMessage item)
275266
{
276-
return (!item.Deleted && this.Sender.FolderType == item.Folder);
267+
return (!item.Deleted && this.FolderType == item.Folder);
277268
}
278269

279-
private class Enumerator<T> : IEnumerator<T>, IDisposable where T : Message
270+
private class Enumerator<T> : IEnumerator<T>, IDisposable where T : MagisterMessage
280271
{
281272
private int Next = 0;
282273
private int Skip = -1;
283-
private Mata Mata { get; set; }
274+
private Mata Mata { get { return this.Sender.Mata; } }
284275
private MagisterMessageFolder Sender { get; set; }
285276
private const int MaxMessages = 750;
286277

287-
public Enumerator(Mata Mata, MagisterMessageFolder Sender)
278+
public Enumerator(MagisterMessageFolder Sender)
288279
{
289-
this.Mata = Mata;
290280
this.Sender = Sender;
291281
}
292282

@@ -401,7 +391,6 @@ public void Reset()
401391
public void Dispose()
402392
{
403393
this.Reset();
404-
this.Mata = null;
405394
this.Sender = null;
406395
GC.Collect();
407396
}

0 commit comments

Comments
 (0)