Ejemplo n.º 1
0
 public void Exec(SubCommandRunningContext context)
 {
     foreach (var command in Commands)
     {
         command.Exec(context);
     }
 }
Ejemplo n.º 2
0
 public void Exec(SubCommandRunningContext context)
 {
     foreach (var command in Commands)
     {
         command.Exec(context);
     }
 }
Ejemplo n.º 3
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener = new ReplayLogListener();
            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand command;
            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return 1;
            }
            catch (OptionParserException e)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }

            if (!(command is ILoggable))
            {
                replayListener.Replay = false;
            }

            var context = new SubCommandRunningContext();
            try
            {
                command.Exec(context);
                return 0;
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return 1;
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return 1;
            }
        }
Ejemplo n.º 4
0
        public void Exec(SubCommandRunningContext context)
        {
            string intermediateFolder = _options.IntermediateFolder;
            string versionName        = _options.VersionName ?? string.Empty;
            var    outputFile         = string.IsNullOrEmpty(_options.DependencyFile) ? Path.Combine(Directory.GetCurrentDirectory(), "dep.json") : _options.DependencyFile;

            var dependency = Load(intermediateFolder, versionName);

            Logger.LogInfo("Exporting dependency file...");
            try
            {
                var expandedDependency = dependency == null ?
                                         ExpandedDependencyMap.Empty :
                                         ExpandedDependencyMap.ConstructFromDependencyGraph(dependency);
                using (var fs = File.Create(outputFile))
                {
                    using var writer = new StreamWriter(fs);
                    expandedDependency.Save(writer);
                }

                Logger.LogInfo($"Dependency file exported at path: {outputFile}.");
            }
            catch (Exception ex)
            {
                LogErrorAndThrow($"Unable to export dependency file: {ex.Message}", ex);
            }
        }
Ejemplo n.º 5
0
        public void Exec(SubCommandRunningContext context)
        {
            string intermediateFolder = _options.IntermediateFolder;
            string versionName        = _options.VersionName ?? string.Empty;
            var    dependencyFile     = string.IsNullOrEmpty(_options.DependencyFile) ? Path.Combine(Directory.GetCurrentDirectory(), "dep.json") : _options.DependencyFile;
            var    buildInfo          = BuildInfo.Load(intermediateFolder);

            if (buildInfo == null)
            {
                LogErrorAndThrow($"Cache files in the folder {intermediateFolder} are corrupted!", null);
            }
            var dg = buildInfo.Versions.FirstOrDefault(v => v.VersionName == versionName)?.Dependency;

            if (dg == null)
            {
                Logger.LogInfo($"Cache files for version {versionName} is not found!", null);
            }
            Logger.LogInfo($"Exporting dependency file...");
            try
            {
                var edg = dg == null ? ExpandedDependencyMap.Empty : ExpandedDependencyMap.ConstructFromDependencyGraph(dg);
                using (var fs = File.Create(dependencyFile))
                    using (var writer = new StreamWriter(fs))
                    {
                        edg.Save(writer);
                    }
                Logger.LogInfo($"Dependency file exported at path: {dependencyFile}.");
            }
            catch (Exception ex)
            {
                LogErrorAndThrow($"Unable to export dependency file: {ex.Message}", ex);
            }
        }
Ejemplo n.º 6
0
        public void Exec(SubCommandRunningContext context)
        {
            var config                   = Config;
            var baseDirectory            = config.BaseDirectory ?? Environment.CurrentDirectory;
            var intermediateOutputFolder = Path.Combine(baseDirectory, "obj");

            MergeDocument(baseDirectory, intermediateOutputFolder);
        }
Ejemplo n.º 7
0
        public void Exec(SubCommandRunningContext context)
        {
            var config = Config;
            var baseDirectory = config.BaseDirectory ?? Directory.GetCurrentDirectory();
            var intermediateOutputFolder = Path.Combine(baseDirectory, "obj");

            MergeDocument(baseDirectory, intermediateOutputFolder);
        }
