-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCallBackEvent.cs
83 lines (72 loc) · 2.23 KB
/
CallBackEvent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Diagnostics;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Threading;
//1using System.Timers;
using DynamicSugar;
using Jint;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Jint.Native;
namespace Jint.Ex
{
internal class CallBackEvent
{
private static int _timeOutIdCounter = 0;
internal Func<Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> Function;
internal List<JsValue> Parameters;
internal int Delay;
internal int Id;
internal CallBackType Type;
internal bool Enabled = true;
internal string Source;
private int _alreadyWaited;
internal bool ReadyForExecution(int waitedMilliSecond)
{
this._alreadyWaited += waitedMilliSecond;
if (this._alreadyWaited > this.Delay)
{
_alreadyWaited = 0;
return true;
}
else return false;
}
internal bool Disabled
{
get { return !this.Enabled; }
}
private CallBackEvent()
{
this.Id = _timeOutIdCounter++;
}
public CallBackEvent(Func<Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> callBackFunction, List<JsValue> parameters) : this()
{
this.Type = CallBackType.UserCallback;
this.Function = callBackFunction;
this.Parameters = parameters;
}
public CallBackEvent(string source) : this()
{
this.Source = source;
this.Type = CallBackType.ScriptExecution;
}
public CallBackEvent(CallBackType callBackType) : this()
{
this.Type = callBackType;
}
public CallBackEvent(Func<Jint.Native.JsValue, Jint.Native.JsValue[], Jint.Native.JsValue> function, double delay, CallBackType type) : this()
{
this.Function = function;
this.Delay = (int)delay;
this.Type = type;
}
public void Disable()
{
this.Enabled = false;
}
}
}