Skip to content

Commit afb306c

Browse files
committed
General Improvements
1 parent dd4dffd commit afb306c

20 files changed

+46
-50
lines changed

bin/MataSharp.dll

0 Bytes
Binary file not shown.

src/MataSharp/Extensions.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace MataSharp
99
public static class Extensions
1010
{
1111
#region General
12-
public static void ForEach<T>(this IEnumerable<T> current, Action<T> action)
12+
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
1313
{
14-
foreach (var item in current) action(item);
14+
foreach (var item in collection) action(item);
1515
}
1616

1717
public static List<Tout> ConvertAll<Tin, Tout>(this IEnumerable<Tin> current, Converter<Tin, Tout> converter)
@@ -97,12 +97,5 @@ public static PersonList ToList(this IEnumerable<MagisterPerson> collection, Ma
9797
return new PersonList(collection, mata);
9898
}
9999
#endregion
100-
101-
internal static MagisterStyleMessage ToMagisterStyleMsg(this string rawData, Mata mata)
102-
{
103-
var tmpMsg = JsonConvert.DeserializeObject<MagisterStyleMessage>(rawData);
104-
tmpMsg.Mata = mata;
105-
return tmpMsg;
106-
}
107100
}
108101
}

src/MataSharp/MagisterMessage.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ internal MagisterStyleMessage ToMagisterStyle()
319319
BerichtMapId = this._Folder,
320320
IsDefinitiefVerwijderd = this.Deleted,
321321
IdKey = this.IDKey,
322-
IdDeelNameSoort = this.SenderGroupID,
323-
Mata = this.Mata
322+
IdDeelNameSoort = this.SenderGroupID
324323
};
325324
}
326325

@@ -367,25 +366,22 @@ sealed internal partial class MagisterStyleMessage
367366
public bool IsDefinitiefVerwijderd { get; set; }
368367
public int IdKey { get; set; }
369368
public int IdDeelNameSoort { get; set; }
370-
371-
[JsonIgnore]
372-
public Mata Mata { get; internal set; }
373369
#endregion
374370

375-
public MagisterMessage ToMagisterMessage(bool download, int index)
371+
public MagisterMessage ToMagisterMessage(Mata mata, bool download, int index)
376372
{
377-
var tmpReceivers = this.Ontvangers.ToList(download, true, this.Mata);
373+
var tmpReceivers = this.Ontvangers.ToList(download, true, mata);
378374
tmpReceivers.Sort();
379375

380-
var tmpCopiedReceivers = this.KopieOntvangers.ToList(download, true, this.Mata);
376+
var tmpCopiedReceivers = this.KopieOntvangers.ToList(download, true, mata);
381377
tmpCopiedReceivers.Sort();
382378

383-
return new MagisterMessage(this.Mata)
379+
return new MagisterMessage(mata)
384380
{
385381
ID = this.Id,
386382
Ref = this.Ref,
387383
Subject = this.Onderwerp,
388-
Sender = this.Afzender.ToPerson(download, this.Mata),
384+
Sender = this.Afzender.ToPerson(download, mata),
389385
Body = this.Inhoud.Trim(),
390386
Recipients = tmpReceivers,
391387
CC = tmpCopiedReceivers,
@@ -395,7 +391,7 @@ public MagisterMessage ToMagisterMessage(bool download, int index)
395391
IsFlagged = this.HeeftPrioriteit,
396392
IDOriginal = this.IdOorspronkelijkeBericht,
397393
IDOrginalReceiver = this.IdOntvangerOorspronkelijkeBericht,
398-
Attachments = this.Bijlagen.ToList(AttachmentType.Message, this.Mata),
394+
Attachments = this.Bijlagen.ToList(AttachmentType.Message, mata),
399395
_Folder = this.BerichtMapId,
400396
Deleted = this.IsDefinitiefVerwijderd,
401397
IDKey = this.IdKey,
@@ -405,10 +401,10 @@ public MagisterMessage ToMagisterMessage(bool download, int index)
405401
};
406402
}
407403

408-
internal void Send(Mata Mata)
404+
internal void Send(Mata mata)
409405
{
410-
string URL = "https://" + Mata.School.URL + "/api/personen/" + Mata.UserID + "/communicatie/berichten/";
411-
this.Mata.WebClient.Post(URL, JsonConvert.SerializeObject(this));
406+
string URL = "https://" + mata.School.URL + "/api/personen/" + mata.UserID + "/communicatie/berichten/";
407+
mata.WebClient.Post(URL, JsonConvert.SerializeObject(this));
412408
}
413409
}
414410
}

src/MataSharp/Mata.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
using System.Collections.Specialized;
66
using System.Linq;
77
using Newtonsoft.Json;
8-
//using Newtonsoft.Json.Linq;
98

109
namespace MataSharp
1110
{
1211
/// <summary>
1312
/// Type to communicate with a Magister School's server.
1413
/// </summary>
15-
sealed public partial class Mata : IDisposable, ICloneable
14+
sealed public class Mata : IDisposable, ICloneable
1615
{
1716
public string Name { get; private set; }
1817
public uint UserID { get; private set; }
@@ -162,7 +161,7 @@ public PersonList GetPersons(string SearchFilter)
162161
this.CheckedPersons.Add(SearchFilter, personRaw);
163162
return new PersonList(this, personRaw, false, false);
164163
}
165-
else return new PersonList(this, this.CheckedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value,false, false);
164+
else return new PersonList(this, this.CheckedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value, false, false);
166165
}
167166

168167
public List<Homework> GetHomework()

