示例#1
0
        public static UnoHostArgs RemoveFrom(IList <string> args, IFileSystem fs)
        {
            var argsAsString = args.Select(a => "\"" + a + "\"").Join(" ");

            try
            {
                var unohostArgs = new UnoHostArgs()
                {
                    AssemblyPath = args.TryRemoveAt(0)
                                   .SelectMany(fs.TryResolveAbsolutePath)
                                   .SelectMany(v => v is AbsoluteFilePath
                                                        ? Optional.Some((AbsoluteFilePath)v)
                                                        : Optional.None())
                                   .OrThrow()
                };
                unohostArgs.IsDebug = args.TryGetAt(0).Select(arg => arg.Contains("--debug")).Or(false);
                if (unohostArgs.IsDebug)                 // We don't have the pipes so lets return
                {
                    unohostArgs.UserDataPath = FilePath.CreateTempFile();
                    return(unohostArgs);
                }

                unohostArgs.InputPipe    = args.TryRemoveAt(0).SelectMany(PipeName.TryParse).OrThrow();
                unohostArgs.OutputPipe   = args.TryRemoveAt(0).SelectMany(PipeName.TryParse).OrThrow();
                unohostArgs.UserDataPath = args.TryRemoveAt(0).SelectMany(AbsoluteFilePath.TryParse).OrThrow();

                return(unohostArgs);
            }
            catch (Exception)
            {
                throw new Exception("Failed to parse UnoHost arguments '" + argsAsString + "'");
            }
        }
示例#2
0
        public static UnoHostProcess Spawn(AbsoluteFilePath assembly, IObservable <IBinaryMessage> messagesToUnoHost, AbsoluteFilePath userDataPath, IEnumerable <string> moreArgs)
        {
            if (Application == null)
            {
                throw new InvalidOperationException("UnoHostProcess.Application has not been initialized");
            }

            var args = new UnoHostArgs
            {
                AssemblyPath = assembly,
                OutputPipe   = PipeName.New(),
                InputPipe    = PipeName.New(),
                UserDataPath = userDataPath,
            };

            var disp = args.InputPipe.BeginWritingMessages("UnoHost", ex => Console.WriteLine("Designer failed to write message to UnoHost: " + ex), messagesToUnoHost);

            return(new UnoHostProcess
            {
                Messages = args.OutputPipe.ReadMessages("UnoHost"),
                Process = Observable.Start(() => Application.Start(args.Serialize().Concat(moreArgs))),
                Disposables = Disposable.Combine(disp)
            });
        }