Skip to content

Commit 45dbd70

Browse files
committed
Death to global variables.
1 parent b7b998d commit 45dbd70

28 files changed

+223
-210
lines changed

bin/MataSharp.XML

Lines changed: 16 additions & 8 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: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,18 @@ internal partial struct MagisterStyleAssignmentVersion
8989
public string LeerlingOpmerking { get; set; }
9090
public string Titel { get; set; }
9191

92+
public Mata Mata { get; internal set; }
93+
9294
public AssignmentVersion ToVersion()
9395
{
9496
return new AssignmentVersion()
9597
{
9698
Grade = this.Beoordeling,
9799
TeacherNotice = this.DocentOpmerking,
98-
FeedbackAttachments = this.FeedbackBijlagen.ToList(AttachmentType.Assignment_teacher),
100+
FeedbackAttachments = this.FeedbackBijlagen.ToList(AttachmentType.Assignment_teacher, this.Mata),
99101
HandInTime = this.IngeleverdOp.ToDateTime(),
100102
DeadLine = this.InleverenVoor.ToDateTime(),
101-
HandedInAttachments = this.LeerlingBijlagen.ToList(AttachmentType.Assignment_pupil),
103+
HandedInAttachments = this.LeerlingBijlagen.ToList(AttachmentType.Assignment_pupil, this.Mata),
102104
HandedInFooter = this.LeerlingOpmerking,
103105
Name = this.Titel
104106
};
@@ -121,24 +123,26 @@ internal partial struct AssignmentFolderItem
121123
public string Vak { get; set; }
122124
public MagisterStyleAssignmentListVersion[] VersieNavigatieItems { get; set; }
123125

126+
public Mata Mata { get; internal set; }
127+
124128
public Assignment toAssignment()
125129
{
126130
var tmpVersions = new List<AssignmentVersion>();
127131
foreach(var compactAssignmentVersion in this.VersieNavigatieItems)
128132
{
129-
string URL = "https://" + _Session.School.URL + "/api/leerlingen/" + _Session.Mata.UserID + "/opdrachten/" + this.Id + "/versie/" + compactAssignmentVersion.Id;
133+
string URL = "https://" + this.Mata.School.URL + "/api/leerlingen/" + this.Mata.UserID + "/opdrachten/" + this.Id + "/versie/" + compactAssignmentVersion.Id;
130134

131-
string versionRaw = _Session.HttpClient.DownloadString(URL);
132-
var versionClean = JsonConvert.DeserializeObject<MagisterStyleAssignmentVersion>(versionRaw);
135+
string versionRaw = this.Mata.HttpClient.DownloadString(URL);
136+
var versionClean = JsonConvert.DeserializeObject<MagisterStyleAssignmentVersion>(versionRaw); versionClean.Mata = this.Mata;
133137

134138
tmpVersions.Add(versionClean.ToVersion());
135139
}
136140

137141
return new Assignment()
138142
{
139143
Grade = this.Beoordeling,
140-
Attachments = this.Bijlagen.ToList(AttachmentType.Assignment_teacher),
141-
Teachers = this.Docenten.ToList(true, true),
144+
Attachments = this.Bijlagen.ToList(AttachmentType.Assignment_teacher, this.Mata),
145+
Teachers = this.Docenten.ToList(true, true, this.Mata),
142146
ID = this.Id,
143147
HandInTime = this.IngeleverdOp.ToDateTime(),
144148
DeadLine = this.InleverenVoor.ToDateTime(),

src/MataSharp/Attachment.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,24 @@ public string MIME
3333
get { return (!string.IsNullOrWhiteSpace(this.Name)) ? MimeMapping.GetMimeMapping(this.Name) : "application/octet-stream"; }
3434
}
3535

36+
[JsonIgnore]
37+
public Mata Mata { get; internal set; }
38+
3639
private string URL
3740
{
3841
get
3942
{
4043
if (this.Type == AttachmentType.Message)
41-
return "https://" + _Session.School.URL + "/api/personen/" + _Session.Mata.UserID + "/communicatie/berichten/bijlagen/" + this.ID;
44+
return "https://" + this.Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/bijlagen/" + this.ID;
4245

4346
else if (this.Type == AttachmentType.Assignment_pupil)
44-
return "https://" + _Session.School.URL + "/api/leerlingen/" + _Session.Mata.UserID + "/opdrachten/bijlagen/Ingeleverd/" + this.ID;
47+
return "https://" + this.Mata.School.URL + "/api/leerlingen/" + this.Mata.UserID + "/opdrachten/bijlagen/Ingeleverd/" + this.ID;
4548

4649
else if (this.Type == AttachmentType.Assignment_teacher)
47-
return "https://" + _Session.School.URL + "/api/leerlingen/" + _Session.Mata.UserID + "/opdrachten/bijlagen/" + this.ID;
50+
return "https://" + this.Mata.School.URL + "/api/leerlingen/" + this.Mata.UserID + "/opdrachten/bijlagen/" + this.ID;
4851

4952
else
50-
return "https://" + _Session.School.URL + "/api/leerlingen/" + _Session.Mata.UserID + "/studiewijzers/" + this.StudyGuideID + "/onderdelen/" + this.StudyGuidePartID + "/bijlagen/" + this.ID;
53+
return "https://" + this.Mata.School.URL + "/api/leerlingen/" + this.Mata.UserID + "/studiewijzers/" + this.StudyGuideID + "/onderdelen/" + this.StudyGuidePartID + "/bijlagen/" + this.ID;
5154
}
5255
}
5356

@@ -59,8 +62,8 @@ private string URL
5962
/// <returns>A string containting the path to the location of the downloaded attachment.</returns>
6063
public string Download(bool AddUserID, string Directory = "")
6164
{
62-
string fileName = (AddUserID) ? ("(" + _Session.Mata.UserID + ") " + this.Name) : (this.Name);
63-
return _Session.HttpClient.DownloadFile(this.URL, fileName, Directory);
65+
string fileName = (AddUserID) ? ("(" + this.Mata.UserID + ") " + this.Name) : (this.Name);
66+
return this.Mata.HttpClient.DownloadFile(this.URL, fileName, Directory);
6467
}
6568

6669
public int CompareTo(Attachment other)

src/MataSharp/Extensions.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Globalization;
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
5+
using Newtonsoft.Json;
56

67
namespace MataSharp
78
{
@@ -74,27 +75,34 @@ internal static DateTime ToDateTime(this String original)
7475
/// <summary>
7576
/// Convert the current Attachment[] to a List
7677
/// </summary>
77-
/// <param name="AttachmentType">AttachmentType to give every attachment in the array.</param>
78+
/// <param name="attachmentType">AttachmentType to give every attachment in the array.</param>
7879
/// <returns>The array as list</returns>
79-
internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentArray, AttachmentType AttachmentType)
80+
internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentArray, AttachmentType attachmentType, Mata mata)
8081
{
8182
var tmpList = new List<Attachment>(currentArray);
82-
tmpList.ForEach(a => a.Type = AttachmentType);
83+
tmpList.ForEach(a => a.Type = attachmentType);
84+
tmpList.ForEach(a => a.Mata = mata);
8385
return new ReadOnlyCollection<Attachment>(tmpList);
8486
}
8587
#endregion
8688

8789
#region PersonList
88-
internal static PersonList ToList(this IEnumerable<MagisterStylePerson> collection, bool download,bool ReadOnly = false, Mata mata = null)
90+
internal static PersonList ToList(this IEnumerable<MagisterStylePerson> collection, bool download, bool ReadOnly, Mata mata)
8991
{
90-
var tmpMata = mata ?? _Session.Mata;
91-
return new PersonList(tmpMata, collection,ReadOnly, download);
92+
return new PersonList(mata, collection, ReadOnly, download);
9293
}
9394

94-
public static PersonList ToList(this IEnumerable<MagisterPerson> collection, Mata mata = null)
95+
public static PersonList ToList(this IEnumerable<MagisterPerson> collection, Mata mata)
9596
{
9697
return new PersonList(collection, mata);
9798
}
9899
#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+
}
99107
}
100108
}

