コード例 #1
0
 public static void Exception(this IBasicLogger logger, Exception exception)
 {
     if (exception == null)
     {
         throw new ArgumentNullException(nameof(exception));
     }
     logger.Log(new LogMessage(LogType.Exception, exception.ToString()));
 }
コード例 #2
0
ファイル: PrefixLogger.cs プロジェクト: ysdavy/ModuleManager
 public void Log(ILogMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     logger.Log(new LogMessage(message, prefix + message.Message));
 }
コード例 #3
0
ファイル: LogSplitter.cs プロジェクト: ysdavy/ModuleManager
 public void Log(ILogMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     logger1.Log(message);
     logger2.Log(message);
 }
コード例 #4
0
        public void Run(IBasicLogger logger)
        {
            if (state != State.Initialized)
            {
                throw new InvalidOperationException($"Cannot run from {state} state");
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            state = State.Running;

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

            while (state == State.Running)
            {
                stopwatch.Start();

                foreach (ILogMessage message in logQueue.TakeAll())
                {
                    logger.Log(message);
                }

                long timeRemaining = timeToWaitForLogsMs - stopwatch.ElapsedMilliseconds;
                if (timeRemaining > 0)
                {
                    System.Threading.Thread.Sleep((int)timeRemaining);
                }

                stopwatch.Reset();
            }

            foreach (ILogMessage message in logQueue.TakeAll())
            {
                logger.Log(message);
            }

            state = State.Stopped;
        }
コード例 #5
0
        public void TestRun()
        {
            ILogMessage message1 = Substitute.For <ILogMessage>();
            ILogMessage message2 = Substitute.For <ILogMessage>();
            ILogMessage message3 = Substitute.For <ILogMessage>();
            ILogMessage message4 = Substitute.For <ILogMessage>();
            ILogMessage message5 = Substitute.For <ILogMessage>();
            ILogMessage message6 = Substitute.For <ILogMessage>();
            IMessageQueue <ILogMessage> messageQueue = Substitute.For <IMessageQueue <ILogMessage> >();
            QueueLogRunner logRunner = new QueueLogRunner(messageQueue, 0);
            int            counter   = 0;

            messageQueue.TakeAll().Returns(delegate
            {
                IMessageQueue <ILogMessage> messageQueue2 = Substitute.For <IMessageQueue <ILogMessage> >();
                if (counter == 0)
                {
                    messageQueue2.GetEnumerator().Returns(new ArrayEnumerator <ILogMessage>(message1, message2));
                }
                else if (counter == 1)
                {
                    logRunner.RequestStop(); // Called from Running state
                    messageQueue2.GetEnumerator().Returns(new ArrayEnumerator <ILogMessage>(message3, message4));
                }
                else
                {
                    logRunner.RequestStop(); // Called from StopRequested state
                    messageQueue2.GetEnumerator().Returns(new ArrayEnumerator <ILogMessage>(message5, message6));
                }
                counter++;
                return(messageQueue2);
            });

            IBasicLogger logger = Substitute.For <IBasicLogger>();

            logRunner.Run(logger);

            logRunner.RequestStop(); // Called from Stopped state

            Received.InOrder(delegate
            {
                logger.Log(message1);
                logger.Log(message2);
                logger.Log(message3);
                logger.Log(message4);
                logger.Log(message5);
                logger.Log(message6);
            });
        }
コード例 #6
0
 public static void Warning(this IBasicLogger logger, string message) => logger.Log(LogType.Warning, message);
コード例 #7
0
 public static void Info(this IBasicLogger logger, string message) => logger.Log(LogType.Log, message);
コード例 #8
0
 public static void Error(this IBasicLogger logger, string message) => logger.Log(LogType.Error, message);
コード例 #9
0
 public void Log(LogType logType, string message) => logger.Log(logType, prefix + message);
コード例 #10
0
 public void Log(LogType logType, string message)
 {
     logger1.Log(logType, message);
     logger2.Log(logType, message);
 }
コード例 #11
0
        public void TestApply__Loop()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg");

            UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "aaa", "1" },
            }, file);

            INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>();

            nodeMatcher.IsMatch(Arg.Is <ConfigNode>(node => int.Parse(node.GetValue("aaa")) < 10)).Returns(true);

            EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@aaa *", "2" },
                { "bbb", "002" },
                new ConfigNode("MM_PATCH_LOOP"),
            }), nodeMatcher, Substitute.For <IPassSpecifier>());

            IPatchProgress progress = Substitute.For <IPatchProgress>();
            IBasicLogger   logger   = Substitute.For <IBasicLogger>();

            List <UrlDir.UrlConfig> modifiedUrlConfigs = new List <UrlDir.UrlConfig>();

            progress.ApplyingUpdate(Arg.Do <UrlDir.UrlConfig>(url => modifiedUrlConfigs.Add(url)), patch.UrlConfig);

            patch.Apply(file, progress, logger);

            Assert.Equal(1, file.configs.Count);
            Assert.NotSame(urlConfig, file.configs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "aaa", "16" },
                { "bbb", "002" },
                { "bbb", "002" },
                { "bbb", "002" },
                { "bbb", "002" },
            }, file.configs[0].config);

            Assert.Same(urlConfig, modifiedUrlConfigs[0]);
            Assert.NotSame(urlConfig, modifiedUrlConfigs[1]);
            Assert.NotSame(urlConfig, modifiedUrlConfigs[2]);
            Assert.NotSame(urlConfig, modifiedUrlConfigs[3]);

            Received.InOrder(delegate
            {
                logger.Log(LogType.Log, "Looping on ghi/jkl/@NODE to abc/def/NODE");
                progress.ApplyingUpdate(urlConfig, patch.UrlConfig);
                progress.ApplyingUpdate(modifiedUrlConfigs[1], patch.UrlConfig);
                progress.ApplyingUpdate(modifiedUrlConfigs[2], patch.UrlConfig);
                progress.ApplyingUpdate(modifiedUrlConfigs[3], patch.UrlConfig);
            });

            progress.DidNotReceiveWithAnyArgs().ApplyingCopy(null, null);
            progress.DidNotReceiveWithAnyArgs().ApplyingDelete(null, null);

            progress.DidNotReceiveWithAnyArgs().Error(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
        }