Ejemplo n.º 8
0
 public void Exec(SubCommandRunningContext context)
 {
     foreach (var command in Commands)
     {
         using (new LoggerPhaseScope(command.Name, LogLevel.Info))
         {
             command.Exec(context);
         }
     }
 }
Ejemplo n.º 9
0
        public void Exec(SubCommandRunningContext context)
        {
            EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(_config.BaseDirectory) ? Directory.GetCurrentDirectory() : _config.BaseDirectory));
            // TODO: remove BaseDirectory from Config, it may cause potential issue when abused
            var baseDirectory   = EnvironmentContext.BaseDirectory;
            var outputFolder    = Path.GetFullPath(Path.Combine(string.IsNullOrEmpty(_config.OutputFolder) ? baseDirectory : _config.OutputFolder, _config.Destination ?? string.Empty));
            var rawOutputFolder = string.IsNullOrEmpty(_config.RawOutputFolder) ? Path.Combine(outputFolder, "_raw") : _config.RawOutputFolder;
            var options         = new PdfOptions
            {
                BasePath      = _config.BasePath,
                CssFilePath   = _config.CssFilePath,
                DestDirectory = outputFolder,
                Host          = _config.Host,
                Locale        = _config.Locale,
                NeedGeneratePdfExternalLink = _config.GeneratesExternalLink,
                GenerateAppendices          = _config.GeneratesAppendices,
                PdfConvertParallelism       = _config.MaxParallelism == null || _config.MaxParallelism <= 0 ? Environment.ProcessorCount : _config.MaxParallelism.Value,
                PdfDocsetName            = _config.Name ?? Path.GetFileName(EnvironmentContext.BaseDirectory),
                SourceDirectory          = Path.Combine(rawOutputFolder, _config.Destination ?? string.Empty),
                ExcludeTocs              = _config.ExcludedTocs?.ToArray(),
                KeepRawFiles             = _config.KeepRawFiles,
                ExcludeDefaultToc        = _config.ExcludeDefaultToc,
                LoadErrorHandling        = _config.LoadErrorHandling,
                FilePath                 = _wkhtmltopdfFilePath,
                AdditionalPdfCommandArgs = _config.Wkhtmltopdf?.AdditionalArguments,
                TocTitle                 = _config.TocTitle,
                OutlineOption            = _config.OutlineOption,
                CoverPageTitle           = _config.CoverPageTitle,
                NoInputStreamArgs        = _config.NoInputStreamArgs,
            };

            // 1. call BuildCommand to generate html files first
            // Output build command exec result to temp folder
            _innerBuildCommand.Config.OutputFolder = rawOutputFolder;

            _innerBuildCommand.Exec(context);

            // 2. call html2pdf converter
            var converter = new ConvertWrapper(options);

            try
            {
                using (new LoggerPhaseScope("PDF", LogLevel.Info))
                {
                    Logger.LogInfo("Start generating PDF files...");
                    converter.Convert();
                }
            }
            catch (IOException ioe)
            {
                throw new DocfxException(ioe.Message, ioe);
            }

            // 3. Should we delete generated files according to manifest
        }
Ejemplo n.º 10
0
        public void Exec(SubCommandRunningContext context)
        {
            var config                   = Config;
            var baseDirectory            = config.BaseDirectory ?? Directory.GetCurrentDirectory();
            var intermediateOutputFolder = config.Destination ?? Path.Combine(baseDirectory, "obj");

            EnvironmentContext.SetBaseDirectory(baseDirectory);
            EnvironmentContext.SetOutputDirectory(intermediateOutputFolder);
            MergeDocument(baseDirectory, intermediateOutputFolder);
            EnvironmentContext.Clean();
        }
Ejemplo n.º 11
0
 public void Exec(SubCommandRunningContext context)
 {
     foreach (var inputModel in InputModels)
     {
         // TODO: Use plugin to generate metadata for files with different extension?
         using (var worker = new Microsoft.DocAsCode.Metadata.ManagedReference.ExtractMetadataWorker(inputModel, inputModel.ForceRebuild))
         {
             // Use task.run to get rid of current context (causing deadlock in xunit)
             var task = Task.Run(worker.ExtractMetadataAsync);
             task.Wait();
         }
     }
 }
