public void Print() { StringBuilder sb = new StringBuilder(); while (true) { sb.Clear(); string value = "NetBenchmark"; Console.CursorTop = 0; Console.CursorLeft = 0; sb.AppendLine("-".PadRight(WIDTH, '-')); int span = WIDTH / 2 - value.Length / 2; sb.AppendLine("".PadLeft(span) + value); value = "Copyright © beetlex.io 2019-2020 email:[email protected]"; span = WIDTH / 2 - value.Length / 2; sb.AppendLine("".PadLeft(span) + value); value = Name; span = 70 / 2 - value.Length / 2; sb.AppendLine("".PadLeft(span) + value); value = $"{Stopwatch.Elapsed}"; span = WIDTH / 2 - value.Length / 2; sb.AppendLine("".PadLeft(span) + value); sb.AppendLine("-".PadRight(WIDTH, '-')); sb.Append("|"); value = $"Name|".PadLeft(18); sb.Append(value); value = $"Max|".PadLeft(10); sb.Append(value); value = $"Avg|".PadLeft(10); sb.Append(value); value = $"Min|".PadLeft(10); sb.Append(value); value = $"RPS/Total|".PadLeft(26); sb.Append(value); sb.AppendLine(""); sb.AppendLine("-".PadRight(WIDTH, '-')); Success.Print(sb); Error.Print(sb); ReceiveBytes.Print(sb, 1024, "(KB)"); SendBytes.Print(sb, 1024, "(KB)"); sb.AppendLine("-".PadRight(WIDTH, '-')); mTimesStatistics.Print(sb); sb.AppendLine("-".PadRight(WIDTH, '-')); Console.WriteLine(sb); System.Threading.Thread.Sleep(1000); } }
private void OnStatistics(object state) { if (Status) { Success.Calculate(); Error.Calculate(); ReceiveBytes.Calculate(); SendBytes.Calculate(); } }
public bool Lunch() { try { if (!EquipmentBus.ControllerRegister.CheckRely(RelyEquipment)) { throw new Exception($"依赖设备尚未启动{string.Join("、", RelyEquipment)}"); } UART = DriversFactory.GetUARTDriver(ComName); UART.RecEvent += ReceivedEvent; EquipmentData.IsEnable = true; EquipmentBus.ControllerRegister.Register(Enum.RegisterType.E34_2G4D20D, true); Task.Run(() => { while (true) { Thread.Sleep(1); try { lock (SendBytes) { if (SendBytes.Count != 0) { if (SendBytes[0] != null) { UART.WriteBytes(SendBytes[0]); } SendBytes.RemoveAt(0); } } } catch { } } }); } catch (Exception ex) { EquipmentData.AddError(Enum.LogType.Error, "启动E34_2G4D20D失败!", ex); Logger.Add(Enum.LogType.Error, "启动E34_2G4D20D失败!", ex); EquipmentData.IsEnable = false; return(false); } return(true); }
public async void Run() { Status = true; foreach (var item in Testers) { await OnPreheating(item); } Stopwatch.Restart(); Success.Reset(); Error.Reset(); ReceiveBytes.Reset(); SendBytes.Reset(); foreach (var item in Testers) { Task.Run(() => OnRunItem(item)); } mStatisticsTimer = new System.Threading.Timer(OnStatistics, null, 1000, 1000); }
private async Task RunSafeDaemon(Func <Task> toRun) { try { while (!disposed) { await toRun(); } } catch (Exception e) { if (!disposed && Socket.State == WebSocketState.Open) { SendBytes sb = new SendBytes(() => Task.FromResult(Socket)); sb.Exception = e; await sb.AwaitFlowControl(); } } finally { Socket.Abort(); Dispose(); } }
public async Task ExecuteOnServer() { SelectionResult selection = await FileSystem.SelectAsync(EntryFullPath, CancellationToken.None); SendBytes sb = new SendBytes(Transport); if (selection.ResultType == SelectionResultType.FoundDocument) { IDocument doc = selection.Document; using (Result = await doc.OpenReadAsync(CancellationToken.None)) { Result.Position = RestartPointer; sb.Stream = Result; await sb.AwaitFlowControl(); } } else { throw new InvalidOperationException("Requested Document is not a Document!"); } }
public void SendCompleted(IClient client, SocketAsyncEventArgs e, bool end) { SendBytes.Add(e.BytesTransferred); }