/// <summary> /// Helper to generate a random hierarchy of the specified depth, with the specified number /// of children at each level. /// </summary> /// <param name="depth">Number of levels in the generated tree.</param> /// <param name="nodesPerLevel">Number of children of each node.</param> /// <returns>The root node of the randomly generated tree.</returns> public static NhlNode CreateRandomTree(int depth, int nodesPerLevel) { NhlNode node = new NhlNode(); node.Name = "N" + depth; if (depth <= 0) { node.Children = new NhlNode[0]; node.GoalsAgainst = _random.Next(1, 50); node.GoalsFor = _random.Next(1, 50); node.Losses = _random.Next(1, 50); node.PenaltyMinutes = _random.Next(1, 50); node.Points = _random.Next(1, 50); node.Rank = _random.Next(1, 50); node.Wins = _random.Next(1, 50); } else { node.Children = (from index in Enumerable.Range(0, nodesPerLevel) select CreateRandomTree(depth - 1, nodesPerLevel)).ToArray(); } return(node); }
/// <summary> /// Loads test data from the default XML data file. /// </summary> /// <returns>A list of NhlNode objects which can be set as the ItemsSource in the TreeMap.</returns> public static IList<NhlNode> LoadDefaultFile() { IList<NhlNode> result = null; NhlNode node = new NhlNode(); // Stream stream = Application.GetResourceStream(new Uri("/System.Windows.Controls.Samples.BusinessObjects.NhlData.NhlData.xml", UriKind.RelativeOrAbsolute)).Stream using (Stream stream = node.GetType().Assembly.GetManifestResourceStream("System.Windows.Controls.Samples.BusinessObjects.NhlData.NhlData.xml")) { result = LoadNhlNodes(XElement.Load(stream).Elements("NhlNode")); } return result; }
/// <summary> /// Loads test data from the default XML data file. /// </summary> /// <returns>A list of NhlNode objects which can be set as the ItemsSource in the TreeMap.</returns> public static IList <NhlNode> LoadDefaultFile() { IList <NhlNode> result = null; NhlNode node = new NhlNode(); // Stream stream = Application.GetResourceStream(new Uri("/System.Windows.Controls.Samples.BusinessObjects.NhlData.NhlData.xml", UriKind.RelativeOrAbsolute)).Stream using (Stream stream = node.GetType().Assembly.GetManifestResourceStream("System.Windows.Controls.Samples.BusinessObjects.NhlData.NhlData.xml")) { result = LoadNhlNodes(XElement.Load(stream).Elements("NhlNode")); } return(result); }
/// <summary> /// Helper to generate a random hierarchy of the specified depth, with the specified number /// of children at each level. /// </summary> /// <param name="depth">Number of levels in the generated tree.</param> /// <param name="nodesPerLevel">Number of children of each node.</param> /// <returns>The root node of the randomly generated tree.</returns> public static NhlNode CreateRandomTree(int depth, int nodesPerLevel) { NhlNode node = new NhlNode(); node.Name = "N" + depth; if (depth <= 0) { node.Children = new NhlNode[0]; node.GoalsAgainst = _random.Next(1, 50); node.GoalsFor = _random.Next(1, 50); node.Losses = _random.Next(1, 50); node.PenaltyMinutes = _random.Next(1, 50); node.Points = _random.Next(1, 50); node.Rank = _random.Next(1, 50); node.Wins = _random.Next(1, 50); } else { node.Children = (from index in Enumerable.Range(0, nodesPerLevel) select CreateRandomTree(depth - 1, nodesPerLevel)).ToArray(); } return node; }