Files
cms_thermo_active/Step/Controllers/SignalR/NcHub.cs
T
Lucio Maranta 306ed6c515 User input hub comunication
Added signalR comunication -> client
Adedd new library and nhandler softkey management
2018-03-07 17:03:04 +01:00

119 lines
3.6 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Step.NC;
using TeamDev.SDK.MVVM;
using static Step.Utils.Constants;
using static Step.Config.ServerConfig;
namespace Step.Controllers.SignalR
{
// [SignalRAuthorize(FunctionAccess = "functionAccess", Action = ACTIONS.READ)]
public class NcHub : Hub
{
public static List<string> ConnectedClients = new List<string>();
public static bool NewConnectedClients = false;
public override Task OnConnected()
{
Groups.Add(Context.ConnectionId, "ncData");
NewConnectedClients = true;
ConnectedClients.Add(Context.ConnectionId);
var result = base.OnConnected();
// Resends data to all the clients
MessageServices.Current.Publish(BROADCAST_DATA);
return result;
}
public override Task OnReconnected()
{
Groups.Add(Context.ConnectionId, "ncData");
NewConnectedClients = true;
ConnectedClients.Add(Context.ConnectionId);
var result = base.OnReconnected();
// Resends data to all the clients
MessageServices.Current.Publish(BROADCAST_DATA);
return result;
}
public override Task OnDisconnected(bool stopCalled)
{
Groups.Remove(Context.ConnectionId, "ncData");
ConnectedClients.Remove(Context.ConnectionId);
return base.OnDisconnected(stopCalled);
}
public void PutPowerOnData(uint id)
{
using (NcHandler ncHandler = new NcHandler())
{
ncHandler.Connect();
ncHandler.PutPowerOnData(id);
}
}
// [SignalRAuthorize(FunctionAccess = "functionAccess", Action = ACTIONS.READ)]
public void RefreshAllAlarms()
{
using (NcHandler ncHandler = new NcHandler())
{
ncHandler.Connect();
ncHandler.RefreshAllAlarms();
}
MessageServices.Current.Publish(SHOW_MSG_UI, null, "Refresh All Alarms.");
}
public void RefreshAlarm(string id)
{
MessageServices.Current.Publish(SHOW_MSG_UI, null, "Refresh Single Alarm. ID: " + id);
}
public void RecoveryProcedure(string id)
{
MessageServices.Current.Publish(SHOW_MSG_UI, null, "Recovery Alarm. ID: " + id);
}
public void UserSoftKeyClicked(int id)
{
using (NcHandler ncHandler = new NcHandler())
{
ncHandler.Connect();
foreach (var softKey in SoftKeysConfig)
{
// Check softKey type
if (softKey.Type == SOFTKEY_TYPE.GROUP)
{
// Find in the subkeys
foreach (var subkey in softKey.SubKeys)
{
if (subkey.Id == id)
{
// Write click button
ncHandler.PutSoftKeyValue((uint)softKey.PlcId);
break;
}
}
}
else
{
if (softKey.Id == id)
{
// Write click button
ncHandler.PutSoftKeyValue((uint)softKey.PlcId);
break;
}
}
}
}
}
}
}