private void AddMetric(Point position, MetricManager.MetricInfo metricInfo) { var viewPosition = nodeGraphPanel.ControlToWorld(position); if (GraphRunning) { if (AskStopGraph()) { StopGraph(); } else { return; } } if (metricInfo != null) { NodeSystemLib2.Node metric = null; try { metric = metricInfo.CreateInstance(_graph); } catch (Exception e) { GlobalSettings.Instance.UserLog.Add(new GraphMessage(Graph, LogMessage.LogType.Error, $"In AddMetric for {metricInfo.Name}: {e}")); return; } var graphNode = new GraphNode( node: metric, factoryId: metricInfo.FactoryGuid, uniqueName: metricInfo.UniqueName, pX: viewPosition.X, pY: viewPosition.Y ); nodeGraphPanel.Nodes.Add(graphNode); } else { throw new ArgumentNullException(); } }
public static GraphNode FromXml(XmlNode node, Graph g) { if (node?.Attributes == null) { return(null); } var x = node.TryGetAttribute("x", otherwise: "0"); var y = node.TryGetAttribute("y", otherwise: "0"); var id = node.TryGetAttribute("id", otherwise: ""); var uniqueName = node.TryGetAttribute("uniqueName", otherwise: ""); var factoryId = new Guid(node.TryGetAttribute("factoryId", otherwise: Guid.Empty.ToString())); //XmlNode settings = null; //for (int i = 0; i < factorySettings.Count; i++) { // if (Guid.Parse(factorySettings[i].TryGetAttribute("guid", Guid.Empty.ToString())).Equals(factoryId)) { // settings = factorySettings[i]; // } //} var nodeInfo = node.SelectSingleNode("node"); if (nodeInfo?.Attributes == null) { return(null); } var type = nodeInfo.TryGetAttribute("type", otherwise: ""); var descr = nodeInfo.TryGetAttribute("description", otherwise: ""); MetricManager.MetricInfo info = null; Node metricNode = null; Exception ex = null; foreach (var metric in GlobalSettings.Instance.MetricManager.Metrics) { if (metric.UniqueName == uniqueName && metric.FactoryGuid == factoryId) { try { metricNode = metric.CreateInstance(g, nodeInfo); metricNode.Description = descr; } catch (Exception e) { ex = e; } break; } } if (metricNode == null) { metricNode = new Metrics.MetricUnknownNode(nodeInfo, g); metricNode.Description = descr; if (ex != null) { GlobalSettings.Instance.UserLog.Add(new NodeMessage(metricNode, LogMessage.LogType.Error, $"Error while creating instance of type {type}. Exception: {ex}")); } else { GlobalSettings.Instance.UserLog.Add(new NodeMessage(metricNode, LogMessage.LogType.Error, $"Error while creating instance of type {type}. Device not connected/Plugin missing?")); } } return(new GraphNode(metricNode, factoryId, uniqueName, int.Parse(x), int.Parse(y), id)); }