diff --git a/AsbCloud.sln b/AsbCloud.sln index 1266d4fb..1d1809ad 100644 --- a/AsbCloud.sln +++ b/AsbCloud.sln @@ -13,9 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp1", "ConsoleApp1\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudDb", "AsbCloudDb\AsbCloudDb.csproj", "{40FBD29B-724B-4496-B5D9-1A5D14102456}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaubPanelOnlineSender", "SaubPanelOnlineSender\SaubPanelOnlineSender.csproj", "{B156D582-4D32-4368-A103-687D15B9846C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyncDicts", "SyncDicts\SyncDicts.csproj", "{39DA5EFF-D018-45AE-B0A0-A241B488660F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SyncDicts", "SyncDicts\SyncDicts.csproj", "{39DA5EFF-D018-45AE-B0A0-A241B488660F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,10 +41,6 @@ Global {40FBD29B-724B-4496-B5D9-1A5D14102456}.Debug|Any CPU.Build.0 = Debug|Any CPU {40FBD29B-724B-4496-B5D9-1A5D14102456}.Release|Any CPU.ActiveCfg = Release|Any CPU {40FBD29B-724B-4496-B5D9-1A5D14102456}.Release|Any CPU.Build.0 = Release|Any CPU - {B156D582-4D32-4368-A103-687D15B9846C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B156D582-4D32-4368-A103-687D15B9846C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B156D582-4D32-4368-A103-687D15B9846C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B156D582-4D32-4368-A103-687D15B9846C}.Release|Any CPU.Build.0 = Release|Any CPU {39DA5EFF-D018-45AE-B0A0-A241B488660F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {39DA5EFF-D018-45AE-B0A0-A241B488660F}.Debug|Any CPU.Build.0 = Debug|Any CPU {39DA5EFF-D018-45AE-B0A0-A241B488660F}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/SaubPanelOnlineSender/CloudDataSender.cs b/SaubPanelOnlineSender/CloudDataSender.cs deleted file mode 100644 index 8c991b62..00000000 --- a/SaubPanelOnlineSender/CloudDataSender.cs +++ /dev/null @@ -1,51 +0,0 @@ -using AsbCloudApp.Data; -using System; -using System.Collections.Generic; -using System.Net; -using System.Text; - -namespace SaubPanelOnlineSender -{ - public class CloudDataSender - { - public CloudDataSender() { } - - public string OnlineUrl => "http://localhost:5000/api/telemetry/0A:00:27:00:11:12/data"; - - public void Send(DataSaubBaseDto data) - { - var request = MakeRequest(); - using var streamWriter = request.GetRequestStream(); - var requestBodyJson = MakeRequestBody(data); - var dataBytes = Encoding.UTF8.GetBytes(requestBodyJson); - streamWriter.Write(dataBytes, 0, dataBytes.Length); - var response = request.GetResponse(); - streamWriter.Close(); - } - - private HttpWebRequest MakeRequest() - { - var request = WebRequest.CreateHttp(OnlineUrl); - request.Method = "POST"; - request.Timeout = 4900; - request.ContentType = "application/json"; - request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; - request.ServicePoint.Expect100Continue = false; - return request; - } - - private string MakeRequestBody(DataSaubBaseDto dataSaub) - { - var telemetry = new TelemetryDataDto - { - Date = DateTime.Now, - DataSaub = new List { dataSaub }, - HmiVersion = "3.1", - UserName = "online sender", - }; - - return Newtonsoft.Json.JsonConvert.SerializeObject(telemetry); - } - - } -} diff --git a/SaubPanelOnlineSender/DbPlayerService.cs b/SaubPanelOnlineSender/DbPlayerService.cs deleted file mode 100644 index 5d583f10..00000000 --- a/SaubPanelOnlineSender/DbPlayerService.cs +++ /dev/null @@ -1,138 +0,0 @@ -using AsbCloudApp.Data; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace SaubPanelOnlineSender -{ - public enum DbPlayerServiceState - { - Unaviable, - Stopped, - Paused, - Working - } - - public class DbPlayerService - { - public DbPlayerServiceState State - { - get => state; - private set - { - if (state == value) - return; - state = value; - OnStateUpdate?.Invoke(this, EventArgs.Empty); - } - } - - public DateTime LastSentDate { get; private set; } - - public EventHandler OnProcessUpdate; - public EventHandler OnError; - public EventHandler OnStateUpdate; - - private CancellationTokenSource cancellationTokenSource; - private DbPlayerServiceState state; - - private static readonly Random rnd = new Random((int)DateTime.Now.Ticks); - - public void Start() - { - State = DbPlayerServiceState.Working; - cancellationTokenSource = new CancellationTokenSource(); - //dataSender = new ModbusDataSender(Host); - Task.Run(async () => await Work(cancellationTokenSource.Token)); - } - - public void Pause() - { - State = State == DbPlayerServiceState.Paused - ? DbPlayerServiceState.Working - : DbPlayerServiceState.Paused; - } - - public void Stop() - { - State = DbPlayerServiceState.Stopped; - cancellationTokenSource.Cancel(); - } - - async Task Work(CancellationToken token) - { - var period = TimeSpan.FromSeconds(1); - DateTime nextTime; - var dataSender = new CloudDataSender(); - - while (!token.IsCancellationRequested) - { - nextTime = DateTime.Now + period; - if ((State != DbPlayerServiceState.Working) - && ((State != DbPlayerServiceState.Paused))) - break; - - if (State == DbPlayerServiceState.Paused) - { - await Task.Delay(100, token).ConfigureAwait(false); - continue; - } - - if (State == DbPlayerServiceState.Working) - { - - try - { - dataSender.Send(MakeDataSaubBaseDto()); - } - catch (Exception ex) - { - OnError?.Invoke(this, ex); - } - - OnProcessUpdate?.Invoke(this, 0); - } - - var waitTime = nextTime - DateTime.Now; - if (waitTime.TotalMilliseconds > 0) - await Task.Delay(waitTime, token).ConfigureAwait(false); - } - - Stop(); - } - - - private static DataSaubBaseDto MakeDataSaubBaseDto() - { - return new DataSaubBaseDto - { - Date = DateTime.Now, - AxialLoad = rnd.NextDouble() * 100d, - AxialLoadLimitMax = rnd.NextDouble() * 100d, - AxialLoadSp = rnd.NextDouble() * 100d, - BitDepth = rnd.NextDouble() * 100d, - BlockPosition = rnd.NextDouble() * 100d, - BlockSpeed = rnd.NextDouble() * 100d, - WellDepth = rnd.NextDouble() * 100d, - BlockSpeedSp = rnd.NextDouble() * 100d, - Flow = rnd.NextDouble() * 100d, - FlowDeltaLimitMax = rnd.NextDouble() * 100d, - FlowIdle = rnd.NextDouble() * 100d, - HookWeight = rnd.NextDouble() * 100d, - HookWeightIdle = rnd.NextDouble() * 100d, - HookWeightLimitMax = rnd.NextDouble() * 100d, - HookWeightLimitMin = rnd.NextDouble() * 100d, - Mode = 1, - Pressure = rnd.NextDouble() * 100d, - PressureDeltaLimitMax = rnd.NextDouble() * 100d, - PressureIdle = rnd.NextDouble() * 100d, - PressureSp = rnd.NextDouble() * 100d, - RotorSpeed = rnd.NextDouble() * 100d, - RotorTorque = rnd.NextDouble() * 100d, - RotorTorqueIdle = rnd.NextDouble() * 100d, - RotorTorqueLimitMax = rnd.NextDouble() * 100d, - RotorTorqueSp = rnd.NextDouble() * 100d, - }; - } - } -} diff --git a/SaubPanelOnlineSender/Program.cs b/SaubPanelOnlineSender/Program.cs deleted file mode 100644 index 64eefeaa..00000000 --- a/SaubPanelOnlineSender/Program.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Threading; - -namespace SaubPanelOnlineSender -{ - class Program - { - static void Main(/*string[] args*/) - { - Console.Write("player starting\n"); - Console.Write("press `Esc` or `Q` to quit\n"); - Console.Write("press `p` to pause/unpause\n"); - Console.Write("press `s` to stop/start\n"); - - var playerService = new DbPlayerService(); - - playerService.OnProcessUpdate = - (s, a) => Console.Write($"Sent: {playerService.LastSentDate:G}\n"); - playerService.OnStateUpdate = - (s, a) => Console.Write($"\nState: {playerService.State}\n"); - playerService.OnError = - (s, a) => - { - var color = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Red; - Console.Write($"ERROR: {a.Message}"); - Console.ForegroundColor = color; - Console.Write("\n"); - }; - - playerService.Start(); - - if (Console.IsInputRedirected) - { - while (true) - Thread.Sleep(1000); - } - else - { - while (true) - { - if (Console.KeyAvailable) - { - var key = Console.ReadKey().Key; - if ((key == ConsoleKey.Escape) || - (key == ConsoleKey.Q)) - break; - - if (key == ConsoleKey.P) - { - switch (playerService.State) - { - case DbPlayerServiceState.Paused: - case DbPlayerServiceState.Working: - playerService.Pause(); - break; - case DbPlayerServiceState.Unaviable: - case DbPlayerServiceState.Stopped: - default: - break; - } - } - - if (key == ConsoleKey.S) - { - switch (playerService.State) - { - case DbPlayerServiceState.Working: - playerService.Stop(); - break; - case DbPlayerServiceState.Stopped: - playerService.Start(); - break; - case DbPlayerServiceState.Unaviable: - case DbPlayerServiceState.Paused: - default: - break; - } - } - } - - Thread.Sleep(200); - } - } - playerService.Stop(); - } - } -} diff --git a/SaubPanelOnlineSender/REAMDE.md b/SaubPanelOnlineSender/REAMDE.md deleted file mode 100644 index 18bf5001..00000000 --- a/SaubPanelOnlineSender/REAMDE.md +++ /dev/null @@ -1,2 +0,0 @@ -* Назначение -проект предназначен для иммитации работы панели САУБ для НОВОГО облака. \ No newline at end of file diff --git a/SaubPanelOnlineSender/SaubPanelOnlineSender.csproj b/SaubPanelOnlineSender/SaubPanelOnlineSender.csproj deleted file mode 100644 index d81cb665..00000000 --- a/SaubPanelOnlineSender/SaubPanelOnlineSender.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - -