Beispiel #1
0
        public static void InitializeLoggers()
        {
            StatusLogger = new Logger("Status", Basic.ConsoleLocker, ConsoleColor.Green);
            InfosLogger = new Logger("Infos", Basic.ConsoleLocker, ConsoleColor.Magenta, Config.GetBoolElement("DEBUG"));
            ErrorsLogger = new Logger("Errors", Basic.ConsoleLocker, ConsoleColor.Yellow);

            StatusLogger.Write(string.Format("Loggers loaded and started : MODE DEBUG = {0}", Config.GetBoolElement("DEBUG").ToString().ToUpper()));
        }
Beispiel #2
0
        public void Test_Clear()
        {
            var node = new Node ("Node");
            var log = new Logger ();

            log.Write (node, 1, "Hello World");
            Assert.AreEqual (1, log.LogCount);

            log.Clear ();
            Assert.AreEqual (0, log.LogCount);
        }
Beispiel #3
0
        public void Test_Write()
        {
            var node = new Node ("Node");
            var log = new Logger ();
            log.Write (node, 1, "Hello World");

            Assert.AreEqual (1, log.LogCount);
            Assert.AreEqual (1, log.Logs.Count ());
            Assert.AreEqual ("Node", log.Logs.ElementAt (0).Node);
            Assert.AreEqual (1, log.Logs.ElementAt (0).Priority);
            Assert.AreEqual ("Hello World", log.Logs.ElementAt (0).Message);
        }
        public void Flush_test()
        {
            var mt = new MobileParamTest();
            var headerMock = new Mock<IRequestRepository>();
            headerMock.Setup<NameValueCollection>(s => s.QueryString).Returns(mt.PrepareHeaderRepository());
            var sqlLoaderLogger = new Logger();

            var mobileParam = new MobileParam(headerMock.Object);
            var log = EntityMapping.Auto<MobileParam, CommunicationLog>(mobileParam);
            log.DomainNameId = 11;
            log.Url = "211.151.64.236/asdfsd/asd/f/sad/f/sd/f/sa/df/s/df?dfdsfsd=中文";
            log.RequestBody = "{\"pid\":100,\"version\":{\"reserved\":2,\"minor\":8,\"major\":1},\"imei\":\"356516040152451\",\"imsi\":\"460001511666063\"}";
            log.ActionId = 10012;
            log.ResultCode = 0;
            log.ProvinceId = 26;
            log.CityId = 10012;
            log.IPAddress = "101.222.33.258,25.36.556.89";

            sqlLoaderLogger.Write<CommunicationLog>(log);
            sqlLoaderLogger.FlushAll();
        }
