Ejemplo n.º 1
0
        private void LoadInclinationConfig(SqlConnection connection)
        {
            string     sqlStatement = "select SensorId,InitX,InitY,Description from InclinationConfig";
            SqlCommand command      = new SqlCommand(sqlStatement, connection);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                Dictionary <string, InclinationConfig> configCollection = new Dictionary <string, InclinationConfig>();

                while (reader.Read())
                {
                    string sensorId = reader.GetString(0);
                    double initX    = reader.GetDouble(1);
                    double initY    = reader.GetDouble(2);
                    object desc     = reader.GetValue(3);

                    InclinationConfig ssv = new InclinationConfig();
                    ssv.SensorId = sensorId;
                    ssv.InitX    = initX;
                    ssv.InitY    = initY;
                    configCollection.Add(sensorId, ssv);

                    string[]     viewItem = { sensorId, sensorId, desc.ToString() };
                    ListViewItem listItem = new ListViewItem(viewItem);
                    this.listView1.Items.Add(listItem);
                }
                InclinationSolve actSolver = new InclinationSolve(configCollection, 300, redis, redisDbIndex, textBoxLog, dataQueue);
                solverCollection.Add(actSolver);
            }
        }
Ejemplo n.º 2
0
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bgWorker = sender as BackgroundWorker;
            string           stamp    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string           str      = "";

            str += stamp + " ";
            if (redis.IsConnected)
            {
            }
            else
            {
                str += "redis server is not connected";
                //lthis.AppendLog(str);
                return;
            }
            Dictionary <RedisKey, RedisValue> pair = new Dictionary <RedisKey, RedisValue>();

            try
            {
                IDatabase db_raw    = this.redis.GetDatabase(0);
                IDatabase db_result = this.redis.GetDatabase(redisDbIndex);

                List <RedisKey> keyCollection = new List <RedisKey>();
                foreach (string k in list.Keys)
                {
                    keyCollection.Add(k);
                }

                RedisKey[] keys = keyCollection.ToArray();

                RedisValue[] vals = db_raw.StringGet(keys);

                foreach (RedisValue rv in vals)
                {
                    if (!rv.IsNull)
                    {
                        ACA826T_Data dv = JsonConvert.DeserializeObject <ACA826T_Data>((string)rv);

                        string key = dv.SensorId;

                        InclinationConfig ptv = list[key];
                        if (ptv.TimeStamp != dv.TimeStamp)
                        {
                            ptv.TimeStamp = dv.TimeStamp;
                            ptv.SensorId  = dv.SensorId;

                            Inclination_Data data = new Inclination_Data();
                            data.SensorId  = dv.SensorId;
                            data.TimeStamp = dv.TimeStamp;
                            data.X         = dv.X;
                            data.Y         = dv.Y;
                            data.DeltaX    = Math.Round(dv.X - ptv.InitX, 3);
                            data.DeltaY    = Math.Round(dv.Y - ptv.InitY, 3);

                            string mq_string = JsonConvert.SerializeObject(data);
                            //mq_string to mq
                            RabbitMsg msg = new RabbitMsg();
                            msg.RouteKey = ptv.SensorId;
                            msg.Body     = mq_string;
                            dataQueue.Enqueue(msg);

                            string    redisKey = ptv.SensorId + "-001";
                            DataValue temp     = new DataValue();
                            temp.SensorId  = ptv.SensorId;
                            temp.TimeStamp = ptv.TimeStamp;
                            temp.ValueType = "001";
                            temp.Value     = dv.X;
                            string result = JsonConvert.SerializeObject(temp);
                            pair[redisKey] = result;

                            redisKey       = ptv.SensorId + "-002";
                            temp.ValueType = "002";
                            temp.Value     = dv.Y;
                            result         = JsonConvert.SerializeObject(temp);
                            pair[redisKey] = result;

                            redisKey       = ptv.SensorId + "-018";
                            temp.ValueType = "018";
                            temp.Value     = data.DeltaX;
                            result         = JsonConvert.SerializeObject(temp);
                            pair[redisKey] = result;

                            redisKey       = ptv.SensorId + "-019";
                            temp.ValueType = "019";
                            temp.Value     = data.DeltaY;
                            result         = JsonConvert.SerializeObject(temp);
                            pair[redisKey] = result;
                        }
                    }
                }

                if (pair.Count > 0)
                {
                    db_result.StringSet(pair.ToArray());
                    pair.Clear();
                }
            }
            catch (Exception ex)
            {
                this.AppendLog(ex.Message);
                using (StreamWriter sw = new StreamWriter(@"ErrLog.txt", true))
                {
                    sw.WriteLine(stamp + " " + ex.Message + " \r\n" + ex.StackTrace.ToString());
                    sw.WriteLine("---------------------------------------------------------");
                    sw.Close();
                }
            }
        }