Skip to content

Commit 64540a2

Browse files
committed
General Improvements
1 parent d84bd92 commit 64540a2

28 files changed

+102
-82
lines changed

bin/MataSharp.XML

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

bin/MataSharp.dll

-512 Bytes
Binary file not shown.

src/MataSharp/Assignment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public Assignment toAssignment(Mata mata)
128128
{
129129
string URL = "https://" + mata.School.URL + "/api/leerlingen/" + mata.UserID + "/opdrachten/" + this.Id + "/versie/" + compactAssignmentVersion.Id;
130130

131-
string versionRaw = mata.HttpClient.DownloadString(URL);
131+
string versionRaw = mata.WebClient.DownloadString(URL);
132132
var versionClean = JsonConvert.DeserializeObject<MagisterStyleAssignmentVersion>(versionRaw);
133133

134134
tmpVersions.Add(versionClean.ToVersion(mata));

src/MataSharp/Attachment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private string URL
6363
public string Download(bool AddUserID, string Directory = "")
6464
{
6565
string fileName = (AddUserID) ? ("(" + this.Mata.UserID + ") " + this.Name) : (this.Name);
66-
return this.Mata.HttpClient.DownloadFile(this.URL, fileName, Directory);
66+
return this.Mata.WebClient.DownloadFile(this.URL, fileName, Directory);
6767
}
6868

6969
public int CompareTo(Attachment other)

src/MataSharp/HTTPClient.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
using System.Text.RegularExpressions;
55
using System.Collections.Specialized;
66
using System.Text;
7+
using System.Security.Authentication;
78

89
namespace MataSharp
910
{
10-
sealed internal class MataHTTPClient : IDisposable
11+
sealed internal class MataWebClient : IDisposable
1112
{
12-
private WebClient Client = new WebClient();
13+
WebClient Client = new WebClient();
1314

1415
internal string Cookie
1516
{
@@ -42,8 +43,7 @@ public string Post(string URL, NameValueCollection Values)
4243
try { tmpArr = this.Client.UploadValues(URL, Values); }
4344
catch(WebException e)
4445
{
45-
if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Unauthorized)
46-
throw new System.Security.Authentication.AuthenticationException("Wrong username and/or password.");
46+
if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.Unauthorized) throw new AuthenticationException("Wrong username and/or password.");
4747
else throw e;
4848
}
4949
return stripString(Encoding.ASCII.GetString(tmpArr));
@@ -55,11 +55,11 @@ public void Post(string URL, string Content)
5555
this.Client.UploadData(URL, System.Text.Encoding.ASCII.GetBytes(Content));
5656
}
5757

58-
public void Delete(string URL, string Cookie)
58+
public void Delete(string URL)
5959
{
6060
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(URL);
6161
req.Method = "DELETE";
62-
req.Headers[HttpRequestHeader.Cookie] = Cookie;
62+
req.Headers[HttpRequestHeader.Cookie] = this.Cookie;
6363
req.Timeout = 15000;
6464
req.GetResponse();
6565
}
@@ -81,7 +81,7 @@ public string DownloadFile(string URL, string Filename, string DIR)
8181
return fullPath;
8282
}
8383

84-
~MataHTTPClient() { this.Dispose(); }
84+
~MataWebClient() { this.Dispose(); }
8585
public void Dispose() { this.Client.Dispose(); }
8686
}
8787
}

src/MataSharp/Homework.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public bool Done
1919
if (this._Done == value) return;
2020

2121
this._Done = value;
22-
this.Mata.HttpClient.Put(this.URL, JsonConvert.SerializeObject(this.ToMagisterStyle()));
22+
this.Mata.WebClient.Put(this.URL, JsonConvert.SerializeObject(this.ToMagisterStyle()));
2323
}
2424
}
2525
public PersonList Teachers { get; set; }

