예제 #1
0
        private static void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var ctx = new Context();

            ctx.Options = CliParser.Parse(args);
            if (ctx.Options == null)
            {
                return;
            }

            using (var logger = new ProgressBar())
            {
                ctx.Logger = logger;
                OpenKeyset(ctx);

                if (ctx.Options.RunCustom)
                {
                    CustomTask(ctx);
                    return;
                }

                RunTask(ctx);
            }
        }
예제 #2
0
        private static bool Run(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var ctx = new Context();

            ctx.Options = CliParser.Parse(args);
            if (ctx.Options == null)
            {
                return(false);
            }

            StreamWriter logWriter = null;

            try
            {
                using (var logger = new ProgressBar())
                {
                    ctx.Logger  = logger;
                    ctx.Horizon = new Horizon(new TimeSpanTimer());

                    if (ctx.Options.AccessLog != null)
                    {
                        logWriter = new StreamWriter(ctx.Options.AccessLog);
                        var accessLog = new TextWriterAccessLog(logWriter);
                        ctx.Horizon.Fs.SetAccessLog(true, accessLog);
                    }

                    OpenKeyset(ctx);

                    if (ctx.Options.RunCustom)
                    {
                        CustomTask(ctx);
                        return(true);
                    }

                    RunTask(ctx);
                }
            }
            finally
            {
                logWriter?.Dispose();
            }

            return(true);
        }
예제 #3
0
        private static bool Run(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var ctx = new Context();

            ctx.Options = CliParser.Parse(args);
            if (ctx.Options == null)
            {
                return(false);
            }

            StreamWriter logWriter    = null;
            ResultLogger resultLogger = null;

            try
            {
                using (var logger = new ProgressBar())
                {
                    ctx.Logger   = logger;
                    ctx.FsClient = new FileSystemClient(new StopWatchTimeSpanGenerator());

                    if (ctx.Options.AccessLog != null)
                    {
                        logWriter = new StreamWriter(ctx.Options.AccessLog);
                        var accessLog = new TextWriterAccessLog(logWriter);

                        ctx.FsClient.SetAccessLogTarget(AccessLogTarget.All);
                        ctx.FsClient.SetGlobalAccessLogMode(GlobalAccessLogMode.Log);

                        ctx.FsClient.SetAccessLogObject(accessLog);
                    }

                    if (ctx.Options.ResultLog != null)
                    {
                        resultLogger = new ResultLogger(new StreamWriter(ctx.Options.ResultLog),
                                                        printStackTrace: true, printSourceInfo: true, combineRepeats: true);

                        Result.SetLogger(resultLogger);
                    }

                    OpenKeyset(ctx);

                    if (ctx.Options.RunCustom)
                    {
                        CustomTask(ctx);
                        return(true);
                    }

                    RunTask(ctx);
                }
            }
            finally
            {
                logWriter?.Dispose();

                if (resultLogger != null)
                {
                    Result.SetLogger(null);
                    resultLogger.Dispose();
                }
            }

            return(true);
        }
예제 #4
0
        private static bool Run(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var ctx = new Context();

            ctx.Options = CliParser.Parse(args);
            if (ctx.Options == null)
            {
                return(false);
            }

            StreamWriter      logWriter    = null;
            ResultLogger      resultLogger = null;
            LogObserverHolder logObserver  = null;

            try
            {
                using (var logger = new ProgressBar())
                {
                    ctx.Logger = logger;
                    OpenKeySet(ctx);
                    InitializeHorizon(ctx);

                    if (ctx.Options.AccessLog != null)
                    {
                        logWriter   = new StreamWriter(ctx.Options.AccessLog);
                        logObserver = new LogObserverHolder();

                        // ReSharper disable once AccessToDisposedClosure
                        // References to logWriter should be gone by the time it's disposed
                        ctx.Horizon.Diag.InitializeLogObserverHolder(ref logObserver,
                                                                     (in LogMetaData data, in LogBody body, object arguments) =>
                                                                     logWriter.Write(body.Message.ToString()), null);

                        ctx.Horizon.Diag.RegisterLogObserver(logObserver);

                        ctx.Horizon.Fs.SetLocalSystemAccessLogForDebug(true);
                        ctx.Horizon.Fs.SetGlobalAccessLogMode(GlobalAccessLogMode.Log).ThrowIfFailure();
                    }

                    if (ctx.Options.ResultLog != null)
                    {
                        resultLogger = new ResultLogger(new StreamWriter(ctx.Options.ResultLog),
                                                        printStackTrace: true, printSourceInfo: true, combineRepeats: true);

                        Result.SetLogger(resultLogger);
                    }

                    if (ctx.Options.RunCustom)
                    {
                        CustomTask(ctx);
                        return(true);
                    }

                    RunTask(ctx);
                }
            }
            finally
            {
                if (logObserver != null)
                {
                    ctx.Horizon.Diag.UnregisterLogObserver(logObserver);
                }

                logWriter?.Dispose();

                if (resultLogger != null)
                {
                    Result.SetLogger(null);
                    resultLogger.Dispose();
                }
            }

            return(true);
        }
예제 #5
0
파일: Program.cs 프로젝트: CaitSith2/libhac
        private static bool Run(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            var ctx = new Context();

            ctx.Options = CliParser.Parse(args);
            if (ctx.Options == null)
            {
                return(false);
            }

            StreamWriter logWriter    = null;
            StreamWriter resultWriter = null;

            try
            {
                Result.GetResultNameHandler = ResultLogFunctions.TryGetResultName;

                using (var logger = new ProgressBar())
                {
                    ctx.Logger  = logger;
                    ctx.Horizon = new Horizon(new StopWatchTimeSpanGenerator());

                    if (ctx.Options.AccessLog != null)
                    {
                        logWriter = new StreamWriter(ctx.Options.AccessLog);
                        var accessLog = new TextWriterAccessLog(logWriter);

                        ctx.Horizon.Fs.SetLocalAccessLogMode(LocalAccessLogMode.All);
                        ctx.Horizon.Fs.SetGlobalAccessLogMode(GlobalAccessLogMode.Log);

                        ctx.Horizon.Fs.SetAccessLogObject(accessLog);
                    }

                    if (ctx.Options.ResultLog != null)
                    {
                        resultWriter = new StreamWriter(ctx.Options.ResultLog);
                        ResultLogFunctions.LogWriter = resultWriter;

                        Result.LogCallback          = ResultLogFunctions.LogResult;
                        Result.ConvertedLogCallback = ResultLogFunctions.LogConvertedResult;
                    }

                    OpenKeyset(ctx);

                    if (ctx.Options.RunCustom)
                    {
                        CustomTask(ctx);
                        return(true);
                    }

                    RunTask(ctx);
                }
            }
            finally
            {
                logWriter?.Dispose();
                resultWriter?.Dispose();

                ResultLogFunctions.LogWriter = null;
            }

            return(true);
        }