Ejemplo n.º 1
0
        protected ChannelEntry?GetChannelDescription(string objectID, string variable)
        {
            var channelRef = ChannelRef.Make(objectID, variable);

            if (cacheChannelEntry.TryGetValue(channelRef, out var mapEnt))
            {
                return(mapEnt);
            }

            using (var command = Factory.MakeCommand($"SELECT * FROM channel_defs WHERE obj = @obj AND var = @var", connection !)) {
                command.Parameters.Add(Factory.MakeParameter("obj", objectID));
                command.Parameters.Add(Factory.MakeParameter("var", variable));
                using (var reader = command.ExecuteReader()) {
                    if (!reader.Read())
                    {
                        return(null);
                    }
                    string type    = (string)reader["type"];
                    var    chEntry = new ChannelEntry()
                    {
                        Object   = objectID,
                        Variable = variable,
                        VarID    = (int)reader["varID"],
                        Type     = (DataType)Enum.Parse(typeof(DataType), type, ignoreCase: true)
                    };
                    cacheChannelEntry[channelRef] = chEntry;
                    return(chEntry);
                }
            }
        }
Ejemplo n.º 2
0
        protected ChannelEntry?GetChannelDescription(string objectID, string variable)
        {
            var channelRef = ChannelRef.Make(objectID, variable);

            if (cacheChannelEntry.TryGetValue(channelRef, out var mapEnt))
            {
                return(mapEnt);
            }

            var stmtSelectChannel = this.stmtSelectChannel;

            if (stmtSelectChannel == null)
            {
                return(null);
            }

            stmtSelectChannel[0] = objectID;
            stmtSelectChannel[1] = variable;

            using (var reader = stmtSelectChannel.ExecuteReader()) {
                if (!reader.Read())
                {
                    return(null);
                }
                string       type    = (string)reader["type"];
                ChannelEntry chEntry = new ChannelEntry()
                {
                    Object        = objectID,
                    Variable      = variable,
                    DataTableName = (string)reader["table_name"],
                    Type          = (DataType)Enum.Parse(typeof(DataType), type, ignoreCase: true)
                };
                cacheChannelEntry[channelRef] = chEntry;
                return(chEntry);
            }
        }