Ancora riorganizzazione servizi
This commit is contained in:
@@ -157,9 +157,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Services\Cache\RedisIobCache.cs" />
|
||||
<Compile Include="Services\Core\BitUtils.cs" />
|
||||
<Compile Include="Services\Utility\BitUtils.cs" />
|
||||
<Compile Include="Services\Core\ByteDataConverter.cs" />
|
||||
<Compile Include="CallMetricsCollector.cs" />
|
||||
<Compile Include="Services\Monitoring\CallMetricsCollector.cs" />
|
||||
<Compile Include="Config\Base\AlarmDto.cs" />
|
||||
<Compile Include="Config\Base\CmdUriDto.cs" />
|
||||
<Compile Include="Config\Base\ConnectionDto.cs" />
|
||||
@@ -195,7 +195,7 @@
|
||||
<Compile Include="Config\Special\FtpActConf.cs" />
|
||||
<Compile Include="Config\GenActConf.cs" />
|
||||
<Compile Include="IniFile.cs" />
|
||||
<Compile Include="IntConditionCheck.cs" />
|
||||
<Compile Include="Services\Utility\IntConditionCheck.cs" />
|
||||
<Compile Include="Services\Core\BitConditionCheck.cs" />
|
||||
<Compile Include="CustomObj.cs" />
|
||||
<Compile Include="Services\Data\DataExport.cs" />
|
||||
@@ -207,13 +207,13 @@
|
||||
<Compile Include="Services\Networking\NetService.cs" />
|
||||
<Compile Include="Services\Data\XmlDataSerializer.cs" />
|
||||
<Compile Include="Services\Core\JobTask2Exe.cs" />
|
||||
<Compile Include="MeasureUtils.cs" />
|
||||
<Compile Include="Services\Utility\MeasureUtils.cs" />
|
||||
<Compile Include="Config\Mem\plcMemMapExt.cs" />
|
||||
<Compile Include="Services\Core\TimerMan.cs" />
|
||||
<Compile Include="Services\Protocols\Eurom63.cs" />
|
||||
<Compile Include="SingleThreadTaskScheduler.cs" />
|
||||
<Compile Include="Services\Core\SingleThreadTaskScheduler.cs" />
|
||||
<Compile Include="Services\Core\TCMan.cs" />
|
||||
<Compile Include="TimeUtils.cs" />
|
||||
<Compile Include="Services\Utility\TimeUtils.cs" />
|
||||
<Compile Include="ToMapo.cs" />
|
||||
<Compile Include="baseUtils.cs" />
|
||||
<Compile Include="Services\Core\BinaryUtils.cs" />
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IOB_UT_NEXT.Services.Core
|
||||
{
|
||||
public class SingleThreadTaskScheduler : TaskScheduler, IDisposable
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public SingleThreadTaskScheduler(string threadName)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
_thread = new Thread(() =>
|
||||
{
|
||||
// Creiamo il contesto di sincronizzazione personalizzato
|
||||
SyncContext = new SingleThreadSynchronizationContext(this);
|
||||
SynchronizationContext.SetSynchronizationContext(SyncContext);
|
||||
tcs.SetResult(true);
|
||||
|
||||
foreach (var task in _tasks.GetConsumingEnumerable())
|
||||
{
|
||||
base.TryExecuteTask(task);
|
||||
}
|
||||
})
|
||||
{ IsBackground = true, Name = threadName };
|
||||
_thread.Start();
|
||||
tcs.Task.Wait(); // Aspetta che il thread sia pronto col suo contesto
|
||||
}
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public override int MaximumConcurrencyLevel => 1;
|
||||
public SynchronizationContext SyncContext { get; private set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public void Dispose() => _tasks.CompleteAdding();
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected override IEnumerable<Task> GetScheduledTasks() => _tasks;
|
||||
|
||||
protected override void QueueTask(Task task) => _tasks.Add(task);
|
||||
|
||||
protected override bool TryExecuteTaskInline(Task task, bool prev)
|
||||
=> Thread.CurrentThread == _thread && base.TryExecuteTask(task);
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly BlockingCollection<Task> _tasks = new BlockingCollection<Task>();
|
||||
private readonly Thread _thread;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Classes
|
||||
|
||||
private class SingleThreadSynchronizationContext : SynchronizationContext
|
||||
{
|
||||
#region Public Constructors
|
||||
|
||||
public SingleThreadSynchronizationContext(SingleThreadTaskScheduler sch) => _sch = sch;
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override void Post(SendOrPostCallback d, object state)
|
||||
=> Task.Factory.StartNew(() => d(state), CancellationToken.None, TaskCreationOptions.None, _sch);
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private readonly SingleThreadTaskScheduler _sch;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
|
||||
#endregion Private Classes
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IOB_UT_NEXT
|
||||
namespace IOB_UT_NEXT.Services.Monitoring
|
||||
{
|
||||
public static class CallMetricsCollector
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace IOB_UT_NEXT.Services.Core
|
||||
namespace IOB_UT_NEXT.Services.Utility
|
||||
{
|
||||
public class BitUtils
|
||||
{
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace IOB_UT_NEXT
|
||||
namespace IOB_UT_NEXT.Services.Utility
|
||||
{
|
||||
public class IntConditionCheck
|
||||
{
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IOB_UT_NEXT
|
||||
namespace IOB_UT_NEXT.Services.Utility
|
||||
{
|
||||
public class MeasureUtils
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace IOB_UT_NEXT
|
||||
namespace IOB_UT_NEXT.Services.Utility
|
||||
{
|
||||
public class TimeUtils
|
||||
{
|
||||
@@ -1,47 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class SingleThreadTaskScheduler : TaskScheduler, IDisposable
|
||||
{
|
||||
private readonly BlockingCollection<Task> _tasks = new BlockingCollection<Task>();
|
||||
private readonly Thread _thread;
|
||||
public SynchronizationContext SyncContext { get; private set; }
|
||||
|
||||
public SingleThreadTaskScheduler(string threadName)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
_thread = new Thread(() =>
|
||||
{
|
||||
// Creiamo il contesto di sincronizzazione personalizzato
|
||||
SyncContext = new SingleThreadSynchronizationContext(this);
|
||||
SynchronizationContext.SetSynchronizationContext(SyncContext);
|
||||
tcs.SetResult(true);
|
||||
|
||||
foreach (var task in _tasks.GetConsumingEnumerable())
|
||||
{
|
||||
base.TryExecuteTask(task);
|
||||
}
|
||||
})
|
||||
{ IsBackground = true, Name = threadName };
|
||||
_thread.Start();
|
||||
tcs.Task.Wait(); // Aspetta che il thread sia pronto col suo contesto
|
||||
}
|
||||
|
||||
private class SingleThreadSynchronizationContext : SynchronizationContext
|
||||
{
|
||||
private readonly SingleThreadTaskScheduler _sch;
|
||||
public SingleThreadSynchronizationContext(SingleThreadTaskScheduler sch) => _sch = sch;
|
||||
public override void Post(SendOrPostCallback d, object state)
|
||||
=> Task.Factory.StartNew(() => d(state), CancellationToken.None, TaskCreationOptions.None, _sch);
|
||||
}
|
||||
|
||||
protected override void QueueTask(Task task) => _tasks.Add(task);
|
||||
protected override bool TryExecuteTaskInline(Task task, bool prev)
|
||||
=> Thread.CurrentThread == _thread && base.TryExecuteTask(task);
|
||||
protected override IEnumerable<Task> GetScheduledTasks() => _tasks;
|
||||
public override int MaximumConcurrencyLevel => 1;
|
||||
public void Dispose() => _tasks.CompleteAdding();
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using IOB_UT_NEXT.Services.Core;
|
||||
using IOB_UT_NEXT.Services.Files;
|
||||
using IOB_UT_NEXT.Services.Monitoring;
|
||||
using NLog;
|
||||
using RestSharp;
|
||||
using System;
|
||||
|
||||
@@ -3,6 +3,7 @@ using IOB_UT_NEXT.Config;
|
||||
using IOB_UT_NEXT.Config.Base;
|
||||
using IOB_UT_NEXT.Services.Core;
|
||||
using IOB_UT_NEXT.Services.Files;
|
||||
using IOB_UT_NEXT.Services.Monitoring;
|
||||
using IOB_UT_NEXT.Services.Networking;
|
||||
using MapoSDK;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -6,7 +6,9 @@ using IOB_UT_NEXT.Services.Cache;
|
||||
using IOB_UT_NEXT.Services.Core;
|
||||
using IOB_UT_NEXT.Services.Data;
|
||||
using IOB_UT_NEXT.Services.Files;
|
||||
using IOB_UT_NEXT.Services.Monitoring;
|
||||
using IOB_UT_NEXT.Services.Networking;
|
||||
using IOB_UT_NEXT.Services.Utility;
|
||||
using MapoSDK;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using Newtonsoft.Json;
|
||||
@@ -9529,7 +9531,7 @@ namespace IOB_WIN_FORM.Iob
|
||||
foreach (var rawJob in listaValori)
|
||||
{
|
||||
// deserializzo...
|
||||
JobTaskData jobTask = JsonConvert.DeserializeObject<JobTaskData>(rawJob);
|
||||
JobTaskData jobTask = JsonDeserialize<JobTaskData>(rawJob);
|
||||
// ora chiamo la cancellazione dei task eseguiti...
|
||||
var taskDict = JobTaskData.TaskDict(jobTask.RawData);
|
||||
foreach (var item in taskDict)
|
||||
|
||||
@@ -4,6 +4,7 @@ using IOB_UT_NEXT.Config;
|
||||
using IOB_UT_NEXT.Config.Mem;
|
||||
using IOB_UT_NEXT.Config.Special;
|
||||
using IOB_UT_NEXT.Services.Data;
|
||||
using IOB_UT_NEXT.Services.Utility;
|
||||
using MapoSDK;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
@@ -3,6 +3,7 @@ using IOB_UT_NEXT;
|
||||
using IOB_UT_NEXT.Config;
|
||||
using IOB_UT_NEXT.Config.Mem;
|
||||
using IOB_UT_NEXT.Services.Core;
|
||||
using IOB_UT_NEXT.Services.Utility;
|
||||
using MapoSDK;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
Reference in New Issue
Block a user