public void Start(string ConfigFilePath) { string strConfig = System.IO.File.ReadAllText(ConfigFilePath); T config = JsonSerializer.Deserialize <T>(strConfig); DriveConfig = config; DeviceConn(config); bus = new BusClient(); this.bus.Subscribe(BusOption.CMD_INPUT); this.bus.OnReceived += Bus_OnReceived; ISRun = true; while (ISRun) { IEnumerable <IOTData> iOTs = GetData(); if (iOTs != null) { if (iOTs.Count() > 0) { bus.Publish(BusOption.DATA_OUTPUT, JsonSerializer.Serialize(iOTs)); } } System.Threading.Thread.Sleep(config.CycleTime); } DeviceDiscnn(); }
public async Task ShouldProcessMessage() { var bus = new BusClient(null, null); bus.SubscribeToEvent <TestEvent, TestEventHandler>(); await bus.ProcessMessage(typeof(TestEvent).Name, JsonConvert.SerializeObject(new TestEvent { Test = "Hello World" })); }
public IOTDataService(ILogger <IOTDataService> logger) { this.logger = logger; bus = new BusClient(); this.bus.Subscribe(BusOption.DATA_OUTPUT); this.bus.OnReceived += Bus_OnReceived; //每10分钟执行一次数据清理 this.timer = new Timer(p => this.ClearData(), null, 0, 1000 * 10 * 60); }
public DriveStatusService(ILogger <DriveStatusService> logger) { this.logger = logger; bus = new BusClient(); this.bus.Subscribe(BusOption.CTRL_START); this.bus.Subscribe(BusOption.CTRL_STOP); this.bus.OnReceived += Bus_OnReceived; driveLists = DriveListConfig.ReadConfig(); StartAllDrive(); //服务启动的时候启动全部的设备 }
public MqttService(ILogger <MqttService> logger) { this.logger = logger; mQTTTran = new MQTTTranData(Program.configInfo.ClientId, Program.configInfo.MQTTerver, Program.configInfo.MQTTPort, Program.configInfo.MQTTUsr, Program.configInfo.MQTTPsw); mQTTTran.OnGetData += MQTTTran_OnGetData; mQTTTran.SubTopic(new string[] { "" }); mQTTTran.Connect(); this.bus = new BusClient(); this.bus.Subscribe(BusOption.CONFIG_CHANGE); this.bus.OnReceived += Bus_OnReceived; }
/// <summary> /// Initiate the socket that connects to all other FOG bus instances /// It MUST be assumed that this socket is compromised /// Do NOT send security relevant data across it /// </summary> /// <returns></returns> private static void Initializesocket() { switch (_mode) { case Mode.Server: // Attempt to become the socket server try { _server = new BusServer(); _server.Socket.NewMessageReceived += socket_RecieveMessage; _server.Socket.NewSessionConnected += client_connect; _server.Start(); Log.Entry(LogName, "Became bus server"); _initialized = true; } catch (Exception ex) { Log.Error(LogName, "Could not enter socket"); Log.Error(LogName, ex); } break; case Mode.Client: try { _client = new BusClient(Port); _client.Socket.MessageReceived += socket_RecieveMessage; _client.Start(); Log.Entry(LogName, "Became bus client"); _initialized = true; } catch (Exception ex) { Log.Error(LogName, "Could not enter socket"); Log.Error(LogName, ex); } break; } }
static void Main(string[] args) { BusClient bus; bus = new BusClient(); while (true) { List <IOTData> iOTs = new List <IOTData>(); iOTs.Add(new IOTData() { DataCode = "test", DataName = "test", DataValue = "test", DriveCode = "test", DriveType = "test", GTime = DateTime.Now, ID = Guid.NewGuid(), Sended = false, Unit = "" }); bus.Publish(BusOption.DATA_OUTPUT, JsonSerializer.Serialize(iOTs)); System.Threading.Thread.Sleep(2000); } }
public async Task <IActionResult> Put([FromBody] EditSetting command) { await BusClient.PublishAsync(command); return(Accepted()); }
public async Task <IActionResult> Delete([FromBody] RemoveSetting command) { await BusClient.PublishAsync(command); return(Accepted()); }
public MessageBusGateway(string connectionString) { _busClient = new BusClient(connectionString); }