static public BMyLog4PB getLogger(BaconArgs ArgBag, Program Assembly)
                {
                    byte filter = getVerbosityFilter(ArgBag);

                    if (filter == 0)
                    {
                        return(null);
                    }
                    string    tag    = ArgBag.hasOption(BMyArgParams.LOG_TAG) ? ArgBag.getOption(BMyArgParams.LOG_TAG)[0] : BMyArgParams.LOG_TAG_DEFAULT;
                    BMyLog4PB Logger = new BMyLog4PB(
                        Assembly,
                        filter,
                        new BMyLog4PB.BMyEchoAppender(Assembly),
                        new BMyLog4PB.BMyKryptDebugSrvAppender(Assembly),
                        new BMyLog4PB.BMyTextPanelAppender(
                            tag,
                            Assembly
                            )
                        );

                    if (ArgBag.hasOption(BMyArgParams.LOG_FORMAT))
                    {
                        Logger.Format = ArgBag.getOption(BMyArgParams.LOG_FORMAT)[0];
                    }
                    Logger.AutoFlush = false;
                    Logger.If(BMyLog4PB.E_DEBUG)?.Debug("Log initialized. Tag: {0}, Format: {1}", tag, Logger.Format);
                    return(Logger);
                }
                static private byte getVerbosityFilter(BaconArgs ArgBag)
                {
                    byte slug      = 0;
                    int  verbosity = ArgBag.getFlag(BMyArgParams.LOG_VERBOSITY);

                    if (verbosity >= 1)
                    {
                        slug |= BMyLog4PB.E_FATAL;
                    }
                    if (verbosity >= 2)
                    {
                        slug |= BMyLog4PB.E_ERROR;
                    }
                    if (verbosity >= 3)
                    {
                        slug |= BMyLog4PB.E_WARN;
                    }
                    if (verbosity >= 4)
                    {
                        slug |= BMyLog4PB.E_INFO;
                    }
                    if (verbosity >= 5 && ArgBag.hasOption(BMyArgParams.LOG_ENABLEDEBUG))
                    {
                        slug |= BMyLog4PB.E_DEBUG;
                    }
                    if (verbosity >= 6 && ArgBag.hasOption(BMyArgParams.LOG_ENABLEDEBUG))
                    {
                        slug |= BMyLog4PB.E_TRACE;
                    }

                    return(slug);
                }
Example #3
0
        private void Run(BaconArgs Args)
        {
            Log?.PushStack("private void Run()");
            if (Args.hasOption("reactors"))
            {
                INCLUDE_REACTORS = true;
                Log?.Info("Include reactors in sorting.");
            }
            if (Args.hasOption("weapons"))
            {
                INCLUDE_WEAPONS = true;
                Log?.Info("Include weapons in sorting.");
            }
            if (Args.hasOption("docked"))
            {
                INCLUDE_DOCKED = true;
                Log?.Info("Include docked in sorting.");
            }
            if (Args.hasOption("ignore") && Args.getOption("ignore")[0] != null)
            {
                TAG_IGNORE = Args.getOption("ignore")[0];
                Log?.Info("Use Tag \"{0}\" instead of \"#!BaconSort\" to exclude containers.", TAG_IGNORE);
            }
            List <IMyTerminalBlock> SourceBlocks = findAllBlocks();
            Dictionary <string, List <IMyTerminalBlock> > DestinationBlockMap = getDestinationMap(SourceBlocks);

            foreach (IMyTerminalBlock SourceBlock in SourceBlocks)
            {
                DoSortContainer(SourceBlock, DestinationBlockMap);
            }
            Log?.PopStack();
        }
Example #4
0
        private bool isAllowedToExecute(BaconArgs Args)
        {
            if (LastRun == null)
            {
                return(true);
            }
            int buff = 0;

            if (Args.hasOption("sleep") && int.TryParse(Args.getOption("sleep")[0], out buff))
            {
                sleepTimeS = buff;
            }
            Log?.Debug("execution limit once every {0} seconds", sleepTimeS);

            TimeSpan TimeSinceLastRun = DateTime.Now.Subtract(LastRun);

            if (sleepTimeS <= TimeSinceLastRun.TotalSeconds)
            {
                LastRun = DateTime.Now;
                return(true);
            }

            Log?.Info("Sorting in {0} seconds.", sleepTimeS - TimeSinceLastRun.TotalSeconds);
            return(false);
        }
Example #5
0
        private void BootstrapLog(BaconArgs Args)
        {
            Log = new BMyLog4PB(this, 0);
            if (!Args.hasOption("log-noecho"))
            {
                Log?.AddAppender(new BMyLog4PB.BMyEchoAppender(this));
            }
            if (Args.hasOption("log-lcd"))
            {
                string logLcdTag = Args.getOption("log-lcd")[0];
                if (logLcdTag != null)
                {
                    Log?.AddAppender(new BMyLog4PB.BMyTextPanelAppender(logLcdTag, this));
                }
            }
            if (Args.hasOption("log-filter") && Args.getOption("log-filter").Count > 0)
            {
                log_Filter = 0;
                foreach (string filterArgValue in Args.getOption("log-filter"))
                {
                    string[] filterList = filterArgValue.ToLowerInvariant().Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string filter in filterList)
                    {
                        switch (filter)
                        {
                        case "trace":
                            log_Filter |= BMyLog4PB.E_TRACE;
                            break;

                        case "debug":
                            log_Filter |= BMyLog4PB.E_DEBUG;
                            break;

                        case "info":
                            log_Filter |= BMyLog4PB.E_INFO;
                            break;

                        case "warn":
                            log_Filter |= BMyLog4PB.E_WARN;
                            break;

                        case "error":
                            log_Filter |= BMyLog4PB.E_ERROR;
                            break;

                        case "fatal":
                            log_Filter |= BMyLog4PB.E_FATAL;
                            break;

                        case "all":
                            log_Filter |= BMyLog4PB.E_ALL;
                            break;
                        }
                    }
                }
            }
            if (Log != null)
            {
                Log.Filter = log_Filter;
            }
        }