Exemplo n.º 1
0
 public static void InvokeAfter(string name, float delay, Action action)
 {
     if (!isRunning)
     {
         Log.Error($"could not queue action with name {name}, loop is shutting down");
         return;
     }
     if (action == null)
     {
         Log.Error($"action was null for invocation with name {name}");
         return;
     }
     inputQueue.Add(new Invocation {
         name     = name,
         action   = action,
         threadId = Thread.CurrentThreadId,
         created  = Time.Now(),
         delay    = delay,
     });
 }
Exemplo n.º 2
0
        static (Action, bool) Compile(string fileName)
        {
            var startTime = Time.Now();
            var source    = File.ReadAllText(fileName);
            var asmGen    = new AssemblyGenerator();

            asmGen.ReferenceAssemblyByName("System.Collections");
            asmGen.ReferenceAssemblyByName("System.Linq");
            asmGen.ReferenceAssemblyContainingType(typeof(Program));
            source = asmGen.Format(source);
            var(assembly, errors) = asmGen.Generate(source);
            if (errors != null)
            {
                Log.Error($"compilation error:\n{String.Join("\n", errors)}");
                return(null, false);
            }
            var scriptType = assembly.GetType("Script");
            var mainMethod = scriptType.GetMethod("Main", BindingFlags.NonPublic | BindingFlags.Static);
            var run        = (Action)mainMethod.CreateDelegate(typeof(Action));
            var duration   = Time.Now() - startTime;

            Log.Info($"compiled script {fileName} in {duration:F2}s");
            return(run, true);
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     action(Time.Now() - start);
 }
Exemplo n.º 4
0
 public Instance(Action <float> action)
 {
     start       = Time.Now();
     this.action = action;
 }
Exemplo n.º 5
0
 static void RunInvocation(Invocation invocation)
 {
     try {
         Log.Trace($"running invocation {invocation.name} [{invocation.threadId}] after {Time.Now() - invocation.created:F2}s (wanted {invocation.delay:F2}s)");
         invocation.action();
     } catch (Exception e) {
         Log.Error($"exception encountered for invocation with name {invocation.name}\n{e.ToString()}");
     }
 }