src/MataSharp/MagisterMessage.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace MataSharp
1010
{
11-
public partial class MagisterMessage : IComparable<MagisterMessage>, ICloneable
11+
sealed public partial class MagisterMessage : IComparable<MagisterMessage>, ICloneable
1212
{
1313
#region Contents
1414
public int ID { get; set; }
@@ -30,7 +30,7 @@ public bool IsRead
3030

3131
this._IsRead = value;
3232

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

@@ -84,7 +84,7 @@ public MagisterMessage(Mata Mata)
8484
this._Folder = 0;
8585
this.Deleted = false;
8686
this.IDKey = 0;
87-
this.SenderGroupID = this.Mata.Person.GroupID;
87+
this.SenderGroupID = this.Mata.Person._GroupID;
8888
this.Sender = this.Mata.Person;
8989
this.Recipients = new PersonList(this.Mata);
9090
this.CC = new PersonList(this.Mata);
@@ -248,7 +248,7 @@ public void Move(int FolderID)
248248

249249
this._Folder = FolderID;
250250

251-
this.Mata.HttpClient.Put(this.URL, JsonConvert.SerializeObject(this.ToMagisterStyle()));
251+
this.Mata.WebClient.Put(this.URL, JsonConvert.SerializeObject(this.ToMagisterStyle()));
252252
thisCopied.Delete();
253253
}
254254

@@ -260,7 +260,7 @@ public void Delete()
260260
if (this.Deleted) return;
261261

262262
this.Deleted = true;
263-
this.Mata.HttpClient.Delete(this.URL, "SESSION_ID=" + this.Mata.SessionID + "&fileDownload=true");
263+
this.Mata.WebClient.Delete(this.URL);
264264
}
265265

266266
/// <summary>
@@ -385,7 +385,7 @@ public MagisterMessage ToMagisterMessage(int index)
385385
ID = this.Id,
386386
Ref = this.Ref,
387387
Subject = this.Onderwerp,
388-
Sender = this.Afzender.ToPerson(true),
388+
Sender = this.Afzender.ToPerson(true, this.Mata),
389389
Body = this.Inhoud.Trim(),
390390
Recipients = tmpReceivers,
391391
CC = tmpCopiedReceivers,
@@ -408,7 +408,7 @@ public MagisterMessage ToMagisterMessage(int index)
408408
internal void Send(Mata Mata)
409409
{
410410
string URL = "https://" + Mata.School.URL + "/api/personen/" + Mata.UserID + "/communicatie/berichten/";
411-
this.Mata.HttpClient.Post(URL, JsonConvert.SerializeObject(this));
411+
this.Mata.WebClient.Post(URL, JsonConvert.SerializeObject(this));
412412
}
413413
}
414414
}

src/MataSharp/MagisterPerson.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace MataSharp
88
{
9-
sealed public partial class MagisterPerson : IComparable<MagisterPerson>, ICloneable, IEqualityComparer<MagisterPerson>
9+
sealed public class MagisterPerson : IComparable<MagisterPerson>, ICloneable, IEqualityComparer<MagisterPerson>
1010
{
1111
public uint ID { get; set; }
1212
public object Ref { get; set; } // Even Schoolmaster doesn't know what this is, it's mysterious. Just keep it in case.
@@ -18,8 +18,8 @@ sealed public partial class MagisterPerson : IComparable<MagisterPerson>, IClone
1818
public string Description { get; set; }
1919
public string Group { get; set; }
2020
public string TeacherCode { get; set; }
21-
internal int GroupID;
22-
public PersonType Type { get { return (PersonType)this.GroupID; } }
21+
internal int _GroupID;
22+
public PersonType Type { get { return (PersonType)this._GroupID; } }
2323

2424
internal MagisterPerson Original { get; set; }
2525

@@ -55,7 +55,7 @@ internal MagisterStylePerson ToMagisterStyle()
5555
Omschrijving = tmpPerson.Description,
5656
Groep = tmpPerson.Group,
5757
DocentCode = tmpPerson.TeacherCode,
58-
Type = tmpPerson.GroupID
58+
Type = tmpPerson._GroupID
5959
};
6060
}
6161