src/MataSharp/MessageList.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public int IndexOf(MagisterMessage item)
123123
/// <param name="predicate">The predicate the messages must match to.</param>
124124
public void RemoveAll(int max, Predicate<MagisterMessage> predicate)
125125
{
126-
this.GetSpecificEnumerator().GetRange(true, max, 0).Where(m => predicate(m)).ToList().ForEach(m => m.Delete());
126+
this.Take(max, true).Where(m => predicate(m)).ForEach(m => m.Delete());
127127
}
128128

129129
/// <summary>
@@ -134,7 +134,7 @@ public void RemoveAll(int max, Predicate<MagisterMessage> predicate)
134134
/// <returns>A List containing the messages that matched the predicate.</returns>
135135
public List<MagisterMessage> Where(int max, Func<MagisterMessage, bool> predicate, bool download = true)
136136
{
137-
return this.GetSpecificEnumerator().GetRange(download, max, 0).Where(m => predicate(m)).ToList();
137+
return this.Take(max, download).Where(m => predicate(m)).ToList();
138138
}
139139

140140
/// <summary>
@@ -307,8 +307,8 @@ public MagisterMessage Current
307307

308308
URL = "https://" + Mata.School.URL + "/api/personen/" + Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
309309
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
310-
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
311-
return MessageClean.ToMagisterMessage(true, this.Skip);
310+
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
311+
return MessageClean.ToMagisterMessage(this.Mata, true, this.Skip);
312312
}
313313
}
314314

@@ -321,8 +321,8 @@ public MagisterMessage GetAt(bool download, int index)
321321

322322
URL = "https://" + Mata.School.URL + "/api/personen/" + Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
323323
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
324-
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
325-
return MessageClean.ToMagisterMessage(download, index);
324+
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
325+
return MessageClean.ToMagisterMessage(this.Mata, download, index);
326326
}
327327

328328
public List<MagisterMessage> GetRange(bool download, int Ammount, int Skip)
@@ -337,8 +337,8 @@ public List<MagisterMessage> GetRange(bool download, int Ammount, int Skip)
337337
{
338338
URL = "https://" + Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
339339
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
340-
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
341-
list.Add(MessageClean.ToMagisterMessage(download, i));
340+
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
341+
list.Add(MessageClean.ToMagisterMessage(this.Mata, download, i));
342342
i++;
343343
}
344344
return list;
@@ -356,8 +356,8 @@ public List<MagisterMessage> GetUnread(bool download, uint Ammount, uint Skip =
356356
{
357357
URL = "https://" + Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
358358
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
359-
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
360-
list.Add(MessageClean.ToMagisterMessage(download, i));
359+
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
360+
list.Add(MessageClean.ToMagisterMessage(this.Mata, download, i));
361361
i++;
362362
}
363363
return list;
@@ -377,8 +377,8 @@ public List<MagisterMessage> GetUnread(bool download)
377377
{
378378
URL = "https://" + Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
379379
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
380-
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
381-
list.Add(MessageClean.ToMagisterMessage(download, index));
380+
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
381+
list.Add(MessageClean.ToMagisterMessage(this.Mata, download, index));
382382
i++;
383383
}
384384
}

src/MataSharp/PersonList.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ public int Count
104104
get { return this.List.Count; }
105105
}
106106

107+
public void Insert(int index, MagisterPerson item)
108+
{
109+
if (this.IsReadOnly) ThrowException();
110+
this.List.Insert(index, item);
111+
}
112+
113+
public void Insert(int index, string name)
114+
{
115+
if (this.IsReadOnly) ThrowException();
116+
this.List.Insert(index, this.Mata.GetPersons(name)[0]);
117+
}
118+
107119
public void InsertRange(int index, IEnumerable<MagisterPerson> collection)
108120
{
109121
if (this.IsReadOnly) ThrowException();
@@ -119,7 +131,7 @@ public void InsertRange(int index, IEnumerable<string> collection)
119131
public void InsertRange(int index, string name)
120132
{
121133
if (this.IsReadOnly) ThrowException();
122-
this.List.InsertRange(index, (IEnumerable<MagisterPerson>)this.Mata.GetPersons(name));
134+
this.List.InsertRange(index, this.Mata.GetPersons(name));
123135
}
124136

125137
internal void InsertRange(int index, IEnumerable<MagisterStylePerson> collection, bool download)
@@ -178,12 +190,6 @@ public int IndexOf(MagisterPerson item)
178190
return this.List.IndexOf(item);
179191
}
180192

181-
public void Insert(int index, MagisterPerson item)
182-
{
183-
if (this.IsReadOnly) ThrowException();
184-
this.List.Insert(index, item);
185-
}
186-
187193
public MagisterPerson this[int index]
188194
{
189195
get

src/MataSharp/Properties/AssemblyInfo.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
4+
using System.Resources;
45

56
// General Information about an assembly is controlled through the following
67
// set of attributes. Change these attribute values to modify the information
78
// associated with an assembly.
89
[assembly: AssemblyTitle("MataSharp")]
9-
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyDescription("Public C# implementation of the non public 'Mata' API.")]
1011
[assembly: AssemblyConfiguration("")]
1112
[assembly: AssemblyCompany("")]
1213
[assembly: AssemblyProduct("MataSharp")]
13-
[assembly: AssemblyCopyright("Copyright © 2013")]
14+
[assembly: AssemblyCopyright("Copyright © 2014 Lieuwe Rooijakkers")]
1415
[assembly: AssemblyTrademark("")]
1516
[assembly: AssemblyCulture("")]
1617

@@ -32,5 +33,6 @@
3233
// You can specify all the values or you can default the Build and Revision Numbers
3334
// by using the '*' as shown below:
3435
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
36+
[assembly: AssemblyVersion("2.0.0.0")]
37+
[assembly: AssemblyFileVersion("2.0.0.0")]
38+
[assembly: NeutralResourcesLanguageAttribute("en-GB")]
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
156 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)