Skip to content

Commit

Permalink
Made the PersonList<T> class.
Browse files Browse the repository at this point in the history
  • Loading branch information
lieuwex committed Feb 12, 2014
1 parent a042187 commit 4e2577c
Show file tree
Hide file tree
Showing 24 changed files with 259 additions and 82 deletions.
26 changes: 13 additions & 13 deletions bin/MataSharp.XML

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified bin/MataSharp.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions src/MataSharp/Assignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class Assignment : IComparable<Assignment>
public uint? Grade { get; set; }
public string Class { get; set; }
public ReadOnlyCollection<Attachment> Attachments { get; set; }
public List<MagisterPerson> Teachers { get; set; }
public PersonList<MagisterPerson> Teachers { get; set; }
public int ID { get; set; }
public DateTime HandInTime { get; set; }
public DateTime DeadLine { get; set; }
Expand Down Expand Up @@ -138,7 +138,7 @@ public Assignment toAssignment()
{
Grade = this.Beoordeling,
Attachments = this.Bijlagen.ToList(AttachmentType.Assignment_teacher),
Teachers = this.Docenten.ConvertAll(p => p.ToPerson(true)),
Teachers = this.Docenten.ToList(true),
ID = this.Id,
HandInTime = this.IngeleverdOp.ToDateTime(),
DeadLine = this.InleverenVoor.ToDateTime(),
Expand Down
71 changes: 49 additions & 22 deletions src/MataSharp/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;

namespace MataSharp
{
public static class Extensions
{
/// <summary>
/// Converts the current string to a DateTime.
/// </summary>
/// <returns>The string parsed as DateTime</returns>
internal static DateTime ToDateTime(this String original)
#region General
public static void ForEach<T>(this IEnumerable<T> current, Action<T> action)
{
return (!string.IsNullOrWhiteSpace(original)) ? DateTime.Parse(original, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) : new DateTime();
foreach (var item in current) action(item);
}

/// <summary>
/// Convert the current Attachment[] to a List
/// </summary>
/// <param name="AttachmentType">AttachmentType to give every attachment in the array.</param>
/// <returns>The array as list</returns>
internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentArray, AttachmentType AttachmentType)
public static List<Tout> ConvertAll<Tin, Tout>(this IEnumerable<Tin> current, Converter<Tin, Tout> converter)
{
var tmpList = new List<Attachment>(currentArray);
tmpList.ForEach(a => a.Type = AttachmentType);
return new ReadOnlyCollection<Attachment>(tmpList);
var tmpList = new List<Tout>();
foreach (var item in current) tmpList.Add(converter(item));
return tmpList;
}
#endregion

#region DateTime
/// <summary>
/// Converts the current DateTime instance to a string.
/// </summary>
/// <returns>The current DateTime instance as string.</returns>
internal static string ToUTCString(this DateTime original)
{
internal static string ToUTCString(this DateTime original)
{
return original.ToString("yyyy-MM-ddTHH:mm:ss.0000000Z");
}

Expand All @@ -43,7 +37,7 @@ internal static string ToUTCString(this DateTime original)
/// <returns>Dutch day of week that represents the day of the current DateTime instance.</returns>
internal static string DayOfWeekDutch(this DateTime Date)
{
switch(Date.DayOfWeek)
switch (Date.DayOfWeek)
{
case DayOfWeek.Monday: return "maandag";
case DayOfWeek.Tuesday: return "dinsdag";
Expand All @@ -66,9 +60,42 @@ internal static string ToString(this DateTime Date, bool dutch)
return (dutch) ? (Date.DayOfWeekDutch() + " " + Date.ToString()) : (Date.DayOfWeek + " " + Date.ToString());
}

public static void ForEach<T>(this IEnumerable<T> current, Action<T> action)
/// <summary>
/// Converts the current string to a DateTime.
/// </summary>
/// <returns>The string parsed as DateTime</returns>
internal static DateTime ToDateTime(this String original)
{
foreach (var item in current) action(item);
return (!string.IsNullOrWhiteSpace(original)) ? DateTime.Parse(original, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) : new DateTime();
}
#endregion

#region Attachments
/// <summary>
/// Convert the current Attachment[] to a List
/// </summary>
/// <param name="AttachmentType">AttachmentType to give every attachment in the array.</param>
/// <returns>The array as list</returns>
internal static ReadOnlyCollection<Attachment> ToList(this Attachment[] currentArray, AttachmentType AttachmentType)
{
var tmpList = new List<Attachment>(currentArray);
tmpList.ForEach(a => a.Type = AttachmentType);
return new ReadOnlyCollection<Attachment>(tmpList);
}
#endregion

#region PersonList
internal static PersonList<MagisterPerson> ToList(this IEnumerable<MagisterStylePerson> collection, bool download, Mata mata = null)
{
var tmpMata = mata ?? _Session.Mata;
return new PersonList<MagisterPerson>(tmpMata, collection, download);
}

public static PersonList<MagisterPerson> ToList(this IEnumerable<MagisterPerson> collection, Mata mata = null)
{
var tmpMata = mata ?? _Session.Mata;
return new PersonList<MagisterPerson>(tmpMata, collection);
}
#endregion
}
}
}
4 changes: 2 additions & 2 deletions src/MataSharp/Homework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public bool Done
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
}
}
public List<MagisterPerson> Teachers { get; set; }
public PersonList<MagisterPerson> Teachers { get; set; }
public DateTime End { get; set; }
public int ID { get; set; }
internal int InfoType;
Expand Down Expand Up @@ -132,7 +132,7 @@ public Homework ToHomework()
{
Notes = this.AantekeningLeerling,
_Done = this.Afgerond,
Teachers = this.Docenten.ConvertAll(p => p.ToPerson(true)),
Teachers = this.Docenten.ToList(true),
End = this.Einde.ToDateTime(),
ID = this.Id,
InfoType = this.InfoType,
Expand Down
26 changes: 13 additions & 13 deletions src/MataSharp/MagisterMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public partial class MagisterMessage : IComparable<MagisterMessage>, ICloneable
public string Subject { get; set; }
public MagisterPerson Sender { get; internal set; }
public string Body { get; set; }
public List<MagisterPerson> Recipients { get; set; }
public List<MagisterPerson> CC { get; set; }
public PersonList<MagisterPerson> Recipients { get; set; }
public PersonList<MagisterPerson> CC { get; set; }
public DateTime SentDate { get; set; }
internal bool _IsRead;

Expand Down Expand Up @@ -86,8 +86,8 @@ public MagisterMessage()
this.IDKey = 0;
this.SenderGroupID = this.Mata.Person.GroupID;
this.Sender = this.Mata.Person;
this.Recipients = new List<MagisterPerson>();
this.CC = new List<MagisterPerson>();
this.Recipients = new PersonList<MagisterPerson>(this.Mata);
this.CC = new PersonList<MagisterPerson>(this.Mata);
}

