//This constructor builds the whole tree of ConfigNodes either // -with default values ("New") // -with a configuration file ("Load") public AppViewModel(WindowViewModel parentWindow, string appDefinitionFileName, string configFilename) { m_parent = parentWindow; //Load the configFile if a configFilename is provided XmlDocument configDoc= null; XmlNode configRootNode = null; if (configFilename != null) { configDoc = new XmlDocument(); configDoc.Load(configFilename); configRootNode = configDoc.LastChild; } init(appDefinitionFileName, configRootNode, Utility.getFileName(configFilename, true)); }
//This constructor builds the whole tree of ConfigNodes either // -with default values ("New") // -with a configuration file ("Load") public AppViewModel(WindowViewModel parentWindow, string appDefinitionFileName, string configFilename) { m_parent = parentWindow; //Load the configFile if a configFilename is provided XmlDocument configDoc = null; XmlNode configRootNode = null; if (configFilename != null) { configDoc = new XmlDocument(); configDoc.Load(configFilename); configRootNode = configDoc.LastChild; } init(appDefinitionFileName, configRootNode, Utility.getFileName(configFilename, true)); }
//EXPERIMENT file: LOAD public static AppViewModel loadExperiment(WindowViewModel parentWindow,Dictionary<string,string> appDefinitions) { string fileDoc = null; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Experiment | *." + XMLConfig.experimentExtension; ofd.InitialDirectory = Path.Combine(Path.GetDirectoryName(Directory.GetCurrentDirectory()), "experiments"); if (ofd.ShowDialog() == DialogResult.OK) { fileDoc = ofd.FileName; } else return null; //open the config file to retrive the app's name before loading it XmlDocument configDocument = new XmlDocument(); configDocument.Load(fileDoc); XmlNode rootNode = configDocument.LastChild; AppViewModel newApp = new AppViewModel(parentWindow,appDefinitions[rootNode.Name], fileDoc); return newApp; }
//This constructor is called when a badger file is loaded. Because all the experiments are embedded within a single //XML file, the calling method will be passing XML nodes belonging to the single XML file instead of filenames public AppViewModel(WindowViewModel parentWindow, string appDefinitionFileName, XmlNode configRootNode,string experimentName) { m_parent = parentWindow; init(appDefinitionFileName, configRootNode,experimentName); }
//This constructor is called when a badger file is loaded. Because all the experiments are embedded within a single //XML file, the calling method will be passing XML nodes belonging to the single XML file instead of filenames public AppViewModel(WindowViewModel parentWindow, string appDefinitionFileName, XmlNode configRootNode, string experimentName) { m_parent = parentWindow; init(appDefinitionFileName, configRootNode, experimentName); }
//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"); } } }