コード例 #1
0
        /// <summary>
        /// Parse a print mode format and add to self for storage.
        /// </summary>
        /// <param name="format">The print mode format to parse.</param>
        /// <param name="factory">The element factory to generate elements after parsing.</param>
        /// <returns>The parsed format.</returns>
        public static PrintModeParser Parse(string format, IPrinterElementFactory factory)
        {
            var parser = new PrintModeParser();

            parser.InternalProcess(format, factory);
            return(parser);
        }
コード例 #2
0
        private void InternalProcess(string format, IPrinterElementFactory factory)
        {
            var finishedState = SMState.InvalidState;

            void ProcessIsComplete(SMState state)
            {
                finishedState = state;
            }

            var stateMachine = CreateStateMachine();

#if DEBUG
            //XXX temp while developing
            string s = Stateless.Graph.UmlDotGraph.Format(stateMachine.GetInfo());
#endif
            stateMachine.Fire(processTrigger, format, factory, ProcessIsComplete);

            if (finishedState.ErrorMessage != null)
            {
                throw new ArgumentException(finishedState.ErrorMessage);
            }
            elements = finishedState.Elements;
            if (finishedState.LogConditionals?.Count > 0)
            {
                GlobalConditional = finishedState.LogConditionals[0];
            }
        }
コード例 #3
0
            public SMState(string format, IPrinterElementFactory factory, StateMachine <State, Trigger> stateMachine, Action <SMState> doneHandler)
            {
                Format         = format;
                ElementFactory = factory;
                ParsingIndex   = 0;

                ErrorMessage = null;

                CurrentElementConditionals = null;
                CurrentLogAttribute        = InvalidLogAttribute;
                CurrentLogFormat           = null;
                CurrentElementModifiers    = null;

                Elements        = null;
                LogConditionals = null;
                LogModifiers    = null;

                PriorState   = State.Uninitialized;
                StateMachine = stateMachine;
                DoneHandler  = doneHandler;
            }
コード例 #4
0
        public void PrintModeCustomAttributeConditionInvalidOnly()
        {
            logConfig.ExtraConfigs = new System.Collections.Generic.Dictionary <string, string>()
            {
                { "printMode", "@-{Message}" }
            };

            AddLog("testentry1", 123, "myFunc", "path/to/location.cpp");

            var failedLog = logRegistry.AddFailedLog();

            logRegistry.AddValueToLog(failedLog, Common.LogAttribute.Timestamp, DateTime.Now);
            logRegistry.AddValueToLog(failedLog, Common.LogAttribute.Message, "testentry2");
            logRegistry.AddValueToLog(failedLog, Common.LogAttribute.ThreadID, 456);
            logRegistry.AddValueToLog(failedLog, Common.LogAttribute.Function, "myFunc2");
            logRegistry.AddValueToLog(failedLog, Common.LogAttribute.SourceFile, "path/to/location.cpp");
            logRegistry.NotifyFailedLogParsed(failedLog);

            var expectedLogPrintout = "testentry2";

#if false
            var element     = Substitute.For <Printers.Internal.PrintMode.IElement>();
            var modifier    = Substitute.For <Printers.Internal.PrintMode.IModifier>();
            var conditional = Substitute.For <Printers.Internal.PrintMode.IConditional>();
            ElementFactory = Substitute.For <IPrinterElementFactory>();

            ElementFactory.CreateRaw(null).ReturnsForAnyArgs(element);
            ElementFactory.CreateElement(Arg.Any <Common.LogAttribute>(), null, null, null).ReturnsForAnyArgs(element);
            ElementFactory.CreateModifier(Arg.Any <ModifierElement>()).ReturnsForAnyArgs(modifier);
            ElementFactory.CreateConditional(Arg.Any <ConditionalElement>()).ReturnsForAnyArgs(conditional);

            conditional.ShouldProcess(null, null).ReturnsForAnyArgs(false);
#endif

            var data = PrintData();

            Assert.That(data, Is.EqualTo(expectedLogPrintout));
        }
コード例 #5
0
 /// <summary>
 /// Create a new console printer.
 /// </summary>
 /// <param name="factory">Element factory to use when parsing formats.</param>
 public ConsolePrinter(IPrinterElementFactory factory = null) : base(factory)
 {
 }