2017-07-26 23:43:38 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
using System.Xml;
|
2017-07-29 18:46:39 +02:00
|
|
|
|
using System.IO;
|
2017-08-08 21:19:56 +02:00
|
|
|
|
using System.Windows.Forms;
|
2017-07-26 23:43:38 +02:00
|
|
|
|
|
|
|
|
|
namespace EduNetworkBuilder
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A class holding a project that needs to be done as either a test, quiz, or homework
|
|
|
|
|
/// </summary>
|
2018-03-15 23:12:20 +01:00
|
|
|
|
[Serializable]
|
2017-07-26 23:43:38 +02:00
|
|
|
|
public class SchoolworkClass
|
|
|
|
|
{
|
2017-08-01 00:01:03 +02:00
|
|
|
|
public Network theProject = null;
|
2017-07-26 23:43:38 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of the project. Homework3, Quiz 4, etc.
|
|
|
|
|
/// </summary>
|
2017-07-30 01:31:19 +02:00
|
|
|
|
public string Name = "";
|
2017-08-02 20:03:14 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The Suggested filename for this homework. The Name + ".eduh"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string FileName { get { return Name + ".eduh"; } }
|
2017-07-26 23:43:38 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The short description of the project.
|
|
|
|
|
/// </summary>
|
2017-07-31 01:18:41 +02:00
|
|
|
|
public string Description = "";
|
2017-07-26 23:43:38 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The class to which this project belongs. If the student is using this for multiple classes,
|
|
|
|
|
/// but more likely just for the teacher to organize things with.
|
|
|
|
|
/// </summary>
|
2017-07-31 01:18:41 +02:00
|
|
|
|
public string Class = "";
|
2017-07-26 23:43:38 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The date / time that the project is due.
|
|
|
|
|
/// </summary>
|
2017-07-31 01:18:41 +02:00
|
|
|
|
public DateTime DueDate;
|
2017-07-26 23:43:38 +02:00
|
|
|
|
|
2017-07-31 01:18:41 +02:00
|
|
|
|
public bool isMaster = false; //Is this the original project? If so, we never replace it.
|
2017-07-26 23:43:38 +02:00
|
|
|
|
|
2017-07-31 01:18:41 +02:00
|
|
|
|
public bool IsSumbitted = false; //Is the student submitting this? If so, date-stamp it and lock it.
|
2017-08-03 00:04:15 +02:00
|
|
|
|
public bool IsGraded = false;
|
2017-07-31 01:18:41 +02:00
|
|
|
|
public DateTime SaveDate; //The date this file was saved.
|
2017-07-31 18:27:25 +02:00
|
|
|
|
public UInt64 ThisID { get; protected set; }
|
2017-07-29 16:11:36 +02:00
|
|
|
|
|
2017-08-14 23:17:50 +02:00
|
|
|
|
public HomeworkSolvedStatus HomeworkStatus = HomeworkSolvedStatus.NeverChecked;
|
|
|
|
|
|
|
|
|
|
|
2017-08-02 19:17:20 +02:00
|
|
|
|
protected SchoolworkClass() { }
|
|
|
|
|
|
2017-07-29 16:11:36 +02:00
|
|
|
|
public SchoolworkClass(XmlNode TheNode)
|
|
|
|
|
{
|
2017-08-08 02:27:59 +02:00
|
|
|
|
List<SchoolworkClass> WhatIs = Load(TheNode);
|
|
|
|
|
if (WhatIs.Count > 0)
|
2017-08-17 20:50:29 +02:00
|
|
|
|
{
|
2017-08-08 02:27:59 +02:00
|
|
|
|
SchoolworkClass.Clone(WhatIs[0], this);
|
2017-08-17 20:50:29 +02:00
|
|
|
|
//Move the packet messages across. They do not get cloned.
|
|
|
|
|
//We do this so we can store the results of an automated test
|
|
|
|
|
if(WhatIs[0].theProject != null && WhatIs[0].theProject.CountMessages() > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach(PacketMessage one in WhatIs[0].theProject.GetAllMessages())
|
|
|
|
|
{
|
|
|
|
|
theProject.AddMessage(one);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-29 16:11:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 19:50:25 +02:00
|
|
|
|
public SchoolworkClass(string FileName)
|
|
|
|
|
{
|
|
|
|
|
Load(FileName);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 18:27:25 +02:00
|
|
|
|
public SchoolworkClass(Network ToAdd, PersonClass WhoFor)
|
2017-07-30 01:31:19 +02:00
|
|
|
|
{
|
2017-07-31 18:27:25 +02:00
|
|
|
|
if(WhoFor != null && WhoFor.UserSettings != null)
|
|
|
|
|
ThisID = WhoFor.UserSettings.IssueID();
|
2017-07-30 01:31:19 +02:00
|
|
|
|
theProject = ToAdd.Clone();
|
|
|
|
|
Name = theProject.PuzzleName;
|
|
|
|
|
Description = theProject.PuzzleName;
|
|
|
|
|
isMaster = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 19:17:20 +02:00
|
|
|
|
public SchoolworkClass Clone()
|
|
|
|
|
{
|
|
|
|
|
SchoolworkClass dest = new SchoolworkClass();
|
|
|
|
|
Clone(this, dest);
|
|
|
|
|
return dest;
|
|
|
|
|
}
|
2017-08-02 19:38:10 +02:00
|
|
|
|
|
2017-08-02 19:17:20 +02:00
|
|
|
|
public static void Clone(SchoolworkClass source, SchoolworkClass dest)
|
|
|
|
|
{
|
2017-08-02 19:29:29 +02:00
|
|
|
|
dest.ThisID = source.ThisID;
|
2017-08-02 19:17:20 +02:00
|
|
|
|
dest.Class = source.Class;
|
|
|
|
|
dest.Description = source.Description;
|
|
|
|
|
dest.DueDate = source.DueDate;
|
|
|
|
|
dest.isMaster = source.isMaster;
|
|
|
|
|
dest.IsSumbitted = source.IsSumbitted;
|
|
|
|
|
dest.Name = source.Name;
|
|
|
|
|
dest.SaveDate = source.SaveDate;
|
|
|
|
|
dest.theProject = source.theProject.Clone();
|
2017-08-03 00:04:15 +02:00
|
|
|
|
dest.IsGraded = source.IsGraded;
|
2017-08-02 19:17:20 +02:00
|
|
|
|
}
|
2017-07-30 01:31:19 +02:00
|
|
|
|
|
2017-08-11 21:56:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Basically for sorting. First by class name, then due date, and then save date
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="WhatTo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int Compare(SchoolworkClass WhatTo)
|
|
|
|
|
{
|
|
|
|
|
int diff = Class.CompareTo(WhatTo.Class);
|
|
|
|
|
if (diff != 0) return diff;
|
|
|
|
|
|
|
|
|
|
diff = DueDate.CompareTo(WhatTo.DueDate);
|
|
|
|
|
if (diff != 0) return diff;
|
|
|
|
|
|
|
|
|
|
return SaveDate.CompareTo(WhatTo.SaveDate);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-29 16:11:36 +02:00
|
|
|
|
#region Load and Save
|
|
|
|
|
//Load and save functions
|
2017-07-29 18:46:39 +02:00
|
|
|
|
public void Load(string filename)
|
|
|
|
|
{
|
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
2017-08-08 21:19:56 +02:00
|
|
|
|
|
2017-07-29 18:46:39 +02:00
|
|
|
|
if (File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
xmlDoc.Load(filename);
|
2017-08-08 21:19:56 +02:00
|
|
|
|
List<SchoolworkClass> results = Load(xmlDoc);
|
|
|
|
|
if (results.Count > 0) Clone(results[0], this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<SchoolworkClass> LoadMultiple(string filename)
|
|
|
|
|
{
|
|
|
|
|
XmlDocument xmlDoc = new XmlDocument();
|
|
|
|
|
List<SchoolworkClass> results = new List<SchoolworkClass>();
|
|
|
|
|
if (File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
xmlDoc.Load(filename);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(e.ToString());
|
|
|
|
|
return results; //return an empty list
|
|
|
|
|
}
|
|
|
|
|
results.AddRange(Load(xmlDoc));
|
2017-07-29 18:46:39 +02:00
|
|
|
|
}
|
2017-08-08 21:19:56 +02:00
|
|
|
|
return results;
|
2017-07-29 18:46:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 02:35:15 +02:00
|
|
|
|
public static List<SchoolworkClass> Load(XmlNode TheNode)
|
2017-07-29 16:11:36 +02:00
|
|
|
|
{
|
2017-08-06 02:35:15 +02:00
|
|
|
|
SchoolworkClass currentOne = new SchoolworkClass();
|
|
|
|
|
List<SchoolworkClass> ThisList = new List<SchoolworkClass>();
|
|
|
|
|
bool AddedList = false;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
foreach (XmlNode Individual in TheNode.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
XmlNodeType myNodetype = Individual.NodeType;
|
|
|
|
|
if (myNodetype == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (Individual.Name.ToLower())
|
|
|
|
|
{
|
2017-08-09 00:45:45 +02:00
|
|
|
|
case "edunetworkbuilderschoolwork":
|
2017-08-02 19:50:25 +02:00
|
|
|
|
case "schoolwork":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
ThisList.AddRange(Load(Individual));
|
|
|
|
|
AddedList = true;
|
2017-08-02 19:50:25 +02:00
|
|
|
|
break;
|
2017-07-31 18:27:25 +02:00
|
|
|
|
case "id":
|
|
|
|
|
UInt64 tID;
|
|
|
|
|
UInt64.TryParse(Individual.InnerText, out tID);
|
2017-08-06 02:35:15 +02:00
|
|
|
|
currentOne.ThisID = tID;
|
2017-07-31 18:27:25 +02:00
|
|
|
|
break;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
case "name":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
currentOne.Name = Individual.InnerText;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case "description":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
currentOne.Description = Individual.InnerText;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case "class":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
currentOne.Class = Individual.InnerText;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case "duedate":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
DateTime.TryParse(Individual.InnerText, out currentOne.DueDate);
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case "savedate":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
DateTime.TryParse(Individual.InnerText, out currentOne.SaveDate);
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
2017-08-14 23:17:50 +02:00
|
|
|
|
case "homeworkstatus":
|
|
|
|
|
currentOne.HomeworkStatus = NB.ParseEnum<HomeworkSolvedStatus>(Individual.InnerText);
|
|
|
|
|
break;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
case "ismaster":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
bool.TryParse(Individual.InnerText, out currentOne.isMaster);
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
2017-08-03 00:04:15 +02:00
|
|
|
|
case "isgraded":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
bool.TryParse(Individual.InnerText, out currentOne.IsGraded);
|
2017-08-03 00:04:15 +02:00
|
|
|
|
break;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
case "issubmitted":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
bool.TryParse(Individual.InnerText, out currentOne.IsSumbitted);
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case "network":
|
2017-08-06 02:35:15 +02:00
|
|
|
|
currentOne.theProject = new Network();
|
|
|
|
|
currentOne.theProject.Load(Individual, "",false,true);
|
2017-07-29 16:11:36 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-06 02:35:15 +02:00
|
|
|
|
if (!AddedList) ThisList.Add(currentOne);
|
|
|
|
|
|
|
|
|
|
return ThisList;
|
2017-07-29 16:11:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-29 18:46:39 +02:00
|
|
|
|
public void Save(string filename)
|
|
|
|
|
{
|
2017-08-02 19:50:25 +02:00
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
settings.NewLineOnAttributes = true;
|
|
|
|
|
XmlWriter writer = XmlWriter.Create(filename, settings);
|
|
|
|
|
|
|
|
|
|
//Now we write the file:
|
|
|
|
|
writer.WriteStartDocument();
|
|
|
|
|
writer.WriteStartElement("EduNetworkBuilderSchoolwork");
|
|
|
|
|
writer.WriteComment("This is a schoolwork file for EduNetworkBuilder.");
|
|
|
|
|
Save(writer);
|
|
|
|
|
writer.WriteEndElement();
|
|
|
|
|
writer.WriteEndDocument();
|
2017-08-06 02:22:36 +02:00
|
|
|
|
writer.Flush();
|
|
|
|
|
writer.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Save(List<SchoolworkClass> homeworks, string filename)
|
|
|
|
|
{
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
settings.NewLineOnAttributes = true;
|
|
|
|
|
XmlWriter writer = XmlWriter.Create(filename, settings);
|
|
|
|
|
|
|
|
|
|
//Now we write the file:
|
|
|
|
|
writer.WriteStartDocument();
|
|
|
|
|
writer.WriteStartElement("EduNetworkBuilderSchoolwork");
|
|
|
|
|
writer.WriteComment("This is a schoolwork file for EduNetworkBuilder.");
|
|
|
|
|
foreach (SchoolworkClass swc in homeworks)
|
|
|
|
|
{
|
|
|
|
|
swc.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
writer.WriteEndElement();
|
|
|
|
|
writer.WriteEndDocument();
|
2017-08-02 19:50:25 +02:00
|
|
|
|
writer.Flush();
|
|
|
|
|
writer.Close();
|
2017-07-29 18:46:39 +02:00
|
|
|
|
}
|
2017-07-29 16:11:36 +02:00
|
|
|
|
|
2017-08-09 00:45:45 +02:00
|
|
|
|
public void ChangeID(PersonClass WhoFor)
|
|
|
|
|
{
|
|
|
|
|
if (WhoFor != null && WhoFor.UserSettings != null)
|
|
|
|
|
ThisID = WhoFor.UserSettings.IssueID();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-15 00:21:24 +02:00
|
|
|
|
public HomeworkSolvedStatus CheckThatHomeworkIsSolved()
|
|
|
|
|
{
|
|
|
|
|
if(theProject != null)
|
|
|
|
|
{
|
|
|
|
|
HomeworkStatus = theProject.CheckThatHomeworkIsSolved();
|
|
|
|
|
}
|
|
|
|
|
return HomeworkStatus;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-29 16:11:36 +02:00
|
|
|
|
public void Save(XmlWriter writer)
|
|
|
|
|
{
|
|
|
|
|
//Save the language name
|
|
|
|
|
//save the number of items
|
|
|
|
|
//Save all the items
|
2017-07-29 18:46:39 +02:00
|
|
|
|
writer.WriteStartElement("schoolwork");
|
2017-07-31 18:27:25 +02:00
|
|
|
|
writer.WriteElementString("ID", ThisID.ToString());
|
2017-07-29 16:11:36 +02:00
|
|
|
|
writer.WriteElementString("Name", Name);
|
|
|
|
|
writer.WriteElementString("Description", Description);
|
|
|
|
|
writer.WriteElementString("Class", Class);
|
|
|
|
|
writer.WriteElementString("DueDate", DueDate.ToString());
|
|
|
|
|
writer.WriteElementString("SaveDate", SaveDate.ToString());
|
|
|
|
|
writer.WriteElementString("IsMaster", isMaster.ToString());
|
2017-08-03 00:04:15 +02:00
|
|
|
|
writer.WriteElementString("IsGraded", IsGraded.ToString());
|
2017-08-14 23:17:50 +02:00
|
|
|
|
if (HomeworkStatus != HomeworkSolvedStatus.NeverChecked)
|
|
|
|
|
writer.WriteElementString("HomeworkStatus", HomeworkStatus.ToString());
|
2017-07-29 16:11:36 +02:00
|
|
|
|
writer.WriteElementString("IsSubmitted", IsSumbitted.ToString());
|
2017-08-17 17:17:20 +02:00
|
|
|
|
if (theProject != null) theProject.Save(writer,true,true);//Save the messages also.
|
2017-07-29 16:11:36 +02:00
|
|
|
|
writer.WriteEndElement();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2017-07-26 23:43:38 +02:00
|
|
|
|
}
|
|
|
|
|
}
|