예제 #1
0
        public void Spatiald_is_running_after_Start()
        {
            using (SpatialdManager.Start().Result)
            {
                var result = RedirectedProcess.Spatial("service", "status")
                             .InDirectory(Common.SpatialProjectRootDir)
                             .RedirectOutputOptions(OutputRedirectBehaviour.None)
                             .RunAsync()
                             .Result;

                Assert.IsTrue(result.Stdout.Any(line => line.Contains("Local API service is running")));
            }
        }
예제 #2
0
        public void Dispose()
        {
            var result = RedirectedProcess
                         .Spatial("service", "stop")
                         .InDirectory(Common.SpatialProjectRootDir)
                         .RedirectOutputOptions(OutputRedirectBehaviour.None)
                         .RunAsync()
                         .Result;

            if (result.ExitCode != 0)
            {
                Debug.LogWarning($"Failed to stop spatiald with error:\n {string.Join("\n", result.Stderr)}");
            }
        }
예제 #3
0
        /// <summary>
        ///     Starts a local deployment asynchronously.
        /// </summary>
        /// <param name="name">The name for the local deployment.</param>
        /// <param name="deploymentJsonPath">
        ///     The path to the launch configuration JSON relative to the root of the SpatialOS project.
        /// </param>
        /// <param name="snapshotFileName">
        ///     The name of the snapshot to use for this deployment. Must be in the snapshots directory of your
        ///     SpatialOS project.
        /// </param>
        /// <returns>A task which represents the deployment that was started.</returns>
        /// <exception cref="ArgumentException">Thrown if <see cref="deploymentJsonPath"/> does not exist.</exception>
        /// <exception cref="Exception">Thrown if the deployment fails to start.</exception>
        public async Task <LocalDeployment> StartLocalDeployment(string name, string deploymentJsonPath, string snapshotFileName = "default.snapshot")
        {
            var fullJsonPath = Path.Combine(Common.SpatialProjectRootDir, deploymentJsonPath);

            if (!File.Exists(fullJsonPath))
            {
                throw new ArgumentException($"Could not find launch config file at {fullJsonPath}");
            }

            var fullSnapshotPath = Path.Combine(Common.SpatialProjectRootDir, "snapshots", snapshotFileName);

            if (!File.Exists(fullSnapshotPath))
            {
                throw new ArgumentException($"Could not find launch config file at {fullSnapshotPath}");
            }

            var buildConfigResult = await RedirectedProcess
                                    .Spatial("build", "build-config")
                                    .InDirectory(Common.SpatialProjectRootDir)
                                    .RedirectOutputOptions(OutputRedirectBehaviour.None)
                                    .RunAsync()
                                    .ConfigureAwait(false);

            if (buildConfigResult.ExitCode != 0)
            {
                throw new Exception($"Failed to build worker configs with error:\n {string.Join("\n", buildConfigResult.Stderr)}");
            }

            var snapshotFile = Path.GetFileNameWithoutExtension(snapshotFileName);

            var result = await RedirectedProcess.Command(SpotBinary)
                         .WithArgs("alpha", "deployment", "create", "-p", ProjectName, "-n", name, "-c", $"\"{fullJsonPath}\"", "-s", snapshotFile, "--json")
                         .InDirectory(Common.SpatialProjectRootDir)
                         .RedirectOutputOptions(OutputRedirectBehaviour.None)
                         .RunAsync()
                         .ConfigureAwait(false);

            if (result.ExitCode != 0)
            {
                throw new Exception($"Failed to start deployment with error:\n {string.Join("\n", result.Stderr)}");
            }

            var deploymentData = Json.Deserialize(string.Join("", result.Stdout));
            var content        = (Dictionary <string, object>)deploymentData["content"];
            var id             = (string)content["id"];

            return(new LocalDeployment(this, id, name, ProjectName));
        }
예제 #4
0
        private static void Package(string packageName, bool useCompression)
        {
            var zipPath  = Path.Combine(EditorPaths.PlayerBuildDirectory, packageName);
            var basePath = Path.Combine(Common.BuildScratchDirectory, packageName);

            using (new ShowProgressBarScope($"Package {basePath}"))
            {
                RedirectedProcess
                .Spatial("file", "zip")
                .WithArgs($"--output=\"{Path.GetFullPath(zipPath)}\"",
                          $"--basePath=\"{Path.GetFullPath(basePath)}\"", "\"**\"",
                          $"--compression={useCompression}")
                .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                .Run();
            }
        }
예제 #5
0
        public static WrappedTask <RedirectedProcessResult, int> Authenticate()
        {
            var source = new CancellationTokenSource();
            var token  = source.Token;

            var task = Task.Run(async() => await RedirectedProcess
                                .Spatial("auth", "login")
                                .WithArgs("--json_output")
                                .InDirectory(Tools.Common.SpatialProjectRootDir)
                                .RedirectOutputOptions(OutputRedirectBehaviour.RedirectStdOut |
                                                       OutputRedirectBehaviour.RedirectStdErr | OutputRedirectBehaviour.ProcessSpatialOutput)
                                .RunAsync(token));

            return(new WrappedTask <RedirectedProcessResult, int>
            {
                Task = task,
                CancelSource = source,
                Context = 0
            });
        }
예제 #6
0
        /// <summary>
        ///     Starts SpatialD.
        /// </summary>
        /// <remarks>
        ///     If SpatialD is already running, it will stop that instance and start a new one.
        /// </remarks>
        /// <exception cref="Exception">Thrown if this fails to start SpatialD.</exception>
        public static async Task <SpatialdManager> Start()
        {
            await RedirectedProcess
            .Spatial("service", "stop")
            .InDirectory(Common.SpatialProjectRootDir)
            .RedirectOutputOptions(OutputRedirectBehaviour.None)
            .RunAsync()
            .ConfigureAwait(false);

            var result = await RedirectedProcess
                         .Spatial("service", "start")
                         .InDirectory(Common.SpatialProjectRootDir)
                         .RedirectOutputOptions(OutputRedirectBehaviour.None)
                         .RunAsync()
                         .ConfigureAwait(false);

            if (result.ExitCode != 0)
            {
                throw new Exception($"Could not start spatiald with error:\n {string.Join("\n", result.Stderr)}");
            }

            return(new SpatialdManager());
        }