Esempio n. 1
0
        // Summarizes the content project
        public static int Summarize(string[] args, bool verbose)
        {
            // Try to load the content project file
            string         filePath = args[1];
            ContentProject project  = null;

            try
            {
                project = ContentProject.LoadFromFile(filePath);
            }
            catch (Exception e)
            {
                CConsole.Error($"Could not load content project file, reason: {e.Message}.");
                if (verbose && (e.InnerException != null))
                {
                    CConsole.Error($"{e.InnerException.GetType().Name}");
                    CConsole.Error(e.InnerException.StackTrace);
                }
                return(-1);
            }

            // Project Info
            Console.WriteLine();
            Console.WriteLine($"========== PROJECT SUMMARY ==========");
            Console.WriteLine($"  Project File:        {project.FilePath}");
            Console.WriteLine($"  Content Root:        {project.Paths.ContentRoot}");
            Console.WriteLine($"  Intermediate Path:   {project.Paths.IntermediateRoot}");
            Console.WriteLine($"  Output Path:         {project.Paths.OutputRoot}");
            Console.WriteLine($"  Compress:            {project.Properties.Compress}");
            Console.WriteLine($"  Pack Size:           {project.Properties.PackSize / ProjectProperties.SIZE_TO_BYTES} MB");
            Console.WriteLine();

            // Function for printing an item
            void __printItem(ContentItem item)
            {
                Console.WriteLine($"  > {item.ItemPath}");
                if (verbose)
                {
                    Console.WriteLine($"      Full Path:   {item.Paths.SourcePath}");
                    Console.WriteLine($"      Importer:    {item.ImporterName}");
                    Console.WriteLine($"      Processor:   {item.ProcessorName} ({item.ProcessorArgs.Count})");
                    Console.WriteLine($"                     {(item.ProcessorArgs.Count > 0 ? String.Join(";", item.ProcessorArgs.Select(pair => $"{pair.Key}={pair.Value}")) : "No Args")}");
                }
                else
                {
                    Console.WriteLine($"      Importer:    {item.ImporterName}");
                    Console.WriteLine($"      Processor:   {item.ProcessorName} ({item.ProcessorArgs.Count})");
                }
            }

            // Items info
            Console.WriteLine($"=========== ITEMS SUMMARY ===========");
            Console.WriteLine($"  Total Item Count:    {project.Items.Count}");
            foreach (var item in project.Items)
            {
                __printItem(item.Value);
            }
            Console.WriteLine($"");

            // All went well
            return(0);
        }
Esempio n. 2
0
        // Runs the action passed, with the original command line arguments tacked on (path should be args[1])
        public static int RunAction(string action, string[] args, bool verbose)
        {
            // Try to load the content project file
            string         filePath = args[1];
            ContentProject project  = null;

            try
            {
                // Check for any parameter override cmd line args
                var oargs = ArgParser.Params(args);

                project = ContentProject.LoadFromFile(filePath, oargs);
            }
            catch (Exception e)
            {
                CConsole.Error($"Could not load content project file, reason: {e.Message}.");
                if (verbose && (e.InnerException != null))
                {
                    CConsole.Error($"{e.InnerException.GetType().Name}");
                    CConsole.Error(e.InnerException.StackTrace);
                }
                return(-1);
            }

            // Report project information
            if (verbose)
            {
                CConsole.Info($" ------ Project Info ------ ");
                CConsole.Info($"     Content Root:       {project.Paths.ContentRoot}");
                CConsole.Info($"     Intermediate Root:  {project.Paths.IntermediateRoot}");
                CConsole.Info($"     Output Root:        {project.Paths.OutputRoot}");
            }

            // Get the parallelization info
            uint threadCount = (action == "clean") ? 1 : ArgParser.Parallel(args);

            if (threadCount > 1)
            {
                CConsole.Info($"Using {threadCount} threads for {action} process.");
            }

            // Create the build engine to manage this action
            BuildEngine engine   = null;
            bool        useStats = ArgParser.Stats(args);

            try
            {
                engine = new BuildEngine(project, new CommandLineLogger(verbose, useStats), threadCount);
            }
            catch (Exception e)
            {
                CConsole.Error($"Unable to create build engine, reason: {e.Message}.");
                if (verbose)
                {
                    CConsole.Error($"{e.GetType().Name}");
                    CConsole.Error(e.StackTrace);
                }
                return(-1);
            }

            // Get the build type
            bool releaseBuild = ArgParser.Release(args);

            // Start the action task and logging
            using (engine)
            {
                try
                {
                    // Launch the correct task
                    Task task = null;
                    switch (action)
                    {
                    case "build": task = engine.Build(false, releaseBuild, useStats); break;

                    case "rebuild": task = engine.Build(true, releaseBuild, useStats); break;

                    case "clean": task = engine.Clean(); break;

                    default: CConsole.Error($"The action '{action}' was not understood."); return(-1);                            // Should never be reached
                    }
                    task.Start();

                    // Wait for the task to finish, logging while we go
                    while (!task.IsCompleted)
                    {
                        Thread.Sleep(50);
                        engine.Logger.Poll();
                    }

                    // Check that the task did not encounter an exception
                    if (task.IsFaulted)
                    {
                        var te = task.Exception.InnerException;
                        CConsole.Error($"Action '{action}' encountered an exception, message: {te?.Message}.");
                        if (verbose)
                        {
                            CConsole.Error($"{te?.GetType().Name}");
                            CConsole.Error(te?.StackTrace);
                        }
                        return(-1);
                    }
                }
                catch (Exception e)
                {
                    CConsole.Error($"Unhandled exception during action '{action}', message: {e.Message}.");
                    if (verbose)
                    {
                        CConsole.Error($"{e.GetType().Name}");
                        CConsole.Error(e.StackTrace);
                    }
                    return(-1);
                }
            }

            // Everything went well
            return(0);
        }