static void Main(string[] args) { PerfTest perf = new PerfTest(); int repeat = 1000; perf.Start(); XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource)); //XmlDocument doc = new XmlDocument(); //doc.Load("test/northwind.xml"); Console.WriteLine("Loading XML document: {0, 6:f2} ms", perf.Stop()); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile("/ROOT/CustomerIDs/OrderIDs/Item[OrderID=' 10330']/ShipAddress"); Console.WriteLine("Regular selection, warming..."); SelectNodes(nav, repeat, perf, expr); Console.WriteLine("Regular selection, testing..."); SelectNodes(nav, repeat, perf, expr); perf.Start(); IndexingXPathNavigator inav = new IndexingXPathNavigator( doc.CreateNavigator()); Console.WriteLine("Building IndexingXPathNavigator: {0, 6:f2} ms", perf.Stop()); perf.Start(); inav.AddKey("orderKey", "OrderIDs/Item", "OrderID"); Console.WriteLine("Adding keys: {0, 6:f2} ms", perf.Stop()); XPathExpression expr2 = inav.Compile("key('orderKey', ' 10330')/ShipAddress"); perf.Start(); inav.BuildIndexes(); Console.WriteLine("Indexing: {0, 6:f2} ms", perf.Stop()); Console.WriteLine("Indexed selection, warming..."); SelectIndexedNodes(inav, repeat, perf, expr2); Console.WriteLine("Indexed selection, testing..."); SelectIndexedNodes(inav, repeat, perf, expr2); }
public void LoadConfiguration() { try { String name = String.Concat(modelConfiguration.configurationNamespace, ".configuration.xml"); Assembly entryAssembly = Assembly.GetEntryAssembly(); using (StreamReader streamReader = new StreamReader(entryAssembly.GetManifestResourceStream(name))) { xmlDoc = new XmlDocument(); xmlDoc.Load(streamReader); } indexedXMLDoc = new IndexingXPathNavigator(xmlDoc.CreateNavigator()); indexedXMLDoc.AddKey("ParameterNameKey", "GME/Global/Components/Component/ComplexParameters/Parameters/Parameter", "concat(@displayedName, '||', @category, '||', ../../../@name)"); indexedXMLDoc.AddKey("ParameterBaseKey", "GME/Global/Components/Component/ComplexParameters/Parameters/Parameter", "concat(@displayedName, '||', @category, '||', ../../../@base)"); indexedXMLDoc.AddKey("ParameterStructNameKey", "GME/Global/Components/Component/ComplexParameters/Parameters/Parameter/Parameters/Parameter", "concat(../../@displayedName, '||', ../../@category, '||', ../../../../../@name, '||', @name)"); indexedXMLDoc.AddKey("ParameterStructBaseKey", "GME/Global/Components/Component/ComplexParameters/Parameters/Parameter/Parameters/Parameter", "concat(../../@displayedName, '||', ../../@category, '||', ../../../../../@base, '||', @name)"); indexedXMLDoc.AddKey("ComponentNameKey", "GME/Global/Components/Component", "@name"); indexedXMLDoc.AddKey("ComponentBaseKey", "GME/Global/Components/Component", "@base"); indexedXMLDoc.AddKey("LinkParameterKey", "GME/Global/Links/Link/Connect/ComplexParameters/Parameters/Parameter", "concat(@displayedName, '||', @category, '||', ../../../@from, '||', ../../../@to, '||', ../../../../@type)"); indexedXMLDoc.AddKey("LinkParameterStructKey", "GME/Global/Links/Link/Connect/ComplexParameters/Parameters/Parameter/Parameters/Parameter", "concat(../../@displayedName, '||', ../../@category, '||', ../../../../../@from, '||', ../../../../../@to, '||', ../../../../../../@type, '||', @name)"); indexedXMLDoc.AddKey("LinkFromToKey", "GME/Global/Links/Link/Connect", "concat(@from, '||', @to, '||', ../@type)"); indexedXMLDoc.AddKey("LinkKey", "GME/Global/Links/Link", "@type"); indexedXMLDoc.AddKey("ConfigurationKey", "GME/Configurations/Configuration", "@name"); indexedXMLDoc.BuildIndexes(); } catch (Exception ex) { MessageBox.Show(ex.Message, String.Format("Failed to load for configuration.xml at path '{0}'!", modelConfiguration.configurationNamespace)); } }
public Diagram() : base() { myHelper = new ViewComponentHelper(this); this.ObjectResized += new GoSelectionEventHandler(Diagram_ObjectResized); this.LinkCreated += new GoSelectionEventHandler(GraphView_LinkCreated); this.SelectionDeleting += new CancelEventHandler(GraphView_SelectionDeleting); this.SelectionMoved += new EventHandler(Diagram_SelectionMoved); this.LinkRelinked += new GoSelectionEventHandler(Diagram_LinkRelinked); this.ObjectContextClicked += new GoObjectEventHandler(Diagram_ObjectSingleClicked); this.IDAttribute = XmlSchemaConstants.Display.Component.Id; this.NameAttribute = XmlSchemaConstants.Display.Component.Name; this.TypeAttribute = XmlSchemaConstants.Display.Component.Type; this.LinkIDAttribute = XmlSchemaConstants.Display.Component.LinkID; this.DragsRealtime = true; this.NoFocusSelectionColor = this.PrimarySelectionColor; // auto scroll this.AutoScrollDelay = 1000; // wait 1 second before auto scrolling this.AutoScrollTime = 100; // autoscroll every 100 milliseconds this.AutoScrollRegion = new Size(16, 16); // detect auto scroll +- 16 pixels from margins // remove cut this.AllowCopy = false; // this will force the mvp xml dll to load... IndexingXPathNavigator tempNav = new IndexingXPathNavigator(new XmlDocument().CreateNavigator()); //Copy Tools mouseMoveCopy = new List<GoTool>(); mouseUpCopy = new List<GoTool>(); mouseDownCopy = new List<GoTool>(); allowedTypes = new List<String>(); foreach (GoTool copyMe in MouseMoveTools) { mouseMoveCopy.Add(copyMe); } foreach (GoTool copyMe in MouseUpTools) { mouseUpCopy.Add(copyMe); } foreach (GoTool copyMe in MouseDownTools) { mouseDownCopy.Add(copyMe); } // no transform to start transform = null; }
private void LoadDiagram() { if (diagramName == null) { return; } //go to controller, get info from DB DrawingUtility.SuspendDrawing(this); IXPathNavigable inav; if (displayID != RootID) // requires an additional level; base is now one node below root { ComponentOptions compOptions = new ComponentOptions(); if (m_level != 0) // use level if specified, otherwise use default. { compOptions.LevelDown = m_level; } else { compOptions.LevelDown = 3; } compOptions.LinkParams = true; compOptions.CompParams = true; compOptions.InstanceUseClassName = true; inav = this.myController.GetComponentAndChildren(this.RootID, this.displayID, DiagramName, compOptions); } else { ComponentOptions compOptions = new ComponentOptions(); if (m_level != 0) // use level if specified, otherwise use default. { compOptions.LevelDown = m_level; } else { compOptions.LevelDown = 2; } compOptions.LinkParams = true; compOptions.CompParams = true; compOptions.InstanceUseClassName = true; inav = this.myController.GetComponentAndChildren(this.RootID, this.RootID, DiagramName, compOptions); } XPathNavigator nav = inav.CreateNavigator(); if (transform != null) { XmlDocument newDocument = new XmlDocument(); using (XmlWriter writer = newDocument.CreateNavigator().AppendChild()) { transform.Transform(inav, (XsltArgumentList)null, writer); } nav = newDocument.CreateNavigator(); } // Perform a CRC checksum on the data coming back, only update if it has changed //MD5CryptoServiceProvider x = new MD5CryptoServiceProvider(); //Byte[] bs = System.Text.Encoding.UTF8.GetBytes(nav.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)) // otherwise update with the new data { //crc = newCrc; this.Document.Clear(); // filter based on displayID bool selectOffRoot = true; if (displayID != RootID) { // set iterator to display ID XPathNodeIterator iterator = nav.Select("//Component[@" + IDAttribute + "='" + displayID + "']"); if (iterator.Count == 1) { iterator.MoveNext(); nav = iterator.Current; selectOffRoot = false; // different xpaths below } } if (nav.HasChildren) { Dictionary<int, DiagramNode> docNodes = new Dictionary<int, DiagramNode>(); XPathDocument pointReadDoc = new XPathDocument(fileName); pointNav = new IndexingXPathNavigator(pointReadDoc.CreateNavigator()); pointNav.AddKey("IDKey", "/Nodes/Node", "concat(@ID, '||', @RootID, '||', @DiagramName)"); pointNav.BuildIndexes(); XPathNodeIterator listOfNodes = null; if (selectOffRoot) { listOfNodes = nav.Select("/Components/Component/Component"); // path relative to root } else { listOfNodes = nav.Select("Component"); // path relative to any component } //bool promptOnce = true; int defaultNodePositionX = 20; int defaultNodePositionY = 20; // for save information StreamReader tempStream = LoadDiagramsXML(); foreach (XPathNavigator nodeNav in listOfNodes) { string componentType = nodeNav.GetAttribute(TypeAttribute, nodeNav.NamespaceURI); if (allowedTypes.Count > 0) // filter if types are provided { if (allowedTypes.Contains(componentType)) { CreateNode(nodeNav, docNodes, ref defaultNodePositionX, ref defaultNodePositionY); } } else { CreateNode(nodeNav, docNodes, ref defaultNodePositionX, ref defaultNodePositionY); } } UnloadDiagramsXML(tempStream, true); int toID, fromID, linkID; String linkString; //now, form links. foreach (XPathNavigator nodeNav in listOfNodes) { fromID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI)); if (nodeNav.HasChildren) { XPathNodeIterator listOfChildren = nodeNav.Select("Component"); foreach (XPathNavigator childNav in listOfChildren) { toID = Int32.Parse(childNav.GetAttribute(IDAttribute, childNav.NamespaceURI)); linkString = childNav.GetAttribute(LinkIDAttribute, childNav.NamespaceURI); if (linkString.Length > 0) { linkID = Int32.Parse(linkString); } else { linkID = -1; } string componentType = childNav.GetAttribute(TypeAttribute, childNav.NamespaceURI); if (allowedTypes.Count > 0) // filter if types are provided { if (allowedTypes.Contains(componentType)) { this.CreateLink(childNav, linkID, docNodes, fromID, toID); } } else { this.CreateLink(childNav, linkID, docNodes, fromID, toID); } } } } } } // ensure if we're at a fixed size that the objects fit inside the document // expand if needed, e.g. negative coordinates if (this.Document.FixedSize == true && this.BackgroundImage != null) { RectangleF newBounds = this.Document.ComputeBounds(); Boolean tlChanged = false; int newWidth = this.BackgroundImage.Width, newHeight = this.BackgroundImage.Height; int newBoundsBottom = (int)(newBounds.Y+newBounds.Height); int newBoundsRight = (int)(newBounds.X + newBounds.Width); if (newBounds.X < 0) { // we've expanded newWidth = newWidth + (int)(0 - newBounds.X); tlChanged = true; } if (newBoundsRight > this.BackgroundImage.Width) { // we've expanded newWidth = newWidth + (int)(newBoundsRight - this.BackgroundImage.Width); tlChanged = true; } if (newBounds.Y < 0) { newHeight = newHeight + (int)(0 - newBounds.Y); tlChanged = true; } if (newBoundsBottom > this.BackgroundImage.Height) { newHeight = newHeight + (int)(newBoundsBottom - this.BackgroundImage.Height); tlChanged = true; } if (tlChanged) { if (newBounds.X < 0) { this.Document.TopLeft = new PointF(newBounds.X, this.Document.TopLeft.Y); } else { this.Document.TopLeft = new PointF(0, this.Document.TopLeft.Y); } if (newBounds.Y < 0) { this.Document.TopLeft = new PointF(this.Document.TopLeft.X, newBounds.Y); } else { this.Document.TopLeft = new PointF(this.Document.TopLeft.X, 0); } this.Document.Size = new SizeF(newWidth, newHeight); this.DocPosition = this.LimitDocPosition(this.DocPosition); } else { this.Document.TopLeft = new PointF(0, 0); this.Document.Size = this.BackgroundImage.Size; this.DocPosition = this.LimitDocPosition(this.DocPosition); } } DrawingUtility.ResumeDrawing(this); }