Skip to content

Commit

Permalink
General Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lieuwex committed Feb 23, 2014
1 parent dd4dffd commit afb306c
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 50 deletions.
Binary file modified bin/MataSharp.dll
Binary file not shown.
11 changes: 2 additions & 9 deletions src/MataSharp/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace MataSharp
public static class Extensions
{
#region General
public static void ForEach<T>(this IEnumerable<T> current, Action<T> action)
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
{
foreach (var item in current) action(item);
foreach (var item in collection) action(item);
}

public static List<Tout> ConvertAll<Tin, Tout>(this IEnumerable<Tin> current, Converter<Tin, Tout> converter)
Expand Down Expand Up @@ -97,12 +97,5 @@ public static PersonList ToList(this IEnumerable<MagisterPerson> collection, Ma
return new PersonList(collection, mata);
}
#endregion

internal static MagisterStyleMessage ToMagisterStyleMsg(this string rawData, Mata mata)
{
var tmpMsg = JsonConvert.DeserializeObject<MagisterStyleMessage>(rawData);
tmpMsg.Mata = mata;
return tmpMsg;
}
}
}
24 changes: 10 additions & 14 deletions src/MataSharp/MagisterMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ internal MagisterStyleMessage ToMagisterStyle()
BerichtMapId = this._Folder,
IsDefinitiefVerwijderd = this.Deleted,
IdKey = this.IDKey,
IdDeelNameSoort = this.SenderGroupID,
Mata = this.Mata
IdDeelNameSoort = this.SenderGroupID
};
}

Expand Down Expand Up @@ -367,25 +366,22 @@ sealed internal partial class MagisterStyleMessage
public bool IsDefinitiefVerwijderd { get; set; }
public int IdKey { get; set; }
public int IdDeelNameSoort { get; set; }

[JsonIgnore]
public Mata Mata { get; internal set; }
#endregion

public MagisterMessage ToMagisterMessage(bool download, int index)
public MagisterMessage ToMagisterMessage(Mata mata, bool download, int index)
{
var tmpReceivers = this.Ontvangers.ToList(download, true, this.Mata);
var tmpReceivers = this.Ontvangers.ToList(download, true, mata);
tmpReceivers.Sort();

var tmpCopiedReceivers = this.KopieOntvangers.ToList(download, true, this.Mata);
var tmpCopiedReceivers = this.KopieOntvangers.ToList(download, true, mata);
tmpCopiedReceivers.Sort();

return new MagisterMessage(this.Mata)
return new MagisterMessage(mata)
{
ID = this.Id,
Ref = this.Ref,
Subject = this.Onderwerp,
Sender = this.Afzender.ToPerson(download, this.Mata),
Sender = this.Afzender.ToPerson(download, mata),
Body = this.Inhoud.Trim(),
Recipients = tmpReceivers,
CC = tmpCopiedReceivers,
Expand All @@ -395,7 +391,7 @@ public MagisterMessage ToMagisterMessage(bool download, int index)
IsFlagged = this.HeeftPrioriteit,
IDOriginal = this.IdOorspronkelijkeBericht,
IDOrginalReceiver = this.IdOntvangerOorspronkelijkeBericht,
Attachments = this.Bijlagen.ToList(AttachmentType.Message, this.Mata),
Attachments = this.Bijlagen.ToList(AttachmentType.Message, mata),
_Folder = this.BerichtMapId,
Deleted = this.IsDefinitiefVerwijderd,
IDKey = this.IdKey,
Expand All @@ -405,10 +401,10 @@ public MagisterMessage ToMagisterMessage(bool download, int index)
};
}

internal void Send(Mata Mata)
internal void Send(Mata mata)
{
string URL = "https://" + Mata.School.URL + "/api/personen/" + Mata.UserID + "/communicatie/berichten/";
this.Mata.WebClient.Post(URL, JsonConvert.SerializeObject(this));
string URL = "https://" + mata.School.URL + "/api/personen/" + mata.UserID + "/communicatie/berichten/";
mata.WebClient.Post(URL, JsonConvert.SerializeObject(this));
}
}
}
5 changes: 2 additions & 3 deletions src/MataSharp/Mata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
using System.Collections.Specialized;
using System.Linq;
using Newtonsoft.Json;
//using Newtonsoft.Json.Linq;

namespace MataSharp
{
/// <summary>
/// Type to communicate with a Magister School's server.
/// </summary>
sealed public partial class Mata : IDisposable, ICloneable
sealed public class Mata : IDisposable, ICloneable
{
public string Name { get; private set; }
public uint UserID { get; private set; }
Expand Down Expand Up @@ -162,7 +161,7 @@ public PersonList GetPersons(string SearchFilter)
this.CheckedPersons.Add(SearchFilter, personRaw);
return new PersonList(this, personRaw, false, false);
}
else return new PersonList(this, this.CheckedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value,false, false);
else return new PersonList(this, this.CheckedPersons.First(x => x.Key.ToUpper() == SearchFilter.ToUpper()).Value, false, false);
}

