public void Badger_LogQueryClone() { LogQueryViewModel query1; query1 = new LogQueryViewModel(); List <string> variableList = new List <string>() { "E_p", "v", "omega_r", "omega_g" }; //init query1 before copying it query1.AddLogVariables(variableList); query1.VariablesVM[0].IsSelected = true; query1.VariablesVM[2].IsSelected = true; query1.LimitTracks = true; query1.MaxNumTracks = 3; query1.AddGroupByFork("fork-1"); query1.InGroupSelectionVariable = "omega_g"; query1.InGroupSelectionFunction = LogQueryViewModel.FunctionMax; query1.OrderByFunction = LogQueryViewModel.FunctionDscBeauty; query1.OrderByVariable = "E_p"; query1.OrderByReportType = ReportType.AllTrainingEpisodes.ToString(); query1.Validate(); Assert.IsTrue(query1.CanGenerateReports); //The deep copy itself Serialiazer.WriteObject("serialization.txt", query1); LogQueryViewModel query2 = Serialiazer.Clone(query1); //check query2 is a deep copy of query1 variableList.Remove("omega_g"); //check the list is a deep copy of the original foreach (string variable in variableList) { Assert.IsTrue(query2.LogVariableExists(variable)); } Assert.IsTrue(query2.LogVariableExists("omega_g")); Assert.IsTrue(query2.LimitTracks); Assert.IsTrue(query2.MaxNumTracks == 3); Assert.IsTrue(query2.IsForkUsedToGroup("fork-1")); Assert.AreEqual(query1.InGroupSelectionVariable, query2.InGroupSelectionVariable); Assert.AreEqual(query1.InGroupSelectionFunction, query2.InGroupSelectionFunction); Assert.AreEqual(query2.OrderByFunction, LogQueryViewModel.FunctionDscBeauty); Assert.AreEqual(query1.OrderByReportType, query2.OrderByReportType); Assert.IsTrue(query2.CanGenerateReports); Assert.AreNotEqual(query1.QueryId, query2.QueryId); }
/// <summary> /// This method saves a set of queries on a experiment batch and their results to some output folder /// </summary> /// <param name="absBatchFilename">The absolute path to the experiment batch to which the query belongs</param> /// <param name="logQueryResults">The set of queries to be saved</param> /// <param name="absOutputFolder">Absolute path to the output folder, the name of the output report is taken from the input batch file</param> static public void SaveReport(string absBatchFilename, BindableCollection <LogQueryResultViewModel> logQueryResults, string absOutputFolder) { //save the queries and the report (a set of log query results referencing the queries and the experiment batch) string nakedBatchFilename = Herd.Utils.RemoveDirectories(Herd.Utils.RemoveExtension(absBatchFilename, 2)); string reportFilename = absOutputFolder + "/" + nakedBatchFilename + Herd.Files.Extensions.ReportExtension; using (TextWriter writer = File.CreateText(reportFilename)) { //open the root node in the report writer.WriteLine("<" + XMLTags.ReportNodeTag + " " + XMLTags.BatchFilenameAttr + "=\"" + absBatchFilename + "\">"); foreach (LogQueryResultViewModel logQueryResult in logQueryResults) { string nakedLogQueryName = Herd.Utils.RemoveSpecialCharacters(logQueryResult.Name); //Save the reports, each one in a different subfolder string absQueryOutputFolder = absOutputFolder + "/" + nakedLogQueryName; string relOutputFolder = nakedLogQueryName; if (!Directory.Exists(absQueryOutputFolder)) { Directory.CreateDirectory(absQueryOutputFolder); } //Save serializable data string relLogQueryResultFilename = nakedLogQueryName + "/" + nakedLogQueryName + ".xml"; string absLogQueryResultFilename = absOutputFolder + "/" + relLogQueryResultFilename; Serialiazer.WriteObject(absLogQueryResultFilename, logQueryResult); //Save non-serializable data Dictionary <string, string> additionalOutputFiles = logQueryResult.ExportNonSerializable(absQueryOutputFolder); //the reference to the query and non-serializable data files writer.WriteLine(" <" + XMLTags.QueryNodeTag + " " + XMLTags.nameAttribute + "=\"" + relLogQueryResultFilename + "\">"); foreach (string file in additionalOutputFiles.Keys) { writer.WriteLine(" <" + additionalOutputFiles[file] + ">" + file + "</" + additionalOutputFiles[file] + ">"); } writer.WriteLine(" </" + XMLTags.QueryNodeTag + ">"); } //close the root node in the report writer.WriteLine("</" + XMLTags.ReportNodeTag + ">"); } }