Пример #1
0
        public static async Task PublishToDocumentHostingServiceAsync()
        {
            var perfScope = new PerformanceScope("PublishToDocumentHostingServiceAsync");

            await RunTaskWithPerfScopeAsync(perfScope, Task.Delay(5000));

            Console.WriteLine("publishtodhs " + perfScope.ElapsedTime.TotalSeconds);
        }
Пример #2
0
        public static async Task RunTaskWithPerfScopeAsync(PerformanceScope perfScope, Task task)
        {
            Guard.ArgumentNotNull(perfScope, nameof(perfScope));
            Guard.ArgumentNotNull(task, nameof(task));

            using (perfScope)
            {
                await task;
                Console.WriteLine("runtaskwithperfscopeasync " + perfScope.ElapsedTime.TotalSeconds);
            }
        }
Пример #3
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();
            }
        }