//BADGER files: LOAD static public void loadExperiments(WindowViewModel parentWindow , ref BindableCollection <AppViewModel> appViewModelList , Dictionary <string, string> appDefinitions , logFunction log) { string fileDoc = null; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Experiment batch | *." + XMLConfig.badgerExtension; ofd.InitialDirectory = Path.Combine(Path.GetDirectoryName(Directory.GetCurrentDirectory()), "experiments"); if (ofd.ShowDialog() == DialogResult.OK) { fileDoc = ofd.FileName; } else { return; } XmlDocument badgerDoc = new XmlDocument(); badgerDoc.Load(fileDoc); XmlElement fileRoot = badgerDoc.DocumentElement; if (fileRoot.Name != XMLConfig.badgerNodeTag) { CaliburnUtility.showWarningDialog("Malformed XML in experiment queue file. No badger node.", "ERROR"); log("ERROR: malformed XML in experiment queue file. No badger node."); return; } XmlNode configNode; foreach (XmlNode experiment in fileRoot.ChildNodes) { if (experiment.Name == XMLConfig.experimentNodeTag && experiment.ChildNodes.Count > 0) { configNode = experiment.FirstChild; appViewModelList.Add(new AppViewModel(parentWindow, appDefinitions[configNode.Name], configNode , experiment.Attributes[XMLConfig.nameAttribute].Value)); } else { CaliburnUtility.showWarningDialog("Malformed XML in experiment queue file. No badger node.", "ERROR"); log("ERROR: malformed XML in experiment queue file"); } } }
//SAVE EXPERIMENT BATCH: the list of (possibly forked) experiments is saved a as set of experiments without forks public static List <Experiment> saveExperimentBatchFile(BindableCollection <AppViewModel> appViewModelList , ref string batchFilename, logFunction log) { List <Experiment> experimentBatch = new List <Experiment>(); if (appViewModelList.Count == 0) { return(null); } if (batchFilename == "") { //Save dialog -> returns the experiment batch file SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Experiment batch | *." + XMLConfig.experimentBatchExtension; sfd.InitialDirectory = experimentRelativeDir; string CombinedPath = Path.Combine(Directory.GetCurrentDirectory(), experimentRelativeDir); if (!Directory.Exists(CombinedPath)) { Directory.CreateDirectory(CombinedPath); } sfd.InitialDirectory = Path.GetFullPath(CombinedPath); if (sfd.ShowDialog() == DialogResult.OK) { batchFilename = sfd.FileName; } else { log("Error saving the experiment queue"); return(null); } } //clean output directory if it exists string batchFileDir; batchFileDir = batchFilename.Split('.')[0]; batchFileDir = Utility.GetRelativePathTo(Directory.GetCurrentDirectory(), batchFileDir); if (Directory.Exists(batchFileDir)) { try { Directory.Delete(batchFileDir, true); } catch { CaliburnUtility.showWarningDialog("It has not been possible to remove the directory: " + batchFileDir + ". Make sure that it's not been using for other app." , "ERROR"); log("Error saving the experiment queue"); return(null); } } using (FileStream batchFile = File.Create(batchFileDir + "." + XMLConfig.experimentBatchExtension)) { using (StreamWriter batchFileWriter = new StreamWriter(batchFile)) { //batch file header batchFileWriter.WriteLine("<" + XMLConfig.batchNodeTag + ">"); int numCombinations; string filePath, folderPath; string experimentName; foreach (AppViewModel experiment in appViewModelList) { numCombinations = experiment.getNumForkCombinations(); for (int i = 0; i < numCombinations; i++) { //Save the combination of forks as a new experiment experimentName = experiment.setForkCombination(i); folderPath = batchFileDir + "/" + experimentName; Directory.CreateDirectory(folderPath); filePath = folderPath + "/" + experimentName + "." + XMLConfig.experimentExtension; experiment.save(filePath, SaveMode.CombineForks); //Save the experiment reference in the batch file batchFileWriter.WriteLine("<" + XMLConfig.experimentNodeTag + " " + XMLConfig.nameAttribute + "=\"" + experimentName + "\" " + XMLConfig.pathAttribute + "=\"" + filePath + "\"/>"); //Add the experiment to the output list experimentBatch.Add(new Experiment(experimentName, filePath, experiment.getExeFilename() , experiment.getPrerrequisites())); } } //batch file footer batchFileWriter.WriteLine("</" + XMLConfig.batchNodeTag + ">"); log("Succesfully saved " + appViewModelList.Count + " experiments"); } } return(experimentBatch); }
//BADGER files: LOAD public static void loadExperiments(WindowViewModel parentWindow ,ref BindableCollection<AppViewModel> appViewModelList ,Dictionary<string,string> appDefinitions ,logFunction log) { string fileDoc = null; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Experiment batch | *." + XMLConfig.badgerExtension; ofd.InitialDirectory = Path.Combine(Path.GetDirectoryName(Directory.GetCurrentDirectory()), "experiments"); if (ofd.ShowDialog() == DialogResult.OK) { fileDoc = ofd.FileName; } else return; XmlDocument badgerDoc = new XmlDocument(); badgerDoc.Load(fileDoc); XmlElement fileRoot = badgerDoc.DocumentElement; if (fileRoot.Name != XMLConfig.badgerNodeTag) { CaliburnUtility.showWarningDialog("Malformed XML in experiment queue file. No badger node.", "ERROR"); log("ERROR: malformed XML in experiment queue file. No badger node."); return; } XmlNode configNode; foreach (XmlNode experiment in fileRoot.ChildNodes) { if (experiment.Name == XMLConfig.experimentNodeTag && experiment.ChildNodes.Count > 0) { configNode = experiment.FirstChild; appViewModelList.Add(new AppViewModel(parentWindow,appDefinitions[configNode.Name], configNode , experiment.Attributes[XMLConfig.nameAttribute].Value)); } else { CaliburnUtility.showWarningDialog("Malformed XML in experiment queue file. No badger node.", "ERROR"); log("ERROR: malformed XML in experiment queue file"); } } }
//SAVE EXPERIMENT BATCH: the list of (possibly forked) experiments is saved a as set of experiments without forks public static List<Experiment> saveExperimentBatchFile(BindableCollection<AppViewModel> appViewModelList , logFunction log) { List<Experiment> experimentBatch = new List<Experiment>(); string batchFilename; if (appViewModelList.Count == 0) return null; //Save dialog -> returns the experiment batch file SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Experiment batch | *." + XMLConfig.experimentBatchExtension; sfd.InitialDirectory = experimentRelativeDir; string CombinedPath = Path.Combine(Directory.GetCurrentDirectory(), experimentRelativeDir); if (!Directory.Exists(CombinedPath)) Directory.CreateDirectory(CombinedPath); sfd.InitialDirectory = Path.GetFullPath(CombinedPath); if (sfd.ShowDialog() == DialogResult.OK) { batchFilename = sfd.FileName; } else { log("Error saving the experiment queue"); return null; } //clean output directory if it exists batchFilename = batchFilename.Split('.')[0]; batchFilename = Utility.GetRelativePathTo(Directory.GetCurrentDirectory(), batchFilename); if (Directory.Exists(batchFilename)) { try { Directory.Delete(batchFilename, true); } catch { CaliburnUtility.showWarningDialog("It has not been possible to remove the directory: " + batchFilename + ". Make sure that it's not been using for other app." , "ERROR"); log("Error saving the experiment queue"); return null; } } using (FileStream batchFile = File.Create(batchFilename + "." + XMLConfig.experimentBatchExtension)) { using (StreamWriter batchFileWriter = new StreamWriter(batchFile)) { //batch file header batchFileWriter.WriteLine("<" + XMLConfig.batchNodeTag + ">"); int numCombinations; string filePath, folderPath; string experimentName; foreach (AppViewModel experiment in appViewModelList) { numCombinations = experiment.getNumForkCombinations(); for (int i = 0; i < numCombinations; i++) { //Save the combination of forks as a new experiment experimentName= experiment.setForkCombination(i); folderPath = batchFilename + "/" + experimentName; Directory.CreateDirectory(folderPath); filePath = folderPath + "/" + experimentName + "." + XMLConfig.experimentExtension; experiment.save(filePath, SaveMode.CombineForks); //Save the experiment reference in the batch file batchFileWriter.WriteLine("<" + XMLConfig.experimentNodeTag + " " + XMLConfig.nameAttribute + "=\"" + experimentName + "\" " + XMLConfig.pathAttribute + "=\"" + filePath + "\"/>"); //Add the experiment to the output list experimentBatch.Add(new Experiment(experimentName, filePath, experiment.getExeFilename() , experiment.getPrerrequisites())); } } //batch file footer batchFileWriter.WriteLine("</" + XMLConfig.batchNodeTag + ">"); log("Succesfully saved " + appViewModelList.Count + " experiments"); } } return experimentBatch; }