/// <summary> /// Saves <see cref="Grading"/> to xml file /// </summary> /// <param name="filename">The name of the file</param> /// <param name="data">The data to be saved</param> public override void WriteToFile(string filename, GradingPercentage data) { // Create brand-new xml document var doc = new XmlDocument(); // Add crucial informations at the top var docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); // Create marks subnode var MarksNode = doc.CreateElement("Marks"); doc.AppendChild(MarksNode); // Add every mark to the marks subnode if (data.IsMarkAIncluded) { AddMarkXml(data.MarkA, "A", MarksNode, doc); } AddMarkXml(data.MarkB, "B", MarksNode, doc); AddMarkXml(data.MarkC, "C", MarksNode, doc); AddMarkXml(data.MarkD, "D", MarksNode, doc); AddMarkXml(data.MarkE, "E", MarksNode, doc); AddMarkXml(data.MarkF, "F", MarksNode, doc); // Finally save the file if (!WriteXmlDocumentFile(filename, doc)) { // If something went wrong, throw an exception throw new Exception("Cannot save criteria file!"); } }
/// <summary> /// Converts to <see cref="GradingPercentage"/> object from specified file /// </summary> /// <param name="filename">The filename</param> /// <returns>The <see cref="GradingPercentage"/> object converted from file</returns> private GradingPercentage GetGradingFromXml(string filename) { // Create result object to return at the end var result = new GradingPercentage { // Set default values Name = Path.GetFileNameWithoutExtension(filename), IsMarkAIncluded = false, }; // Get the list of mark nodes var markNodeList = GetNodeListByNameFromFile(filename, "Mark"); // Loop each node for mark info foreach (XmlNode node in markNodeList) { // Get mark attributes var mark = (Marks)Enum.Parse(typeof(Marks), node.ChildNodes.Item(0).InnerText); var topLimit = int.Parse(node.ChildNodes.Item(1).InnerText); var bottomLimit = int.Parse(node.ChildNodes.Item(2).InnerText); // Add them to result object result.UpdateMark(mark, topLimit, bottomLimit); // Check if mark A should be included if (mark == Marks.A) { result.IsMarkAIncluded = true; } } // Finally return the result object return(result); }
/// <summary> /// Converts values in points to percentage values /// </summary> /// <returns>New grading with value in percentage</returns> public static GradingPercentage ConvertToPercentage(this GradingPoints Grades) { var result = new GradingPercentage(); var bottom = 0; var top = 0; var maxPoints = 0; if (Grades.IsMarkAIncluded) { maxPoints = Grades.MarkA.TopLimit; top = PointsToPercent(Grades.MarkA.TopLimit, maxPoints); bottom = PointsToPercent(Grades.MarkA.BottomLimit, maxPoints); result.UpdateMark(Marks.A, top, bottom); result.IsMarkAIncluded = true; } else { result.IsMarkAIncluded = false; maxPoints = Grades.MarkB.TopLimit; } top = PointsToPercent(Grades.MarkB.TopLimit, maxPoints); bottom = PointsToPercent(Grades.MarkB.BottomLimit, maxPoints); result.UpdateMark(Marks.B, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkC.BottomLimit, maxPoints); result.UpdateMark(Marks.C, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkD.BottomLimit, maxPoints); result.UpdateMark(Marks.D, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkE.BottomLimit, maxPoints); result.UpdateMark(Marks.E, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkF.BottomLimit, maxPoints); result.UpdateMark(Marks.F, top, bottom); return(result); }
/// <summary> /// Writes the <see cref="GradingPercentage"/> to the file /// </summary> public virtual void WriteToFile(string filename, GradingPercentage grading) { }