Exemple #1
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>
        /// <param name="status"> Status of variable, default to good </param>
        public void updateBuffer(string name, object value, DateTime time, uint status)
        {
            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("Request for Variable {0} to update.", name);
                if (value != null)
                {
                    logger.Debug("\t Value: {0} ", value.ToString());
                }
                logger.Debug("\t Status: {0} ", new StatusCode(status).ToString());

                if (value != null)
                {
                    var_idx.value = Convert.ChangeType(value, Type.GetType(var_idx.systemType));
                }
                // else var_idx.value = null;
                var_idx.timestamp  = time;
                var_idx.statuscode = status;
                latestValues.Upsert(var_idx);
            }
            catch (Exception e)
            {
                logger.Error("Error in updating value for variable " + name);
                logger.Error(e.Message);
            }
        }
Exemple #2
0
 public ReadVarResponse(dbVariableValue v) : base()
 {
     Id         = v.Id;
     name       = v.name;
     value      = v.value;
     systemType = v.systemType;
     timestamp  = v.timestamp;
     success    = StatusCode.IsGood(v.statuscode);
     statusCode = new StatusCode(v.statuscode);
 }
Exemple #3
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);
            }
        }