diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/ScriptEngine/Common/Executor.cs | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/OpenSim/Grid/ScriptEngine/Common/Executor.cs b/OpenSim/Grid/ScriptEngine/Common/Executor.cs deleted file mode 100644 index 676af7b..0000000 --- a/OpenSim/Grid/ScriptEngine/Common/Executor.cs +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Runtime.Remoting.Lifetime; | ||
32 | |||
33 | namespace OpenSim.Grid.ScriptEngine.Common | ||
34 | { | ||
35 | public class Executor : MarshalByRefObject | ||
36 | { | ||
37 | // Private instance for each script | ||
38 | |||
39 | private IScript m_Script; | ||
40 | private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>(); | ||
41 | private bool m_Running = true; | ||
42 | //private List<IScript> Scripts = new List<IScript>(); | ||
43 | |||
44 | public Executor(IScript Script) | ||
45 | { | ||
46 | m_Script = Script; | ||
47 | } | ||
48 | |||
49 | // Object never expires | ||
50 | public override Object InitializeLifetimeService() | ||
51 | { | ||
52 | //Console.WriteLine("Executor: InitializeLifetimeService()"); | ||
53 | // return null; | ||
54 | ILease lease = (ILease) base.InitializeLifetimeService(); | ||
55 | |||
56 | if (lease.CurrentState == LeaseState.Initial) | ||
57 | { | ||
58 | lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1); | ||
59 | // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); | ||
60 | // lease.RenewOnCallTime = TimeSpan.FromSeconds(2); | ||
61 | } | ||
62 | return lease; | ||
63 | } | ||
64 | |||
65 | public AppDomain GetAppDomain() | ||
66 | { | ||
67 | return AppDomain.CurrentDomain; | ||
68 | } | ||
69 | |||
70 | public void ExecuteEvent(string FunctionName, object[] args) | ||
71 | { | ||
72 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. | ||
73 | // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! | ||
74 | //try | ||
75 | //{ | ||
76 | if (m_Running == false) | ||
77 | { | ||
78 | // Script is inactive, do not execute! | ||
79 | return; | ||
80 | } | ||
81 | |||
82 | string EventName = m_Script.State() + "_event_" + FunctionName; | ||
83 | |||
84 | //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args); | ||
85 | |||
86 | //Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\""); | ||
87 | |||
88 | if (Events.ContainsKey(EventName) == false) | ||
89 | { | ||
90 | // Not found, create | ||
91 | Type type = m_Script.GetType(); | ||
92 | try | ||
93 | { | ||
94 | MethodInfo mi = type.GetMethod(EventName); | ||
95 | Events.Add(EventName, mi); | ||
96 | } | ||
97 | catch | ||
98 | { | ||
99 | // Event name not found, cache it as not found | ||
100 | Events.Add(EventName, null); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | // Get event | ||
105 | MethodInfo ev = null; | ||
106 | Events.TryGetValue(EventName, out ev); | ||
107 | |||
108 | if (ev == null) // No event by that name! | ||
109 | { | ||
110 | //Console.WriteLine("ScriptEngine Can not find any event named: \"" + EventName + "\""); | ||
111 | return; | ||
112 | } | ||
113 | |||
114 | // Found | ||
115 | //try | ||
116 | //{ | ||
117 | // Invoke it | ||
118 | ev.Invoke(m_Script, args); | ||
119 | |||
120 | //} | ||
121 | //catch (Exception e) | ||
122 | //{ | ||
123 | // // TODO: Send to correct place | ||
124 | // Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString()); | ||
125 | //} | ||
126 | |||
127 | |||
128 | //} | ||
129 | //catch { } | ||
130 | } | ||
131 | |||
132 | public void StopScript() | ||
133 | { | ||
134 | m_Running = false; | ||
135 | } | ||
136 | } | ||
137 | } | ||