Beispiel #5
0
        public static void InitialiseLoggers()
        {
            StatusLogger = new Logger("Status", Basic.ConsoleLocker, ConsoleColor.Green);
            {
                if (Config.GetConfig.GetBoolElement("Status_inConsole") == true)
                    StatusLogger.StartConsoleLogger();
                if (Config.GetConfig.GetBoolElement("Status_inFile") == true)
                    StatusLogger.StartFileLogger();
            }

            InfosLogger = new Logger("Infos", Basic.ConsoleLocker, ConsoleColor.Magenta);
            {
                if (Config.GetConfig.GetBoolElement("Infos_inFile") == true)
                    InfosLogger.StartFileLogger();

                if (Config.GetConfig.GetBoolElement("Infos_inConsole") == true)
                    InfosLogger.StartConsoleLogger();
            }

            ErrorsLogger = new Logger("Errors", Basic.ConsoleLocker, ConsoleColor.Yellow);
            {
                if (Config.GetConfig.GetBoolElement("Errors_inFile") == true)
                    ErrorsLogger.StartFileLogger();

                if (Config.GetConfig.GetBoolElement("Errors_inConsole") == true)
                    ErrorsLogger.StartConsoleLogger();
            }

            CommandsLogger = new Logger("Commands", Basic.ConsoleLocker, ConsoleColor.Cyan);
            {
                if (Config.GetConfig.GetBoolElement("Commands_inFile") == true)
                    CommandsLogger.StartFileLogger();

                if (Config.GetConfig.GetBoolElement("Commands_inConsole") == true)
                    CommandsLogger.StartConsoleLogger();
            }

            StatusLogger.Write("@Loggers@ loaded and started !");
        }
        // ---------------------------------------------------------------------
        #region TestSelf
        // ---------------------------------------------------------------------
        /// <summary>
        /// Simple self test.  See StreamTokenizerTestCase for full
        /// tests.
        /// </summary>
        /// <returns>bool - true for success, false for failure.</returns>
        public static bool TestSelf()
        {
            Logger log = new Logger("testSelf");
            log.Verbosity = VerbosityLevel.Debug;
            log.Info("Starting...");
            string testString;
            ArrayList tokens;

            // setup tokenizer
            StreamTokenizer tokenizer = new StreamTokenizer();
            tokenizer.Settings.SetupForCodeParse();
            tokenizer.Verbosity = VerbosityLevel.Debug;

            //
            // try string parse
            //
            log.Write("--------------------------------------------------------\n");
            log.Info("string parse:");
            log.Write("--------------------------------------------------------\n");
            tokens = new ArrayList();
            testString = "-1.2ej";
            tokenizer.Settings.DoUntermCheck = false;
            tokenizer.Settings.GrabWhitespace = false;

            if (!tokenizer.TokenizeString(testString, tokens))
            {
                log.Error("Unable to parse into token vector.");
                return (false);
            }

            foreach (Token t in tokens) log.Info("Token = '{0}'", t);
            tokens = new ArrayList();

            //
            // try NextToken style
            //
            //			log.Write("--------------------------------------------------------\n");
            //			log.Info("NextToken use");
            //			log.Write("--------------------------------------------------------\n");
            //string fileName = "st-testSelf.tmp";
            //testString = "this is a simple string";
            //tokenizer.TextReader = new StringReader(testString);
            //tokenizer.TextReader = File.OpenText(fileName);
            //Token token;
            //while (tokenizer.NextToken(out token)) log.Info("Token = '{0}'", token);

            //
            // try TokenizeFile
            //
            log.Write("--------------------------------------------------------\n");
            log.Info("Tokenize missing file");
            log.Write("--------------------------------------------------------\n");
            string nonExistentFileName = "ThisFile better not exist";
            bool caughtIt = false;
            try
            {
                tokenizer.TokenizeFile(nonExistentFileName);
            }
            catch (FileNotFoundException e)
            {
                log.Info("Correctly caught exception: {0}: {1}", e.GetType(), e.Message);
                caughtIt = true;
            }
            if (!caughtIt)
            {
                log.Error("Didn't get a file not found exception from TokenizeFile.");
                return (false);
            }

            //
            // test line numbers in tokens
            //

            // done
            log.Info("Done.");
            return (true);
        }
        public void realtime_log_model()
        {
            var sqlLoaderLogger = new Logger();

            var log = new ChannelInfo();

            log.Key = "中文";
            log.DisplayName = "460001511666063";

            DateTime start = DateTime.Now;
            for (int i = 0; i < 100; i++)
            {
                //Random r = new Random();
                sqlLoaderLogger.Write<ChannelInfo>(log);
                //Thread.Sleep( 2000);
            }
            DateTime end = DateTime.Now;

            Console.WriteLine((end - start).TotalMilliseconds);
        }
        //[Fact]
        public void pool_log_model()
        {
            var mt = new MobileParamTest();
            var headerMock = new Mock<IRequestRepository>();
            headerMock.Setup<NameValueCollection>(s => s.QueryString).Returns(mt.PrepareHeaderRepository());
            var sqlLoaderLogger = new Logger();

            var mobileParam = new MobileParam(headerMock.Object);
            var log = EntityMapping.Auto<MobileParam, CommunicationLog>(mobileParam);
            log.DomainNameId = 11;
            log.Url = "211.151.64.236/asdfsd/asd/f/sad/f/sd/f/sa/df/s/df?dfdsfsd=中文";
            log.RequestBody = "{\"pid\":100,\"version\":{\"reserved\":2,\"minor\":8,\"major\":1},\"imei\":\"356516040152451\",\"imsi\":\"460001511666063\"}";
            log.ActionId = 10012;
            log.ResultCode = 0;
            log.ProvinceId = 26;
            log.CityId = 10012;
            log.IPAddress = "101.222.33.258,25.36.556.89";

            DateTime start = DateTime.Now;
            for (int i = 0; i < 10000; i++)
            {
                //Random r = new Random();
                sqlLoaderLogger.Write<CommunicationLog>(log);
                //Thread.Sleep( 2000);
            }
            DateTime end = DateTime.Now;

            Console.WriteLine((end-start).TotalMilliseconds);
        }