Ejemplo n.º 12
0
 public void Exec(SubCommandRunningContext context)
 {
     var builder = new XRefArchiveBuilder();
     Uri uri;
     if (Uri.TryCreate(_options.Uri, UriKind.RelativeOrAbsolute, out uri))
     {
         builder.DownloadAsync(uri, _options.ArchiveFile).Wait();
     }
     else
     {
         Logger.LogError($"Invalid uri: {_options.Uri}");
     }
 }
Ejemplo n.º 13
0
 public void Exec(SubCommandRunningContext context)
 {
     foreach (var inputModel in InputModels)
     {
         // TODO: Use plugin to generate metadata for files with different extension?
         using (var worker = new ExtractMetadataWorker(inputModel, inputModel.ForceRebuild, inputModel.UseCompatibilityFileName))
         {
             // Use task.run to get rid of current context (causing deadlock in xunit)
             var task = Task.Run(worker.ExtractMetadataAsync);
             task.Wait();
         }
     }
 }
Ejemplo n.º 14
0
 public void Exec(SubCommandRunningContext context)
 {
     foreach (var inputModel in InputModels)
     {
         // TODO: Use plugin to generate metadata for files with different extension?
         using (var worker = new ExtractMetadataWorker(inputModel, inputModel.ForceRebuild, inputModel.UseCompatibilityFileName))
         {
             // Use task.run to get rid of current context (causing deadlock in xunit)
             var task = Task.Run(worker.ExtractMetadataAsync);
             task.Wait();
         }
     }
 }
Ejemplo n.º 15
0
        public void Exec(SubCommandRunningContext context)
        {
            var builder = new XRefArchiveBuilder();

            if (Uri.TryCreate(_options.Uri, UriKind.RelativeOrAbsolute, out Uri uri))
            {
                builder.DownloadAsync(uri, _options.ArchiveFile).Wait();
            }
            else
            {
                Logger.LogError($"Invalid uri: {_options.Uri}");
            }
        }
Ejemplo n.º 16
0
        public void Exec(SubCommandRunningContext context)
        {
            switch (_commandType)
            {
            case TemplateCommandType.List:
                ExecListTemplate();
                break;

            case TemplateCommandType.Export:
                ExecExportTemplate();
                break;
            }
        }
Ejemplo n.º 17
0
 public void Exec(SubCommandRunningContext context)
 {
     try
     {
         using (new LoggerPhaseScope("ExtractMetadata"))
         {
             ExecCore();
         }
     }
     finally
     {
         EnvironmentContext.Clean();
     }
 }
Ejemplo n.º 18
0
 public void Exec(SubCommandRunningContext context)
 {
     switch (_commandType)
     {
         case TemplateCommandType.List:
             ExecListTemplate();
             break;
         case TemplateCommandType.Export:
             ExecExportTemplate();
             break;
         default:
             break;
     }
 }
Ejemplo n.º 19
0
        public void Exec(SubCommandRunningContext context)
        {
            string outputFolder = null;

            try
            {
                var config          = new DefaultConfigModel();
                var questionContext = new QuestionContext
                {
                    Quiet = _options.Quiet
                };
                foreach (var question in _selectorQuestions)
                {
                    question.Process(config, questionContext);
                }

                foreach (var question in _overallQuestion)
                {
                    question.Process(config, questionContext);
                }

                if (questionContext.ContainsMetadata)
                {
                    foreach (var question in _metadataQuestions)
                    {
                        question.Process(config, questionContext);
                    }
                }

                foreach (var question in _buildQuestions)
                {
                    question.Process(config, questionContext);
                }
                config.Build.MarkdownEngineName = "markdig";

                if (_options.OnlyConfigFile)
                {
                    GenerateConfigFile(_options.OutputFolder, config, _options.Quiet, _options.Overwrite);
                }
                else
                {
                    outputFolder = Path.GetFullPath(string.IsNullOrEmpty(_options.OutputFolder) ? DefaultOutputFolder : _options.OutputFolder).ToDisplayPath();
                    GenerateSeedProject(outputFolder, config, _options.Quiet, _options.Overwrite);
                }
            }
            catch (Exception e)
            {
                throw new DocfxInitException($"Error with init docfx project under \"{outputFolder}\" : {e.Message}", e);
            }
        }
