Added NightAlert project for travel kit
This commit is contained in:
62
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer.cs
vendored
Normal file
62
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer.cs
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet.Thread
|
||||
{
|
||||
public class EasyTimer
|
||||
{
|
||||
private CancellationTokenSource ts;
|
||||
|
||||
public EasyTimer(CancellationTokenSource ts)
|
||||
{
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
public static EasyTimer SetTimeout(Action method, int delayInMilliseconds)
|
||||
{
|
||||
var ts = new CancellationTokenSource();
|
||||
CancellationToken ct = ts.Token;
|
||||
var task = Task.Delay(delayInMilliseconds,ct);
|
||||
var awaiter = task.GetAwaiter();
|
||||
|
||||
awaiter.OnCompleted(
|
||||
() =>
|
||||
{
|
||||
if (!ts.IsCancellationRequested)
|
||||
{
|
||||
method();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Returns a stop handle which can be used for stopping
|
||||
// the timer, if required
|
||||
return new EasyTimer(ts);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
//var log = LogManager.GetLogger(Global.CallerName());
|
||||
//log.Info("EasyTimer stop");
|
||||
if (ts != null)
|
||||
{
|
||||
ts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void TaskRun(Action action)
|
||||
{
|
||||
Task.Run(action).Wait();
|
||||
}
|
||||
|
||||
public static void TaskRunNoWait(Action action)
|
||||
{
|
||||
Task.Run(action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
76
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer_net35.cs
vendored
Normal file
76
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer_net35.cs
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet.Thread
|
||||
{
|
||||
public class EasyTimer
|
||||
{
|
||||
|
||||
|
||||
private CancellationTokenSource ts;
|
||||
|
||||
|
||||
public EasyTimer(CancellationTokenSource ts)
|
||||
{
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
public static EasyTimer SetTimeout(Action method, int delayInMilliseconds)
|
||||
{
|
||||
var ts = new CancellationTokenSource();
|
||||
var ct = ts.Token;
|
||||
|
||||
|
||||
var worker = new BackgroundWorker();
|
||||
|
||||
worker.DoWork += (s, e) => System.Threading.Thread.Sleep(delayInMilliseconds);
|
||||
|
||||
worker.RunWorkerCompleted += (s, e) =>
|
||||
{
|
||||
if (!ts.IsCancellationRequested)
|
||||
{
|
||||
Task.Factory.StartNew(method, ct, TaskCreationOptions.None, TaskScheduler.Default);
|
||||
}
|
||||
};
|
||||
|
||||
worker.RunWorkerAsync();
|
||||
|
||||
|
||||
|
||||
// Returns a stop handle which can be used for stopping
|
||||
// the timer, if required
|
||||
return new EasyTimer(ts);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("EasyTimer stop");
|
||||
if (ts != null)
|
||||
{
|
||||
ts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public static void TaskRun(Action action)
|
||||
{
|
||||
Task.Run(action).Wait();
|
||||
}
|
||||
|
||||
public static Task TaskRunNoWait(Action action)
|
||||
{
|
||||
return Task.Run(action);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
88
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer_net40.cs
vendored
Normal file
88
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/EasyTimer_net40.cs
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet.Thread
|
||||
{
|
||||
public class EasyTimer
|
||||
{
|
||||
|
||||
|
||||
private CancellationTokenSource ts;
|
||||
|
||||
|
||||
public EasyTimer(CancellationTokenSource ts)
|
||||
{
|
||||
this.ts = ts;
|
||||
}
|
||||
|
||||
public static EasyTimer SetTimeout(Action method, int delayInMilliseconds)
|
||||
{
|
||||
var ts = new CancellationTokenSource();
|
||||
var ct = ts.Token;
|
||||
|
||||
|
||||
var worker = new BackgroundWorker();
|
||||
|
||||
worker.DoWork += (s, e) => System.Threading.Thread.Sleep(delayInMilliseconds);
|
||||
|
||||
worker.RunWorkerCompleted += (s, e) =>
|
||||
{
|
||||
if (!ts.IsCancellationRequested)
|
||||
{
|
||||
Task.Factory.StartNew(method, ct, TaskCreationOptions.None, TaskScheduler.Default);
|
||||
}
|
||||
};
|
||||
|
||||
worker.RunWorkerAsync();
|
||||
|
||||
|
||||
|
||||
// Returns a stop handle which can be used for stopping
|
||||
// the timer, if required
|
||||
return new EasyTimer(ts);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
var log = LogManager.GetLogger(Global.CallerName());
|
||||
log.Info("EasyTimer stop");
|
||||
if (ts != null)
|
||||
{
|
||||
ts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public static void TaskRun(Action action)
|
||||
{
|
||||
var t = new Task(action);
|
||||
t.RunSynchronously();
|
||||
if (t.IsFaulted)
|
||||
{
|
||||
if (t.Exception != null)
|
||||
{
|
||||
throw t.Exception;
|
||||
}
|
||||
throw new Exception();
|
||||
}
|
||||
//Task.Run(action).Wait();
|
||||
}
|
||||
|
||||
public static Task TaskRunNoWait(Action action)
|
||||
{
|
||||
var t = new Task(action);
|
||||
t.Start();
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
55
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/Heartbeat_net35.cs
vendored
Normal file
55
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/Heartbeat_net35.cs
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet.Thread
|
||||
{
|
||||
public class Heartbeat
|
||||
{
|
||||
private volatile bool gotHeartbeat = false;
|
||||
private BackgroundWorker heartBeatTimer;
|
||||
private CancellationTokenSource ts;
|
||||
|
||||
private Heartbeat()
|
||||
{
|
||||
ts = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public static Heartbeat Start(Action onTimeout, int timeout)
|
||||
{
|
||||
Heartbeat heartbeat = new Heartbeat();
|
||||
heartbeat.Run(onTimeout, timeout);
|
||||
return heartbeat;
|
||||
}
|
||||
|
||||
public void OnHeartbeat()
|
||||
{
|
||||
gotHeartbeat = true;
|
||||
}
|
||||
|
||||
private void Run(Action onTimeout, int timeout)
|
||||
{
|
||||
heartBeatTimer = new BackgroundWorker();
|
||||
|
||||
heartBeatTimer.DoWork += (s, e) =>
|
||||
{
|
||||
while (!ts.IsCancellationRequested)
|
||||
{
|
||||
System.Threading.Thread.Sleep(timeout);
|
||||
if (!gotHeartbeat && !ts.IsCancellationRequested)
|
||||
{
|
||||
onTimeout();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
heartBeatTimer.RunWorkerAsync();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
ts.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
61
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/TriggeredLoopTimer_net35.cs
vendored
Normal file
61
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.mono/Thread/TriggeredLoopTimer_net35.cs
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet.Thread
|
||||
{
|
||||
public class TriggeredLoopTimer
|
||||
{
|
||||
private ManualResetEvent trigger;
|
||||
private CancellationTokenSource ts;
|
||||
|
||||
private TriggeredLoopTimer()
|
||||
{
|
||||
trigger = new ManualResetEvent(false);
|
||||
ts = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public static TriggeredLoopTimer Start (Action method, int delayInMilliseconds)
|
||||
{
|
||||
TriggeredLoopTimer ping = new TriggeredLoopTimer();
|
||||
ping.Run (method, delayInMilliseconds);
|
||||
return ping;
|
||||
}
|
||||
|
||||
|
||||
public void Trigger()
|
||||
{
|
||||
trigger.Set();
|
||||
}
|
||||
|
||||
private void Run (Action method, int delayInMilliseconds)
|
||||
{
|
||||
var worker = new BackgroundWorker();
|
||||
|
||||
worker.DoWork += (s, e) =>
|
||||
{
|
||||
while (!ts.IsCancellationRequested)
|
||||
{
|
||||
System.Threading.Thread.Sleep (delayInMilliseconds);
|
||||
if (!ts.IsCancellationRequested)
|
||||
{
|
||||
method();
|
||||
trigger.WaitOne();
|
||||
trigger.Reset();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
worker.RunWorkerAsync();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (ts != null)
|
||||
{
|
||||
ts.Cancel();
|
||||
trigger.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user