/// <summary>
Expand All @@ -112,8 +112,8 @@ public MagisterMessage(Mata Mata)
this.IDKey = 0;
this.SenderGroupID = this.Mata.Person.GroupID;
this.Sender = this.Mata.Person;
this.Recipients = new List<MagisterPerson>();
this.CC = new List<MagisterPerson>();
this.Recipients = new PersonList<MagisterPerson>(this.Mata);
this.CC = new PersonList<MagisterPerson>(this.Mata);
}

/// <summary>
Expand All @@ -140,7 +140,7 @@ public MagisterMessage CreateForwardMessage()
Deleted = false,
_IsRead = true,
Subject = tmpSubject,
Recipients = new List<MagisterPerson>(),
Recipients = new PersonList<MagisterPerson>(this.Mata),
Ref = null,
State = 0,
SentDate = DateTime.UtcNow,
Expand Down Expand Up @@ -172,7 +172,7 @@ public MagisterMessage CreateForwardMessage(string ContentAdd)
Deleted = false,
_IsRead = true,
Subject = tmpSubject,
Recipients = new List<MagisterPerson>(),
Recipients = new PersonList<MagisterPerson>(this.Mata),
Ref = null,
State = 0,
SentDate = DateTime.UtcNow,
Expand All @@ -198,7 +198,7 @@ public MagisterMessage CreateReplyToAllMessage(string ContentAdd)
Sender = this.Sender,
_Folder = this._Folder,
Attachments = new ReadOnlyCollection<Attachment>(new List<Attachment>()),
CC = tmpCC,
CC = new PersonList<MagisterPerson>(this.Mata, tmpCC),
IsFlagged = this.IsFlagged,
ID = this.ID,
SenderGroupID = 4,
Expand All @@ -209,7 +209,7 @@ public MagisterMessage CreateReplyToAllMessage(string ContentAdd)
Deleted = false,
_IsRead = true,
Subject = tmpSubject,
Recipients = new List<MagisterPerson>() { this.Sender },
Recipients = new PersonList<MagisterPerson>(this.Mata) { this.Sender },
Ref = null,
State = 0,
SentDate = DateTime.UtcNow,
Expand Down Expand Up @@ -242,7 +242,7 @@ public MagisterMessage CreateReplyMessage(string ContentAdd)
Deleted = false,
_IsRead = true,
Subject = tmpSubject,
Recipients = new List<MagisterPerson>() { this.Sender },
Recipients = new PersonList<MagisterPerson>(this.Mata) { this.Sender },
Ref = null,
State = 0,
SentDate = DateTime.UtcNow,
Expand Down Expand Up @@ -396,10 +396,10 @@ internal partial class MagisterStyleMessage

public MagisterMessage ToMagisterMessage(int index)
{
var tmpReceivers = this.Ontvangers.ConvertAll(p => p.ToPerson(true));
var tmpReceivers = this.Ontvangers.ToList(true);
tmpReceivers.Sort();

var tmpCopiedReceivers = this.KopieOntvangers.ConvertAll(p => p.ToPerson(true));
var tmpCopiedReceivers = this.KopieOntvangers.ToList(true);
tmpCopiedReceivers.Sort();

return new MagisterMessage()
Expand Down
1 change: 1 addition & 0 deletions src/MataSharp/MataSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="Mata.cs" />
<Compile Include="MagisterSchool.cs" />
<Compile Include="MessageList.cs" />
<Compile Include="PersonList.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StudyGuide.cs" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 4e2577c

Please sign in to comment.