public void Load(Stream stream) { XmlScanner scanner; scanner = new XmlScanner(stream); try { this.Load(scanner); } finally { scanner.Close(); } }
public void Load(XmlReader reader) { XmlScanner scanner; scanner = new XmlScanner(reader); try { this.Load(scanner); } finally { scanner.Close(); } }
private void loadWebStatisticsToolStripMenuItem_Click(object sender, EventArgs e) { string statsDir = Path.Combine("Demo Programs", Path.Combine("WebVisits", "Sample Web Statistics")); openFileDialog.Filter = "Web Statistics|*.xml|All files|*.*"; openFileDialog.InitialDirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)), statsDir); openFileDialog.FileName = string.Empty; if (openFileDialog.ShowDialog() == DialogResult.OK) { // Create a new diagram ShapeType boxType = project.ShapeTypes["Ellipse"]; ShapeType multiLineType = project.ShapeTypes["Polyline"]; Dictionary <int, RectangleBase> boxes = new Dictionary <int, RectangleBase>(); List <Polyline> lines = new List <Polyline>(); // // Create shapes for the web pages and connect them with lines XmlScanner scanner = new XmlScanner(openFileDialog.FileName); scanner.ReadElement(); scanner.ReadElement("WebVisits"); scanner.ReadChild("Pages"); if (scanner.ReadChild("Page")) { do { scanner.ReadAttribute(); // id attribute RectangleBase box = (RectangleBase)boxType.CreateInstance(pageTemplate); box.Width = 140; boxes.Add(scanner.IntValue, box); scanner.ReadAttribute(); box.Text = scanner.StringValue; } while (scanner.ReadElement()); } scanner.ReadParent(); if (scanner.ReadChild("Referral")) { do { scanner.ReadAttribute(); // id1 int id1 = scanner.IntValue; Shape shape1 = boxes[id1]; scanner.ReadAttribute(); // id2 int id2 = scanner.IntValue; Shape shape2 = boxes[id2]; scanner.ReadAttribute(); // count int count = scanner.IntValue; Polyline line = (Polyline)multiLineType.CreateInstance(); line.EndCapStyle = project.Design.CapStyles.Arrow; line.LineStyle = GetLineStyle(count); line.Connect(ControlPointId.FirstVertex, shape1, ControlPointId.Reference); line.Connect(ControlPointId.LastVertex, shape2, ControlPointId.Reference); lines.Add(line); } while (scanner.ReadElement()); } scanner.ReadParent(); scanner.Close(); // // Insert all shapes into the diagram int cnt = 0; foreach (Diagram d in project.Repository.GetDiagrams()) { ++cnt; } Diagram diagram = new Diagram(string.Format("WebVisits Diagram {0}", cnt)); diagram.Width = 1000; diagram.Height = 1000; diagram.BackgroundImageLayout = Dataweb.NShape.ImageLayoutMode.Fit; foreach (RectangleBase b in boxes.Values) { diagram.Shapes.Add(b, project.Repository.ObtainNewTopZOrder(diagram)); } foreach (Polyline l in lines) { diagram.Shapes.Add(l, project.Repository.ObtainNewBottomZOrder(diagram)); } boxes.Clear(); lines.Clear(); // // Insert the diagram (including all shapes) into the repository project.Repository.InsertDiagram(diagram); // // Layout the shapes if (layouter == null) { layouter = new RepulsionLayouter(project); } layouter.SpringRate = 14; layouter.Repulsion = 7; layouter.RepulsionRange = 400; layouter.Friction = 0; layouter.Mass = 50; // layouter.AllShapes = diagram.Shapes; layouter.Shapes = diagram.Shapes; layouter.Prepare(); layouter.Execute(10); layouter.Fit(50, 50, diagram.Width - 100, diagram.Height - 100); // // Display the result display.Diagram = diagram; } }