Ejemplo n.º 20
0
 public void Exec(SubCommandRunningContext context)
 {
     EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(Config.BaseDirectory) ? Directory.GetCurrentDirectory() : Config.BaseDirectory));
     foreach (var inputModel in InputModels)
     {
         // TODO: Use plugin to generate metadata for files with different extension?
         using (var worker = new ExtractMetadataWorker(inputModel, inputModel.ForceRebuild, inputModel.UseCompatibilityFileName))
         {
             // Use task.run to get rid of current context (causing deadlock in xunit)
             var task = Task.Run(worker.ExtractMetadataAsync);
             task.Wait();
         }
     }
     EnvironmentContext.Clean();
 }
Ejemplo n.º 21
0
        public void Exec(SubCommandRunningContext context)
        {
            var config = Config;
            var baseDirectory = config.BaseDirectory ?? Environment.CurrentDirectory;
            var intermediateOutputFolder = Path.Combine(baseDirectory, "obj");
            var outputFolder = Path.Combine(config.OutputFolder ?? config.BaseDirectory ?? string.Empty, config.Destination ?? string.Empty);

            BuildDocument(baseDirectory, outputFolder);

            _templateManager.ProcessTheme(outputFolder, true);
            // TODO: SEARCH DATA

            if (config?.Serve ?? false)
            {
                ServeCommand.Serve(outputFolder, config.Port);
            }
        }
Ejemplo n.º 22
0
        public void Exec(SubCommandRunningContext context)
        {
            var config                   = Config;
            var baseDirectory            = config.BaseDirectory ?? Environment.CurrentDirectory;
            var intermediateOutputFolder = Path.Combine(baseDirectory, "obj");
            var outputFolder             = Path.Combine(config.OutputFolder ?? config.BaseDirectory ?? string.Empty, config.Destination ?? string.Empty);

            BuildDocument(baseDirectory, outputFolder);

            _templateManager.ProcessTheme(outputFolder, true);
            // TODO: SEARCH DATA

            if (config?.Serve ?? false)
            {
                ServeCommand.Serve(outputFolder, config.Port);
            }
        }
Ejemplo n.º 23
0
        public void Exec(SubCommandRunningContext context)
        {
            // TODO: remove BaseDirectory from Config, it may cause potential issue when abused
            var baseDirectory            = EnvironmentContext.BaseDirectory;
            var intermediateOutputFolder = Path.Combine(baseDirectory, "obj");
            var outputFolder             = Path.GetFullPath(Path.Combine(string.IsNullOrEmpty(Config.OutputFolder) ? baseDirectory : Config.OutputFolder, Config.Destination ?? string.Empty));

            BuildDocument(baseDirectory, outputFolder);

            _templateManager.ProcessTheme(outputFolder, true);
            // TODO: SEARCH DATA

            if (Config?.Serve ?? false)
            {
                ServeCommand.Serve(outputFolder, Config.Port);
            }
        }
Ejemplo n.º 24
0
        public void Exec(SubCommandRunningContext context)
        {
            if (string.IsNullOrWhiteSpace(_options.ArchiveFile))
            {
                Logger.LogError("Please provide output file.");
                return;
            }
            var builder = new XRefArchiveBuilder();

            if (Uri.TryCreate(_options.Uri, UriKind.RelativeOrAbsolute, out Uri uri))
            {
                builder.DownloadAsync(uri, _options.ArchiveFile).Wait();
            }
            else
            {
                Logger.LogError($"Invalid uri: {_options.Uri}");
            }
        }
