protected override XPathNodeIterator GetListChildren() { ComponentOptions forFetch = new ComponentOptions(); forFetch.LevelDown = 3; forFetch.CompParams = true; forFetch.InstanceUseClassName = true; try { IXPathNavigable nav = this.listController.GetComponentAndChildren(m_rootIDForList, m_rootIDForList, m_listLinkType, forFetch); XPathNodeIterator search = nav.CreateNavigator().Select("Components/Component/Component[@Type='" + m_listItemType + "']/Component[@Type='" + m_listItemType + "']"); // forcount ComponentOptions countOptions = new ComponentOptions(); countOptions.LevelDown = 1; forCount = callingController.GetComponentAndChildren(m_callingRootID, m_callingRootID, m_callingLinkType, countOptions).CreateNavigator(); return search; } catch (Exception e) { MessageBox.Show(e.Message); return null; } }
protected override XPathNodeIterator GetListChildren() { ComponentOptions forFetch = new ComponentOptions(); forFetch.LevelDown = 3; forFetch.CompParams = true; forFetch.InstanceUseClassName = true; try { IXPathNavigable nav = this.listController.GetComponentAndChildren(m_rootIDForList, m_rootIDForList, m_listLinkType, forFetch); //XPathNodeIterator search = nav.CreateNavigator().Select("Components/Component/Component[@Type='" + m_listItemType + "']"); XPathNodeIterator search = nav.CreateNavigator().Select("//Component[@Type='" + m_listItemType + "']"); XPathNavigator returnNav = null; if (removeDuplicates) { // remove duplicate IDs XPathNavigator[] searchTemp = new XPathNavigator[search.Count]; int index = 0; foreach (XPathNavigator searchItem in search) { searchTemp[index] = searchItem; index++; } XmlDocument returnDoc = new XmlDocument(); XmlElement rootEle = returnDoc.CreateElement("Root"); returnDoc.AppendChild(rootEle); returnNav = returnDoc.CreateNavigator(); XPathNavigator rootNav = returnNav.SelectSingleNode("/Root"); Dictionary<String, String> seenIDs = new Dictionary<String, String>(); for (int i = searchTemp.Length - 1; i >= 0; i--) { String ID = searchTemp[i].GetAttribute(XmlSchemaConstants.Display.Component.Id, ""); if (!seenIDs.ContainsKey(ID)) { seenIDs.Add(ID, ID); rootNav.AppendChild(searchTemp[i]); } } } if (removeDuplicates) { return returnNav.Select("/Root/*"); } else { return search; } } catch (Exception e) { MessageBox.Show(e.Message); return null; } }
private void PopulateCustomAttributes() { populating = true; listBoxCustomAttributes.Items.Clear(); IXPathNavigable iNavSensor = controller.GetParametersForComponent(sensorId); XPathNavigator navSensor = iNavSensor.CreateNavigator(); //XPathNavigator sensorAttributeParameter = navSensor.SelectSingleNode("ComponentParameters/Parameter[@category='Engram']/Parameter[@displayedName='Initial Value']"); //if (sensorAttributeParameter != null) //{ //String sensorAttribute = sensorAttributeParameter.GetAttribute("value", navSensor.NamespaceURI); ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 4; compOptions.CompParams = true; IXPathNavigable iNavScenario = controller.GetComponentAndChildren(controller.ScenarioId, controller.ConfigurationLinkType, compOptions); XPathNavigator navScenario = iNavScenario.CreateNavigator(); XPathNodeIterator itNavEmitters = navScenario.Select("/Components/Component/Component[@Type='Engram']");///Component[@Type='State']/Component[@Type='Emitter']"); while (itNavEmitters.MoveNext()) { String engramName = itNavEmitters.Current.GetAttribute("Name", navScenario.NamespaceURI); if (!listBoxCustomAttributes.Items.Contains(engramName)) { listBoxCustomAttributes.Items.Add(engramName); } //XPathNavigator emitterAttributeParameter = itNavEmitters.Current.SelectSingleNode("ComponentParameters/Parameter[@category='Engram']"); //if (emitterAttributeParameter != null) //{ // String emitterAttribute = emitterAttributeParameter.GetAttribute("value", navScenario.NamespaceURI); // //if (sensorAttribute.Equals(emitterAttribute)) // //{ // // XPathNodeIterator itNavLevels = itNavEmitters.Current.Select("Component[@Type='Level']"); // // while (itNavLevels.MoveNext()) // // { // // String levelName = itNavLevels.Current.GetAttribute("Name", navScenario.NamespaceURI); // // if (!comboBox1.Items.Contains(levelName)) // // comboBox1.Items.Add(levelName); // // } // //} //} } //} SelectItem(); populating = false; }
protected override XPathNodeIterator GetListChildren() { ComponentOptions forFetch = new ComponentOptions(); forFetch.LevelDown = 2; forFetch.CompParams = true; IXPathNavigable nav = this.listController.GetComponentAndChildren(m_rootIDForList, m_rootIDForList, m_listLinkType, forFetch); if (xpath == null) { xpath = "//Component[@Type='" + m_listItemType + "']"; } XPathNodeIterator search = nav.CreateNavigator().Select(xpath); return search; }
protected override XPathNodeIterator GetListChildren() { ComponentOptions forFetch = new ComponentOptions(); forFetch.LevelDown = 2; forFetch.CompParams = true; IXPathNavigable nav = this.listController.GetComponentAndChildren(m_rootIDForList, m_rootIDForList, m_listLinkType, forFetch); XPathNodeIterator search = nav.CreateNavigator().Select("Components/Component/Component"); // forcount ComponentOptions countOptions = new ComponentOptions(); countOptions.LevelDown = 1; countOptions.ClassInstanceInfo = true; countOptions.InstanceUseClassName = true; forCount = callingController.GetComponentAndChildren(m_callingRootID, m_callingRootID, m_callingLinkType, countOptions).CreateNavigator(); return search; }
public Int32 GetVisualizationId(int runId) { ComponentOptions compOptions = new ComponentOptions(); compOptions.CompParams = true; IXPathNavigable iNavigator = base._GetComponentAndChildren(runId, "Visualization", true, compOptions);// Doesnt return base type visualization!? XPathNavigator navigator = iNavigator.CreateNavigator(); String visId = String.Empty; Int32 id = -1; if (navigator != null) { XPathNavigator navVisComponent = navigator.SelectSingleNode("Components/Component/Component[@BaseType='Visualization']"); if (navVisComponent != null) { visId = navVisComponent.GetAttribute("ID", navigator.NamespaceURI); id = Int32.Parse("0" + visId); } } return id; }
public IXPathNavigable GetSimRunData(int id) { ComponentOptions compOptions = new ComponentOptions(); compOptions.CompParams = true; IXPathNavigable iNavigator = base._GetComponentAndChildren(id, "Raw", true, compOptions); XPathNavigator navigator = iNavigator.CreateNavigator(); XPathNavigator navFilename = navigator.SelectSingleNode("/Components/Component/Component/ComponentParameters/Parameter/Parameter[@displayedName='Filename']"); String filename = navFilename.GetAttribute("value", navFilename.NamespaceURI); try { return this.m_model.GetOutputXml(filename); } catch (FileNotFoundException e) { logger.Debug("The data for the Run ID " + id + " is not found. FileNotFoundException: " + e.Message); return null; } }
private void fillLevels() { populating = true; comboBox1.Items.Clear(); comboBox1.Text = "<Select Capability>"; ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 5; IXPathNavigable iNavScenario = controller.GetComponentAndChildren(controller.ScenarioId, controller.ConfigurationLinkType, compOptions); XPathNavigator navScenario = iNavScenario.CreateNavigator(); XPathNodeIterator itCapabilities = navScenario.Select("/Components/Component/Component[@Type='Species']/Component[@Type='State']/Component[@Type='Capability']"); while (itCapabilities.MoveNext()) { String name = itCapabilities.Current.GetAttribute("Name", navScenario.NamespaceURI); if (!comboBox1.Items.Contains(name)) comboBox1.Items.Add(name); } selectItem(); populating = false; }
public List<string> GetParameterValues(String parameterName) { List<string> returnList = new List<string>(); for (int j = 0; j < this.selectedItems.Count; j++) { CheckBoxItem fetch = this.selectedItems[j]; int id = fetch.Id; ComponentOptions options = new ComponentOptions(); options.CompParams = true; options.LevelDown = 1; IXPathNavigable raw = myController.GetComponentAndChildren(id, linktype, options); //IXPathNavigable nav = myController.GetParametersForComponent(id); if (raw != null) { String value = GetParameter(raw.CreateNavigator(), parameterName, true); if (value != null && value.Length > 0) { returnList.Add(value); } } } return returnList; }
public void UpdateViewComponent() { updating = true; this.Items.Clear(); this.Columns.Clear(); foreach (String columnName in columnsOnUpdate) { this.Columns.Add(columnName); } if (myController == null) return; ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 1; compOptions.CompParams = true; IXPathNavigable document = myController.GetComponentAndChildren(id, linktype, compOptions); XPathNavigator navigator = document.CreateNavigator(); DrawingUtility.SuspendDrawing(this); XPathNodeIterator elements = null; if (itemtype != "") { elements = navigator.Select(String.Format( "/Components/Component/Component[@Type='{0}' or @BaseType='{0}']", itemtype )); } if (elements != null) { String elementName, elementType; int elementID; foreach (XPathNavigator element in elements) { String runName = GetParameter(element, "Simulation.Simulation Run Name", false); //add the name/id paired item. elementName = element.GetAttribute("Name", element.NamespaceURI); elementType = element.GetAttribute("Type", element.NamespaceURI); elementID = Int32.Parse(element.GetAttribute("ID", element.NamespaceURI)); if (runName != null) { elementName = runName + "-" + elementID; } CheckBoxItem add = new CheckBoxItem(); add.DisplayName = elementName; add.Id = elementID; add.Type = elementType; this.Items.Add(add); } List<int> indicesToRemove = new List<int>(); List<int> indicesToCheck = new List<int>(); for (int i = 0; i < selectedItems.Count; i++) { CheckBoxItem selectedItem = selectedItems[i]; bool found = false; for (int j = 0; j < this.Items.Count; j++) { if (((CheckBoxItem)this.Items[j]).Id.Equals(selectedItem.Id)) { indicesToCheck.Add(j); found = true; } } if (!found) { indicesToRemove.Add(i); } } indicesToRemove.Reverse(); // remove in reverse order for (int i = 0; i < indicesToRemove.Count; i++) { if (indicesToRemove[i] < selectedItems.Count) { selectedItems.RemoveAt(indicesToRemove[i]); } } foreach (int checkme in indicesToCheck) { this.Items[checkme].Checked = true; } //for (int i = 0; i < this.Items.Count; i++) //{ // int itemID = ((CheckBoxItem)this.Items[i]).Id; // if ( // (SmallImageList != null && imageKeysOnUpdate.ContainsKey(itemID)) || // (LargeImageList != null && imageKeysOnUpdate.ContainsKey(itemID)) // ) // { // //this.Items[i].ImageKey = imageKeysOnUpdate[itemID]; // } //} } foreach (ColumnHeader header in this.Columns) { header.Width = -2; // autosize } DrawingUtility.ResumeDrawing(this); updating = false; }
protected override void AddButton_Click(object sender, EventArgs e) { added.Clear(); // commit spinner if active // to have current value for subitems[2] for controller call below this._SaveNumericUpDownValue(); System.Windows.Forms.ListView.SelectedListViewItemCollection selectedCol = this.myScrollingListView.SelectedItems; Boolean update = false; foreach (ListViewItem item in selectedCol) { CustomListItem castItem = (CustomListItem)item; int amountToAdd = Int32.Parse(castItem.SubItems[2].Text); if (amountToAdd > 0) { if (callingController.ViewUpdateStatus == true) { callingController.TurnViewUpdateOff(); // first, turn off updates if we need to update = true; } added.Add(castItem.getID()); try { // just link callingController.Connect(m_callingRootID, m_callingRootID, castItem.getID(), m_callingLinkType); // Get children //m_listLinkType ComponentOptions options = new ComponentOptions(); IXPathNavigable iNav = this.listController.GetComponentAndChildren(m_rootIDForList, castItem.getID(), m_listLinkType, options); XPathNavigator nav = iNav.CreateNavigator(); XPathNavigator navComponent = nav.SelectSingleNode("Components/Component"); if (navComponent != null) { linkChild(navComponent); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } if (update) { callingController.TurnViewUpdateOn(); // turn back on updates if we need to } }
public IXPathNavigable GetComponentAndChildren(int compID, string linkType, ComponentOptions compOptions) { if (compID != -1) { String key = cache.CreateCacheKey(compID, linkType); if (!cache.Contains(m_model, key) || (compOptions.Includes != null && compOptions.Includes.Count > 0) || processingIncludes) { ComponentOptions full = new ComponentOptions(); full.CompParams = true; full.ClassInstanceInfo = true; full.SubclassInstanceInfo = true; full.LinkParams = true; if (processingIncludes) // use the level down and parameter settings for the includes { full.CompParams = compOptions.CompParams; full.LinkParams = compOptions.LinkParams; full.LevelDown = compOptions.LevelDown; } if (compOptions.Includes != null) // index includes for get call { includesMap.Clear(); foreach(Include include in compOptions.Includes) { if (!includesMap.ContainsKey(include.ComponentType)) { includesMap[include.ComponentType] = new List<Include>(); } includesMap[include.ComponentType].Add(include); } } XmlDocument returnDocument = this._GetComponentsXmlDoc(null, compID, linkType, full); if ( (compOptions.LevelDown.HasValue && compOptions.LevelDown.Value > 0) || !compOptions.LevelDown.HasValue) { if (!UseDelayedValidation && !processingIncludes) // skip when either is true { cache.AddCacheDocument(m_model, key, returnDocument); } } if (compOptions.Includes != null) // clear when we're done if we used the map { includesMap.Clear(); } return returnDocument; } else { return cache.GetDocumentFromCache(m_model, key); } } else { return this._GetComponentsXmlDoc(null, compID, linkType, compOptions); } }//GetComponentAndChildren
public void UpdateViewComponent() { DrawingUtility.SuspendDrawing(this); updating = true; // Remove items. this.Items.Clear(); ComponentOptions options = new ComponentOptions(); // Defaults should do. options.LevelDown = 1; IXPathNavigable iNav = controller.GetComponentAndChildren(displayRootId, displayLinkType, options); XPathNavigator nav = iNav.CreateNavigator(); if (transform != null) { XmlDocument newDocument = new XmlDocument(); using (XmlWriter writer = newDocument.CreateNavigator().AppendChild()) { try { transform.Transform(iNav, (XsltArgumentList)null, writer); } catch (XsltException e) { MessageBox.Show(e.Message); } } nav = newDocument.CreateNavigator(); } XPathNodeIterator itNav = nav.Select(String.Format("/Components/Component[@ID='{0}']/Component[@Type='{1}']", displayRootId, displayComponent)); // Add new items. while (itNav.MoveNext()) { String atrributeId = itNav.Current.GetAttribute("ID", nav.NamespaceURI); String atrributeType = itNav.Current.GetAttribute("Type", nav.NamespaceURI); String atrributeName = itNav.Current.GetAttribute("Name", nav.NamespaceURI); CustomLinkComboBoxItem item = new CustomLinkComboBoxItem(); item.Id = Int32.Parse(atrributeId); item.Name = atrributeName; item.Type = atrributeType; this.Items.Add(item); } options.LevelDown = linkLevel; IXPathNavigable iNavConnectLink; if (connectLinkDynamic) iNavConnectLink = controller.GetComponentAndChildren(connectRootId, controller.GetDynamicLinkType(connectLinkType, connectDynamicId.ToString()), options); else iNavConnectLink = controller.GetComponentAndChildren(connectRootId, connectLinkType, options); XPathNavigator navConnectLink = iNavConnectLink.CreateNavigator(); XPathNavigator navLink = navConnectLink.SelectSingleNode(String.Format("//Component[@ID='{0}']/Component[@Type='{1}']", connectFromId, displayComponent)); if (navLink != null) { String atrributeId = navLink.GetAttribute("ID", nav.NamespaceURI); String atrributeType = navLink.GetAttribute("Type", nav.NamespaceURI); String atrributeName = navLink.GetAttribute("Name", nav.NamespaceURI); String atrributeLinkId = navLink.GetAttribute("LinkID", nav.NamespaceURI); Int32 id = Int32.Parse(atrributeId); Int32 linkId = Int32.Parse(atrributeLinkId); for (Int32 i = 0; i <= (this.Items.Count - 1); i++) { CustomLinkComboBoxItem item = this.Items[i] as CustomLinkComboBoxItem; if (id.Equals(item.Id)) { this.SelectedItem = item; this.Tag = linkId; item.LinkId = linkId; break; } } //this.Text = String.Empty; } else { this.Tag = null; this.Text = String.Empty; } updating = false; DrawingUtility.ResumeDrawing(this); }
}//ConfigSchemaFilePath private XmlDocument _GetComponentsXmlDoc(ComponentOptions compOptions) { //Getting validation document XmlDocument validationDoc = this._GetXmlDoc_RootValidation(); //Reading default values from schema through validation document. SchemaDefaults schemaDefs = base._GetDefaultValuesFromSchema(validationDoc); XmlElement topNode; XmlDocument doc = base._GetComponentsXmlDoc(out topNode); //get all of the components of type root and add them to root DataTable rootComponents = base._GetComponentTable(base.RootComponentType); Dictionary<String, String> typeToBaseCache = new Dictionary<String, String>(); Dictionary<String, XmlNode> typeToParametersXMLCache = new Dictionary<String, XmlNode>(); Dictionary<String, List<DataRow>> parameterTableCache = null; if (useLoadingCaches) { parameterTableCache = loadingParameterCache[m_model]; } else { parameterTableCache = GetParameterTableCache(); } foreach (DataRow rootComponent in rootComponents.Rows) { XmlElement xmlElement = base._GetXmlTree(doc, rootComponent, compOptions, schemaDefs, typeToBaseCache, typeToParametersXMLCache, parameterTableCache); if (xmlElement != null) { topNode.AppendChild(xmlElement); } } return doc; }//_GetComponentsXmlDoc
public SensorNode(Diagram dg, List<String> actionValues, XPathNavigator nodeNav, ImageList globalIl, int nodeID, int linkID, String nodeName, String nodeType, List<Function> nodeFunctions, bool xyFromDB, ref int startX, ref int startY, Dictionary<int, DiagramNode> docNodes) { // for now, copy DiagramNode creation. String imagePath = nodeType; //String imagePath = String.Empty; //String paramValueForImage = FunctionHelper.GetParameterValue(actionValues[0], nodeNav); //try //{ // imagePath = FunctionHelper.UpdateImageList(nodeImages, paramValueForImage); //} //catch (Exception ex) //{ // //MessageBox.Show(ex.Message, "Image Load"); // // use type //} dg.LoadNode(nodeID, linkID, nodeName, nodeType, nodeFunctions, imagePath, xyFromDB, ref startX, ref startY, docNodes); // also lookup and add sensor information ComponentOptions options = new ComponentOptions(); options.LevelDown = 1; options.LinkParams = false; options.CompParams = false; String IDConstant = XmlSchemaConstants.Display.Component.Id; String ValueConstant = ConfigFileConstants.Value; XPathNavigator createEvent = null; IXPathNavigable navigable; XPathNavigator nav; // Event to CreateEvent navigable = dg.Controller.GetComponentAndChildren(nodeID, "EventID", options); nav = navigable.CreateNavigator(); createEvent = nav.SelectSingleNode("Components/Component/Component"); if (createEvent != null) { int createEventID = Int32.Parse(createEvent.GetAttribute(IDConstant, nav.NamespaceURI)); // CreateEvent to Species navigable = dg.Controller.GetComponentAndChildren(createEventID, "CreateEventKind", options); nav = navigable.CreateNavigator(); XPathNavigator species = nav.SelectSingleNode("Components/Component/Component"); if (species != null) { int speciesID = Int32.Parse(species.GetAttribute(IDConstant, nav.NamespaceURI)); // Species to FullyFunctional navigable = dg.Controller.GetComponentAndChildren(speciesID, "Scenario", options); nav = navigable.CreateNavigator(); XPathNavigator fullyFunctional = nav.SelectSingleNode("Components/Component/Component[@Name='FullyFunctional']"); if (fullyFunctional != null) { int ffID = Int32.Parse(fullyFunctional.GetAttribute(IDConstant, nav.NamespaceURI)); // Species to Sensor options.CompParams = true; navigable = dg.Controller.GetComponentAndChildren(ffID, "StateSensor", options); nav = navigable.CreateNavigator(); XPathNodeIterator allSensors = nav.Select("Components/Component/Component"); // Sensor.Attribute_Sensor // Sensor.Global_Sensor // Sensor.Attribute // Sensor.Range String globalSensor = String.Empty; String attributeSensor = String.Empty; String attribute = String.Empty; String range = String.Empty; int largestRange = 0; foreach (XPathNavigator sensor in allSensors) { int sensorID = Int32.Parse(sensor.GetAttribute(IDConstant, nav.NamespaceURI)); // is it global or attribute = location XPathNavigator globalNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Global_Sensor']"); if (globalNav != null) { globalSensor = globalNav.GetAttribute(ValueConstant, globalNav.NamespaceURI); } XPathNavigator attributeSensorNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Attribute_Sensor']"); if (attributeSensorNav != null) { attributeSensor = attributeSensorNav.GetAttribute(ValueConstant, attributeSensorNav.NamespaceURI); } XPathNavigator attributeNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Attribute']"); if (attributeNav != null) { attribute = attributeNav.GetAttribute(ValueConstant, attributeNav.NamespaceURI); } XPathNavigator rangeNav = sensor.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='Sensor'][@displayedName='Range']"); if (rangeNav != null) { range = rangeNav.GetAttribute(ValueConstant, rangeNav.NamespaceURI); } if (globalSensor.Equals("true", StringComparison.CurrentCultureIgnoreCase) || (attributeSensor.Equals("true", StringComparison.CurrentCultureIgnoreCase) && attribute.Equals("Location")) ) { // use range int rangeInt = Int32.Parse(range); if (rangeInt > largestRange) { largestRange = rangeInt; } String srSpread = String.Empty; String srRange = String.Empty; // check sensor ranges navigable = dg.Controller.GetComponentAndChildren(sensorID, "Scenario", options); nav = navigable.CreateNavigator(); XPathNodeIterator srsNav = nav.Select("Components/Component/Component[@Type='SensorRange']"); foreach (XPathNavigator srNav in srsNav) { // check spread and range XPathNavigator spreadNav = srNav.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='SensorRange'][@displayedName='Spread']"); if (spreadNav != null) { srSpread = spreadNav.GetAttribute(ValueConstant, spreadNav.NamespaceURI); } XPathNavigator srRangeNav = srNav.SelectSingleNode ("ComponentParameters/Parameter/Parameter[@category='SensorRange'][@displayedName='Range']"); if (srRangeNav != null) { srRange = srRangeNav.GetAttribute(ValueConstant, srRangeNav.NamespaceURI); } int spread = Int32.Parse(srSpread); if (spread == 360) { rangeInt = Int32.Parse(srRange); if (rangeInt > largestRange) { largestRange = rangeInt; } } } } } if (largestRange > 0) { // meters to pixels if (dg.CoordinateTransformer != null) { largestRange = (int)dg.CoordinateTransformer.RetrieveX(largestRange); } GoEllipse sensorEllipse = new GoEllipse(); sensorEllipse.Pen = new Pen(Color.Green, 2.0f); sensorEllipse.Position = new PointF(startX-(largestRange/2), startY-(largestRange/2)); sensorEllipse.Size = new SizeF(largestRange, largestRange); sensorEllipse.Movable = false; sensorEllipse.Selectable = false; dg.Document.Add(sensorEllipse); } } } } }
protected override void LoadParameterData() { String ComponentIDAttribute = XmlSchemaConstants.Display.Component.Id; String ComponentNameAttribute = XmlSchemaConstants.Display.Component.Name; String ParameterNameAttribute = ConfigFileConstants.displayedName; String ParameterCategoryAttribute = ConfigFileConstants.category; String ParameterValueAttribute = ConfigFileConstants.Value; ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 1; compOptions.CompParams = true; IXPathNavigable iNavigator = myController.GetComponentAndChildren(SelectedID, linkType, compOptions); XPathNavigator navigator = iNavigator.CreateNavigator(); DrawingUtility.SuspendDrawing(this); { this.Columns.Clear(); columnCategory.Clear(); paintLeftColumnBorder.Clear(); paintRightColumnBorder.Clear(); this.ContextMenuStrip = null; if (navigator.HasChildren) { tableIndexToComponentID.Clear(); XPathNodeIterator listOfNodes = navigator.Select(String.Format("/Components/Component/Component[@Type='{0}']", filterByType)); List<NameIDParams> nameIDs = new List<NameIDParams>(); Boolean columnsLoaded = false; Boolean rowLoaded = false; List<NameValuePair> paramNameValues; foreach (XPathNavigator nodeNav in listOfNodes) { XPathNodeIterator parameterNodes = nodeNav.Select("ComponentParameters/Parameter/Parameter"); paramNameValues = new List<NameValuePair>(); String paramName, paramValue, paramCategory; foreach (XPathNavigator paramNav in parameterNodes) { paramName = paramNav.GetAttribute(ParameterNameAttribute, paramNav.NamespaceURI); paramCategory = paramNav.GetAttribute(ParameterCategoryAttribute, paramNav.NamespaceURI); paramValue = paramNav.GetAttribute(ParameterValueAttribute, paramNav.NamespaceURI); if (!filterCategories.Contains(paramCategory)) { paramNameValues.Add(new NameValuePair(paramCategory + SchemaConstants.ParameterDelimiter + paramName, paramValue)); } } paramNameValues.Sort(); String[] parameterValues = new String[paramNameValues.Count]; String[] rowValues = new String[paramNameValues.Count]; NameValuePair aColumnNameToAdd; String previousColumnName = ""; String combined; for (int i = 0; i < paramNameValues.Count; i++) { aColumnNameToAdd = paramNameValues[i]; parameterValues[i] = aColumnNameToAdd.Value; if (!columnsLoaded) { // parse combined = aColumnNameToAdd.Name; int delimiterIndex = combined.IndexOf(SchemaConstants.ParameterDelimiter); // "." if (delimiterIndex > 0) { String category = combined.Substring(0, delimiterIndex); int startOfNameIndex = delimiterIndex + 1; String name = combined.Substring(startOfNameIndex, combined.Length - startOfNameIndex); rowValues[i] = name; int addedColumn = -1; if (!category.Equals(previousColumnName)) { addedColumn = this.Columns.Add(" ", " "); columnCategory[addedColumn] = category; // set previous column to draw right border if (addedColumn > 0) { paintRightColumnBorder[addedColumn - 1] = true; } if (i == paramNameValues.Count -1) // last one, paint right { paintLeftColumnBorder[addedColumn] = false; paintRightColumnBorder[addedColumn] = true; } else { paintLeftColumnBorder[addedColumn] = false; paintRightColumnBorder[addedColumn] = false; } } else { addedColumn = this.Columns.Add(" ", " "); columnCategory[addedColumn] = category; if (i == paramNameValues.Count - 1) // last one, paint right { paintLeftColumnBorder[addedColumn] = false; paintRightColumnBorder[addedColumn] = true; } else { paintLeftColumnBorder[addedColumn] = false; paintRightColumnBorder[addedColumn] = false; } } previousColumnName = category; if (addedColumn != -1) { this.Columns[addedColumn].SortMode = DataGridViewColumnSortMode.NotSortable; Size textSize = TextRenderer.MeasureText(rowValues[i], this.Font); int prefWidth = textSize.Width; if (prefWidth < 2) { prefWidth = 2; } this.Columns[addedColumn].MinimumWidth = prefWidth+1;// buffer, TextRenderer can be off this.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(MultiParameterGrid_ColumnHeaderMouseClick); } } // category check } // columns load } // name values columnsLoaded = true; if (!rowLoaded) { if (this.Columns.Count > 0) { this.Rows.Add(rowValues); rowLoaded = true; } } String nodeName = nodeNav.GetAttribute(ComponentNameAttribute, nodeNav.NamespaceURI); int nodeID = Int32.Parse(nodeNav.GetAttribute(ComponentIDAttribute, nodeNav.NamespaceURI)); NameIDParams addPair = new NameIDParams(nodeName, nodeID, parameterValues); nameIDs.Add(addPair); } // all params nameIDs.Sort(); foreach (NameIDParams aPair in nameIDs) { if (Columns.Count > 0) { int addedRow = this.Rows.Add(aPair.ParameterValues); Rows[addedRow].HeaderCell.Value = aPair.Name; tableIndexToComponentID.Add(addedRow, aPair.Id); } } if (Columns.Count == 0) { this.ContextMenuStrip = contextMenuStrip2; // show contextmenu if no columns } } // nav } }
protected virtual XmlDocument buildSourceXml(Int32 selectedId, List<Int32> selectedInputIds) { // Build the source xml file XmlDocument source = new XmlDocument(); XmlDeclaration declaration = source.CreateXmlDeclaration("1.0", "UTF-8", String.Empty); source.AppendChild(declaration); XmlElement root = source.CreateElement("Inputs"); ComponentOptions compOptionsSelNodes = new ComponentOptions(); compOptionsSelNodes.CompParams = true; compOptionsSelNodes.ClassInstanceInfo = true; compOptionsSelNodes.SubclassInstanceInfo = true; Dictionary<String, String> typeToBaseCache = new Dictionary<String, String>(); Dictionary<String, XmlNode> typeToParametersXMLCache = new Dictionary<String, XmlNode>(); Dictionary<String, List<DataRow>> parameterTableCache = this.GetParameterTableCache(); XmlNode nodeSelected = _GetXmlTree(source, this._GetComponent(selectedId), compOptionsSelNodes, null, typeToBaseCache, typeToParametersXMLCache, parameterTableCache); root.AppendChild(nodeSelected); foreach (Int32 input in selectedInputIds) { XmlNode nodeComponent = _GetXmlTree(source, this._GetComponent(input), compOptionsSelNodes, null, typeToBaseCache, typeToParametersXMLCache, parameterTableCache); String component = nodeComponent.Attributes["Type"].Value; String selectedType = (String)_GetComponent(selectedId)["name"]; // Think about this, why reversed in DB String selectedName = (String)_GetComponent(selectedId)["type"]; IXPathNavigable iComponentSimType = m_model.GetComponent(selectedName); XPathNavigator navComponentSimType = iComponentSimType.CreateNavigator(); XPathNodeIterator itLinkTypes = navComponentSimType.Select(String.Format("EngineModel/Inputs/Input[@name='{0}']/Links/Link", component)); foreach (XPathNavigator navLinkType in itLinkTypes) { String linkType = navLinkType.GetAttribute("type", String.Empty); XmlNode nodeLinkType = source.CreateElement("Link"); XmlAttribute attributeLinkType = source.CreateAttribute("Name"); attributeLinkType.Value = linkType; nodeLinkType.Attributes.Append(attributeLinkType); // 3/11/09 mw // Look for includes to pass to ComponentOptions in controller for bridging link types List<Include> includes = new List<Include>(); XPathNodeIterator includesIterator = navLinkType.Select("Include"); foreach (XPathNavigator includeNavigator in includesIterator) { Boolean isDynamic = Boolean.Parse(includeNavigator.GetAttribute("isDynamic", String.Empty)); String linkTypeInclude = includeNavigator.GetAttribute("linkType", String.Empty); String componentType = includeNavigator.GetAttribute("componentType", String.Empty); uint? levelDown = null; bool includeParameters = true; String sLevelDown = includeNavigator.GetAttribute("level", String.Empty); if (sLevelDown != null) { levelDown = uint.Parse(sLevelDown); } String sIncludeParameters = includeNavigator.GetAttribute("includeParameters", String.Empty); if (sIncludeParameters != null) { includeParameters = Boolean.Parse(sIncludeParameters); } Include include = new Include(componentType, linkTypeInclude, isDynamic, levelDown, includeParameters); includes.Add(include); } // 5/8/08 mw - configuration xml change. Input now looks like Inputs/Input/Links/Link[@type]. // so take the type given there and go find the link under Global/Links/Link IXPathNavigable linkIteratorIXP = m_model.GetLink(linkType); if (linkIteratorIXP == null) { throw new Exception("Could not find linktype in Global/Links/Link: " + linkType); } XPathNavigator linkIterator = linkIteratorIXP.CreateNavigator(); // Is this a dynamic linktype? XPathNavigator navDynamic = linkIterator.SelectSingleNode("Dynamic"); // Yes then get names. if (navDynamic != null) { String dynamicComponent = navDynamic.GetAttribute("component", navDynamic.NamespaceURI); String refLinkType = navDynamic.GetAttribute("refLinkType", navDynamic.NamespaceURI); Boolean isRoot = Boolean.Parse(navDynamic.GetAttribute("isRoot", navDynamic.NamespaceURI)); ComponentOptions optionsRefLinkType = new ComponentOptions(); //optionsRefLinkType.LevelDown = 2; // Level needs to be removed when bug fix is completed! optionsRefLinkType.CompParams = false; optionsRefLinkType.LinkParams = false; optionsRefLinkType.ClassInstanceInfo = false; optionsRefLinkType.SubclassInstanceInfo = false; // Should ref link always be dynamic? This could be fixed with always using dynamic links! String refLinkTypeDynamic = navDynamic.GetAttribute("refLinkTypeDynamic", navDynamic.NamespaceURI); Boolean isRefLinkTypeDynamic = true; if (!refLinkTypeDynamic.Equals(String.Empty)) isRefLinkTypeDynamic = XmlConvert.ToBoolean(refLinkTypeDynamic); // What if we dont want PROJECT as the root id for inputs? IXPathNavigable iNavRefLinkType = isRefLinkTypeDynamic ? this.GetComponentAndChildren(input, this.GetDynamicLinkType(refLinkType, input.ToString()), optionsRefLinkType) : this.GetComponentAndChildren(input, refLinkType, optionsRefLinkType); XPathNavigator navRefLinkType = iNavRefLinkType.CreateNavigator(); XPathNodeIterator itDynamicComponents = isRoot ? navRefLinkType.Select(String.Format("/Components/Component[@Type='{0}']", dynamicComponent)) : navRefLinkType.Select(String.Format("/Components/Component/Component[@Type='{0}']", dynamicComponent)); while (itDynamicComponents.MoveNext()) { ComponentOptions optionsDynamicComponent = new ComponentOptions(); optionsDynamicComponent.LevelDown = 2; // Level needs to be removed when bug fix is completed! optionsDynamicComponent.CompParams = true; optionsDynamicComponent.LinkParams = true; optionsDynamicComponent.ClassInstanceInfo = true; optionsDynamicComponent.SubclassInstanceInfo = true; optionsDynamicComponent.Includes = includes; Int32 dynamicComponentId = Int32.Parse(itDynamicComponents.Current.GetAttribute("ID", itDynamicComponents.Current.NamespaceURI)); String dynamicLinkType = GetDynamicLinkType(linkType, dynamicComponentId.ToString()); IXPathNavigable iNavDynamicLink = this.GetComponentAndChildren(input, dynamicLinkType, optionsDynamicComponent); XPathNavigator navDynamicLink = iNavDynamicLink.CreateNavigator(); navDynamicLink = navDynamicLink.SelectSingleNode("/Components/Component"); XmlNode nDynamicLink = source.CreateNode(XmlNodeType.Element, "Dynamic", navDynamicLink.NamespaceURI); XmlAttribute aDynamicLinkName = source.CreateAttribute("Name"); aDynamicLinkName.Value = dynamicLinkType; nDynamicLink.Attributes.Append(aDynamicLinkName); nodeLinkType.AppendChild(nDynamicLink); XPathNodeIterator itDynamicLinks = navDynamicLink.SelectChildren(XPathNodeType.All); while (itDynamicLinks.MoveNext()) { XmlNode nodeSource = ((IHasXmlNode)itDynamicLinks.Current).GetNode(); XmlNode nodeDestination = source.ImportNode(nodeSource, true); nDynamicLink.AppendChild(nodeDestination); } nodeComponent.AppendChild(nodeLinkType); } } // No, just get components. else { ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 2; // Level needs to be removed when bug fix is completed! compOptions.CompParams = true; compOptions.ClassInstanceInfo = true; compOptions.SubclassInstanceInfo = true; compOptions.Includes = includes; IXPathNavigable inav = this.GetComponentAndChildren(input, linkType, compOptions); XPathNavigator nav = inav.CreateNavigator(); nav = nav.SelectSingleNode(String.Format("/Components/Component[@Type='{0}' and @ID='{1}']", component, input)); XPathNodeIterator itNav = nav.SelectChildren(XPathNodeType.All); while (itNav.MoveNext()) { XmlNode nodeSource = ((IHasXmlNode)itNav.Current).GetNode(); XmlNode nodeDestination = source.ImportNode(nodeSource, true); nodeLinkType.AppendChild(nodeDestination); } nodeComponent.AppendChild(nodeLinkType); } } root.AppendChild(nodeComponent); } source.AppendChild(root); source.Save(Path.Combine(this.OutputPath, "source.xml")); return source; }
private void RefreshList() { ComponentOptions compOptions = new ComponentOptions(); IXPathNavigable iNavigator = rc.GetRootComponents(compOptions); XPathNavigator navigator = iNavigator.CreateNavigator(); MD5CryptoServiceProvider x = new MD5CryptoServiceProvider(); Byte[] bs = System.Text.Encoding.UTF8.GetBytes(navigator.OuterXml); bs = x.ComputeHash(bs); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (Byte b in bs) { s.Append(b.ToString("x2").ToLower()); } String newCrc = s.ToString(); if (!crc.Equals(newCrc)) // CRC check - see CustomTreeView and ParameterTable { DrawingUtility.SuspendDrawing(this); listView1.Items.Clear(); crc = newCrc; XPathNodeIterator listofRootElements; listofRootElements = navigator.Select("//Components/Component"); if (listofRootElements != null) { string nodeName; int nodeID; foreach (XPathNavigator paramNav in listofRootElements) { //add the name/id paired item. nodeName = paramNav.GetAttribute(NameAttribute, paramNav.NamespaceURI); nodeID = Int32.Parse(paramNav.GetAttribute(IDAttribute, paramNav.NamespaceURI)); CustomListItem item = new CustomListItem(nodeName, "", nodeID, ""); if (listView1.SmallImageList != null && listView1.SmallImageList.Images.Count > 0) { item.ImageIndex = 0; } listView1.Items.Add(item); } } DrawingUtility.ResumeDrawing(this); } listView1.SelectedItems.Clear(); // delete / open display selected project if (MyProjectFormType == ProjectFormType.Delete || MyProjectFormType == ProjectFormType.Open) { System.Windows.Forms.ListView.ListViewItemCollection items = this.listView1.Items; foreach(ListViewItem anItem in items) { CustomListItem theItem = (CustomListItem)anItem; if (theItem.getID() == SelectedProjectID) { theItem.Selected = true; this.listView1.Select(); } } } this.Show(); }
public IXPathNavigable GetComponent(int compID) { XmlElement topNode; XmlDocument doc = this._GetComponentsXmlDoc(out topNode); ComponentOptions compOptions = new ComponentOptions(); XmlElement element = this._GetXmlTree(doc, this._GetComponent(compID), compOptions, null); if (element != null) topNode.AppendChild(element); return doc; }//GetComponent
}//GetComponentAndChildren public IXPathNavigable GetComponentAndChildren(int topID, int compID, string linkType, ComponentOptions compOptions) { if (topID != -1 && compID != -1) { String key = cache.CreateCacheKey(topID, compID, linkType); if (!cache.Contains(m_model, key)) { // special case - display IDs with no level down, i.e. just the component if ((compOptions.LevelDown.HasValue && compOptions.LevelDown.Value == 0)) { String tryFullRootKey = cache.CreateCacheKey(topID, topID, linkType); if (cache.Contains(m_model, tryFullRootKey)) { XmlDocument baseDoc = cache.GetDocumentFromCache(m_model, tryFullRootKey); XmlNode displayIDNode = baseDoc.SelectSingleNode("//Component[@ID='" + compID + "']"); XmlElement topXmlNode; XmlDocument displayDoc = this._GetComponentsXmlDoc(out topXmlNode); displayIDNode = displayDoc.ImportNode(displayIDNode, true); topXmlNode.AppendChild(displayIDNode); return displayDoc; } else { // error finding display ID ComponentOptions full = new ComponentOptions(); full.CompParams = true; full.ClassInstanceInfo = true; full.SubclassInstanceInfo = true; full.LinkParams = true; XmlDocument returnDocument = this._GetComponentsXmlDoc(topID, compID, linkType, full); if (!UseDelayedValidation) // skip when true { cache.AddCacheDocument(m_model, key, returnDocument); } return returnDocument; } } else { // use full options when adding to cache ComponentOptions full = new ComponentOptions(); full.CompParams = true; full.ClassInstanceInfo = true; full.SubclassInstanceInfo = true; full.LinkParams = true; XmlDocument returnDocument = this._GetComponentsXmlDoc(topID, compID, linkType, full); if (!UseDelayedValidation) // skip when true { cache.AddCacheDocument(m_model, key, returnDocument); } return returnDocument; } } else { return cache.GetDocumentFromCache(m_model, key); } } else { return this._GetComponentsXmlDoc(topID, compID, linkType, compOptions); } }//GetComponentAndChildren
public void UpdateViewComponent() { DrawingUtility.SuspendDrawing(this); // Remove items. this.Items.Clear(); ComponentOptions options = new ComponentOptions(); // Defaults should do. options.LevelDown = 1; IXPathNavigable iNav = controller.GetComponentAndChildren(displayRootId, displayLinkType, options); XPathNavigator nav = iNav.CreateNavigator(); String displayXpath = String.Format("/Components/Component[@ID='{0}']/Component[@Type='{1}']", displayRootId, displayComponentType); if (displayRecursiveCheck) displayXpath = String.Format("/Components/Component[@ID='{0}']//Component[@Type='{1}']", displayRootId, displayComponentType); XPathNodeIterator itNav = nav.Select(displayXpath); // Add new items. while (itNav.MoveNext()) { String atrributeId = itNav.Current.GetAttribute("ID", nav.NamespaceURI); String atrributeType = itNav.Current.GetAttribute("Type", nav.NamespaceURI); String atrributeName = itNav.Current.GetAttribute("Name", nav.NamespaceURI); //String attributeLinkId = itNav.Current.GetAttribute("LinkID", nav.NamespaceURI); CustomLinkBoxItem linkItem = new CustomLinkBoxItem(); linkItem.Id = Int32.Parse(atrributeId); linkItem.LinkId = -1;// Int32.Parse(attributeLinkId); linkItem.Type = atrributeType; if (displayParameterName.Equals(String.Empty)) { linkItem.Name = atrributeName; if (filterResult) { IXPathNavigable iNavParameters = controller.GetParametersForComponent(Int32.Parse(atrributeId)); XPathNavigator navParameters = iNavParameters.CreateNavigator(); XPathNavigator node = navParameters.SelectSingleNode(String.Format("ComponentParameters/Parameter[@category='{0}']/Parameter[@displayedName='{1}']", parameterFilterCategory, parameterFilterName)); if (node != null) { String text = node.GetAttribute("value", String.Empty); if (text.Equals(parameterFilterValue)) { this.Items.Add(linkItem); } } } else this.Items.Add(linkItem); } else { IXPathNavigable iNavParameters = controller.GetParametersForComponent(Int32.Parse(atrributeId)); XPathNavigator navParameters = iNavParameters.CreateNavigator(); XPathNavigator navDisplayParameterName = navParameters.SelectSingleNode(String.Format("ComponentParameters/Parameter[@category='{0}']/Parameter[@displayedName='{1}']", displayParameterCategory, displayParameterName)); if (navDisplayParameterName != null) { String displayParameterValue = navDisplayParameterName.GetAttribute("value", String.Empty); if (!displayParameterValue.Equals(String.Empty)) { linkItem.Name = displayParameterValue; if (filterResult) { XPathNavigator navParameterFilterName = navParameters.SelectSingleNode(String.Format("ComponentParameters/Parameter[@category='{0}']/Parameter[@displayedName='{1}']", parameterFilterCategory, parameterFilterName)); if (navParameterFilterName != null) { String parameterValue = navParameterFilterName.GetAttribute("value", String.Empty); if (parameterValue.Equals(parameterFilterValue)) { this.Items.Add(linkItem); } } } else this.Items.Add(linkItem); } } } } // Now check for links. updatingView = true; checkForLinks(); updatingView = false; DrawingUtility.ResumeDrawing(this); }
private void customParameterEnumBox1_SelectedValueChanged(object sender, EventArgs e) { if (customParameterEnumBox1.SelectedItem != null) { string value = customParameterEnumBox1.SelectedItem.ToString(); if (((value == "Default") || (value == "Invisible")) && (!updating)) { // get parameters using node id ComponentOptions c = new ComponentOptions(); c.CompParams = true; IXPathNavigable iNavParameters = controller.GetComponentAndChildren(emitterId, "Scenario", c); XPathNavigator navParameters = iNavParameters.CreateNavigator(); XPathNodeIterator itr = navParameters.Select(".//Component[@Type='Level']"); if (itr.Count > 0) { if (MessageBox.Show("Selecting this option will delete this emitter's existing levels.\nDo you want to continue?", "Delete Levels", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { foreach (XPathNavigator node in itr) { String attributeValue = node.GetAttribute("ID", node.NamespaceURI); if (attributeValue != string.Empty) { controller.DeleteComponent(Convert.ToInt32(attributeValue)); } } } else { customParameterEnumBox1.SelectedIndex = previous_index; } } } previous_index = customParameterEnumBox1.SelectedIndex; } }
private void checkForLinks() { ComponentOptions options = new ComponentOptions(); // Defaults should do. //options.LevelDown = checkLinkLevel; IXPathNavigable iNav = controller.GetComponentAndChildren(connectRootId, connectLinkType, options); XPathNavigator nav = iNav.CreateNavigator(); XPathNodeIterator itNav = nav.Select(String.Format("//Component[@ID='{0}']/Component[@Type='{1}']", connectFromId, displayComponentType)); // Check appropriate items. while (itNav.MoveNext()) { String atrributeId = itNav.Current.GetAttribute("ID", nav.NamespaceURI); String atrributeType = itNav.Current.GetAttribute("Type", nav.NamespaceURI); String atrributeName = itNav.Current.GetAttribute("Name", nav.NamespaceURI); String atrributeLinkId = itNav.Current.GetAttribute("LinkID", nav.NamespaceURI); Int32 id = Int32.Parse(atrributeId); Int32 linkId = Int32.Parse(atrributeLinkId); for (Int32 i = 0; i <= (this.Items.Count - 1); i++) { CustomLinkBoxItem item = this.Items[i] as CustomLinkBoxItem; if (id.Equals(item.Id)) { this.SetItemChecked(i, true); item.LinkId = linkId; this.SetSelected(i, true); } } } }
private void PopulateCustomAttributes() { populating = true; listBoxCustomAttribute.Items.Clear(); IXPathNavigable iNavEmitter = controller.GetParametersForComponent(emitterId); XPathNavigator navEmitter = iNavEmitter.CreateNavigator(); ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 4; compOptions.CompParams = true; IXPathNavigable iNavScenario = controller.GetComponentAndChildren(controller.ScenarioId, controller.ConfigurationLinkType, compOptions); XPathNavigator navScenario = iNavScenario.CreateNavigator(); /*standard attribute*/ //customRadioButton2.Checked = !Convert.ToBoolean(navEmitter.SelectSingleNode("ComponentParameters/Parameter[@category='Emitter']/Parameter[@displayedName='Custom_Attribute_Emitter']").GetAttribute("value", navEmitter.NamespaceURI)); XPathNodeIterator itNavEngrams = navScenario.Select("/Components/Component/Component[@Type='Engram']"); while (itNavEngrams.MoveNext()) { String engramName = itNavEngrams.Current.GetAttribute("Name", navScenario.NamespaceURI); if (!listBoxCustomAttribute.Items.Contains(engramName)) { listBoxCustomAttribute.Items.Add(engramName); } } if (this.customRadioButton1.Checked) SelectItem(); populating = false; }
public void UpdateViewComponent() { if (controller == null) return; if (componentId < 0) { this.SuspendLayout(); this.Columns.Clear(); this.ResumeLayout(); return; } this.SuspendLayout(); controller.TurnViewUpdateOff(); this.Columns.Clear(); ComponentOptions compOptions = new ComponentOptions(); IXPathNavigable iNavComponent = controller.GetComponentAndChildren(this.rootId, sourceLink, compOptions); XPathNavigator navComponent = iNavComponent.CreateNavigator(); // The xpath here needs to be configurable if the component is to remain totally reusable. XPathNodeIterator itComponent = navComponent.Select(String.Format("/Components/Component/Component[@Type='{0}']", this.componentFrom)); this.Columns.Add(this.componentTo, this.componentTo); this.Columns.Add("Parameter", this.parameter); this.Columns[0].ReadOnly = true; //this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; // Might want this to be configurrable for links that are not dynamic... however the AME will soon be able to detect when to do this. String dynamicLink = controller.GetDynamicLinkType(link, this.componentId.ToString()); while (itComponent.MoveNext()) { String id = itComponent.Current.GetAttribute("ID", itComponent.Current.NamespaceURI); String name = itComponent.Current.GetAttribute("Name", itComponent.Current.NamespaceURI); DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellFirst = new DataGridViewTextBoxCell(); cellFirst.Tag = id; cellFirst.Value = name; row.Cells.Add(cellFirst); Int32 linkId = this.controller.GetLinkID(this.componentId, Int32.Parse(id), dynamicLink); if (linkId < 0) linkId = controller.Connect(componentId, componentId, Int32.Parse(id), dynamicLink); if (linkId >= 0) { IXPathNavigable iNavLinkParameters = controller.GetParametersForLink(linkId); XPathNavigator navLinkParameters = iNavLinkParameters.CreateNavigator(); XPathNavigator navLinkParameter = navLinkParameters.SelectSingleNode(String.Format("/LinkParameters/Parameter[@category='{0}']/Parameter[@displayedName='{1}']", this.parameterCategory, this.parameter)); String value = navLinkParameter.GetAttribute("value", navLinkParameter.NamespaceURI); DataGridViewTextBoxCell cellLast = new DataGridViewTextBoxCell(); cellLast.Tag = linkId; cellLast.Value = value; row.Cells.Add(cellLast); } else { //throw new Exception("Error in Indentity to Indentity links"); System.Windows.Forms.MessageBox.Show("Error with data!", "Error"); //this.Rows[index].Visible = false; return; } this.Rows.Add(row); } foreach (DataGridViewColumn column in this.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; this.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); controller.TurnViewUpdateOn(false, false); this.ResumeLayout(); }
private void fillLevels() { populating = true; comboBox1.Items.Clear(); comboBox1.Text = "<Select Level>"; IXPathNavigable iNavSensor = _vsgController.GetParametersForComponent(_sensorID); XPathNavigator navSensor = iNavSensor.CreateNavigator(); _isCustomAttribute = Convert.ToBoolean(navSensor.SelectSingleNode("ComponentParameters/Parameter[@category='Sensor']/Parameter[@displayedName='Custom_Attribute_Sensor']").GetAttribute("value", navSensor.NamespaceURI)); XPathNavigator sensorAttributeParameter;// = navSensor.SelectSingleNode("ComponentParameters/Parameter[@category='Sensor']/Parameter[@displayedName='Attribute']"); if (_isCustomAttribute) { sensorAttributeParameter = navSensor.SelectSingleNode("ComponentParameters/Parameter[@category='Sensor']/Parameter[@displayedName='Custom_Attribute']"); } else { sensorAttributeParameter = navSensor.SelectSingleNode("ComponentParameters/Parameter[@category='Sensor']/Parameter[@displayedName='Attribute']"); } if (sensorAttributeParameter != null) { String sensorAttribute = sensorAttributeParameter.GetAttribute("value", navSensor.NamespaceURI); ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 4; compOptions.CompParams = true; IXPathNavigable iNavScenario = _vsgController.GetComponentAndChildren(_vsgController.ScenarioId, _vsgController.ConfigurationLinkType, compOptions); XPathNavigator navScenario = iNavScenario.CreateNavigator(); XPathNodeIterator itNavEmitters = navScenario.Select("/Components/Component/Component[@Type='Species']/Component[@Type='State']/Component[@Type='Emitter']"); while (itNavEmitters.MoveNext()) { XPathNavigator emitterAttributeParameter; if (_isCustomAttribute) { emitterAttributeParameter = itNavEmitters.Current.SelectSingleNode("ComponentParameters/Parameter[@category='Emitter']/Parameter[@displayedName='Custom_Attribute']"); } else { emitterAttributeParameter = itNavEmitters.Current.SelectSingleNode("ComponentParameters/Parameter[@category='Emitter']/Parameter[@displayedName='Attribute']"); } if (emitterAttributeParameter != null) { String emitterAttribute = emitterAttributeParameter.GetAttribute("value", navScenario.NamespaceURI); if (sensorAttribute.Equals(emitterAttribute)) { XPathNodeIterator itNavLevels = itNavEmitters.Current.Select("Component[@Type='Level']"); while (itNavLevels.MoveNext()) { String levelName = itNavLevels.Current.GetAttribute("Name", navScenario.NamespaceURI); if (!comboBox1.Items.Contains(levelName)) comboBox1.Items.Add(levelName); } } } } } selectItem(); populating = false; }
}//UpdateRootName public IXPathNavigable GetRootComponents(ComponentOptions compOptions) { return this._GetComponentsXmlDoc(compOptions).Clone(); }//GetRootComponents
private void checkEngramRange() { if (displayID >= 0) { updating = true; ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 1; IXPathNavigable iNav = _controller.GetComponentAndChildren(displayID, customLinkBox1.ConnectLinkType, compOptions); XPathNavigator nav = iNav.CreateNavigator(); if (nav.SelectSingleNode("/Components/Component/Component[@Type='Engram']") != null) { useEngramRangeCheckbox.Checked = true; groupBox1.Enabled = true; bool storeUpdating = updating; updating = false; UpdateViewComponent(); updating = storeUpdating; } else { ClearViewComponents(); } updating = false; } }
protected override void LoadParameterData() { String IDAttribute = XmlSchemaConstants.Display.Component.Id; String NameAttribute = XmlSchemaConstants.Display.Component.Name; String LinkIDAttribute = XmlSchemaConstants.Display.Component.LinkID; IXPathNavigable iNavigator; if (displayID != SelectedID) // requires an additional level; base is now one node below root { ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 3; compOptions.LinkParams = true; iNavigator = this.myController.GetComponentAndChildren(SelectedID, linkType, compOptions); } else { ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 2; compOptions.LinkParams = true; iNavigator = this.myController.GetComponentAndChildren(SelectedID, linkType, compOptions); } XPathNavigator navigator = iNavigator.CreateNavigator(); DrawingUtility.SuspendDrawing(this); { this.Columns.Clear(); pairInformation = new List<ComponentPair>(); bool selectOffRoot = true; if (displayID != SelectedID) { // set iterator to display ID XPathNodeIterator iterator = navigator.Select("//Component[@" + IDAttribute + "='" + displayID + "']"); if (iterator.Count == 1) { iterator.MoveNext(); navigator = iterator.Current; selectOffRoot = false; // different xpaths below } } if (navigator.HasChildren) { tableIndexToComponentID = new Dictionary<int, int>(); componentIDToTableIndex = new Dictionary<int,int>(); XPathNodeIterator listOfNodes; if (selectOffRoot) { listOfNodes = navigator.Select("/Components/Component/Component"); // path relative to root } else { listOfNodes = navigator.Select("Component"); // path relative to any component } List<NameIDPair> nameIDs = new List<NameIDPair>(); foreach (XPathNavigator nodeNav in listOfNodes) { String nodeName = nodeNav.GetAttribute(NameAttribute, nodeNav.NamespaceURI); int nodeID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI)); NameIDPair addPair = new NameIDPair(nodeName, nodeID); nameIDs.Add(addPair); } nameIDs.Sort(); foreach (NameIDPair aPair in nameIDs) { int addedColumn = Columns.Add(aPair.Name, aPair.Name); int addedRow = this.Rows.Add(); this.Columns[addedColumn].SortMode = DataGridViewColumnSortMode.NotSortable; this.Columns[addedColumn].MinimumWidth = this.Columns[addedColumn].HeaderCell.PreferredSize.Width; Rows[addedRow].HeaderCell.Value = aPair.Name; tableIndexToComponentID.Add(addedRow, aPair.Id); componentIDToTableIndex.Add(aPair.Id, addedRow); } int fromID, toID; int rowIndex, columnIndex, linkID; String linkString = "", paramValue = ""; //now, form links. foreach (XPathNavigator nodeNav in listOfNodes) { fromID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI)); rowIndex = componentIDToTableIndex[fromID]; if (nodeNav.HasChildren) { XPathNodeIterator listOfChildren = nodeNav.Select("Component"); foreach (XPathNavigator childNav in listOfChildren) { toID = Int32.Parse(childNav.GetAttribute(IDAttribute, childNav.NamespaceURI)); if (componentIDToTableIndex.ContainsKey(toID)) { columnIndex = componentIDToTableIndex[toID]; linkString = childNav.GetAttribute(LinkIDAttribute, childNav.NamespaceURI); if (linkString != "") { linkID = Int32.Parse(linkString); } else { linkID = -1; } pairInformation.Add(new ComponentPair(fromID, toID, linkID)); XPathNavigator pnav = childNav.SelectSingleNode("LinkParameters/Parameter/Parameter"); if (pnav != null) { paramValue = pnav.GetAttribute("value", pnav.NamespaceURI); if (paramValue.Equals("")) { this[columnIndex, rowIndex].Value = linkWithNoValueRepresentation; } else { this[columnIndex, rowIndex].Value = paramValue; } } else { this[columnIndex, rowIndex].Value = linkRepresentation; } } } } } } } }
public void UpdateViewComponent() { Dictionary<int, CheckboxItem> items = new Dictionary<int, CheckboxItem>(); ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 1; IXPathNavigable document = m_controller.GetComponentAndChildren(m_sourceParentComponentId, m_sourceLinkType, compOptions); XPathNavigator navigator = document.CreateNavigator(); DrawingUtility.SuspendDrawing(this); this.Items.Clear(); XPathNodeIterator listofRootElements; //listofRootElements = navigator.Select(String.Format("/Components/Component/Component")); listofRootElements = navigator.Select(String.Format( "/Components/Component/Component[@Type='{0}' or @BaseType='{0}']", "DecisionMaker" )); // Add the checkbox items if (listofRootElements != null) { //bool selectedFound = false; String nodeName; int nodeID; foreach (XPathNavigator paramNav in listofRootElements) { //add the name/id paired item. nodeName = paramNav.GetAttribute(NameAttribute, paramNav.NamespaceURI); nodeID = Int32.Parse(paramNav.GetAttribute(IDAttribute, paramNav.NamespaceURI)); CheckboxItem item = new CheckboxItem(nodeName, nodeID); //this.Items.Add(item); this.Items.Add(item,((VSGController)m_controller).IsLinked(nodeID,m_destParentComponentId,m_destLinkType)); items[item.MyID] = item; } } // Select the items that are connected to the destination /* IXPathNavigable document2 = m_controller.GetComponentAndChildren(m_destParentComponentId, m_destLinkType, compOptions); XPathNavigator navigator2 = document2.CreateNavigator(); XPathNodeIterator listofRootElements2; listofRootElements2 = navigator2.Select(String.Format("/Components/Component/Component")); foreach (XPathNavigator paramNav in listofRootElements2) { String nodeName2; int nodeID2; nodeName2 = paramNav.GetAttribute(NameAttribute, paramNav.NamespaceURI); nodeID2 = Int32.Parse(paramNav.GetAttribute(IDAttribute, paramNav.NamespaceURI)); if (items.ContainsKey(nodeID2)) { int i = this.Items.IndexOf(items[nodeID2]); this.SetItemChecked(i, true); } } */ DrawingUtility.ResumeDrawing(this); }