src/MataSharp/Homework.cs

Lines changed: 8 additions & 5 deletions
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-
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
22+
this.Mata.HttpClient.Put(this.URL, JsonConvert.SerializeObject(this.ToMagisterStyle()));
2323
}
2424
}
2525
public PersonList Teachers { get; set; }
@@ -37,7 +37,9 @@ public bool Done
3737
public string ClassName { get; set; }
3838
public string ClassAbbreviation { get; set; }
3939

40-
internal string URL() { return "https://" + _Session.School.URL + "/api/leerlingen/" + _Session.Mata.UserID + "/huiswerk/huiswerk/" + this.ID; }
40+
public Mata Mata { get; internal set; }
41+
42+
internal string URL { get { return "https://" + this.Mata.School.URL + "/api/leerlingen/" + this.Mata.UserID + "/huiswerk/huiswerk/" + this.ID; } }
4143

4244
internal Huiswerk ToMagisterStyle()
4345
{
@@ -126,13 +128,13 @@ internal partial class Huiswerk
126128
public int Status { get; set; }
127129
public string VakOmschrijvingen { get; set; }
128130

129-
public Homework ToHomework()
131+
public Homework ToHomework(Mata mata)
130132
{
131133
return new Homework()
132134
{
133135
Notes = this.AantekeningLeerling,
134136
_Done = this.Afgerond,
135-
Teachers = this.Docenten.ToList(true, true),
137+
Teachers = this.Docenten.ToList(true, true, mata),
136138
End = this.Einde.ToDateTime(),
137139
ID = this.Id,
138140
InfoType = this.InfoType,
@@ -143,7 +145,8 @@ public Homework ToHomework()
143145
ClassDescription = this.Omschrijving,
144146
Start = this.Start.ToDateTime(),
145147
State = this.Status,
146-
ClassName = this.VakOmschrijvingen
148+
ClassName = this.VakOmschrijvingen,
149+
Mata = mata
147150
};
148151
}
149152
}

0 commit comments

Comments
 (0)