Skip to content

Commit 51a1a34

Browse files
committedFeb 11, 2014
Fixed moving of Messages to other MessageFolders.
1 parent 4645cd7 commit 51a1a34

20 files changed

+93
-28
lines changed
 

‎bin/MataSharp.XML

Lines changed: 18 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ internal enum AttachmentType
7575
Assignment_teacher,
7676
Assignment_pupil,
7777
StudyGuide
78-
};
78+
}
7979
}

‎src/MataSharp/MagisterMessage.cs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public partial class MagisterMessage : IComparable<MagisterMessage>, ICloneable
1313
public int ID { get; set; }
1414
public object Ref { get; set; } // Even Schoolmaster doesn't know what this is, it's mysterious. Just keep it in case.
1515
public string Subject { get; set; }
16-
public MagisterPerson Sender { get; set; }
16+
public MagisterPerson Sender { get; internal set; }
1717
public string Body { get; set; }
1818
public List<MagisterPerson> Recipients { get; set; }
1919
public List<MagisterPerson> CC { get; set; }
@@ -40,20 +40,10 @@ public bool IsRead
4040
public List<Attachment> Attachments { get; internal set; }
4141
internal int _Folder { get; set; }
4242

43-
public MessageFolder Folder
44-
{
43+
public MessageFolder Folder
44+
{
4545
get { return (MessageFolder)this._Folder; }
46-
set
47-
{
48-
if (this._Folder == (int)value) return;
49-
50-
var thisCopied = (MagisterMessage)this.MemberwiseClone();
51-
52-
this._Folder = (int)value;
53-
54-
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
55-
thisCopied.Delete();
56-
}
46+
set { this.Move(value); }
5747
}
5848

5949
public bool Deleted { get; internal set; }
@@ -259,6 +249,34 @@ public MagisterMessage CreateReplyMessage(string ContentAdd)
259249
};
260250
}
261251

252+
/// <summary>
253+
/// Moves the current Message to the given folder.
254+
/// </summary>
255+
/// <param name="Folder">The folder to move the current message to.</param>
256+
public void Move(MessageFolder Folder) { this.Move((int)Folder); }
257+
258+
/// <summary>
259+
/// Moves the current Message to the given folder.
260+
/// </summary>
261+
/// <param name="Folder">The folder to move the current message to.</param>
262+
public void Move(MagisterMessageFolder Folder) { this.Move(Folder.ID); }
263+
264+
/// <summary>
265+
/// Moves the current Message to the given folder.
266+
/// </summary>
267+
/// <param name="FolderID">The folder to move the current message to.</param>
268+
public void Move(int FolderID)
269+
{
270+
if (this._Folder == FolderID) return;
271+
272+
var thisCopied = (MagisterMessage)this.MemberwiseClone();
273+
274+
this._Folder = FolderID;
275+
276+
_Session.HttpClient.Put(this.URL(), JsonConvert.SerializeObject(this.ToMagisterStyle()));
277+
thisCopied.Delete();
278+
}
279+
262280
/// <summary>
263281
/// CAUTION: Permanently deletes the current message on the server.
264282
/// </summary>
@@ -332,7 +350,7 @@ internal MagisterStyleMessage ToMagisterStyle()
332350

333351
public override string ToString()
334352
{
335-
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 + "\"";
353+
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 + "\"";
336354
}
337355

338356
public int CompareTo(MagisterMessage other)

‎src/MataSharp/Mata.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public List<MagisterMessageFolder> GetMessageFolders()
112112
List<MagisterMessageFolder> tmplst = new List<MagisterMessageFolder>();
113113
foreach (var messageFolder in MessageFolders)
114114
{
115-
var tmpFolderType = (Enum.IsDefined(typeof(MessageFolder), messageFolder.Id)) ? (MessageFolder)messageFolder.Id : MessageFolder.Unknown;
116115
tmplst.Add(new MagisterMessageFolder()
117116
{
118117
Name = messageFolder.Naam,
@@ -122,7 +121,7 @@ public List<MagisterMessageFolder> GetMessageFolders()
122121
Ref = messageFolder.Ref,
123122
MessagesURI = messageFolder.BerichtenUri,
124123
Mata = this,
125-
FolderType = tmpFolderType
124+
FolderType = (MessageFolder)messageFolder.Id
126125
});
127126
}
128127
return tmplst;

‎src/MataSharp/MessageFolder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public enum MessageFolder : int
2525
{ //Defines the folders where messages can be in, server handles it as ID's. We? We handle it as an enum :D
2626
Inbox = -101,
2727
SentMessages = -103,
28-
Bin = -102,
29-
Unknown = 0
28+
Bin = -102
3029
}
3130

3231
internal partial struct MagisterStyleMessageFolderListItem

‎src/MataSharp/bin/Release/MataSharp.XML

Lines changed: 18 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.
2 KB
Binary file not shown.
1 KB
Binary file not shown.
2 KB
Binary file not shown.

‎src/MataTest/Program.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ static void Main(string[] args)
4141
var clonedMata = mata.Clone();
4242
Console.WriteLine("Equal?: " + clonedMata.Equals(mata));
4343

44-
new MagisterMessage()
45-
{
46-
Body = "test",
47-
Subject = "test",
48-
Recipients = new List<MagisterPerson>() { mata.Person }
49-
}.Send();
50-
5144
twentyMessages.First(m => m.Attachments.Count != 0).Attachments[0].Download(true);
5245

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

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

7772
#region Message
7873
var Inbox = mata.Inbox;

‎src/MataTest/bin/Debug/MataSharp.dll

1 KB
Binary file not shown.

‎src/MataTest/bin/Debug/MataSharp.pdb

2 KB
Binary file not shown.

‎src/MataTest/bin/Debug/MataSharp.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/MataTest/bin/Debug/MataTest.exe

0 Bytes
Binary file not shown.

‎src/MataTest/bin/Debug/MataTest.pdb

0 Bytes
Binary file not shown.
Binary file not shown.

‎src/MataTest/obj/Debug/MataTest.exe

0 Bytes
Binary file not shown.

‎src/MataTest/obj/Debug/MataTest.pdb

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)