268 lines
9.6 KiB
C#
268 lines
9.6 KiB
C#
using CMS_CORE_Library.Models;
|
|
using Microsoft.AspNet.SignalR;
|
|
using Step.Attributes;
|
|
using Step.NC;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using TeamDev.SDK.MVVM;
|
|
using static CMS_CORE_Library.Models.DataStructures;
|
|
using static Step.Config.ServerConfig;
|
|
using static Step.Model.Constants;
|
|
using static Step.Model.Constants.FUNCTIONALITY_NAMES;
|
|
|
|
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);
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = STARTUP_ICONS, Action = ACTIONS.WRITE)]
|
|
public void PutPowerOnData(uint id)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
ncAdapter.Connect();
|
|
ncAdapter.PutPowerOnData(id);
|
|
}
|
|
}
|
|
|
|
// [SignalRAuthorize(FunctionAccess = "functionAccess", Action = ACTIONS.READ)]
|
|
|
|
[SignalRAuthorize(FunctionAccess = ALARM_CMD, Action = ACTIONS.WRITE)]
|
|
public void RefreshAllAlarms()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
// Call the library functions
|
|
libraryError = ncAdapter.RefreshAllAlarms();
|
|
}
|
|
// MessageServices.Current.Publish(SHOW_MSG_UI, null, "Refresh All Alarms.");
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = ALARM_CMD, Action = ACTIONS.WRITE)]
|
|
public void RefreshAlarm(uint id)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
// Call the library functions
|
|
libraryError = ncAdapter.RefreshAlarm(id);
|
|
if (libraryError.IsError())
|
|
throw new HubException(libraryError.localizationKey);
|
|
}
|
|
|
|
// MessageServices.Current.Publish(SHOW_MSG_UI, null, "Refresh Single Alarm. ID: " + id);
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = ALARM_CMD, Action = ACTIONS.WRITE)]
|
|
public void RecoveryProcedure(uint id)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
// Call the library functions
|
|
libraryError = ncAdapter.RestoreAlarm(id);
|
|
if (libraryError.IsError())
|
|
throw new HubException(libraryError.localizationKey);
|
|
}
|
|
|
|
// MessageServices.Current.Publish(SHOW_MSG_UI, null, "Recovery Alarm. ID: " + id);
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = NC_SOFTKEY, Action = ACTIONS.WRITE)]
|
|
public void NcSoftKeyClick(int id)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
ncAdapter.Connect();
|
|
// Write the click into memory
|
|
CmsError libraryError = ncAdapter.PutNcSoftKeyClick((uint)id);
|
|
if (libraryError.IsError())
|
|
throw new HubException(libraryError.localizationKey);
|
|
}
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = USER_SOFTKEY, Action = ACTIONS.WRITE)]
|
|
public void UserSoftKeyClick(int id)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
ncAdapter.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
|
|
ncAdapter.PutUserSoftKeyClick((uint)subkey.PlcId);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (softKey.Id == id)
|
|
{
|
|
// Write click button
|
|
ncAdapter.PutUserSoftKeyClick((uint)softKey.PlcId);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = PROCESS_CMD, Action = ACTIONS.WRITE)]
|
|
public void SelectProcess(ushort procNumber)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Connect the NC
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
// Put value into memory
|
|
libraryError = ncAdapter.PutSelectProcess(procNumber);
|
|
if (libraryError.IsError())
|
|
throw new HubException(libraryError.localizationKey);
|
|
}
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = AXES_SELECTION, Action = ACTIONS.WRITE)]
|
|
public void SelectAxis(byte axisId)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Connect the Nc
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
// Put value into memory
|
|
libraryError = ncAdapter.PutSelectAxis(axisId);
|
|
if (libraryError.IsError())
|
|
throw new HubException(libraryError.localizationKey);
|
|
}
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = HEADS_CMD, Action = ACTIONS.WRITE)]
|
|
public void AddOverride(uint id)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Connect the Nc
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
|
|
// Put value into memory
|
|
libraryError = ncAdapter.PutOverride(id, "plus");
|
|
if (libraryError.IsError())
|
|
throw new HubException(libraryError.localizationKey);
|
|
}
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = HEADS_CMD, Action = ACTIONS.WRITE)]
|
|
public void SubOverride(uint id)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Connect the Nc
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
|
|
// Put value into memory
|
|
libraryError = ncAdapter.PutOverride(id, "minus");
|
|
if (libraryError.IsError())
|
|
throw new HubException(libraryError.localizationKey);
|
|
}
|
|
}
|
|
|
|
[SignalRAuthorize(FunctionAccess = GENERAL, Action = ACTIONS.WRITE)]
|
|
public void WriteM155Response(int process, double responseVal)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
ncAdapter.Connect();
|
|
CmsError cmsError = ncAdapter.WriteM155Data(process, responseVal);
|
|
if (cmsError.IsError())
|
|
throw new HubException(cmsError.localizationKey);
|
|
}
|
|
}
|
|
|
|
|
|
[SignalRAuthorize(FunctionAccess = GENERAL, Action = ACTIONS.WRITE)]
|
|
public void WriteM156Response(int process, double responseVal)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
ncAdapter.Connect();
|
|
CmsError cmsError = ncAdapter.WriteM156Data(process, responseVal);
|
|
if (cmsError.IsError())
|
|
throw new HubException(cmsError.localizationKey);
|
|
}
|
|
}
|
|
|
|
|
|
[SignalRAuthorize(FunctionAccess = GENERAL, Action = ACTIONS.WRITE)]
|
|
public void WriteM157Response(int process, ushort responseVal)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
ncAdapter.Connect();
|
|
CmsError cmsError = ncAdapter.WriteM157Data(process, responseVal);
|
|
|
|
if (cmsError.IsError())
|
|
throw new HubException(cmsError.localizationKey);
|
|
}
|
|
}
|
|
|
|
|
|
[SignalRAuthorize(FunctionAccess = GENERAL, Action = ACTIONS.WRITE)]
|
|
public void WriteScadaValue(string memIndex, SCADA_MEM_TYPE memType, object value)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
ncAdapter.Connect();
|
|
CmsError cmsError = ncAdapter.WriteScada(memIndex, memType, value);
|
|
if (cmsError.IsError())
|
|
throw new HubException(cmsError.localizationKey);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |