SignalR: IsConnected, Disconnect

This commit is contained in:
Stoyan Zlatev 2024-03-25 10:35:36 +01:00
parent 9677121bac
commit 6fbb69ade0
11 changed files with 126 additions and 270 deletions

View File

@ -155,7 +155,7 @@
</site>
<site name="MeterProcessState" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="D:\Projekte\SENSUS_GitLab\laa_production\Common\Service\MeterProcessState" />
<virtualDirectory path="/" physicalPath="C:\Users\SZLATEV\source\repos\laa_production\Common\Service\MeterProcessState" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:56011:localhost" />

View File

@ -78,12 +78,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="816232411998.log" />
<None Include="816232412000.log" />
<None Include="816232412002.log" />
<None Include="816232412804.log" />
<None Include="816232413622.log" />
<None Include="816232413834.log" />
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -1,208 +1,11 @@
namespace CommonConsole
{
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using Xylem.Common.Logic.SoftwareAccessHelper;
public class Program
{
public static void Main()
{
foreach (var drive in Directory.GetLogicalDrives())
{
try
{
foreach (var vbpFile in Directory.GetFiles(drive, "*.vbp", SearchOption.AllDirectories))
{
Console.WriteLine(vbpFile);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
//const string BASE_URL = "http://localhost:52822/LaaProductionWeb/api/cordonels/eolprogress";
//public static void Main()
//{
// var pcbid = 1000000001;
// var model = new EOLProgressModel { PcbId = pcbid };
// var response = $"{BASE_URL}/{pcbid}".GetAsJson<EOLProgressModel>();
// model = response.Value ?? new EOLProgressModel();
// LogErrors(response.Errors);
// LogModel(model);
// model.RebootDone = "OK";
// model.ExportDone = "OK";
// model.ParameterizationDone = "OK";
// model.ProductionStatusChecked = "FAIL";
// response = model.PutAsJson<EOLProgressModel>(BASE_URL);
// model = response.Value ?? new EOLProgressModel();
// LogErrors(response.Errors);
// LogModel(model);
// model.RebootDone = "FAIL";
// model.ExportDone = "FAIL";
// model.ParameterizationDone = "FAIL";
// model.ProductionStatusChecked = "OK";
// response = model.PutAsJson<EOLProgressModel>(BASE_URL);
// model = response.Value ?? new EOLProgressModel();
// LogErrors(response.Errors);
// LogModel(model);
// model.SentinelDate = DateTime.Now;
// model.PasswordFileInstalled = "OK";
// model.RequirementChecked = "OK";
// model.StoreConfigurationDone = "NA";
// response = model.PutAsJson<EOLProgressModel>(BASE_URL);
// model = response.Value ?? new EOLProgressModel();
// LogErrors(response.Errors);
// LogModel(model);
// response = $"{BASE_URL}/{model.PcbId}/OK".PostAsJson<EOLProgressModel>();
// model = response.Value ?? new EOLProgressModel();
// LogErrors(response.Errors);
// LogModel(model);
// response = $"{BASE_URL}/{model.PcbId}".DeleteAsJson<EOLProgressModel>();
// model = response.Value ?? new EOLProgressModel();
// LogErrors(response.Errors);
// LogModel(model);
//}
private static void LogModel(EOLProgressModel model)
{
if (model != null)
{
Console.WriteLine(JsonConvert.SerializeObject(model, Formatting.Indented));
}
}
private static void LogErrors(Dictionary<String, String> errors)
{
if (errors != null)
{
foreach (var kvp in errors)
{
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
}
}
}
}
public class EOLProgressModel
{
public Int32 Id { get; set; }
public Int32 PcbId { get; set; }
public Int32? RequirementId { get; set; }
public String RequirementChecked { get; set; }
public String PasswordFileInstalled { get; set; }
public String ProductionStatusChecked { get; set; }
public String ParameterizationDone { get; set; }
public String RebootDone { get; set; }
public String StoreConfigurationDone { get; set; }
public String ExportDone { get; set; }
public Int64? RaioCheckId { get; set; }
public DateTime? SentinelDate { get; set; }
public String Completed { get; set; }
public DateTime? CompleteDate { get; set; }
public String CompleteHost { get; set; }
public DateTime AddDate { get; set; }
public String AddHost { get; set; }
}
}
//--- Connected: COM9, 2400, 8, None, One
//>>> 01
//<<< 01-39-34-37-30-35-36-38-36-00
//>>> 07
//<<< 01-00
//>>> 13
//<<< 01-30-30-30-30-30-31-30-31-00
//>>> FD-3D
//<<< 01-87-F2-BA-00
//>>> FD-64-00-F2-BA-BD-51-33-44-07-00
//<<< 01
//>>> FD-02
//<<< 01-00-00-E1-84-06-00
//>>> FD-25-00-00-E1-84-06-00-00-00-30-00-00-00-07
//<<< 01
//--- Connected: COM9, 2400, 8, None, One
//>>> 01
//<<< 01-39-34-37-30-35-36-38-33-00
//>>> 07
//<<< 01-00
//>>> 13
//<<< 01-30-30-30-30-30-33-37-38-00
//>>> FD-3D
//<<< 01-0D-24-B3-00
//>>> FD-64-00-24-B3-18-01-33-44-09-00
//<<< 02
//>>> 17
//<<< 01-38-31-36-32-33-33-35-30-30-39-32-31-00
//>>> FD-08
//<<< 01-00
//>>> FD-02
//<<< 01-00-00-E1-84-06-00
//>>> FD-25-00-00-E1-84-06-00-00-00-30-00-00-00-07
//<<< 01
//--- Disconnected: COM9, 2400, 8, None, One
//--- Connected: COM9, 2400, 8, None, One
//>>> 01
//<<< 01-39-34-37-30-35-36-38-32-00
//>>> 07
//<<< 01-00
//>>> 13
//<<< 01-30-30-30-30-30-30-39-39-00
//>>> FD-3D
//<<< 01-CA-12-B3-00
//>>> FD-64-00-12-B3-39-11-33-44-06-00
//<<< 01
//>>> 17
//<<< 01-38-31-36-32-33-33-35-31-35-32-34-37-00
//>>> FD-08
//<<< 01-31
//>>> FD-02
//<<< 01-00-00-E1-84-06-00
//>>> FD-25-00-00-E1-84-06-00-00-00-30-00-00-00-07
//<<< 01
//--- Disconnected: COM9, 2400, 8, None, One
}

View File

@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client;
public delegate void DataReceivedHandler(DataDictionary data);
@ -23,8 +23,12 @@
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IDataHubClient
{
bool IsConnected { get; }
void Connect(string url);
void Disconnect();
void Send(DataDictionary dictionary);
}
@ -45,6 +49,23 @@
public event DataReceivedHandler DataReceived;
public event StateHandler StateChanged;
public bool IsConnected
{
get
{
try
{
return this.connection.State == ConnectionState.Connected;
}
catch (Exception e)
{
this.NotifyStateChanged(e);
return false;
}
}
}
public void Connect(string url)
{
this.connection = new HubConnection(url, queryString: $"key={Environment.MachineName}");
@ -71,6 +92,30 @@
}
}
public void Disconnect()
{
Task.Factory.StartNew(() =>
{
try
{
this.disposable.Dispose();
}
catch (Exception e)
{
this.NotifyStateChanged(e);
}
try
{
this.connection.Stop();
}
catch (Exception e)
{
this.NotifyStateChanged(e);
}
});
}
public void Send(DataDictionary dictionary)
{
this.proxy.Invoke(nameof(this.Send), dictionary.Generic());

View File

@ -61,9 +61,6 @@
</Compile>
<Compile Include="Models\Appsettings.cs" />
<Compile Include="Models\CompilerServices.cs" />
<Compile Include="PluginsWindow.xaml.cs">
<DependentUpon>PluginsWindow.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\PluginsVM.cs" />
<Compile Include="ViewModels\DefaultsHeaderRow.cs" />
<Compile Include="ViewModels\DefaultsRowVM.cs" />
@ -94,10 +91,6 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="PluginsWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">

View File

@ -1,43 +0,0 @@
<Window x:Class="InspectionUI.PluginsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:VM="clr-namespace:InspectionUI.ViewModels"
xmlns:Local="clr-namespace:InspectionUI"
FontFamily="Consolas"
Height="450"
Width="800">
<Window.DataContext>
<VM:PluginsVM />
</Window.DataContext>
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding ItemsSource}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type VM:PluginVM}">
<Border Background="WhiteSmoke"
BorderBrush="LightGray"
BorderThickness="1"
CornerRadius="3"
Margin="10, 10, 0, 0"
Padding="10">
<StackPanel>
<Label Content="{Binding Title}" FontWeight="Bold" Padding="0, 0, 0, 3" />
<Label Content="{Binding Description}" Padding="0, 0, 0, 3"/>
<Label Content="{Binding Company}" Padding="0, 0, 0, 3" />
<Label Content="{Binding Product}" Padding="0, 0, 0, 3" />
<Label Content="{Binding Copyright}" Padding="0, 0, 0, 3" />
<Label Content="{Binding Trademark}" Padding="0, 0, 0, 3" />
<Label Content="{Binding Culture}" Padding="0, 0, 0, 3" />
<Label Content="{Binding Version}" Padding="0, 0, 0, 3" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Window>

View File

@ -1,12 +0,0 @@
namespace InspectionUI
{
using System.Windows;
public partial class PluginsWindow : Window
{
public PluginsWindow()
{
this.InitializeComponent();
}
}
}

View File

@ -0,0 +1,10 @@
namespace LaaProductionWeb.API.Cordonel
{
using System.Web.Http;
[RoutePrefix("api/Cordonels/CSR")]
public class CSRController : ControllerBase
{
}
}

View File

@ -14,8 +14,8 @@
[RoutePrefix("api/Cordonels/EOLProgress")]
public class EOLProgressController : ControllerBase
{
const string PCBID_KEY = "PcbId";
const string PCBID_ERROR = "PcbId should not be <= 0";
//const string PCBID_KEY = "PcbId";
//const string PCBID_ERROR = "PcbId should not be <= 0";
private readonly IEOLProgressService eolProgress;

View File

@ -1,8 +1,10 @@
namespace LaaProductionWeb.Hubs
{
using LaaProduction.Http.Interfaces;
using LaaProduction.SQL.Interfaces;
using LaaProductionDI;
using LaaProductionWeb.API;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
@ -10,6 +12,8 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
[HubName(nameof(DataHub))]
@ -111,5 +115,66 @@
})
.SendAsync<object>();
}
private static void SaveIni(Dictionary<string, object> data)
{
var psnr = data.TryGetValue("psnr", out var _psnr) && _psnr is int nr ? nr : 0;
var host = data.TryGetValue("groupname", out var _host) ? _host as string : default(string);
var ini = data.TryGetValue("ini", out var _ini) ? _ini as string : default(string);
var iniBytes = Encoding.UTF8.GetBytes(ini);
var md5 = new MD5CryptoServiceProvider();
var iniHashBytes = md5.ComputeHash(iniBytes);
var hash = Convert.ToBase64String(iniHashBytes);
var iniId = LaaServiceProvider
.GetService<ISQLConnection>()
.CreateCommand($@"
SELECT [Id]
FROM [Configurations]
WHERE [PsNr] = @{nameof(psnr)}
AND [Type] = 'INI'
ORDER BY [Id] DESC")
.SetParameter(nameof(psnr), psnr)
.FirstOrDefault(x => x.GetInt());
if (iniId <= 0)
{
LaaServiceProvider
.GetService<ISQLConnection>()
.CreateCommand($@"
INSERT INTO [Configurations]
( [PsNr]
, [Host]
, [Type]
, [Hash]
, [Content])
VALUES (@{nameof(psnr)}
, @{nameof(host)}
, 'INI'
, @{nameof(hash)}
, @{nameof(ini)})")
.SetParameter(nameof(psnr), psnr)
.SetParameter(nameof(host), host)
.SetParameter(nameof(hash), hash)
.SetParameter(nameof(ini), ini)
.FirstOrDefault(x => x.GetInt());
}
else
{
LaaServiceProvider
.GetService<ISQLConnection>()
.CreateCommand($@"
UPDATE [Configurations]
SET [Host] = @{nameof(host)}
, [Hash] = @{nameof(hash)}
, [Content] = @{nameof(ini)}
WHERE [Id] = @{nameof(iniId)}")
.SetParameter(nameof(host), host)
.SetParameter(nameof(hash), hash)
.SetParameter(nameof(ini), ini)
.SetParameter(nameof(iniId), iniId)
.FirstOrDefault(x => x.GetInt());
}
}
}
}

View File

@ -179,6 +179,7 @@
<ItemGroup>
<Compile Include="API\APIExtensions.cs" />
<Compile Include="API\ControllerBase.cs" />
<Compile Include="API\Cordonel\CSRController.cs" />
<Compile Include="API\Cordonel\EOLProgressController.cs" />
<Compile Include="API\LoginController.cs" />
<Compile Include="API\Personalization\EmployeesController.cs" />