public List<Homework> GetHomework()
Expand Down
24 changes: 12 additions & 12 deletions src/MataSharp/MessageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public int IndexOf(MagisterMessage item)
/// <param name="predicate">The predicate the messages must match to.</param>
public void RemoveAll(int max, Predicate<MagisterMessage> predicate)
{
this.GetSpecificEnumerator().GetRange(true, max, 0).Where(m => predicate(m)).ToList().ForEach(m => m.Delete());
this.Take(max, true).Where(m => predicate(m)).ForEach(m => m.Delete());
}

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

/// <summary>
Expand Down Expand Up @@ -307,8 +307,8 @@ public MagisterMessage Current

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

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

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

public List<MagisterMessage> GetRange(bool download, int Ammount, int Skip)
Expand All @@ -337,8 +337,8 @@ public List<MagisterMessage> GetRange(bool download, int Ammount, int Skip)
{
URL = "https://" + Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
list.Add(MessageClean.ToMagisterMessage(download, i));
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
list.Add(MessageClean.ToMagisterMessage(this.Mata, download, i));
i++;
}
return list;
Expand All @@ -356,8 +356,8 @@ public List<MagisterMessage> GetUnread(bool download, uint Ammount, uint Skip =
{
URL = "https://" + Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
list.Add(MessageClean.ToMagisterMessage(download, i));
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
list.Add(MessageClean.ToMagisterMessage(this.Mata, download, i));
i++;
}
return list;
Expand All @@ -377,8 +377,8 @@ public List<MagisterMessage> GetUnread(bool download)
{
URL = "https://" + Mata.School.URL + "/api/personen/" + this.Mata.UserID + "/communicatie/berichten/mappen/" + Sender.ID + "/berichten/" + CompactMessage.Id;
string MessageRAW = this.Mata.WebClient.DownloadString(URL);
var MessageClean = MessageRAW.ToMagisterStyleMsg(this.Mata);
list.Add(MessageClean.ToMagisterMessage(download, index));
var MessageClean = JsonConvert.DeserializeObject<MagisterStyleMessage>(MessageRAW);
list.Add(MessageClean.ToMagisterMessage(this.Mata, download, index));
i++;
}
}
Expand Down
20 changes: 13 additions & 7 deletions src/MataSharp/PersonList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public int Count
get { return this.List.Count; }
}

public void Insert(int index, MagisterPerson item)
{
if (this.IsReadOnly) ThrowException();
this.List.Insert(index, item);
}

public void Insert(int index, string name)
{
if (this.IsReadOnly) ThrowException();
this.List.Insert(index, this.Mata.GetPersons(name)[0]);
}

public void InsertRange(int index, IEnumerable<MagisterPerson> collection)
{
if (this.IsReadOnly) ThrowException();
Expand All @@ -119,7 +131,7 @@ public void InsertRange(int index, IEnumerable<string> collection)
public void InsertRange(int index, string name)
{
if (this.IsReadOnly) ThrowException();
this.List.InsertRange(index, (IEnumerable<MagisterPerson>)this.Mata.GetPersons(name));
this.List.InsertRange(index, this.Mata.GetPersons(name));
}

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

public void Insert(int index, MagisterPerson item)
{
if (this.IsReadOnly) ThrowException();
this.List.Insert(index, item);
}

public MagisterPerson this[int index]
{
get
Expand Down
10 changes: 6 additions & 4 deletions src/MataSharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MataSharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Public C# implementation of the non public 'Mata' API.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MataSharp")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyCopyright("Copyright © 2014 Lieuwe Rooijakkers")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +33,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en-GB")]
Binary file modified src/MataSharp/bin/Release/MataSharp.dll
Binary file not shown.
Binary file modified src/MataSharp/bin/Release/MataSharp.pdb
Binary file not shown.
Binary file modified src/MataSharp/obj/Release/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file modified src/MataSharp/obj/Release/MataSharp.dll
Binary file not shown.
Binary file modified src/MataSharp/obj/Release/MataSharp.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion src/MataTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace MataTest
{
class Program
{
static void Main(string[] args)
static void Main()
{
#region MagisterSchool
Console.WriteLine("Typ gedeelte van je school in: ");
Expand Down
Binary file modified src/MataTest/bin/Debug/MataSharp.dll
Binary file not shown.
Binary file modified src/MataTest/bin/Debug/MataSharp.pdb
Binary file not shown.
Binary file modified src/MataTest/bin/Debug/MataTest.exe
Binary file not shown.
Binary file modified src/MataTest/bin/Debug/MataTest.pdb
Binary file not shown.
Binary file not shown.
Binary file modified src/MataTest/obj/Debug/MataTest.exe
Binary file not shown.
Binary file modified src/MataTest/obj/Debug/MataTest.pdb
Binary file not shown.

0 comments on commit afb306c

Please sign in to comment.