示例#1
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        private static async Task<Tuple<bool, List<Error>>> BuildMonoGameAsync(
            ServiceContainer services, string applicationName, TextDocument document, DelegateCommand<Error> goToLocationCommand)
        {
            string errorMessage = await Task.Run(() =>
            {
                using (var tempDirectoryHelper = new TempDirectoryHelper(applicationName, "ShaderDocument"))
                {
                    var contentBuilder = new GameContentBuilder(services)
                    {
                        IntermediateFolder = tempDirectoryHelper.TempDirectoryName + "\\obj",
                        OutputFolder = tempDirectoryHelper.TempDirectoryName + "\\bin",
                    };

                    string message;
                    contentBuilder.Build(document.Uri.LocalPath, null, "EffectProcessor", null, out message);
                    return message;
                }
            });

            List<Error> errors = null;
            if (!string.IsNullOrEmpty(errorMessage))
            {
                errorMessage = errorMessage.TrimEnd(' ', '\r', '\n');
                errors = new List<Error>();

                // Use regular expression to parse the MSBuild output lines.
                // Example: "X:\DigitalRune\Samples\DigitalRune.Graphics.Content\DigitalRune\Billboard.fx(22,3) : Unexpected token 'x' found. Expected CloseBracket"
                var regex = new Regex(@"(?<file>[^\\/]*)\((?<line>\d+),(?<column>\d+)\) : (?<message>.*)");

                var match = regex.Match(errorMessage);
                if (match.Success)
                {
                    string lineText = match.Groups["line"].Value;
                    string columnText = match.Groups["column"].Value;
                    string message = match.Groups["message"].Value;
                    bool isWarning = match.Groups["warning"].Success;
                    var error = new Error(
                        isWarning ? ErrorType.Warning : ErrorType.Error,
                        $"[MonoGame] {message}",
                        match.Groups["file"].Value,
                        int.Parse(lineText),
                        int.Parse(columnText));

                    error.UserData = document;
                    error.GoToLocationCommand = goToLocationCommand;
                    errors.Add(error);
                }
                else
                {
                    errors.Add(new Error(ErrorType.Error, errorMessage));
                }
            }

            return Tuple.Create(string.IsNullOrEmpty(errorMessage), errors);
        }
示例#2
0
        private static Tuple<string, TempDirectoryHelper> BuildXnb(IServiceLocator services, string applicationName, string fileName, bool createModelNode, bool recreateModelAndMaterialFiles)
        {
            Debug.Assert(services != null);
            Debug.Assert(applicationName != null);
            Debug.Assert(applicationName.Length > 0);
            Debug.Assert(fileName != null);
            Debug.Assert(fileName.Length > 0);

            var tempDirectoryHelper = new TempDirectoryHelper(applicationName, "ModelDocument");
            try
            {
                var contentBuilder = new GameContentBuilder(services)
                {
                    IntermediateFolder = tempDirectoryHelper.TempDirectoryName + "\\obj",
                    OutputFolder = tempDirectoryHelper.TempDirectoryName + "\\bin",
                };

                string processorName;
                var processorParams = new OpaqueDataDictionary();
                if (createModelNode)
                {
                    processorName = "GameModelProcessor";
                    processorParams.Add("RecreateModelDescriptionFile", recreateModelAndMaterialFiles);
                    processorParams.Add("RecreateMaterialDefinitionFiles", recreateModelAndMaterialFiles);
                }
                else
                {
                    processorName = "ModelProcessor";
                }

                string errorMessage;
                bool success = contentBuilder.Build(Path.GetFullPath(fileName), null, processorName, processorParams, out errorMessage);
                if (!success)
                    throw new EditorException(Invariant($"Could not process 3d model: {fileName}.\n See output window for details."));

                // Return output folder into which we built the XNB.
                var outputFolder = contentBuilder.OutputFolder;
                if (!Path.IsPathRooted(outputFolder))
                    outputFolder = Path.GetFullPath(Path.Combine(contentBuilder.ExecutableFolder, contentBuilder.OutputFolder));

                return Tuple.Create(outputFolder, tempDirectoryHelper);
            }
            catch
            {
                tempDirectoryHelper.Dispose();
                throw;
            }
        }