Skip to content

Commit

Permalink
Fixed moving of Messages to other MessageFolders.
Browse files Browse the repository at this point in the history
  • Loading branch information
lieuwex committed Feb 11, 2014
1 parent 4645cd7 commit 51a1a34
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 28 deletions.
18 changes: 18 additions & 0 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.
2 changes: 1 addition & 1 deletion src/MataSharp/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ internal enum AttachmentType
Assignment_teacher,
Assignment_pupil,
StudyGuide
};
}
}
48 changes: 33 additions & 15 deletions src/MataSharp/MagisterMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class MagisterMessage : IComparable<MagisterMessage>, ICloneable
public int ID { get; set; }
public object Ref { get; set; } // Even Schoolmaster doesn't know what this is, it's mysterious. Just keep it in case.
public string Subject { get; set; }
public MagisterPerson Sender { 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; }
Expand All @@ -40,20 +40,10 @@ public bool IsRead
public List<Attachment> Attachments { get; internal set; }
internal int _Folder { get; set; }

public MessageFolder Folder
{
public MessageFolder Folder
{
get { return (MessageFolder)this._Folder; }
set
{
if (this._Folder == (int)value) return;

var thisCopied = (MagisterMessage)this.MemberwiseClone();

this._Folder = (int)value;

_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
thisCopied.Delete();
}
set { this.Move(value); }
}

public bool Deleted { get; internal set; }
Expand Down Expand Up @@ -259,6 +249,34 @@ public MagisterMessage CreateReplyMessage(string ContentAdd)
};
}

/// <summary>
/// Moves the current Message to the given folder.
/// </summary>
/// <param name="Folder">The folder to move the current message to.</param>
public void Move(MessageFolder Folder) { this.Move((int)Folder); }

/// <summary>
/// Moves the current Message to the given folder.
/// </summary>
/// <param name="Folder">The folder to move the current message to.</param>
public void Move(MagisterMessageFolder Folder) { this.Move(Folder.ID); }

/// <summary>
/// Moves the current Message to the given folder.
/// </summary>
/// <param name="FolderID">The folder to move the current message to.</param>
public void Move(int FolderID)
{
if (this._Folder == FolderID) return;

var thisCopied = (MagisterMessage)this.MemberwiseClone();

this._Folder = FolderID;

_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
thisCopied.Delete();
}

/// <summary>
/// CAUTION: Permanently deletes the current message on the server.
/// </summary>
Expand Down Expand Up @@ -332,7 +350,7 @@ internal MagisterStyleMessage ToMagisterStyle()

public override string ToString()
{
return "From: " + this.Sender.Description + "\nSent: " + this.SentDate.DayOfWeek + " " + this.SentDate.ToString() + "\nTo: " + String.Join(", ", this.Recipients.Select(x => x.Name)) + ((this.Attachments.Count > 0) ? ("\nAttachments (" + this.Attachments.Count + "): " + String.Join(", ", this.Attachments)) : "") + "\nSubject: " + this.Subject + "\n\n\"" + this.Body + "\"";
return "From: " + this.Sender.Description + "\nSent: " + this.SentDate.ToString(false) + "\nTo: " + String.Join(", ", this.Recipients.Select(x => x.Name)) + ((this.Attachments.Count > 0) ? ("\nAttachments (" + this.Attachments.Count + "): " + String.Join(", ", this.Attachments)) : "") + "\nSubject: " + this.Subject + "\n\n\"" + this.Body + "\"";
}

public int CompareTo(MagisterMessage other)
Expand Down
3 changes: 1 addition & 2 deletions src/MataSharp/Mata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public List<MagisterMessageFolder> GetMessageFolders()
List<MagisterMessageFolder> tmplst = new List<MagisterMessageFolder>();
foreach (var messageFolder in MessageFolders)
{
var tmpFolderType = (Enum.IsDefined(typeof(MessageFolder), messageFolder.Id)) ? (MessageFolder)messageFolder.Id : MessageFolder.Unknown;
tmplst.Add(new MagisterMessageFolder()
{
Name = messageFolder.Naam,
Expand All @@ -122,7 +121,7 @@ public List<MagisterMessageFolder> GetMessageFolders()
Ref = messageFolder.Ref,
MessagesURI = messageFolder.BerichtenUri,
Mata = this,
FolderType = tmpFolderType
FolderType = (MessageFolder)messageFolder.Id
});
}
return tmplst;
Expand Down
3 changes: 1 addition & 2 deletions src/MataSharp/MessageFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public enum MessageFolder : int
{ //Defines the folders where messages can be in, server handles it as ID's. We? We handle it as an enum :D
Inbox = -101,
SentMessages = -103,
Bin = -102,
Unknown = 0
Bin = -102
}

internal partial struct MagisterStyleMessageFolderListItem
Expand Down
18 changes: 18 additions & 0 deletions src/MataSharp/bin/Release/MataSharp.XML

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

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/MataSharp.dll
Binary file not shown.
Binary file modified src/MataSharp/obj/Release/MataSharp.pdb
Binary file not shown.
11 changes: 3 additions & 8 deletions src/MataTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ static void Main(string[] args)
var clonedMata = mata.Clone();
Console.WriteLine("Equal?: " + clonedMata.Equals(mata));

new MagisterMessage()
{
Body = "test",
Subject = "test",
Recipients = new List<MagisterPerson>() { mata.Person }
}.Send();

twentyMessages.First(m => m.Attachments.Count != 0).Attachments[0].Download(true);

var utilitiesTest = mata.GetDigitalSchoolUtilities();
Expand All @@ -64,7 +57,7 @@ static void Main(string[] args)
Console.WriteLine(assignment.Description);
assignment.Attachments.ForEach(a => a.Download(true));
}
assignmentTest.ElementAt(0).Attachments.ForEach(a => a.Download(true));
assignmentTest.First().Attachments.ForEach(a => a.Download(true));

new MagisterMessage()
{
Expand All @@ -73,6 +66,8 @@ static void Main(string[] args)
Recipients = new List<MagisterPerson>() { mata.Person },
CC = new List<MagisterPerson>() { mata.Person },
}.Send();
mata.ComposeAndSendMessage("Hallotjees :D", "TESSST D:", new List<MagisterPerson>() { mata.Person });
//Both do the same thing, except the first method is more customizable and, in this example, adds a person to the CC field.

#region Message
var Inbox = mata.Inbox;
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.
18 changes: 18 additions & 0 deletions src/MataTest/bin/Debug/MataSharp.xml

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

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 51a1a34

Please sign in to comment.