コード例 #12
0
        public void TestRunTestCases__WrongNumberOfNodes()
        {
            UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/blah1.cfg", databaseRoot);

            // Call CreateCopy otherwise XUnit sees that it's an IEnumerable and attempts to compare by enumeration
            ConfigNode testNode1 = new TestConfigNode("NODE1")
            {
                { "key1", "value1" },
            }.CreateCopy();

            ConfigNode testNode2 = new ConfigNode("NODE2");

            ConfigNode expectNode = new TestConfigNode("MMTEST_EXPECT")
            {
                new TestConfigNode("NODE1")
                {
                    { "key1", "value1" },
                },
            }.CreateCopy();

            UrlBuilder.CreateConfig(testNode1, file1);
            UrlBuilder.CreateConfig(testNode2, file1);
            UrlBuilder.CreateConfig(expectNode, file1);

            testRunner.RunTestCases(databaseRoot);

            Received.InOrder(delegate
            {
                logger.Log(LogType.Log, "Running tests...");
                logger.Log(LogType.Error, $"Test blah1 failed as expected number of nodes differs expected: 1 found: 2");
                logger.Log(LogType.Log, testNode1.ToString());
                logger.Log(LogType.Log, testNode2.ToString());
                logger.Log(LogType.Log, expectNode.ToString());
                logger.Log(LogType.Log, "tests complete.");
            });

            Assert.Equal(3, file1.configs.Count);
            Assert.Equal(testNode1, file1.configs[0].config);
            Assert.Equal(testNode2, file1.configs[1].config);
            Assert.Equal(expectNode, file1.configs[2].config);
        }
コード例 #13
0
 public void LogTo(IBasicLogger logger)
 {
     logger.Log(logType, message);
 }
コード例 #14
0
        public void TestApplyPatches()
        {
            IBasicLogger   logger       = Substitute.For <IBasicLogger>();
            IPatchProgress progress     = Substitute.For <IPatchProgress>();
            PatchApplier   patchApplier = new PatchApplier(progress, logger);

            UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/def.cfg");
            UrlDir.UrlFile file2 = UrlBuilder.CreateFile("ghi/jkl.cfg");
            IPass          pass1 = Substitute.For <IPass>();
            IPass          pass2 = Substitute.For <IPass>();
            IPass          pass3 = Substitute.For <IPass>();

            pass1.Name.Returns(":PASS1");
            pass2.Name.Returns(":PASS2");
            pass3.Name.Returns(":PASS3");

            UrlDir.UrlConfig[] patchUrlConfigs = new UrlDir.UrlConfig[9];
            IPatch[]           patches         = new IPatch[9];
            for (int i = 0; i < patches.Length; i++)
            {
                patches[i] = Substitute.For <IPatch>();
            }

            pass1.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[0], patches[1], patches[2]));
            pass2.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[3], patches[4], patches[5]));
            pass3.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[6], patches[7], patches[8]));

            IPass[] patchList = new IPass[] { pass1, pass2, pass3 };

            patchApplier.ApplyPatches(new[] { file1, file2 }, new[] { pass1, pass2, pass3 });

            progress.DidNotReceiveWithAnyArgs().Error(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);

            logger.DidNotReceive().Log(LogType.Warning, Arg.Any <string>());
            logger.DidNotReceive().Log(LogType.Error, Arg.Any <string>());
            logger.DidNotReceiveWithAnyArgs().Exception(null, null);

            Received.InOrder(delegate
            {
                logger.Log(LogType.Log, ":PASS1 pass");
                patches[0].Apply(file1, progress, logger);
                patches[0].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[1].Apply(file1, progress, logger);
                patches[1].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[2].Apply(file1, progress, logger);
                patches[2].Apply(file2, progress, logger);
                progress.PatchApplied();
                logger.Log(LogType.Log, ":PASS2 pass");
                patches[3].Apply(file1, progress, logger);
                patches[3].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[4].Apply(file1, progress, logger);
                patches[4].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[5].Apply(file1, progress, logger);
                patches[5].Apply(file2, progress, logger);
                progress.PatchApplied();
                logger.Log(LogType.Log, ":PASS3 pass");
                patches[6].Apply(file1, progress, logger);
                patches[6].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[7].Apply(file1, progress, logger);
                patches[7].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[8].Apply(file1, progress, logger);
                patches[8].Apply(file2, progress, logger);
                progress.PatchApplied();
            });
        }