Ejemplo n.º 1
0
        private bool HandleMessage(string routingKey, string msg)
        {
            string tableName  = "t_" + routingKey.Replace('.', '_');
            string deviceType = routingKey.Split('.')[1];
            bool   result     = false;

            switch (deviceType)
            {
            case "02":
                Temperature_Data td = JsonConvert.DeserializeObject <Temperature_Data>(msg);
                result = InsertTemperatureData(tableName, td);
                break;

            case "08":
                Strain_Data sd = JsonConvert.DeserializeObject <Strain_Data>(msg);
                result = InsertStrainData(tableName, sd);
                break;

            case "09":
                Settlement_Data obj = JsonConvert.DeserializeObject <Settlement_Data>(msg);
                result = InsertSettlementData(tableName, obj);
                break;

            case "11":
                Inclination_Data id = JsonConvert.DeserializeObject <Inclination_Data>(msg);
                result = InsertInclinationData(tableName, id);
                break;

            case "13":
                TemperatureHumidity_Data thd = JsonConvert.DeserializeObject <TemperatureHumidity_Data>(msg);
                result = InsertTemperatureHumidityData(tableName, thd);
                break;

            case "19":
                LaserRange_Data lrd = JsonConvert.DeserializeObject <LaserRange_Data>(msg);
                result = InsertLaserRangeData(tableName, lrd);
                break;

            default: break;
            }
            return(result);
        }
Ejemplo n.º 2
0
        private bool InsertSettlementData(string tableName, Settlement_Data data)
        {
            string sqlStatement = "INSERT INTO " + tableName + "(Stamp,Innage,DeltaInnage,Deflection) VALUES(@stamp,@innage,@deltaInnage,@deflection)";

            bool result = true;

            try
            {
                using (SqlCommand cmd = new SqlCommand(sqlStatement, sqlConnection))
                {
                    cmd.Parameters.AddWithValue("@stamp", data.TimeStamp);
                    cmd.Parameters.AddWithValue("@innage", data.Innage);
                    cmd.Parameters.AddWithValue("@deltaInnage", data.DeltaInnage);
                    cmd.Parameters.AddWithValue("@deflection", data.Deflection);
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                result = false;
                form.AppendLog(ex.StackTrace.ToString() + "\r\n");
            }
            return(result);
        }