Ejemplo n.º 25
0
 public void Exec(SubCommandRunningContext context)
 {
     try
     {
         using (new LoggerPhaseScope("ExtractMetadata"))
         {
             ExecCore();
         }
     }
     catch (AggregateException e)
     {
         throw e.GetBaseException();
     }
     finally
     {
         EnvironmentContext.Clean();
     }
 }
Ejemplo n.º 26
0
        public void Exec(SubCommandRunningContext context)
        {
            EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(_config.BaseDirectory) ? Directory.GetCurrentDirectory() : _config.BaseDirectory));
            // TODO: remove BaseDirectory from Config, it may cause potential issue when abused
            var baseDirectory            = EnvironmentContext.BaseDirectory;
            var intermediateOutputFolder = Path.Combine(baseDirectory, "obj");
            var outputFolder             = Path.GetFullPath(Path.Combine(string.IsNullOrEmpty(_config.OutputFolder) ? baseDirectory : _config.OutputFolder, _config.Destination ?? string.Empty));

            var options = new PdfOptions
            {
                BasePath      = _config.BasePath,
                CssFilePath   = _config.CssFilePath,
                DestDirectory = outputFolder,
                Host          = _config.Host,
                Locale        = _config.Locale,
                NeedGeneratePdfExternalLink = _config.GeneratesExternalLink,
                GenerateAppendices          = _config.GeneratesAppendices,
                PdfConvertParallelism       = _config.MaxParallelism == null || _config.MaxParallelism <= 0 ? Environment.ProcessorCount : _config.MaxParallelism.Value,
                PdfDocsetName   = _config.Name ?? Path.GetFileName(EnvironmentContext.BaseDirectory),
                SourceDirectory = outputFolder,
                ExcludeTocs     = _config.ExcludedTocs?.ToArray(),
            };

            // 1. call BuildCommand to generate html files first
            _innerBuildCommand.Exec(context);

            // 2. call html2pdf converter
            var converter = new ConvertWrapper(options);

            try
            {
                using (new LoggerPhaseScope("PDF", LogLevel.Info))
                {
                    Logger.LogInfo("Start generating PDF files...");
                    converter.Convert();
                }
            }
            catch (IOException ioe)
            {
                throw new DocfxException(ioe.Message, ioe);
            }

            // 3. Should we delete generated files according to manifest
        }
Ejemplo n.º 27
0
        public void Exec(SubCommandRunningContext context)
        {
            string name = null;
            string path = null;

            try
            {
                var config          = new DefaultConfigModel();
                var questionContext = new QuestionContext
                {
                    Quite = _options.Quiet
                };
                foreach (var question in _selectorQuestions)
                {
                    question.Process(config, questionContext);
                }

                if (questionContext.ContainsMetadata)
                {
                    foreach (var question in _metadataQuestions)
                    {
                        question.Process(config, questionContext);
                    }
                }

                foreach (var question in _buildQuestions)
                {
                    question.Process(config, questionContext);
                }

                name = string.IsNullOrEmpty(_options.Name) ? ConfigName : _options.Name;
                path = string.IsNullOrEmpty(_options.OutputFolder) ? name : Path.Combine(_options.OutputFolder, name);

                JsonUtility.Serialize(path, config, Formatting.Indented);
                Logger.LogInfo($"Generated {name} to {path}");
            }
            catch (Exception e)
            {
                throw new DocfxInitException($"Error init { name ?? ConfigName}: {e.Message}", e);
            }
        }
