/// <summary> /// 读取xml文件的sql methodId就是标签的id 不要内容不要带空格 /// </summary> /// <param name="methodId"></param> /// <returns></returns> public static XmlSql GetXmlSql(string methodId) { string root = System.Environment.CurrentDirectory; root = root.Replace("bin\\Debug", ""); XmlSql xmlSql = new XmlSql(); XmlDocument doc = new XmlDocument(); doc.Load(root + "\\mapper\\UserMapper.xml"); // 得到根节点mapper XmlNode xn = doc.SelectSingleNode("mapper"); XmlNodeList nodeList = xn.ChildNodes; string sqlxml = ""; for (int i = 0; i < nodeList.Count; i++) { XmlAttributeCollection attributes = nodeList.Item(i).Attributes; sqlxml = nodeList.Item(i).OuterXml; //匹配方法 if (sqlxml.Contains("id=\"" + methodId + "\"")) { xmlSql.Type = nodeList.Item(i).Name; xmlSql.SqlTem = nodeList.Item(i).InnerXml; for (int k = 0; k < attributes.Count; k++) { if (methodId.Equals(attributes[k].Value)) { xmlSql.SqlId = attributes[k].Value; } else if ("parameterType".Equals(attributes[k].Name)) { xmlSql.ParameterType = attributes[k].Value; } else if ("resultType".Equals(attributes[k].Name)) { xmlSql.ResultType = attributes[k].Value; } } break; } } return(xmlSql); }
/// <summary> /// Mit dieser Methode wird die Konfiguration wieder aus dem Dictionary exportiert /// </summary> /// <returns>XmlUarcConfig</returns> public async Task <XmlUarcConfig> ExportXmlConfigAsync() { // XmlUarcConfig Objekt wird erzeugt. XmlUarcConfig opcXmlConfig = new XmlUarcConfig(); // XmlUarcConfig Objekt wird mit den Daten aus dem Dicitionary befüllt. foreach (UarcOpcUaClient client in m_OpcUaVerbindungen.Values) { // Das Server Abbild wird erstellt. XmlOpcUaServer xmlOpcUaServer = new XmlOpcUaServer { XmlUser = client.Username, XmlPassword = client.Password, XmlServerlabel = client.ServerLabel, XmlOpcUrl = client.EndpointUrl }; // Alle Subscriptions werden aus der Session gelesen und im Client Obj gesichert. await client.SaveAllSubscriptionsAsync(); // Für alle Subscription wird ein Abbild erstellt. foreach (Subscription sub in client.Subscriptions) { XmlOpcUaSubscription xmlOpcUaSubscription = new XmlOpcUaSubscription { XmlPublishingInterval = Convert.ToString(sub.PublishingInterval) }; foreach (MonitoredItem item in sub.MonitoredItems) { XmlOpcUaVariable xmlOpcUaVariable = new XmlOpcUaVariable { XmlVarLabel = item.DisplayName, XmlNodeId = Convert.ToString(item.ResolvedNodeId), XmlSamplingInterval = Convert.ToString(item.SamplingInterval) }; xmlOpcUaSubscription.XmlOpcUaVariablen.Add(xmlOpcUaVariable); } xmlOpcUaServer.XmlOpcUaSubscriptions.Add(xmlOpcUaSubscription); } // Alle gesicherten Subscriptions werden entfernt. client.Subscriptions.ToList().Clear(); // Jede Client Konfiguration wird dem KonfigurationsObjekt hinzugefügt opcXmlConfig.XmlOpcUaServers.Add(xmlOpcUaServer); } XmlSql SqlConfig = new XmlSql { XmlSqlConnectionString = m_SqlConnectionString, }; // Der Connectionstring wird ermittelt. opcXmlConfig.XmlSQLConfig = SqlConfig; // Das XmlUarcConfig Objekt wird überprüft. OpcUaXmlConfigChecker.FormatAndValidate(opcXmlConfig); // XmlUarcConfig Objekt wird zurückgegeben. return(opcXmlConfig); }
// Erzeugen der Xml Beispiel Konfiguration. public XmlUarcConfig OpcUaXmlExampleFileCreate() { XmlUarcConfig config = new XmlUarcConfig(); XmlOpcUaServer StandardOpcUaServer = new XmlOpcUaServer { XmlUser = "******", XmlPassword = "******", XmlServerlabel = "OPC UA Server - OPC Foundation", XmlOpcUrl = "opc.tcp://*****:*****@"Server=localhost\SQLEXPRESS;Database=OpcUaDataDb;Trusted_Connection=True;", }; XmlOpcUaSubscription StandardSubscription = new XmlOpcUaSubscription { XmlPublishingInterval = "1", }; XmlOpcUaSubscription BeispielSubscription = new XmlOpcUaSubscription { XmlPublishingInterval = "10", }; StandardSubscription.XmlOpcUaVariablen.Add(StandardOpcUaVar); BeispielSubscription.XmlOpcUaVariablen.Add(S7OpcUaVar); StandardOpcUaServer.XmlOpcUaSubscriptions.Add(StandardSubscription); S7OpcUaServer.XmlOpcUaSubscriptions.Add(BeispielSubscription); config.XmlOpcUaServers.Add(StandardOpcUaServer); config.XmlOpcUaServers.Add(S7OpcUaServer); config.XmlSQLConfig = SqlConfig; return(config); }