示例#1
0
    static void ProcessRequestHandler <I, O>(GetProcessInstance <I, O> getProcessInstance, object sender, ProcessRequestEventArgs <I, O> args)
    {
        var process = getProcessInstance();

        if (args.Parent != null)
        {
            ProcessExitCallback forceChildExit = (s, e) => process.ForceExit();
            ProcessExitCallback detachChild    = (s, e) => {
                args.Parent.OnExit -= forceChildExit;
                Debug.Log("Detached child: " + process);
            };
            process.OnExit     += detachChild;
            args.Parent.OnExit += forceChildExit;
        }

        if (args.SetChild != null)
        {
            args.SetChild(process);
        }

        ProcessExitCallback castCallback = (s, e) => args.Callback(s, (O)e);

        process.OnExit += castCallback;

        //Debug.Log("Started: " + process);
        //process.OnExit += (s, e) => Debug.Log("Ended: " + process);

        process.Initialize(args.Data);
    }
示例#2
0
 public static void Raise <T>(this ProcessExitCallback <T> eventHandler, object sender, T args)
 {
     if (eventHandler != null)
     {
         var e = eventHandler;
         e(sender, args);
     }
 }
示例#3
0
 public static void Raise <I, O>(this ProcessExitCallback eventHandler, IProcess <I, O> sender, object args)
 {
     if (eventHandler != null)
     {
         var e = eventHandler;
         e(sender, args);
     }
 }
示例#4
0
    public static IProcess Get <I, O>(this ProcessFactoryRef <I, O> fact, I input, ProcessExitCallback <O> callback, IProcess parent)
    {
        if (fact == null)
        {
            Debug.LogError(string.Format("Factory reference has not been intialized. ({0})", fact));
            return(null);
        }

        IProcess <I> process = null;

        if (fact == null)
        {
            Debug.LogWarning(string.Format("Factory instance has not been intialized. Using temporary process. ({0})", fact));
            process = new TempProcess <I, O>();
        }
        else
        {
            process = fact.Factory.GetInstance(input, parent);
        }

        if (fact.Factory is IProcessModifier <I> )
        {
            ((IProcessModifier <I>)fact.Factory).ModifyProcess(process);
        }

        process.Run_Internal(input, callback, parent);
        return(process);
        //if (process is ISettableParent) {
        //    ((ISettableParent)process).SetParent(parent);
        //}

        //ProcessExitCallback castCallback = null;
        //if (parent != null) {
        //    ProcessExitCallback forceChildExit = (s, e) => {
        //        process.OnExit -= castCallback;
        //        process.ForceExit();
        //    };
        //    ProcessExitCallback detachChild = (s, e) => parent.OnExit -= forceChildExit;
        //    process.OnExit += detachChild;
        //    process.OnExit += (s, e) => RemoveAllEvents(process);
        //    parent.OnExit += forceChildExit;
        //}

        //if (callback != null) {
        //    castCallback = (s, e) => callback(s, (O)e);
        //    process.OnExit += castCallback;
        //}

        //if (process is IDebugMethods) {
        //    var methods = ((IDebugMethods)process).GetMethods().ToArray();
        //    DebugMenuListener.AddContextMethods(methods);
        //    process.OnExit += (s, e) => DebugMenuListener.RemoveContextMethods(methods);
        //}

        ////CoroutineManager.Instance.WaitAndDo(() =>
        //process.Initialize(input);
        //return process;
    }
示例#5
0
    public static void Initialize <I, O>(this ITemporaryUI <I, O> ui, I args, EventHandler <EventArgs <O> > callback, IProcess parent)
    {
        if (ui is Component)
        {
            if (ui is IHasCanvasBranch)
            {
                MainCanvas.main.Add(((Component)ui).transform, ((IHasCanvasBranch)ui).Branch);
            }
            else
            {
                MainCanvas.main.Add(((Component)ui).transform);
            }
        }

        if (ui is IDebugMethods)
        {
            var methods = ((IDebugMethods)ui).GetMethods().ToArray();
            DebugMenuListener.AddContextMethods(methods);
            ui.Complete += (s, e) => DebugMenuListener.RemoveContextMethods(methods);
        }

        if (callback != null)
        {
            EventHandler <EventArgs <O> > handler = null;

            ProcessExitCallback exitCallback = (s, e) => {
                ui.Complete -= handler;
                Debug.Log("Detaching UI callback: " + ui + "; " + parent);
            };

            handler = (s, e) => {
                if (parent != null)
                {
                    parent.OnExit -= exitCallback;
                }
                callback(s, e);
                //Debug.Log("Detaching process callback: " + i + "; " + parent);
            };

            ui.Complete += handler;
            if (parent != null)
            {
                parent.OnExit += exitCallback;
            }
        }

        ui.Initialize(args);
    }