Ejemplo n.º 28
0
        public void Exec(SubCommandRunningContext context)
        {
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");
            var baseUri    = new Uri(_options.BaseUrl);

            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }

            var source = _options.Source.TrimEnd('/', '\\');

            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                var files = FileGlob.GetFiles(source, new string[] { _options.Glob }, null).ToList();
                if (_options.FlatMode)
                {
                    ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, files);
                }
                else
                {
                    foreach (var g in from f in files
                             group f by Path.GetDirectoryName(f) into g
                             select new
                    {
                        Folder = g.Key.Substring(source.Length).Replace('\\', '/').Trim('/'),
                        Files = g.ToList(),
                    })
                    {
                        if (g.Folder.Length == 0)
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, string.Empty, g.Files);
                        }
                        else
                        {
                            ExternalReferencePackageHelper.AddFiles(package, baseUri, _options.UrlPattern, g.Folder + "/", g.Files);
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public void Exec(SubCommandRunningContext context)
        {
            _metadataCommand.Exec(context);

            // 2. convert.
            var inputModels = _metadataCommand.InputModels;
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");
            if (string.IsNullOrWhiteSpace(_options.BaseUrl))
            {
                throw new InvalidOptionException("BaseUrl cannot be empty.", "BaseUrl");
            }

            var baseUri = new Uri(_options.BaseUrl);
            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }
            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                package.AddProjects(inputModels.SelectMany(s => s.Items).Select(s => s.Key).ToList());
            }
        }
Ejemplo n.º 30
0
        public void Exec(SubCommandRunningContext context)
        {
            var outputFile = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");
            var baseUri = new Uri(_options.BaseUrl);
            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }

            var source = _options.Source.TrimEnd('/', '\\');
            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                var files = FileGlob.GetFiles(source, new string[] { _options.Glob }, null).ToList();
                if (_options.FlatMode)
                {
                    package.AddFiles(string.Empty, files);
                }
                else
                {
                    foreach (var g in from f in files
                                      group f by Path.GetDirectoryName(f) into g
                                      select new
                                      {
                                          Folder = g.Key.Substring(source.Length).Replace('\\', '/').Trim('/'),
                                          Files = g.ToList(),
                                      })
                    {
                        if (g.Folder.Length == 0)
                        {
                            package.AddFiles(string.Empty, g.Files);
                        }
                        else
                        {
                            package.AddFiles(g.Folder + "/", g.Files);
                        }
                    }
                }
            }
        }
Ejemplo n.º 31
0
        public void Exec(SubCommandRunningContext context)
        {
            EnvironmentContext.SetGitFeaturesDisabled(Config.DisableGitFeatures);
            EnvironmentContext.SetBaseDirectory(Path.GetFullPath(string.IsNullOrEmpty(Config.BaseDirectory) ? Directory.GetCurrentDirectory() : Config.BaseDirectory));
            // TODO: remove BaseDirectory from Config, it may cause potential issue when abused
            var baseDirectory = EnvironmentContext.BaseDirectory;

            Config.IntermediateFolder = Config.IntermediateFolder ?? Path.Combine(baseDirectory, "obj", ".cache", "build");

            var outputFolder = Path.GetFullPath(Path.Combine(string.IsNullOrEmpty(Config.OutputFolder) ? baseDirectory : Config.OutputFolder, Config.Destination ?? string.Empty));

            BuildDocument(baseDirectory, outputFolder);

            _templateManager.ProcessTheme(outputFolder, true);
            // TODO: SEARCH DATA

            if (Config?.Serve ?? false)
            {
                ServeCommand.Serve(outputFolder, Config.Host, Config.Port);
            }
            EnvironmentContext.Clean();
        }
Ejemplo n.º 32
0
        public void Exec(SubCommandRunningContext context)
        {
            _metadataCommand.Exec(context);

            // 2. convert.
            var inputModels = _metadataCommand.InputModels;
            var outputFile  = Path.Combine(_options.OutputFolder ?? Environment.CurrentDirectory, _options.Name ?? "externalreference.rpk");

            if (string.IsNullOrWhiteSpace(_options.BaseUrl))
            {
                throw new InvalidOptionException("BaseUrl cannot be empty.", "BaseUrl");
            }

            var baseUri = new Uri(_options.BaseUrl);

            if (!baseUri.IsAbsoluteUri)
            {
                throw new InvalidOptionException("BaseUrl should be absolute url.", "BaseUrl");
            }
            using (var package = _options.AppendMode ? ExternalReferencePackageWriter.Append(outputFile, baseUri) : ExternalReferencePackageWriter.Create(outputFile, baseUri))
            {
                package.AddProjects(inputModels.SelectMany(s => s.Items).Select(s => s.Key).ToList());
            }
        }