@@ -115,31 +115,29 @@ sealed internal class MagisterStylePerson
115115
public string Voornamen { get; set; }
116116
public string Voorletters { get; set; }
117117

118-
public Mata Mata { get; internal set; }
119-
120-
private List<MagisterStylePerson> GetPersons(string SearchFilter)
118+
private MagisterStylePerson[] GetPersons(string SearchFilter, Mata mata)
121119
{
122-
if (string.IsNullOrWhiteSpace(SearchFilter) || SearchFilter.Length < 3) return new List<MagisterStylePerson>();
120+
if (string.IsNullOrWhiteSpace(SearchFilter) || SearchFilter.Length < 3) return new MagisterStylePerson[0];
123121

124-
if (!this.Mata.checkedPersons.ContainsKey(SearchFilter))
122+
if (!mata.CheckedPersons.ContainsKey(SearchFilter))
125123
{
126-
string URL = "https://" + this.Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/contactpersonen?q=" + SearchFilter;
124+
string URL = "https://" + mata.School.URL + "/api/personen/" + mata.UserID + "/communicatie/contactpersonen?q=" + SearchFilter;
127125

128-
string personsRAW = this.Mata.HttpClient.DownloadString(URL);
126+
string personsRAW = mata.WebClient.DownloadString(URL);
129127

130-
var persons = JsonConvert.DeserializeObject<MagisterStylePerson[]>(personsRAW).ToList();
131-
this.Mata.checkedPersons.Add(SearchFilter, persons);
128+
var persons = JsonConvert.DeserializeObject<MagisterStylePerson[]>(personsRAW);
129+
mata.CheckedPersons.Add(SearchFilter, persons);
132130
return persons;
133131
}
134-
else return this.Mata.checkedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value;
132+
else return mata.CheckedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value;
135133
}
136134

137-
public MagisterPerson ToPerson(bool download)
135+
public MagisterPerson ToPerson(bool download, Mata mata)
138136
{
139137
MagisterStylePerson tmpPerson;
140138
if (download)
141139
{
142-
try { tmpPerson = (GetPersons(this.Naam).Count == 1) ? GetPersons(this.Naam)[0] : this; } //Main building ground.
140+
try { tmpPerson = (GetPersons(this.Naam, mata).Length == 1) ? GetPersons(this.Naam, mata).Single() : this; } //Main building ground.
143141
catch { tmpPerson = this; }
144142
}
145143
else tmpPerson = this;
@@ -179,7 +177,7 @@ public MagisterPerson ToPerson(bool download)
179177
Description = tmpPerson.Omschrijving ?? tmpName,
180178
Group = tmpPerson.Groep,
181179
TeacherCode = (!string.IsNullOrWhiteSpace(tmpPerson.DocentCode)) ? tmpPerson.DocentCode : null,
182-
GroupID = tmpPerson.Type,
180+
_GroupID = tmpPerson.Type,
183181
Initials = tmpPerson.Voorletters,
184182
};
185183

src/MataSharp/MagisterSchool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MagisterSchool : IComparable<MagisterSchool>, ICloneable
2323
/// <returns>List containing MagisterSchool instances</returns>
2424
public static List<MagisterSchool> GetSchools(string SearchFilter)
2525
{
26-
if (string.IsNullOrWhiteSpace(SearchFilter) || SearchFilter.Length < 3) return new List<MagisterSchool>();
26+
if (string.IsNullOrWhiteSpace(SearchFilter) || SearchFilter.Length < 3) return new List<MagisterSchool>(0);
2727

2828
string URL = "https://schoolkiezer.magister.net/home/query?filter=" + SearchFilter;
2929

0 commit comments

Comments
 (0)