示例#6
0
    static void Run_Internal <I, O>(this IProcess <I> process, I input, ProcessExitCallback <O> callback, IProcess parent)
    {
        if (process is ISettableParent)
        {
            ((ISettableParent)process).SetParent(parent);
        }

        ProcessExitCallback castCallback = null;

        if (parent != null)
        {
            ProcessExitCallback forceChildExit = (s, e) => {
                process.OnExit -= castCallback;
                process.ForceExit();
            };
            ProcessExitCallback detachChild = (s, e) => parent.OnExit -= forceChildExit;
            process.OnExit += detachChild;
            process.OnExit += (s, e) => RemoveAllEvents(process);
            parent.OnExit  += forceChildExit;
        }

        if (callback != null)
        {
            castCallback    = (s, e) => callback(s, (O)e);
            process.OnExit += castCallback;
        }

        if (process is IDebugMethods)
        {
            var methods = ((IDebugMethods)process).GetMethods().ToArray();
            DebugMenuListener.AddContextMethods(methods);
            process.OnExit += (s, e) => DebugMenuListener.RemoveContextMethods(methods);
        }

        process.Initialize(input);
    }
示例#7
0
 public void StartProcess(BenchEnvironment env,
     string cwd, string executable, string arguments,
     ProcessExitCallback cb, ProcessMonitoring monitoring)
 {
     if (IsDisposed)
     {
         throw new ObjectDisposedException(nameof(ConEmuExecutionHost));
     }
     if (!IsPowerShellExecutionHostRunning)
     {
         backupHost.StartProcess(env, cwd, executable, arguments, cb, monitoring);
         return;
     }
     var collectOutput = (monitoring & ProcessMonitoring.Output) == ProcessMonitoring.Output;
     var response = SendCommand("exec", cwd, executable, arguments);
     AsyncManager.StartTask(() =>
     {
         var exitCode = 999999;
         var transcriptPath = default(string);
         foreach (var l in response)
         {
             ParseExitCode(l, ref exitCode);
             ParseTranscriptPath(l, ref transcriptPath);
         }
         var output = default(string);
         if (collectOutput && transcriptPath != null && File.Exists(transcriptPath))
         {
             output = File.ReadAllText(transcriptPath, Encoding.Default);
             File.Delete(transcriptPath);
         }
         var result = new ProcessExecutionResult(exitCode, output);
         cb(result);
     });
 }
示例#8
0
 /// <summary>
 /// Starts a Windows process in an asynchronous fashion.
 /// </summary>
 /// <param name="env">The environment variables of Bench.</param>
 /// <param name="cwd">The working directory, to start the process in.</param>
 /// <param name="exe">The path to the executable.</param>
 /// <param name="arguments">The string with the command line arguments.</param>
 /// <param name="cb">The handler method to call when the execution of the process finishes.</param>
 /// <param name="monitoring">A flag to control the level of monitoring.</param>
 /// <seealso cref="CommandLine.FormatArgumentList(string[])"/>
 public void StartProcess(BenchEnvironment env,
     string cwd, string exe, string arguments,
     ProcessExitCallback cb, ProcessMonitoring monitoring)
 {
     if (IsDisposed)
     {
         throw new ObjectDisposedException(nameof(DefaultExecutionHost));
     }
     AsyncManager.StartTask(() =>
     {
         cb(RunProcess(env, cwd, exe, arguments, monitoring));
     });
 }
示例#9
0
 public IProcess Get(ProcessExitCallback callback, IProcess parent)
 {
     return(factoryRef.GetNullOutput(input, callback, parent));
 }
示例#10
0
 public static IProcess GetNested <I, O>(this ProcessFactoryRef <IProcessGetter, O> fact, ProcessFactoryRef <I, O> inner, I input, ProcessExitCallback <O> callback, IProcess parent)
 {
     return(fact.Get <IProcessGetter, O>(
                new ProcessGetter <I, O>(inner, input),
                callback,
                parent));
 }
示例#11
0
 public static void Run <I, O>(this IProcess <I, O> process, I input, ProcessExitCallback <O> callback, IProcess parent)
 {
     Run_Internal <I, O>(process, input, callback, parent);
 }
示例#12
0
 public static IProcess GetNullOutput <I, O>(this ProcessFactoryRef <I, O> fact, I input, ProcessExitCallback callback, IProcess parent)
 {
     return(fact.Get <I, O>(input, (s, e) => callback(s, e), parent));
 }
示例#13
0
 public void BeginInteraction(ProcessExitCallback<object> callback, IProcess parent)
 {
     SpeechBubbleManager2D.Instance.Add(transform, _phrase.Get());
     callback.Raise(null, null);
 }