Пример #1
0
 private static void raiseTask(uint task_id)
 {
     try
     {
         var dbl = new SortedList <uint, CommDataBlock>();
         for (int i = 0; i < received_blocks.Count; i++)
         {
             var rdb = received_blocks[i];
             if (rdb.getTaskId() == task_id)
             {
                 var block_id = rdb.getBlockId();
                 //判断是否有重复的block_id, 有的话忽略, 重复的block有可能是在传输过程中ACK确认未收到导致多次发送
                 if (!dbl.ContainsKey(block_id))
                 {
                     dbl.Add(block_id, rdb);
                 }
                 received_blocks.RemoveAt(i);
                 i--;
             }
         }
         if (dbl.Count <= 0)
         {
             return;
         }
         //判断是否重复触发
         if (recent_raised_tasks.Contains(task_id))
         {
             return;
         }
         recent_raised_tasks.Add(task_id);
         if (recent_raised_tasks.Count > 100)
         {
             recent_raised_tasks.RemoveRange(0, recent_raised_tasks.Count - 100);
         }
         var content = new CommDataContent()
         {
             data_blocks = dbl
         };
         OnDataContentReceived?.Invoke("", content);
     }
     catch { }
 }
Пример #2
0
 public static void sendData(string data_content)
 {
     try
     {
         if (data_content.isNull())
         {
             return;
         }
         if (sending_data == null)
         {
             sending_data = new List <CommDataBlock>();
         }
         var dc = new CommDataContent(data_content);
         foreach (var db in dc.data_blocks)
         {
             sending_data.Add(db.Value);
         }
         sending_data.Add(CommDataBlock.createEndBlock(dc.task_id));
     }
     catch { }
 }