Beispiel #9
0
		/// <summary>
		/// Simple test of some ParseUtil methods.
		/// </summary>
		/// <returns>bool - true for all passed, false otherwise</returns>
		public static bool TestSelf()
		{
			Logger log = new Logger("ParseUtil: TestSelf");
			log.Info("Starting...");

			StreamTokenizer tokenizer = new StreamTokenizer();
			tokenizer.Verbosity = VerbosityLevel.Warn;

			// FindMatch
			ArrayList alist = new ArrayList();
			tokenizer.TokenizeString("{ [ ] '}' }", alist);
			foreach(Token t in alist) log.Debug("Token = {0}", t);

			Token[] tarray = (Token[])alist.ToArray(typeof(Token));
			int i = 0;
			if (!FindMatch(tarray, ref i, '{'))
			{
				log.Error("FindMatch failed to match { char");
				return(false);
			}

			if (i != 4)
			{
				log.Error("FindMatch got the wrong answer {0}", i);
				return(false);
			}
			else log.Info("FindMatch worked.");

			//
			// try BuildArray
			//
			ArrayList tokens = new ArrayList();
			tokenizer.TokenizeString("1 2 3 4 5", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			Int16[] shorts = (short[])ParseUtil.BuildArray(tokens, ref i, typeof(Int16), null,
				-1, log);
		
			if (shorts == null) 
			{
				log.Error("Unable to BuildArray of shorts.");
				return(false);
			}

			log.Info("Parsed shorts:");
			foreach(Int16 s in shorts)
			{
				log.Write("{0}, ", s);
			}
			log.WriteLine("");

			//
			// try BuildArray of floats, char terminated
			//
			tokens.Clear();
			tokenizer.TokenizeString("1 2 ; 3 4", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			Single[] floats = (float[])ParseUtil.BuildArray(tokens, ref i, typeof(Single), 
				new CharToken(';'), -1, log);
		
			if (floats == null) 
			{
				log.Error("Unable to BuildArray of floats.");
				return(false);
			}

			log.Info("Parsed floats:");
			foreach(float f in floats)
			{
				log.Write("{0}, ", f);
			}
			log.WriteLine("");

			if (i != 2)
			{
				log.Error("BuildArray left i = {0} which is incorrect");
				return(false);
			}

			//
			// try BuildArray on high-precision floats
			//
			tokens.Clear();
			float f1 = 1.23456f;
			float f2 = 2.34567f;
			tokenizer.TokenizeString(String.Format("{0:f6} {1:f6}", f1,f2), tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			floats = (float[])ParseUtil.BuildArray(tokens, ref i, typeof(Single), 
				null, -1, log);
		
			if (floats == null) 
			{
				log.Error("Unable to BuildArray of floats.");
				return(false);
			}

			log.Info("Parsed floats:");
			foreach(float f in floats)
			{
				log.Write("{0}, ", f);
			}
			log.WriteLine("");

			if (floats[0] != f1)
			{
				log.Error("BuildArray produced float {0:f6} instead of {1:f6}",
					floats[0], f1);
				return(false);
			}

			//
			// try BuildArray of chars, maxLength terminated
			//
			log.Info("Chars, terminated by maxLength");
			tokens.Clear();
			tokenizer.TokenizeString("12 2 ; 3 4", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			char[] chars = (char[])ParseUtil.BuildArray(tokens, ref i, typeof(Char), 
				null, 3, log);
		
			if (chars == null) 
			{
				log.Error("Unable to BuildArray of chars.");
				return(false);
			}

			log.Info("Parsed chars:");
			foreach(char f in chars)
			{
				log.Write("{0}, ", f);
			}
			log.WriteLine("");

			if (i != 4)
			{
				log.Error("BuildArray left i = {0} which is incorrect", i);
				return(false);
			}

			//
			// try BuildArray of hex numbers
			//
			log.Info("Hex numbers");
			tokens.Clear();
			tokenizer.Settings.ParseHexNumbers = true;
			tokenizer.TokenizeString("0xfff, 0xffe", tokens);
			foreach(Token t in tokens) log.Debug("Token = {0}", t);

			i = 0;
			ushort[] ushorts = (ushort[])ParseUtil.BuildArray(tokens, ref i, typeof(ushort), 
				null, 3, log);
		
			if (ushorts == null) 
			{
				log.Error("Unable to BuildArray of ushorts.");
				return(false);
			}

			log.Info("Parsed ushorts:");
			foreach(ushort us in ushorts)
			{
				log.Write("{0}, ", us);
			}
			log.WriteLine("");

//			if (i != 4)
//			{
//				log.Error("BuildArray left i = {0} which is incorrect", i);
//				return(false);
//			}

			log.Info("All PASSED");
			return(true);
		}
        public void WriteWithSucceeds()
        {
            // Arrange
            var message = "{0}{1}";
            var arg0 = "42";
            var arg1 = "arbitrary-string";

            // Act
            var sut = new Logger();
            sut.Write(message, arg0, arg1);

            // Assert
            // N/A
        }
        public void WriteWithEmptyStringThrowsContractException()
        {
            // Arrange
            var message = string.Empty;
            var arg0 = default(object);
            var arg1 = default(object);

            // Act
            var sut = new Logger();
            sut.Write(message, arg0, arg1);

            // Assert
            // N/A
        }
Beispiel #12
0
 private void PrintVector(Logger.ILogger logger, double[] vector)
 {
     for (int i = 0; i < vector.Length; ++i)
     {
         logger.Write(vector[i].ToString() + "; ");
     }
     logger.WriteLn("");
 }
Beispiel #13
0
 private void PrintMatrix(Logger.ILogger logger, double[][] matrix)
 {
     for (int i = 0; i < matrix.Length; ++i)
     {
         for (int j = 0; j < matrix[i].Length; ++j)
         {
             logger.Write(matrix[i][j].ToString() + "; ");
         }
         logger.WriteLn("");
     }
 }