public InstanceItem(string name, CounterItem parent) { Name = name; Parent = parent; }
public void ReadXml(XmlReader reader) { var mainWindow = (MainWindow)Application.Current.MainWindow; if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName.Equals("ChartItem")) { Title = reader.GetAttribute("Title"); Row = int.Parse(reader.GetAttribute("Row")); Column = int.Parse(reader.GetAttribute("Column")); if (reader.ReadToDescendant("Series")) { while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName.Equals("Series")) { string name = reader.GetAttribute("Name"); var color = (Color)ColorConverter.ConvertFromString(reader.GetAttribute("Color")); LineSeriesBrushConverter brushConverter = new LineSeriesBrushConverter(); object[] brushes = brushConverter.ConvertBack(color, new Type[] { typeof(SolidColorBrush), typeof(SolidColorBrush) }, null, CultureInfo.InvariantCulture); var strokeBrush = (SolidColorBrush)brushes[0]; var fillBrush = (SolidColorBrush)brushes[1]; string path = reader.GetAttribute("Path"); Match match = Regex.Match(path, @"^\\\\(.*)\\(.*)\((.*)\)\\(.*)$"); if (!match.Success) { throw new InvalidOperationException("Invalid counter path"); } string[] machineName = match.Groups[1].Value.Split(':'); string host = machineName[0]; int port = int.Parse(machineName[1]); string categoryName = match.Groups[2].Value; string counterName = match.Groups[4].Value; Connection conn = mainWindow.Connections.FirstOrDefault(c => c.Host == host && c.Port == port); if (conn == null) { conn = new Connection(host, port); mainWindow.Connections.Add(conn); conn.Open(); } CategoryItem categoryItem = conn.MachineItem.CategoryItems.FirstOrDefault(item => item.Name == categoryName); if (categoryItem != null) { CounterItem counterItem = categoryItem.CounterItems.FirstOrDefault(item => item.Name == counterName); if (counterItem != null && counterItem.IsChecked == false) { counterItem.IsChecked = true; } } Series series = MainWindow.CreateSeries(name); series.Stroke = strokeBrush; series.Fill = fillBrush; SeriesCollection.Add(series); mainWindow.AddCounterListener(path, series); reader.Read(); } } reader.Read(); } }