コード例 #1
0
        /// <summary>
        /// Initialization of the variable value in DB, this is used if the variable does not exist yet,
        /// then one looks into the nodelist.
        /// </summary>
        /// <param name="name">name of the variable value to initialize</param>
        /// <returns></returns>
        private dbVariableValue _initVarValue(string name)
        {
            dbNode var_idx = nodes.FindOne(Query.EQ("name", name));

            if (var_idx == null)
            {
                throw new Exception("variable does not exist: " + name);
            }
            else
            {
                dbVariableValue new_var = new dbVariableValue {
                    Id         = var_idx.Id,
                    name       = var_idx.name,
                    systemType = var_idx.systemType,
                };
                return(new_var);
            }
        }
コード例 #2
0
        /// <summary>
        /// Update the cache with the new value of that variable
        /// </summary>
        /// <param name="name">name of variable</param>
        /// <param name="value"> updated value of variable</param>
        /// <param name="time"> timestamp of when it changed</param>
        public void updateBuffer(string name, object value, DateTime time)
        {
            try{
                dbVariableValue var_idx = latestValues.FindOne(Query.EQ("name", name));

                // if not found then search in nodes list
                if (var_idx == null)
                {
                    var_idx = _initVarValue(name);
                }
                logger.Debug("value -> " + value.ToString() + "  type --> " + var_idx.systemType);
                var_idx.value     = Convert.ChangeType(value, Type.GetType(var_idx.systemType));
                var_idx.timestamp = time;
                latestValues.Upsert(var_idx);
            }
            catch (Exception e) {
                logger.Error(e, "Error in updating value for variable " + name);
                Console.WriteLine(e.Message);
            }
        }