123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- using Quartz;
- using System;
- using log4net;
- using RDIFramework.Utilities;
- using System.Collections.Generic;
- using RabbitMQ.Client;
- using System.Text;
- using Newtonsoft.Json;
- using System.Data;
- namespace TimedUpload.QuartzJobs
- {
- [DisallowConcurrentExecution]
- public class NoiseDataUploadJob : IJob
- {
- private readonly ILog log = LogManager.GetLogger(typeof(NoiseDataUploadJob));
- private const String NOISECHANNELNAME = "noiseMonitor.deviceHis";
- public void Execute(IJobExecutionContext context)
- {
- string[] uploadUrls = Constants.UploadUrl.Split('|');
- Dictionary<string, IConnection> connections = new Dictionary<string, IConnection>();
- Dictionary<string, IModel> channels = new Dictionary<string, IModel>();
- Dictionary<string, IBasicProperties> properties = new Dictionary<string, IBasicProperties>();
- foreach (string uploadUrl in uploadUrls)
- {
- ConnectionFactory factory = new ConnectionFactory();
- factory.HostName = uploadUrl;
- factory.UserName = Constants.UploadUserName;
- factory.Password = Constants.UploadPassword;
- factory.AutomaticRecoveryEnabled = true;
- IConnection connection = factory.CreateConnection();
- IModel channel = connection.CreateModel();
- channel.QueueDeclare(NOISECHANNELNAME, true, false, false, null);
- IBasicProperties property = channel.CreateBasicProperties();
- property.ContentType = "text/plain";
- property.DeliveryMode = 2;
- connections.Add(uploadUrl, connection);
- properties.Add(uploadUrl, property);
- channels.Add(uploadUrl, channel);
- }
- if (channels.Count > 0)
- {
- SendNoiseDataUploadHistory(channels, properties);
- }
- foreach (KeyValuePair<string, IConnection> item in connections)
- {
- IConnection connection = item.Value;
- connection.Close();
- }
- }
-
-
-
-
-
- private void SendNoiseDataUploadHistory(Dictionary<string, IModel> channels, Dictionary<string, IBasicProperties> properties) {
- try
- {
- NoiseModel model = new NoiseModel();
- log.Info("同步噪声声设备数据...............start\r\n");
- String sql = "";
- DataTable dt = dbHelper.Fill(sql);
- if (dt != null)
- {
-
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- model.deviceCode = "";
- model.readTime = DateTime.Now;
- model.videoUrl = "";
- model.weather = "";
- model.isLeakPoint = 0;
- model.csq = 0;
- model.psrp = 0;
- model.snr = 0;
- model.ecl = 0;
- model.pcl = 0;
- model.isBatteryUnusual = 0;
- model.isHitch = 0;
- model.singnalType = 1;
- string message = JsonConvert.SerializeObject(model);
- foreach (var item in channels)
- {
- string key = item.Key;
- IModel channel = item.Value;
- IBasicProperties property = properties[key];
- channel.BasicPublish(NOISECHANNELNAME, "", property, Encoding.UTF8.GetBytes(message));
- }
- }
- }
- log.Info("同步噪声声设备数据...............end\r\n");
- }
- catch (Exception ex)
- {
- log.Error("步噪声声设备数据错误:" + ex.Message+ "====" + ex.StackTrace + "\r\n");
- }
- }
- static IDbProvider dbHelper
- {
- get
- {
- var DbDefine = DbFactoryProvider.GetProvider(CurrentDbType.SqlServer, Constants.WaterFactoryDbConncetion);
- return DbDefine;
- }
- }
- }
- class NoiseModel
- {
-
-
-
- public string deviceCode { get; set; }
-
-
-
- public DateTime readTime { get; set; }
-
-
-
- public string videoUrl { get; set; }
-
-
-
- public string weather { get; set; }
-
-
-
- public int isLeakPoint { get; set; }
-
-
-
-
-
-
- public int csq { get; set; }
-
-
-
-
-
-
-
-
-
- public int psrp { get; set; }
-
-
-
-
- public int snr { get; set; }
-
-
-
-
-
- public int ecl { get; set; }
-
-
-
- public int pcl { get; set; }
-
-
-
- public int isBatteryUnusual { get; set; }
-
-
-
- public int isHitch { get; set; }
-
-
-
- public int singnalType { get; set; }
- }
- }
|