Ejemplo n.º 33
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener     = new ReplayLogListener();

            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand       command;

            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command    = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return(1);
            }
            catch (Exception e) when(e is OptionParserException || e is InvalidOptionException)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }

            replayListener.Replay = command.AllowReplay;

            var context = new SubCommandRunningContext();

            try
            {
                ThreadPool.SetMinThreads(4, 4);
                using (new PerformanceScope("executing", LogLevel.Info))
                {
                    command.Exec(context);
                }

                return(0);
            }
            catch (DocumentException de)
            {
                Logger.LogError(de.Message);
                return(1);
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return(1);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return(1);
            }
        }
Ejemplo n.º 34
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener = new ReplayLogListener();
            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand command;
            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return 1;
            }
            catch (Exception e) when (e is OptionParserException || e is InvalidOptionException)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return 1;
            }

            replayListener.Replay = command.AllowReplay;

            var context = new SubCommandRunningContext();
            try
            {
                ThreadPool.SetMinThreads(4, 4);
                using (new PerformanceScope("executing", LogLevel.Info))
                {
                    command.Exec(context);
                }

                return 0;
            }
            catch (DocumentException de)
            {
                Logger.LogError(de.Message);
                return 1;
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return 1;
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return 1;
            }
        }
Ejemplo n.º 35
0
        internal static int ExecSubCommand(string[] args)
        {
            EnvironmentContext.SetVersion(typeof(Program).Assembly.GetName().Version.ToString());

            var consoleLogListener    = new ConsoleLogListener();
            var aggregatedLogListener = new AggregatedLogListener();

            Logger.RegisterListener(consoleLogListener);
            Logger.RegisterListener(aggregatedLogListener);

            CommandController controller = null;
            ISubCommand       command;

            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command    = controller.Create();
            }
            catch (Exception e) when(e is System.IO.FileNotFoundException fe || e is DocfxException || e is JsonSerializationException)
            {
                Logger.LogError(e.Message);
                return(1);
            }
            catch (Exception e) when(e is OptionParserException || e is InvalidOptionException)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }

            if (command.AllowReplay)
            {
                Logger.RegisterAsyncListener(new AggregatedLogListener(aggregatedLogListener));
            }

            Logger.UnregisterListener(aggregatedLogListener);

            var context            = new SubCommandRunningContext();
            PerformanceScope scope = null;

            try
            {
                // TODO: For now reuse AllowReplay for overall elapsed time statistics
                if (command.AllowReplay)
                {
                    scope = new PerformanceScope(string.Empty, LogLevel.Info);
                }

                command.Exec(context);
                return(0);
            }
            catch (Exception e) when(e is DocumentException || e is DocfxException)
            {
                Logger.LogError(e.Message);
                return(1);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return(1);
            }
            finally
            {
                scope?.Dispose();
            }
        }
Ejemplo n.º 36
0
 public void Exec(SubCommandRunningContext context)
 {
     Console.WriteLine(_message);
 }
Ejemplo n.º 37
0
 public void Exec(SubCommandRunningContext context)
 {
     Serve(_options.Folder,
           _options.Host,
           _options.Port.HasValue ? _options.Port.Value.ToString() : null);
 }
Ejemplo n.º 38
0
 public void Exec(SubCommandRunningContext context)
 {
     Serve(_options.Folder, _options.Port.HasValue ? _options.Port.Value.ToString() : null);
 }
Ejemplo n.º 39
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener     = new ReplayLogListener();

            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand       command;

            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command    = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return(1);
            }
            catch (OptionParserException e)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }

            if (!(command is ILoggable))
            {
                replayListener.Replay = false;
            }

            var context = new SubCommandRunningContext();

            try
            {
                command.Exec(context);
                return(0);
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return(1);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return(1);
            }
        }