示例#1
0
 public OPCGroupConfig()
 {
     OPCItems       = new List <string>();
     DBConnection   = new OPCGroupDatabaseConnectionConfig();
     Deadband       = 0;
     UpdateRate     = 1000;
     IsActive       = true;
     IsSubscribed   = true;
     TimeoutSetting = 0;
 }
示例#2
0
        private OPCGroupDatabaseConnectionConfig GetOPCDBConnectionConfig(XmlNode opcGroupDBConnNode)
        {
            OPCGroupDatabaseConnectionConfig connConfig = new OPCGroupDatabaseConnectionConfig();

            int databaseType = 0;

            connConfig.DatabaseType = int.TryParse(opcGroupDBConnNode.Attributes["databasetype"].Value, out databaseType) && databaseType >= 0 && databaseType <= 1
                ? databaseType : 0;

            foreach (XmlNode connNode in opcGroupDBConnNode)
            {
                switch (connNode.LocalName)
                {
                case "connection":
                    connConfig.ServerName   = connNode.Attributes["servername"].Value;
                    connConfig.DatabaseName = connNode.Attributes["databasename"].Value;
                    connConfig.UserName     = connNode.Attributes["username"].Value;
                    connConfig.Password     = connNode.Attributes["password"].Value;
                    break;

                case "newdatatable":
                    connConfig.NewDataTable = connNode.Attributes["tablename"].Value;
                    break;

                case "historydatatable":
                    connConfig.HistoryDataTable = connNode.Attributes["tablename"].Value;
                    break;

                case "fields":
                    List <OPCGroupDatabaseFieldConfig> fields = GetOPCDBFieldsConfig(connNode);
                    foreach (OPCGroupDatabaseFieldConfig fieldConfig in fields)
                    {
                        connConfig.Fields.Add(fieldConfig);
                    }
                    break;

                default:
                    break;
                }
            }

            return(connConfig);
        }
示例#3
0
        private OPCGroupConfig GetOPCGroupConfig(XmlNode opcGroupNode)
        {
            if (opcGroupNode == null)
            {
                return(null);
            }

            OPCGroupConfig group = new OPCGroupConfig();

            group.GroupName    = opcGroupNode.Attributes["groupname"].Value;
            group.IsActive     = opcGroupNode.Attributes["isactive"].Value == "1";
            group.IsSubscribed = opcGroupNode.Attributes["issubscribed"].Value == "1";
            group.AutoInsert   = opcGroupNode.Attributes["autoinsert"].Value == "1";
            float deadband = 0;

            group.Deadband = float.TryParse(opcGroupNode.Attributes["deadband"].Value, out deadband) && deadband >= 0
                ? deadband : 0;
            int updateRate = 0;

            group.UpdateRate = int.TryParse(opcGroupNode.Attributes["updaterate"].Value, out updateRate) && updateRate > 0
                ? updateRate : 1000;
            int timeoutsetting = 0;

            group.TimeoutSetting = int.TryParse(opcGroupNode.Attributes["timeoutsetting"].Value, out timeoutsetting) && timeoutsetting >= 0
                ? timeoutsetting : 0;

            foreach (XmlNode node in opcGroupNode.ChildNodes)
            {
                switch (node.LocalName)
                {
                case "opcitems":
                    List <string> opcItems = GetOPCGroupItems(node);
                    foreach (string opcItem in opcItems)
                    {
                        group.OPCItems.Add(opcItem);
                    }
                    break;

                case "database-connection":
                    OPCGroupDatabaseConnectionConfig dbConnConfig = GetOPCDBConnectionConfig(node);

                    group.DBConnection.DatabaseType     = dbConnConfig.DatabaseType;
                    group.DBConnection.ServerName       = dbConnConfig.ServerName;
                    group.DBConnection.DatabaseName     = dbConnConfig.DatabaseName;
                    group.DBConnection.UserName         = dbConnConfig.UserName;
                    group.DBConnection.Password         = dbConnConfig.Password;
                    group.DBConnection.NewDataTable     = dbConnConfig.NewDataTable;
                    group.DBConnection.HistoryDataTable = dbConnConfig.HistoryDataTable;

                    group.DBConnection.Fields.Clear();
                    foreach (OPCGroupDatabaseFieldConfig field in dbConnConfig.Fields)
                    {
                        group.DBConnection.Fields.Add(field);
                    }
                    break;

                default:
                    break;
                }
            }

            return(group);
        }