Exemplo n.º 1
0
        public static Promise <RunResult> ReportIssueAsync(string reporter, IssueType type, string description, string[] attachments)
        {
            if (string.IsNullOrEmpty(reporter))
            {
                throw new ArgumentException("Value cannot be null or empty.", "reporter");
            }
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }
            if (attachments == null)
            {
                throw new ArgumentNullException("attachments");
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments
                (
                    "SERVER", "REPORTISSUE",
                    "--reporter", reporter,
                    "--type", type,
                    "--description", description,
                    "--attachments", attachments
                )
                          );

            return(runTask);
        }
Exemplo n.º 2
0
        public static Promise <RunResult> ValidateAsync(string gameDataPath, ValidationOptions validationOptions, CommandOutput output)
        {
            if (gameDataPath == null)
            {
                throw new ArgumentNullException("gameDataPath");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            if (File.Exists(gameDataPath) == false)
            {
                throw new IOException(string.Format("GameData file '{0}' doesn't exists.", gameDataPath));
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments(
                    "DATA", "VALIDATE", gameDataPath,
                    "--validationOptions", ((int)validationOptions).ToString(),
                    "--output", output.Target,
                    "--outputFormat", output.Format,
                    "--outputFormattingOptions", output.FormattingOptions
                    )
                          );

            return(output.Capture(runTask));
        }
Exemplo n.º 3
0
        public static Promise <RunResult> GenerateUnityCSharpCodeAsync(string gameDataPath, string outputFilePath,
                                                                       CodeGenerationOptions options = CodeGenerationOptions.HideReferences | CodeGenerationOptions.HideLocalizedStrings,
                                                                       string documentClassName      = "Document", string apiClassName = "GameData",
                                                                       string @namespace             = "GameParameters",
                                                                       string outputEncoding         = "utf-8")
        {
            if (gameDataPath == null)
            {
                throw new ArgumentNullException("gameDataPath");
            }
            if (outputFilePath == null)
            {
                throw new ArgumentNullException("outputFilePath");
            }
            if (documentClassName == null)
            {
                throw new ArgumentNullException("documentClassName");
            }
            if (apiClassName == null)
            {
                throw new ArgumentNullException("apiClassName");
            }
            if (@namespace == null)
            {
                throw new ArgumentNullException("namespace");
            }
            if (outputEncoding == null)
            {
                throw new ArgumentNullException("outputEncoding");
            }

            if (File.Exists(gameDataPath) == false)
            {
                throw new IOException(string.Format("GameData file '{0}' doesn't exists.", gameDataPath));
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments
                (
                    "GENERATE", "UNITYCSHARPCODE", gameDataPath,
                    "--documentClassName", documentClassName,
                    "--apiClassName", apiClassName,
                    "--namespace", @namespace,
                    "--options", ((int)options).ToString(),
                    "--output", outputFilePath,
                    "--outputEncoding", outputEncoding
                )
                          );

            return(runTask);
        }
Exemplo n.º 4
0
        public static Promise <RunResult> ExportAsync(string gameDataPath, string[] entities, string[] attributes, CultureInfo[] languages, CommandOutput output, ExportMode mode)
        {
            if (gameDataPath == null)
            {
                throw new ArgumentNullException("gameDataPath");
            }
            if (entities == null)
            {
                throw new ArgumentNullException("entities");
            }
            if (attributes == null)
            {
                throw new ArgumentNullException("attributes");
            }
            if (languages == null)
            {
                throw new ArgumentNullException("languages");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            if (Enum.IsDefined(typeof(ExportMode), mode) == false)
            {
                throw new ArgumentException("Unknown export mode.", "mode");
            }
            if (File.Exists(gameDataPath) == false)
            {
                throw new IOException(string.Format("GameData file '{0}' doesn't exists.", gameDataPath));
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments(
                    "DATA", "EXPORT", gameDataPath,
                    "--entities", entities,
                    "--attributes", attributes,
                    "--languages", Array.ConvertAll(languages, l => l.Name),
                    "--mode", mode,
                    "--output", output.Target,
                    "--outputFormat", output.Format,
                    "--outputFormattingOptions", output.FormattingOptions
                    )
                          );

            return(runTask);
        }
Exemplo n.º 5
0
        public static Promise <RunResult> DeleteDocumentAsync(string gameDataPath, string entity, string id, CommandInput input, CommandOutput output)
        {
            if (gameDataPath == null)
            {
                throw new ArgumentNullException("gameDataPath");
            }
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            if (File.Exists(gameDataPath) == false)
            {
                throw new IOException(string.Format("GameData file '{0}' doesn't exists.", gameDataPath));
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments(
                    "DATA", "DELETE", gameDataPath,
                    "--entity", entity,
                    "--id", id,
                    "--input", input.Source,
                    "--inputFormat", input.Format,
                    "--inputFormattingOptions", input.FormattingOptions,
                    "--output", output.Target,
                    "--outputFormat", output.Format,
                    "--outputFormattingOptions", output.FormattingOptions
                    )
                          );

            input.StickWith(runTask);
            return(output.Capture(runTask));
        }
Exemplo n.º 6
0
        public static Promise <RunResult> ImportAsync(string gameDataPath, string[] entities, CommandInput input, ImportMode mode)
        {
            if (gameDataPath == null)
            {
                throw new ArgumentNullException("gameDataPath");
            }
            if (entities == null)
            {
                throw new ArgumentNullException("entities");
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (Enum.IsDefined(typeof(ImportMode), mode) == false)
            {
                throw new ArgumentException("Unknown import mode.", "mode");
            }
            if (File.Exists(gameDataPath) == false)
            {
                throw new IOException(string.Format("GameData file '{0}' doesn't exists.", gameDataPath));
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments(
                    "DATA", "IMPORT", gameDataPath,
                    "--entities", entities,
                    "--mode", mode,
                    "--input", input.Source,
                    "--inputFormat", input.Format,
                    "--inputFormattingOptions", input.FormattingOptions
                    )
                          );

            input.StickWith(runTask);
            return(runTask);
        }
Exemplo n.º 7
0
        public static Promise <RunResult> RestoreAsync(string gameDataPath, CommandInput input)
        {
            if (gameDataPath == null)
            {
                throw new ArgumentNullException("gameDataPath");
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            var runTask = RunInternal
                          (
                RunOptions.FlattenArguments(
                    "DATA", "RESTORE", gameDataPath,
                    "--input", input.Source,
                    "--inputFormat", input.Format,
                    "--inputFormattingOptions", input.FormattingOptions
                    )
                          );

            input.StickWith(runTask);
            return(runTask);
        }
Exemplo n.º 8
0
        internal static Promise <Process> Listen(string gameDataPath, string lockFilePath, int port, bool shadowCopy = true, Action <string, float> progressCallback = null)
        {
            if (string.IsNullOrEmpty(gameDataPath))
            {
                throw new ArgumentException("Value cannot be null or empty.", "gameDataPath");
            }
            if (string.IsNullOrEmpty(lockFilePath))
            {
                throw new ArgumentException("Value cannot be null or empty.", "lockFilePath");
            }
            if (port <= 0 || port > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException("port");
            }

            var charonPath = Path.GetFullPath(Settings.CharonPath);

            if (File.Exists(gameDataPath) == false)
            {
                throw new IOException(string.Format("File '{0}' doesn't exists.", gameDataPath));
            }
            if (File.Exists(charonPath) == false)
            {
                throw new IOException(string.Format("File '{0}' doesn't exists.", charonPath));
            }

            if (shadowCopy)
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_COPYING_EXECUTABLE, 0.10f);
                }

                var charonMd5       = FileAndPathUtils.ComputeHash(charonPath);
                var shadowDirectory = Path.GetFullPath(Path.Combine(TempDirectory, charonMd5));
                if (Directory.Exists(shadowDirectory) == false)
                {
                    if (Settings.Current.Verbose)
                    {
                        Debug.Log("Making shadow copy of '" + Path.GetFileName(charonPath) + "' to '" + shadowDirectory + "'.");
                    }

                    Directory.CreateDirectory(shadowDirectory);

                    var shadowCharonPath = Path.Combine(shadowDirectory, Path.GetFileName(charonPath));
                    File.Copy(charonPath, shadowCharonPath, overwrite: true);

                    var configPath       = charonPath + ".config";
                    var configShadowPath = shadowCharonPath + ".config";
                    if (File.Exists(configPath))
                    {
                        if (Settings.Current.Verbose)
                        {
                            Debug.Log("Making shadow copy of '" + Path.GetFileName(configPath) + "' to '" + shadowDirectory + "'.");
                        }

                        File.Copy(configPath, configShadowPath);
                    }
                    else
                    {
                        Debug.LogWarning("Missing required configuration file at '" + configPath + "'.");
                    }

                    charonPath = shadowCharonPath;
                }
                else
                {
                    charonPath = Path.Combine(shadowDirectory, Path.GetFileName(charonPath));
                }
            }
            if (progressCallback != null)
            {
                progressCallback(Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_LAUNCHING_EXECUTABLE, 0.30f);
            }
            var unityPid            = Process.GetCurrentProcess().Id;
            var scriptingAssemblies = FindAndLoadScriptingAssemblies(gameDataPath);
            var runTask             = CommandLine.Run(
                new RunOptions
                (
                    charonPath,

                    RunOptions.FlattenArguments(
                        "SERVE", Path.GetFullPath(gameDataPath),
                        "--port", port.ToString(),
                        "--watchPid", unityPid.ToString(),
                        "--lockFile", Path.GetFullPath(lockFilePath),
                        "--environment", "Unity",
                        "--extensions", Settings.SupportedExtensions,
                        "--scriptAssemblies", scriptingAssemblies,
                        Settings.Current.Verbose ? "--verbose" : ""
                        )
                )
            {
                RequireDotNetRuntime  = true,
                CaptureStandardError  = false,
                CaptureStandardOutput = false,
                ExecutionTimeout      = TimeSpan.Zero,
                WaitForExit           = false,
                StartInfo             =
                {
                    EnvironmentVariables =
                    {
                        { "CHARON_APP_DATA", Settings.GetLocalUserDataPath() },
                        { "CHARON_SERVER",   Settings.Current.ServerAddress  }
                    }
                }
            }
                );

            if (progressCallback != null)
            {
                runTask.ContinueWith(_ => progressCallback(Resources.UI_UNITYPLUGIN_WINDOW_EDITOR_LAUNCHING_EXECUTABLE, 1.0f));
            }

            return(runTask.ContinueWith(t => t.GetResult().Process));
        }