public BranchConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent , XmlNode definitionNode, string parentXPath, XmlNode configNode= null, bool initChildren= true) { commonInit(appDefinition,parent, definitionNode,parentXPath); m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value; if (definitionNode.Attributes.GetNamedItem(XMLConfig.windowAttribute) != null) m_window = definitionNode.Attributes[XMLConfig.windowAttribute].Value; else m_window = ""; if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null) bIsOptional = definitionNode.Attributes[XMLConfig.optionalAttribute].Value == "true"; else bIsOptional = false; if (configNode != null) { configNode = configNode[name]; if (configNode != null && bIsOptional) bIsUsed = true; } else if (bIsOptional) bIsUsed = true; if (initChildren) childrenInit(appDefinition, appDefinition.getClassDefinition(m_className), m_xPath, configNode); }
public ChoiceElementConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode , string parentXPath, XmlNode configNode= null) { commonInit(appDefinition,parent,definitionNode,parentXPath); m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value; if (definitionNode.Attributes.GetNamedItem(XMLConfig.windowAttribute) != null) m_window = definitionNode.Attributes[XMLConfig.windowAttribute].Value; else m_window = ""; if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null) m_bOptional = definitionNode.Attributes[XMLConfig.optionalAttribute].Value == "true"; else m_bOptional = false; if (definitionNode.Attributes.GetNamedItem(XMLConfig.loadXMLFileAttribute) != null) m_loadXML = definitionNode.Attributes[XMLConfig.loadXMLFileAttribute].Value; else m_loadXML = ""; if (m_loadXML != "") { m_appViewModel.loadAuxDefinitions(m_loadXML); } if (configNode != null) configNode = configNode[name]; //we allow an undefined class ("", most likely) and we just ignore children childrenInit(appDefinition, appDefinition.getClassDefinition(m_className,true) , m_xPath, configNode); }
//constructor called when loading a fork from a .badger file public ForkValueViewModel(AppViewModel appViewModel,XmlNode classDefinition , ConfigNodeViewModel parentNode, XmlNode configNode) { name = configNode.Attributes[XMLConfig.nameAttribute].Value; //not sure how to do this in a more elegant way this.configNode = ConfigNodeViewModel.getInstance(appViewModel, parentNode , classDefinition, parentNode.xPath, configNode); this.configNode.bCanBeForked = false; //already belongs to a fork }
//Constructor used from the experiment editor public ForkedNodeViewModel(AppViewModel appViewModel,ConfigNodeViewModel forkedNode) { m_parent = forkedNode.parent; ForkValueViewModel newForkValue= new ForkValueViewModel("Value-0", this, forkedNode); children.Add(newForkValue); selectedForkValue = newForkValue; m_appViewModel = appViewModel; nodeDefinition = forkedNode.nodeDefinition; name = forkedNode.name; NotifyOfPropertyChange(() => selectedForkValue); }
public DoubleValueConfigViewModel(AppViewModel appViewModel, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { commonInit(appViewModel, parent, definitionNode, parentXPath); if (configNode == null || configNode[name]==null) { //default init content = definitionNode.Attributes[XMLConfig.defaultAttribute].Value; textColor = XMLConfig.colorDefaultValue; } else { //init from config file content = configNode[name].InnerText; } }
public EnumeratedValueConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { commonInit(appDefinition, parent, definitionNode, parentXPath); m_class = definitionNode.Attributes[XMLConfig.classAttribute].Value; enumeratedNames = m_appViewModel.getEnumeratedType(m_class); if (configNode == null || configNode[name] == null) { content = m_default; textColor = XMLConfig.colorDefaultValue; } else { //init from config file content = configNode[name].InnerText; } }
//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; }
//Initialization stuff common to all types of configuration nodes protected void commonInit(AppViewModel appViewModel, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath) { name = definitionNode.Attributes[XMLConfig.nameAttribute].Value; //#if DEBUG // System.Console.WriteLine("loading " + name); //#endif m_parent = parent; m_appViewModel = appViewModel; nodeDefinition = definitionNode; xPath = parentXPath + "/" + name; if (definitionNode.Attributes.GetNamedItem(XMLConfig.defaultAttribute) != null) { m_default = definitionNode.Attributes[XMLConfig.defaultAttribute].Value; } if (definitionNode.Attributes.GetNamedItem(XMLConfig.commentAttribute) != null) { comment = definitionNode.Attributes[XMLConfig.commentAttribute].Value; } }
//Constructor called when loading an experiment config file public ForkedNodeViewModel(AppViewModel appViewModel,ConfigNodeViewModel parentNode ,XmlNode classDefinition,XmlNode configNode= null, bool initChildren= true) { m_appViewModel = appViewModel; nodeDefinition = classDefinition; m_parent = parentNode; name = configNode.Attributes[XMLConfig.nameAttribute].Value; if (initChildren) { foreach (XmlNode forkValueConfig in configNode.ChildNodes) { children.Add(new ForkValueViewModel(appViewModel, classDefinition, this, forkValueConfig)); } } //notify changes if (children.Count > 0) selectedForkValue = children[0] as ForkValueViewModel; NotifyOfPropertyChange(() => children); }
public BranchConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent , XmlNode definitionNode, string parentXPath, XmlNode configNode = null, bool initChildren = true) { commonInit(appDefinition, parent, definitionNode, parentXPath); m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value; if (definitionNode.Attributes.GetNamedItem(XMLConfig.windowAttribute) != null) { m_window = definitionNode.Attributes[XMLConfig.windowAttribute].Value; } else { m_window = ""; } if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null) { bIsOptional = bool.Parse(definitionNode.Attributes[XMLConfig.optionalAttribute].Value); } else { bIsOptional = false; } if (configNode != null) { configNode = configNode[name]; if (configNode != null && bIsOptional) { bIsUsed = true; } } else if (bIsOptional) { bIsUsed = true; } if (initChildren) { childrenInit(appDefinition, appDefinition.getClassDefinition(m_className), m_xPath, configNode); } }
public MultiValuedItemConfigViewModel(AppViewModel appDefinition,MultiValuedConfigViewModel parent ,XmlNode definitionNode, string parentXPath, XmlNode configNode=null) { commonInit(appDefinition,parent,definitionNode,parentXPath); m_parent = parent; m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value; switch (m_className) { case XMLConfig.integerNodeTag: children.Add(new IntegerValueConfigViewModel(appDefinition, this,definitionNode, m_xPath, configNode));break; case XMLConfig.doubleNodeTag: children.Add(new DoubleValueConfigViewModel(appDefinition, this,definitionNode, m_xPath, configNode));break ; case XMLConfig.stringNodeTag: children.Add(new StringValueConfigViewModel(appDefinition, this, definitionNode, m_xPath, configNode));break ; case XMLConfig.filePathNodeTag: children.Add(new FilePathValueConfigViewModel(appDefinition, this,definitionNode, m_xPath, configNode));break ; case XMLConfig.dirPathNodeTag: children.Add(new DirPathValueConfigViewModel(appDefinition, this,definitionNode, m_xPath, configNode));break ; default: XmlNode classDefinition = appDefinition.getClassDefinition(m_className); if (classDefinition != null) childrenInit(appDefinition, appDefinition.getClassDefinition(m_className), m_xPath, configNode); break; } }
//Constructor called when loading an experiment config file public ForkedNodeViewModel(AppViewModel appViewModel, ConfigNodeViewModel parentNode , XmlNode classDefinition, XmlNode configNode = null, bool initChildren = true) { m_appViewModel = appViewModel; nodeDefinition = classDefinition; m_parent = parentNode; name = configNode.Attributes[XMLConfig.nameAttribute].Value; if (initChildren) { foreach (XmlNode forkValueConfig in configNode.ChildNodes) { children.Add(new ForkValueViewModel(appViewModel, classDefinition, this, forkValueConfig)); } } //notify changes if (children.Count > 0) { selectedForkValue = children[0] as ForkValueViewModel; } NotifyOfPropertyChange(() => children); }
public MultiValuedConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent , XmlNode definitionNode, string parentXPath, XmlNode configNode= null, bool initChildren= true) { commonInit(appDefinition,parent, definitionNode,parentXPath); m_className = definitionNode.Attributes[XMLConfig.classAttribute].Value; if (definitionNode.Attributes.GetNamedItem(XMLConfig.optionalAttribute) != null) m_bOptional = definitionNode.Attributes[XMLConfig.optionalAttribute].Value == "true"; else m_bOptional = false; if (configNode!=null) { foreach(XmlNode configChild in configNode.ChildNodes) { if (configChild.Name==name) children.Add(new MultiValuedItemConfigViewModel(appDefinition, this,definitionNode, m_xPath, configChild)); } } else //default initialization { if (initChildren && !m_bOptional) children.Add(new MultiValuedItemConfigViewModel(appDefinition, this,definitionNode, m_xPath)); } }
public XmlDefRefValueConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent, XmlNode definitionNode, string parentXPath, XmlNode configNode = null) { commonInit(appDefinition, parent, definitionNode, parentXPath); m_hangingFrom = definitionNode.Attributes[XMLConfig.hangingFromAttribute].Value; if (configNode != null) { configNode = configNode[name]; selectedEnumeratedName = configNode.InnerText; } //the xml definition file may not be yet loaded enumeratedNames = m_appViewModel.getAuxDefinition(m_hangingFrom); if (enumeratedNames == null) { //Either we have loaded the config but the list is of values has not yet been loaded //or no config file has been loaded. In Either case, we register for a deferred load step m_appViewModel.registerDeferredLoadStep(updateXMLDefRef); } m_appViewModel.registerXMLDefRef(updateXMLDefRef); }
public ChoiceConfigViewModel(AppViewModel appDefinition, ConfigNodeViewModel parent , XmlNode definitionNode , string parentXPath, XmlNode configNode = null, bool initChildren= true) { string choiceElementName; commonInit(appDefinition, parent, definitionNode, parentXPath); if (configNode != null) configNode = configNode[name]; if (initChildren) { foreach (XmlNode choiceElement in definitionNode.ChildNodes) { choiceElementName = choiceElement.Attributes[XMLConfig.nameAttribute].Value; m_choiceNames.Add(choiceElementName); if (configNode != null && choiceElementName == configNode.ChildNodes[0].Name) { loadSelectedChoiceElement(choiceElementName, configNode); } } } }
public void close(AppViewModel app) { tabControlExperiments.Remove(app); NotifyOfPropertyChange(() => listControlExperiments); checkEmptyExperimentList(); }
public void newExperiment() { if (m_selectedAppName == null) return; string xmlDefinitionFile = appDefinitions[m_selectedAppName]; AppViewModel newApp = new AppViewModel(this,xmlDefinitionFile,null,"New"); tabControlExperiments.Add( newApp); NotifyOfPropertyChange(() => tabControlExperiments); NotifyOfPropertyChange(() => listControlExperiments); checkEmptyExperimentList(); selectedTabControlExperiment = newApp; }
public static void saveExperiment(AppViewModel experiment) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Experiment | *." + XMLConfig.experimentExtension; sfd.InitialDirectory = experimentRelativeDir; string CombinedPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), experimentRelativeDir); if (!Directory.Exists(CombinedPath)) System.IO.Directory.CreateDirectory(CombinedPath); sfd.InitialDirectory = System.IO.Path.GetFullPath(CombinedPath); if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { experiment.save(sfd.FileName, SaveMode.SaveForks); } }