コード例 #1
0
ファイル: Process.cs プロジェクト: gabeculbertson/Utils
    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
ファイル: UIFactoryRef.cs プロジェクト: gabeculbertson/Utils
    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
ファイル: Actor2D.cs プロジェクト: rcd229/Crystallize2D
 public void BeginInteraction(ProcessExitCallback<object> callback, IProcess parent)
 {
     SpeechBubbleManager2D.Instance.Add(transform, _phrase.Get());
     callback.Raise(null, null);
 }