| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 | 
							- using Newtonsoft.Json;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.ComponentModel;
 
- using System.Data;
 
- using System.Drawing;
 
- using System.IO;
 
- using System.Linq;
 
- using System.Net;
 
- using System.Net.Http;
 
- using System.Net.Sockets;
 
- using System.Text;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- using System.Windows.Forms;
 
- using XdCxRhDW.Dto;
 
- using XdCxRhDW.Sender.Properties;
 
- namespace XdCxRhDW.Sender
 
- {
 
-     public partial class Form1 : DevExpress.XtraEditors.XtraForm
 
-     {
 
-         public Form1()
 
-         {
 
-             InitializeComponent();
 
-         }
 
-         CancellationTokenSource cts1;
 
-         private async void btn1_Click(object sender, EventArgs e)
 
-         {
 
-             layoutControlItem1.Enabled = false;
 
-             layoutControlItem7.Enabled = false;
 
-             if (btn1.Text == "推送")
 
-             {
 
-                 try
 
-                 {
 
-                     cts1 = new CancellationTokenSource();
 
-                     btn1.Text = "停止";
 
-                     var addrArr = txtAddr1.Text.Trim().Replace(":", ":").Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 
-                     string ip = addrArr[0];
 
-                     int port = Convert.ToInt32(addrArr[1]);
 
-                     if (txtTskType.EditValue == null)
 
-                     {
 
-                         Log($"请选择定位类型");
 
-                         return;
 
-                     }
 
-                     string tskType = txtTskType.EditValue.ToString();
 
-                     //S:
 
-                     using (var client = new HttpClient())
 
-                     {
 
-                         try
 
-                         {
 
-                             var lines = File.ReadAllLines("Simulation_Data2023.dat");
 
-                              int idx = 1;
 
-                             string url = string.Format("http://{0}:{1}/Api/Pos/", ip, port);
 
-                             if (tskType== "X1D1CX")//一星一地测向定位
 
-                             {
 
-                                 url += "PosX1D1Async";
 
-                             }
 
-                             if (tskType == "X2D1")//两星一地定位
 
-                             {
 
-                                 url += "PosX2D1Async";
 
-                             }
 
-                             if (tskType == "RH")//融合定位
 
-                             {
 
-                                 url += "PosRHAsync";
 
-                             }
 
-                             foreach (var line in lines)
 
-                             {
 
-                                 if (string.IsNullOrWhiteSpace(line)) continue;
 
-                                 var items = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 
-                                 SendDto dto = new SendDto()
 
-                                 {
 
-                                     SxDto = Convert.ToDouble(items[0]),
 
-                                     XdDto = Convert.ToDouble(items[1]),
 
-                                     MainYbDto = Convert.ToDouble(items[2]),
 
-                                     AdjaYbDto = Convert.ToDouble(items[3]),
 
-                                     CxRes = Convert.ToDouble(items[4]),
 
-                                     MainX = Convert.ToDouble(items[7]),
 
-                                     MainY = Convert.ToDouble(items[8]),
 
-                                     MainZ = Convert.ToDouble(items[9]),
 
-                                     AdjaX = Convert.ToDouble(items[10]),
 
-                                     AdjaY = Convert.ToDouble(items[11]),
 
-                                     AdjaZ = Convert.ToDouble(items[12]),
 
-                                 };
 
-                                 var content = new StringContent(JsonConvert.SerializeObject(dto), System.Text.Encoding.UTF8, "application/json");
 
-                                 var response = await client.PostAsync(url, content);
 
-                                 Log($"已向[{txtAddr1.Text}]发送第{idx++}条仿真结果");
 
-                             }
 
-                         }
 
-                         catch (Exception ex)
 
-                         {
 
-                             Log($"向[{txtAddr1.Text}]发送结果失败.{ex.Message}");
 
-                         }
 
-                     }
 
-                     //if (string.IsNullOrWhiteSpace(localPort1.Text))
 
-                     //    client1 = new TcpClient();
 
-                     //else
 
-                     //    client1 = new TcpClient(new IPEndPoint(IPAddress.Any, Convert.ToInt32(localPort1.Text)));
 
-                     //client1.NoDelay = true;
 
-                     //client1.SendTimeout = 5000;
 
-                     //client1.ReceiveTimeout = 5000;
 
-                     //while (!cts1.IsCancellationRequested)
 
-                     //{
 
-                     //    try
 
-                     //    {
 
-                     //        await client1.ConnectAsync(IPAddress.Parse(ip), port);
 
-                     //        break;
 
-                     //    }
 
-                     //    catch (Exception ex)
 
-                     //    {
 
-                     //        Log(ex);
 
-                     //        await Task.Delay(5000, cts1.Token);
 
-                     //    }
 
-                     //}
 
-                     //Log($"已成功连接到[{txtAddr1.Text}]");
 
-                     //var lines = File.ReadAllLines("Simulation_Data2023.dat");
 
-                     //while (!cts1.IsCancellationRequested)
 
-                     //{
 
-                     //    try
 
-                     //    {
 
-                     //        int idx = 1;
 
-                     //        foreach (var line in lines)
 
-                     //        {
 
-                     //            if (cts1.IsCancellationRequested) break;
 
-                     //            if (string.IsNullOrWhiteSpace(line)) continue;
 
-                     //            var items = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 
-                     //            //SendDto dto = new SendDto()
 
-                     //            //{
 
-                     //            //    SxDto = Convert.ToDouble(items[0]),
 
-                     //            //    XdDto = Convert.ToDouble(items[1]),
 
-                     //            //    MainYbDto = Convert.ToDouble(items[2]),
 
-                     //            //    AdjaYbDto = Convert.ToDouble(items[3]),
 
-                     //            //    CxRes = Convert.ToDouble(items[4]),
 
-                     //            //    MainX = Convert.ToDouble(items[7]),
 
-                     //            //    MainY = Convert.ToDouble(items[8]),
 
-                     //            //    MainZ = Convert.ToDouble(items[9]),
 
-                     //            //    AdjaX = Convert.ToDouble(items[10]),
 
-                     //            //    AdjaY = Convert.ToDouble(items[11]),
 
-                     //            //    AdjaZ = Convert.ToDouble(items[12]),
 
-                     //            //};
 
-                     //            SendDto dto = new SendDto()
 
-                     //            {
 
-                     //                SxDto = Convert.ToDouble(items[0]),
 
-                     //                XdDto = Convert.ToDouble(items[1]),
 
-                     //                MainYbDto = Convert.ToDouble(items[2]),
 
-                     //                AdjaYbDto = Convert.ToDouble(items[3]),
 
-                     //                CxRes = Convert.ToDouble(items[4]),
 
-                     //                MainX = null,
 
-                     //                MainY = null,
 
-                     //                MainZ = null,
 
-                     //                AdjaX = null,
 
-                     //                AdjaY = null,
 
-                     //                AdjaZ = null,
 
-                     //            };
 
-                     //            var msg = Newtonsoft.Json.JsonConvert.SerializeObject(dto);
 
-                     //            var data = Encoding.UTF8.GetBytes(msg);
 
-                     //            var dataWithHeader = BitConverter.GetBytes(data.Length).Concat(data).ToArray();
 
-                     //            await client1.GetStream().WriteAsync(dataWithHeader, 0, dataWithHeader.Length);
 
-                     //            Log($"已向[{txtAddr1.Text}]发送第{idx++}条仿真结果");
 
-                     //            await Task.Delay(3000, cts1.Token);
 
-                     //        }
 
-                     //    }
 
-                     //    catch (InvalidOperationException)
 
-                     //    {
 
-                     //        goto S;
 
-                     //    }
 
-                     //    catch (Exception ex)
 
-                     //    {
 
-                     //        Log($"向[{txtAddr1.Text}]发送结果失败.{ex.Message}");
 
-                     //        await Task.Delay(5000, cts1.Token);
 
-                     //    }
 
-                     //}
 
-                 }
 
-                 catch (Exception ex)
 
-                 {
 
-                     Log(ex);
 
-                 }
 
-                 finally
 
-                 {
 
-                     btn1.Text = "推送";
 
-                     layoutControlItem1.Enabled = true;
 
-                     layoutControlItem7.Enabled = true;
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 cts1?.Cancel();
 
-                // client1?.Dispose();
 
-             }
 
-         }
 
-         private void Log(string msg)
 
-         {
 
-             try
 
-             {
 
-                 if (this.InvokeRequired)
 
-                 {
 
-                     this.Invoke(new Action(() =>
 
-                     {
 
-                         if (listBoxControl1.ItemCount > 5000)
 
-                             listBoxControl1.Items.Clear();
 
-                         listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{msg}");
 
-                         listBoxControl1.SelectedIndex = 0;
 
-                     }));
 
-                 }
 
-                 else
 
-                 {
 
-                     if (listBoxControl1.ItemCount > 5000)
 
-                         listBoxControl1.Items.Clear();
 
-                     listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{msg}");
 
-                     listBoxControl1.SelectedIndex = 0;
 
-                 }
 
-             }
 
-             catch
 
-             { }
 
-         }
 
-         private void Log(Exception ex)
 
-         {
 
-             try
 
-             {
 
-                 if (this.InvokeRequired)
 
-                 {
 
-                     this.Invoke(new Action(() =>
 
-                     {
 
-                         if (listBoxControl1.ItemCount > 5000)
 
-                             listBoxControl1.Items.Clear();
 
-                         listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{ex.Message}");
 
-                         listBoxControl1.SelectedIndex = 0;
 
-                     }));
 
-                 }
 
-                 else
 
-                 {
 
-                     if (listBoxControl1.ItemCount > 5000)
 
-                         listBoxControl1.Items.Clear();
 
-                     listBoxControl1.Items.Insert(0, $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}--{ex.Message}");
 
-                     listBoxControl1.SelectedIndex = 0;
 
-                 }
 
-             }
 
-             catch
 
-             { }
 
-         }
 
-         private void listBoxControl1_MouseClick(object sender, MouseEventArgs e)
 
-         {
 
-             if (e.Button == MouseButtons.Right)
 
-             {
 
-                 popupMenu1.ShowPopup(MousePosition);
 
-             }
 
-         }
 
-         private void btnClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 
-         {
 
-             listBoxControl1.Items.Clear();
 
-         }
 
-         private void btnCopyAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 
-         {
 
-             StringBuilder sb = new StringBuilder();
 
-             foreach (var item in listBoxControl1.Items)
 
-             {
 
-                 sb.AppendLine(item.ToString());
 
-             }
 
-             var data = sb.ToString();
 
-             if (string.IsNullOrWhiteSpace(data)) return;
 
-             Clipboard.SetText(sb.ToString());
 
-         }
 
-     }
 
- }
 
 
  |