Skip to content

Commit 1eb633d

Browse files
committed
Improved PersonList<T>
1 parent 4e2577c commit 1eb633d

21 files changed

+180
-21
lines changed

bin/MataSharp.XML

Lines changed: 23 additions & 0 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: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,22 @@ public string MIME
3333
get { return (!string.IsNullOrWhiteSpace(this.Name)) ? MimeMapping.GetMimeMapping(this.Name) : "application/octet-stream"; }
3434
}
3535

36-
private string URL()
36+
private string URL
3737
{
38-
if (this.Type == AttachmentType.Message)
39-
return "https://" + _Session.School.URL + "/api/personen/" + _Session.Mata.UserID + "/communicatie/berichten/bijlagen/" + this.ID;
38+
get
39+
{
40+
if (this.Type == AttachmentType.Message)
41+
return "https://" + _Session.School.URL + "/api/personen/" + _Session.Mata.UserID + "/communicatie/berichten/bijlagen/" + this.ID;
4042

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

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

47-
else
48-
return "https://" + _Session.School.URL + "/api/leerlingen/" + _Session.Mata.UserID + "/studiewijzers/" + this.StudyGuideID + "/onderdelen/" + this.StudyGuidePartID + "/bijlagen/" + this.ID;
49+
else
50+
return "https://" + _Session.School.URL + "/api/leerlingen/" + _Session.Mata.UserID + "/studiewijzers/" + this.StudyGuideID + "/onderdelen/" + this.StudyGuidePartID + "/bijlagen/" + this.ID;
51+
}
4952
}
5053

5154
/// <summary>
@@ -57,7 +60,7 @@ private string URL()
5760
public string Download(bool AddUserID, string Directory = "")
5861
{
5962
string fileName = (AddUserID) ? ("(" + _Session.Mata.UserID + ") " + this.Name) : (this.Name);
60-
return _Session.HttpClient.DownloadFile(URL(), fileName, Directory);
63+
return _Session.HttpClient.DownloadFile(this.URL, fileName, Directory);
6164
}
6265

6366
public int CompareTo(Attachment other)

src/MataSharp/HTTPClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private static string stripString(string original)
2222
string stripped = Regex.Replace(original, "<br />|<p />|<p>|[\r\n]", "\n");
2323
stripped = stripped.Replace("&nbsp;", " ");
2424
stripped = Regex.Replace(stripped, "<[^>]*>|&[^&;]+;", "");
25-
return stripped.Replace("ā,¬", "€").Replace("Ć«", "ë").Replace("Ć©", "é");
25+
return stripped.Replace("ā,¬", "€").Replace("Ć«", "ë").Replace("Ć©", "é").Replace("é", "é");
2626
}
2727

2828
public string DownloadString(string URL)

src/MataSharp/MagisterPerson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public MagisterPerson ToPerson(bool download)
143143
{
144144
try
145145
{
146-
splitted.RemoveAt(0); splitted.RemoveAt(splitted.Count - 1);
146+
splitted.RemoveAt(0); splitted.Remove(splitted.Last());
147147

148148
if (splitted != null && splitted.Count != 0 && splitted[0] != "")
149149
tmpPrefix = string.Join(" ", splitted);

src/MataSharp/Mata.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ public void ComposeAndSendMessage(string Subject, string Body, IEnumerable<Magis
8383
}.Send();
8484
}
8585

86+
/// <summary>
87+
/// Quickly composes new MagisterMessage and sends it.
88+
/// </summary>
89+
/// <param name="Subject">Subject to use</param>
90+
/// <param name="Body">Body to use</param>
91+
/// <param name="Recipients">Name of the persons to send to</param>
92+
public void ComposeAndSendMessage(string Subject, string Body, IEnumerable<string> Recipients)
93+
{
94+
new MagisterMessage(this)
95+
{
96+
Subject = Subject,
97+
Body = Body,
98+
Recipients = new PersonList<MagisterPerson>(this, Recipients)
99+
}.Send();
100+
}
101+
86102
/// <summary>
87103
/// Quickly composes new MagisterMessage and sends it. Instead of throwing exceptions (ComposeAndSendMessage()) this gives back a boolean value.
88104
/// </summary>
@@ -99,6 +115,22 @@ public bool ComposeAndTrySendMessage(string Subject, string Body, IEnumerable<Ma
99115
}.TrySend();
100116
}
101117

