Inheritance: IPerformanceTest
Beispiel #1
0
        public void RemoveElement(T elem)
        {
            System.Diagnostics.Debug.WriteLine("remove elem:" + elem);
            int idx = this.IndexOf(elem);

            this.RemoveAt(idx);
            ListRemove.Raise(this, new ListChangedEventArg(idx, elem));
        }
Beispiel #2
0
 private void ReceiveMsg()
 {
     while (receiveFlag)
     {
         try
         {
             IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
             Byte[]     receiveBytes     = udpClient.Receive(ref RemoteIpEndPoint);
             //ReceiveData:0000;
             if (receiveFlag)
             {
                 if (receiveBytes.Length > 4)
                 {
                     if (RemoteIpEndPoint.Address.ToString() != IPAddress.Any.ToString())
                     {
                         using MemoryStream memoryStream = new MemoryStream(receiveBytes);
                         using BinaryReader binaryReader = new BinaryReader(memoryStream);
                         string IPAddr = RemoteIpEndPoint.Address.ToString();
                         MKInfo mkInfo = new MKInfo()
                         {
                             IPAddr = IPAddr
                         };
                         //TLV格式的数据指针偏移4
                         binaryReader.BaseStream.Position = 4;
                         //开始读取TLV格式的数据
                         //递归方法读取二进制流的数据。
                         ReadBytes(binaryReader, ref mkInfo);
                         foreach (MKInfo t in mkInfos)
                         {
                             if (t.IPAddr == mkInfo.IPAddr && t.MacAddr == mkInfo.MacAddr)
                             {
                                 int        i  = mkInfos.IndexOf(t);
                                 ListRemove lr = new ListRemove(MKInfoRemove);
                                 lr(i);
                                 break;
                             }
                         }
                         ListAdd la = new ListAdd(MKInfoAdd);
                         la(mkInfo);
                     }
                 }
             }
         }
         catch (ObjectDisposedException) { }
         catch (SocketException) { }
     }
     udpClient.Dispose();
 }
Beispiel #3
0
        public IActionResult DeleteFromCart(int id)
        {
            List <Product> listProducts = new List <Product>();
            Product        product      = _db.Products.FirstOrDefault(i => i.Id == id);

            if (string.IsNullOrEmpty(HttpContext.Session.GetString("cart")))
            {
                HttpContext.Session.SetString("cart", JsonSerializer.Serialize(listProducts));
            }
            var fromSession = HttpContext.Session.GetString("cart");

            listProducts = JsonSerializer.Deserialize <List <Product> >(fromSession);
            ListRemove.Remove(ref listProducts, id);
            HttpContext.Session.SetString("cart", JsonSerializer.Serialize(listProducts));
            return(RedirectToAction("Basket"));
        }
Beispiel #4
0
 private void OnListRemove(EventArgs e)
 {
     ListRemove?.Invoke(this, e);
 }
Beispiel #5
0
 private void ReceiveMsg()
 {
     while (receiveFlag)
     {
         try
         {
             IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
             Byte[]     receiveBytes     = udpClient.Receive(ref RemoteIpEndPoint);
             //ReceiveData:0000;
             if (receiveFlag)
             {
                 if (receiveBytes.Length > 4)
                 {
                     //可能返回0.0.0.0未配置的设备。过滤掉。
                     if (IPAddress.Any.ToString() != RemoteIpEndPoint.Address.ToString())
                     {
                         using MemoryStream memoryStream = new MemoryStream(receiveBytes);
                         using BinaryReader binaryReader = new BinaryReader(memoryStream);
                         string IPAddr       = RemoteIpEndPoint.Address.ToString();
                         MKInfo mikroTikInfo = new MKInfo()
                         {
                             IPAddr = IPAddr
                         };
                         //TLV格式的数据指针偏移4
                         binaryReader.BaseStream.Position = 4;
                         //开始读取TLV格式的数据
                         //递归方法读取二进制流的数据。
                         ReadBytes(binaryReader, ref mikroTikInfo);
                         //注释掉
                         //逐一读取二进制流的数据
                         //ReadBytes_v2(binaryReader,ref mikroTikInfo);
                         //更新List集合里面的数据
                         //主要更新Uptime的数据
                         int i = int.MinValue;
                         foreach (MKInfo t in mikroTikInfos)
                         {
                             if (t.MacAddr == mikroTikInfo.MacAddr)
                             {
                                 //删除集合List的数据。
                                 i = mikroTikInfos.IndexOf(t);
                                 break;
                             }
                         }
                         if (i >= 0)
                         {
                             //删除集合中存在元素
                             ListRemove lr = new ListRemove(MikroTikInfoRemove);
                             lr(i);
                             //插入到删除元素得位置
                             ListInsert li = new ListInsert(MikroTikInfoInsert);
                             li(i, mikroTikInfo);
                         }
                         else
                         {
                             //追加集合List的数据
                             ListAdd la = new ListAdd(MikroTikInfoAdd);
                             la(mikroTikInfo);
                         }
                     }
                 }
             }
         }
         catch (ObjectDisposedException) { }
         catch (SocketException) { }
         catch (Exception) { }
     }
     udpClient.Dispose();
 }