示例#1
0
        static void Main(string[] args)
        {
            DateTime start, end;
            var      rnd = new Random();

            try
            {
                RedisConnector connector = new RedisConnector(ConfigurationManager.AppSettings["redisserver"]);

                #region delete
                Console.WriteLine("DELETE all \"Product*\"-pattern keys in Redis...");
                start = DateTime.Now;
                int countDeleted = connector.KeyDelete("Product*");
                end = DateTime.Now;
                Console.WriteLine($"There are {countDeleted} \"Product*\"-pattern keys. Deleted them in {(end - start).TotalMilliseconds} millisecs");
                #endregion

                #region add
                Console.Write("How many Products do you want to prepare in Redis? ");
                int NumberOfProducts = int.Parse(Console.ReadLine());
                Console.WriteLine($"Preparing {NumberOfProducts} products...");
                start = DateTime.Now;
                for (int i = 1; i <= NumberOfProducts; i++)
                {
                    connector.StringSet($"Product{i}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                }
                end = DateTime.Now;
                Console.WriteLine($"Prepared {NumberOfProducts} products in {(end - start).TotalMilliseconds} millisecs");
                #endregion

                Console.Write($"How many heartbeats do you want to play on {NumberOfProducts} products? ");
                int NumberOfHeartbeats = int.Parse(Console.ReadLine());
                Console.WriteLine($"Preparing to spam {NumberOfHeartbeats} heatbeats on {NumberOfProducts} products...");
                start = DateTime.Now;
                for (int i = 0; i < NumberOfHeartbeats; i++)
                {
                    string key   = $"Product{rnd.Next(1, NumberOfProducts + 1)}";
                    string value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    connector.StringSet(key, value);
                }
                end = DateTime.Now;
                Console.WriteLine($"Updating {NumberOfHeartbeats} heatbeats in {(end - start).TotalMilliseconds} millisecs");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            Console.Write("Press Enter to exit.");
            Console.ReadLine();
        }
示例#2
0
        public void DataReceived(object sender, PacketDataReceivedEventArgs e)
        {
            Log4netLogger.Info(MethodBase.GetCurrentMethod().DeclaringType, $"Get {e.TotalBytesRead} byte(s): 0x{e.DataRead} from {e.DestinationTuple.RemoteEndPoint}");
            if (e.TotalBytesRead == 8 && e.DataRead.Substring(0, 6) == "AB0106" && e.DataRead.Substring(14, 2) == "00")
            {
                try
                {
                    byte[] ImeiStream = e.BytesRead.Skip(3).Take(4).ToArray();
                    int    ImeiInt    = BitConverter.ToInt32(ImeiStream.Reverse().ToArray(), 0);
                    string ImeiWithLeadingZerosLength20 = ImeiInt.ToString("00000000000000000000");
                    Log4netLogger.Info(MethodBase.GetCurrentMethod().DeclaringType, $"Imei: {ImeiInt}. With leading zeros: {ImeiWithLeadingZerosLength20}");
                    string key   = $"Product_{ImeiWithLeadingZerosLength20}_Heartbeat";
                    string value = _connector.StringGet(key);

                    //if found the key (value == null)
                    if (value != null)
                    {
                        _connector.StringSet(key, DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                        PacketConnection.Send(new byte[] { 0xAB, 0xFF, 0x06, e.BytesRead[3], e.BytesRead[4], e.BytesRead[5], e.BytesRead[6], 0x01, 0x01 }, e.DestinationTuple);
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.Log4netLogger.Error(MethodBase.GetCurrentMethod().DeclaringType, $"Error during DataReceived (UDP)", ex);
                }
            }
        }
示例#3
0
 private void btnInsert_Click(object sender, EventArgs e)
 {
     try
     {
         var start = DateTime.Now;
         NumberOfProducts = int.Parse(txtNumberOfProducts.Text);
         for (int i = 1; i <= NumberOfProducts.Value; i++)
         {
             connector.StringSet($"Product{i}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
         }
         var end = DateTime.Now;
         MessageBox.Show($"Prepared {NumberOfProducts.Value} products in {(end - start).TotalMilliseconds} millisecs");
     }
     catch (Exception ex)
     {
         NumberOfProducts = null;
         MessageBox.Show(ex.ToString());
     }
 }