118+
/// <summary>
119+
/// Quickly composes new MagisterMessage and sends it. Instead of throwing exceptions (ComposeAndSendMessage()) this gives back a boolean value.
120+
/// </summary>
121+
/// <param name="Subject">Subject to use</param>
122+
/// <param name="Body">Body to use</param>
123+
/// <param name="Recipients">MagisterPersons to send to</param>
124+
public bool ComposeAndTrySendMessage(string Subject, string Body, IEnumerable<string> Recipients)
125+
{
126+
return new MagisterMessage(this)
127+
{
128+
Subject = Subject,
129+
Body = Body,
130+
Recipients = new PersonList<MagisterPerson>(this, Recipients)
131+
}.TrySend();
132+
}
133+
102134
/// <summary>
103135
/// <para>Get all messagefolders linked with the current Mata instance.</para>
104136
/// </summary>

src/MataSharp/MessageFolder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public partial class MagisterMessageFolder
1919
internal MagisterSchool School { get { return this.Mata.School; } }
2020

2121
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+
}
2231
}
2332

2433
public enum MessageFolder : int

src/MataSharp/PersonList.cs

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System.Linq;
2+
using System.Collections.Generic;
23

34
namespace MataSharp
45
{
@@ -33,14 +34,14 @@ public PersonList(Mata mata, IEnumerable<T> collection)
3334

3435
public PersonList(Mata mata, IEnumerable<string> collection)
3536
{
36-
this.List = new List<T>();
37+
this.List = new List<T>(collection.Count());
3738
this.Mata = mata;
3839
this.AddRange(collection);
3940
}
4041

4142
internal PersonList(Mata mata, IEnumerable<MagisterStylePerson> collection, bool download)
4243
{
43-
this.List = new List<T>();
44+
this.List = new List<T>(collection.Count());
4445
this.Mata = mata;
4546
this.AddRange(collection, download);
4647
}
@@ -70,6 +71,11 @@ public void AddRange(IEnumerable<string> collection)
7071
this.List.AddRange(collection.ConvertAll(x => (T)this.Mata.GetPersons(x)[0]));
7172
}
7273

74+
public void AddRange(string name)
75+
{
76+
this.List.AddRange((IEnumerable<T>)this.Mata.GetPersons(name));
77+
}
78+
7379
internal void AddRange(IEnumerable<MagisterStylePerson> collection, bool download)
7480
{
7581
this.List.AddRange(collection.ConvertAll(p => (T)p.ToPerson(download)));
@@ -95,6 +101,26 @@ public int Count
95101
get { return this.List.Count; }
96102
}
97103

104+
public void InsertRange(int index, IEnumerable<T> collection)
105+
{
106+
this.List.InsertRange(index, collection);
107+
}
108+
109+
public void InsertRange(int index, IEnumerable<string> collection)
110+
{
111+
this.List.InsertRange(index, collection.ConvertAll(x => (T)this.Mata.GetPersons(x)[0]));
112+
}
113+
114+
public void InsertRange(int index, string name)
115+
{
116+
this.List.InsertRange(index, (IEnumerable<T>)this.Mata.GetPersons(name));
117+
}
118+
119+
internal void InsertRange(int index, IEnumerable<MagisterStylePerson> collection, bool download)
120+
{
121+
this.List.InsertRange(index, collection.ConvertAll(p => (T)p.ToPerson(download)));
122+
}
123+
98124
public bool IsReadOnly
99125
{
100126
get { return false; }
@@ -105,6 +131,31 @@ public bool Remove(T item)
105131
return this.List.Remove(item);
106132
}
107133

134+
public void RemoveRange(int index, int count)
135+
{
136+
this.List.RemoveRange(index, count);
137+
}
138+
139+
public void RemoveAt(int index)
140+
{
141+
this.List.RemoveAt(index);
142+
}
143+
144+
public int RemoveAll(System.Predicate<T> predicate)
145+
{
146+
return this.List.RemoveAll(predicate);
147+
}
148+
149+
public void TrimExcess()
150+
{
151+
this.List.TrimExcess();
152+
}
153+
154+
public bool TrueForAll(System.Predicate<T> predicate)
155+
{
156+
return this.List.TrueForAll(predicate);
157+
}
158+
108159
public IEnumerator<T> GetEnumerator()
109160
{
110161
return this.List.GetEnumerator();
@@ -125,11 +176,6 @@ public void Insert(int index, T item)
125176
this.List.Insert(index, item);
126177
}
127178

128-
public void RemoveAt(int index)
129-
{
130-
this.List.RemoveAt(index);
131-
}
132-
133179
public T this[int index]
134180
{
135181
get
@@ -147,4 +193,4 @@ public void Sort()
147193
this.List.Sort();
148194
}
149195
}
150-
}
196+
}

src/MataSharp/bin/Release/MataSharp.XML

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
1 KB
Binary file not shown.

0 commit comments

Comments
 (0)