123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- using System;
- using System.Collections.Generic;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using FBoxClientDriver;
- using FBoxClientDriver.Contract;
- using FBoxClientDriver.Impl;
- using NLog;
- namespace Ropin.Environmentally.WebScada
- {
- public class FlexBox
- {
- }
- public class FBoxClientParameters
- {
-
- public static string IdServer { get; set; } = "https://account.flexem.com/core";
- public static string MainServer { get; set; } = "http://fbox360.com";
- public static string HdataServer { get; set; } = "http://fbhs1.fbox360.com";
-
- public static string ClientId { get; set; } = "b19d14eeacb74522bd29627b79c18ab8";
- public static string ClientSecret { get; set; } = "7b89e021586c43d3b79440ba6eea0b67";
- }
- public class demo : IDisposable
- {
- public static Logger logger = LogManager.GetLogger("SimpleDemo");
- public readonly IFBoxClientManager _fbox;
- private readonly string guid = Guid.NewGuid().ToString("N");
- public demo()
- {
- HttpClient httpClient = new HttpClient();
- var provider = new DefaultCredentialProvider(FBoxClientParameters.ClientId, FBoxClientParameters.ClientSecret);
- _fbox = new FBoxClientManager(FBoxClientParameters.IdServer, FBoxClientParameters.MainServer,
- FBoxClientParameters.HdataServer, provider, guid, null, httpClient);
-
- _fbox.BoxConnectStateChanged += _fbox_BoxConnectStateChanged;
-
-
-
-
-
-
- Console.WriteLine(guid);
- Console.WriteLine();
- }
- public void Dispose()
- {
- _fbox?.Dispose();
- }
-
- private void _fbox_DataMonitorValueChanged(object sender, IList<DataMonitorValueChangedArgs> e)
- {
- foreach (var dmon in e)
- {
- Console.WriteLine(
- $"dmv:{dmon.Uid},Value:{dmon.Value},Status:{dmon.Status},BoxNo:{dmon.BoxNo},Name:{dmon.Name},BoxId:{dmon.BoxId},GroupName:{dmon.GroupName},Timestamp:{dmon.Timestamp}");
-
- System.DateTime currentTime = new System.DateTime();
- currentTime = System.DateTime.Now;
- Console.WriteLine(currentTime);
- logger.Info("时间" + currentTime + "Uid" + dmon.Uid + "名称:" + dmon.Name + "值:" + dmon.Value + "状态:" + dmon.Status + "盒子号:" + dmon.BoxNo + "分组名称:" + dmon.GroupName + "时间" + dmon.Timestamp);
- }
-
- }
-
-
-
-
-
-
-
-
- private void _fbox_BoxConnectStateChanged(object sender, IList<BoxConnectionStateItem> e)
- {
- foreach (var stateItem in e)
- {
-
- if (stateItem.NewState == BoxConnectionState.Connected ||
- stateItem.NewState == BoxConnectionState.TimedOut)
- {
-
- _fbox.StartAllDataMonitorPointsOnBox(new BoxArgs(stateItem.BoxNo)).Wait();
- }
- Console.WriteLine($"{stateItem.BoxNo},{stateItem.NewState},{stateItem.NetworkType}");
- logger.Error($"{stateItem.BoxNo},{stateItem.NewState}");
- logger.Info("盒子号:" + stateItem.BoxNo + "状态:" + stateItem.NewState);
- logger.Info("信号:" + stateItem.Rssi);
- }
- }
- private int guard;
-
- private void _fbox_AlarmTriggered(object sender, IList<AlarmTriggerDefinitionArgs> e)
- {
- foreach (var triggered in e)
- {
- Console.WriteLine(
- $"dmv:{triggered.BoxNo},{triggered.BoxId}{triggered.Uid},{triggered.Value},{triggered.Name}{triggered.Message}");
- }
- System.DateTime currentTime = new System.DateTime();
- currentTime = System.DateTime.Now;
- Console.WriteLine(currentTime);
- }
-
- private void _fbox_AlarmRecoverd(object sender, IList<AlarmRecoverDefinitonArgs> e)
- {
- foreach (var recover in e)
- {
- Console.WriteLine($"dmv:{recover.Uid},{recover.Value},{recover.Name},{recover.Message}");
- }
- }
-
-
-
- public async Task Start()
- {
- try
- {
-
- await _fbox.Restart();
-
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- throw e;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
|