Upload project.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using Syski.Data;
|
||||
using System;
|
||||
|
||||
namespace Syski.WebSocket.Services.WebSockets.Actions.Tasks
|
||||
{
|
||||
public abstract class ActionTask
|
||||
{
|
||||
|
||||
protected readonly string action;
|
||||
protected readonly IServiceProvider serviceProvider;
|
||||
protected readonly SyskiDBContext context;
|
||||
|
||||
public ActionTask(string action, IServiceProvider serviceProvider)
|
||||
{
|
||||
this.action = action;
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public abstract void ExecuteActionTask(WebSocketConnection webSocketConnection);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Syski.Data;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syski.WebSocket.Services.WebSockets.Actions.Tasks
|
||||
{
|
||||
public class CommandTask : ActionTask
|
||||
{
|
||||
|
||||
public CommandTask(IServiceProvider serviceProvider) : base("command", serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExecuteActionTask(WebSocketConnection webSocketConnection)
|
||||
{
|
||||
using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||
{
|
||||
var context = serviceScope.ServiceProvider.GetService<SyskiDBContext>();
|
||||
var systemUUID = serviceProvider.GetService<WebSocketManager>().GetSystemId(webSocketConnection.Id);
|
||||
var command = context.SystemCommands.FirstOrDefault(sc => sc.SystemId.Equals(systemUUID) && sc.ExecutedTime == null);
|
||||
if (command != null)
|
||||
{
|
||||
command.ExecutedTime = DateTime.Now;
|
||||
context.Update(command);
|
||||
if (command.Properties != null)
|
||||
{
|
||||
JObject properties = JObject.Parse(command.Properties);
|
||||
webSocketConnection.SendAction(command.Action, properties);
|
||||
}
|
||||
else
|
||||
{
|
||||
webSocketConnection.SendAction(command.Action);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Syski.Data;
|
||||
|
||||
namespace Syski.WebSocket.Services.WebSockets.Actions.Tasks
|
||||
{
|
||||
public class DefaultTask : ActionTask
|
||||
{
|
||||
|
||||
public DefaultTask(string action, IServiceProvider serviceProvider) : base(action, serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExecuteActionTask(WebSocketConnection webSocketConnection)
|
||||
{
|
||||
webSocketConnection.SendAction(action);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Syski.Data;
|
||||
|
||||
namespace Syski.WebSocket.Services.WebSockets.Actions.Tasks
|
||||
{
|
||||
public class VariablePingTask : ActionTask
|
||||
{
|
||||
|
||||
public VariablePingTask(IServiceProvider serviceProvider) : base("variableping", serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ExecuteActionTask(WebSocketConnection webSocketConnection)
|
||||
{
|
||||
using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
|
||||
{
|
||||
var context = serviceScope.ServiceProvider.GetService<SyskiDBContext>();
|
||||
var systemUUID = serviceProvider.GetService<WebSocketManager>().GetSystemId(webSocketConnection.Id);
|
||||
context.Add(new SystemPingData
|
||||
{
|
||||
SystemId = systemUUID,
|
||||
SendPingTime = DateTime.Now
|
||||
});
|
||||
context.SaveChanges();
|
||||
webSocketConnection.SendAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user