public void RefreshLog() { if (ServerSpeedLogList == null) { return; } Configuration config = controller.GetCurrentConfiguration(); if (listOrder.Count > config.configs.Count) { listOrder.RemoveRange(config.configs.Count, listOrder.Count - config.configs.Count); } while (listOrder.Count < config.configs.Count) { listOrder.Add(0); } while (ServerDataGrid.Rows.Count < config.configs.Count) { ServerDataGrid.Rows.Add(); int id = ServerDataGrid.Rows.Count - 1; ServerDataGrid[0, id].Value = id; } if (ServerDataGrid.Rows.Count > config.configs.Count) { for (int list_index = 0; list_index < ServerDataGrid.Rows.Count; ++list_index) { DataGridViewCell id_cell = ServerDataGrid[0, list_index]; int id = (int)id_cell.Value; if (id >= config.configs.Count) { ServerDataGrid.Rows.RemoveAt(list_index); --list_index; } } } //int index = 0; //foreach (Server server in config.configs) //for ( int id = 0; id < config.configs.Count; ++id) try { for (int list_index = (lastRefreshIndex >= ServerDataGrid.Rows.Count) ? 0 : lastRefreshIndex, rowChangeCnt = 0; list_index < ServerDataGrid.Rows.Count && rowChangeCnt <= 200; ++list_index, ++rowChangeCnt) { lastRefreshIndex = list_index + 1; DataGridViewCell id_cell = ServerDataGrid[0, list_index]; int id = (int)id_cell.Value; Server server = config.configs[id]; ServerSpeedLogShow serverSpeedLog = ServerSpeedLogList[id]; listOrder[id] = list_index; rowChange = false; for (int curcol = 0; curcol < ServerDataGrid.Columns.Count; ++curcol) { DataGridViewCell cell = ServerDataGrid[curcol, list_index]; string columnName = ServerDataGrid.Columns[curcol].Name; // Server if (columnName == "Server") { if (config.index == id) { SetBackColor(cell, Color.Cyan); } else { SetBackColor(cell, Color.White); } SetCellText(cell, server.FriendlyName()); } // Enable if (columnName == "Enable") { if (server.isEnable()) { SetBackColor(cell, Color.White); } else { SetBackColor(cell, Color.Red); } } // TotalConnectTimes else if (columnName == "TotalConnect") { SetCellText(cell, serverSpeedLog.totalConnectTimes); } // TotalConnecting else if (columnName == "Connecting") { SetCellText(cell, server.GetConnections().Count); //SetCellText(cell, serverSpeedLog.totalConnectTimes - serverSpeedLog.totalDisconnectTimes); } // AvgConnectTime else if (columnName == "AvgLatency") { if (serverSpeedLog.avgConnectTime >= 0) { SetCellText(cell, serverSpeedLog.avgConnectTime); } else { SetCellText(cell, "-"); } } // AvgSpeed else if (columnName == "AvgSpeed") { long avgBytes = serverSpeedLog.avgDownloadBytes; string valStr = FormatBytes(avgBytes); Color[] colList = new Color[6] { Color.White, Color.LightGreen, Color.Yellow, Color.Pink, Color.Red, Color.Red }; long[] bytesList = new long[6] { 0, 1024 * 64, 1024 * 512, 1024 * 1024 * 4, 1024 * 1024 * 16, 1024 * 1024 * 1024 }; for (int i = 1; i < colList.Length; ++i) { if (avgBytes < bytesList[i]) { SetBackColor(cell, ColorMix(colList[i - 1], colList[i], (double)(avgBytes - bytesList[i - 1]) / (bytesList[i] - bytesList[i - 1]) ) ); break; } } SetCellText(cell, valStr); } // MaxSpeed else if (columnName == "MaxSpeed") { long maxBytes = serverSpeedLog.maxDownloadBytes; string valStr = FormatBytes(maxBytes); Color[] colList = new Color[6] { Color.White, Color.LightGreen, Color.Yellow, Color.Pink, Color.Red, Color.Red }; long[] bytesList = new long[6] { 0, 1024 * 64, 1024 * 512, 1024 * 1024 * 4, 1024 * 1024 * 16, 1024 * 1024 * 1024 }; for (int i = 1; i < colList.Length; ++i) { if (maxBytes < bytesList[i]) { SetBackColor(cell, ColorMix(colList[i - 1], colList[i], (double)(maxBytes - bytesList[i - 1]) / (bytesList[i] - bytesList[i - 1]) ) ); break; } } SetCellText(cell, valStr); } // TotalUploadBytes else if (columnName == "Upload") { string valStr = FormatBytes(serverSpeedLog.totalUploadBytes); string fullVal = serverSpeedLog.totalUploadBytes.ToString(); if (cell.ToolTipText != fullVal) { if (fullVal == "0") { SetBackColor(cell, Color.White); } else { SetBackColor(cell, Color.LightGreen); cell.Tag = 8; } } else if (cell.Tag != null) { cell.Tag = (int)cell.Tag - 1; if ((int)cell.Tag == 0) { SetBackColor(cell, Color.White); } //Color col = cell.Style.BackColor; //SetBackColor(cell, Color.FromArgb(Math.Min(255, col.R + colAdd), Math.Min(255, col.G + colAdd), Math.Min(255, col.B + colAdd))); } SetCellToolTipText(cell, fullVal); SetCellText(cell, valStr); } // TotalDownloadBytes else if (columnName == "Download") { string valStr = FormatBytes(serverSpeedLog.totalDownloadBytes); string fullVal = serverSpeedLog.totalDownloadBytes.ToString(); if (cell.ToolTipText != fullVal) { if (fullVal == "0") { SetBackColor(cell, Color.White); } else { SetBackColor(cell, Color.LightGreen); cell.Tag = 8; } } else if (cell.Tag != null) { cell.Tag = (int)cell.Tag - 1; if ((int)cell.Tag == 0) { SetBackColor(cell, Color.White); } //Color col = cell.Style.BackColor; //SetBackColor(cell, Color.FromArgb(Math.Min(255, col.R + colAdd), Math.Min(255, col.G + colAdd), Math.Min(255, col.B + colAdd))); } SetCellToolTipText(cell, fullVal); SetCellText(cell, valStr); } // ErrorConnectTimes else if (columnName == "ConnectError") { SetCellText(cell, serverSpeedLog.errorConnectTimes); } // ErrorTimeoutTimes else if (columnName == "ConnectTimeout") { SetCellText(cell, serverSpeedLog.errorTimeoutTimes); } // ErrorContinurousTimes else if (columnName == "Continuous") { long val = serverSpeedLog.errorContinurousTimes; Color col = Color.FromArgb(255, (byte)Math.Max(0, 255 - val * 8), (byte)Math.Max(0, 255 - val * 8)); SetBackColor(cell, col); SetCellText(cell, val); } // ErrorPersent else if (columnName == "ErrorPercent") { if (serverSpeedLog.totalConnectTimes > 0) { double percent = (serverSpeedLog.errorConnectTimes + serverSpeedLog.errorTimeoutTimes) * 100.00 / serverSpeedLog.totalConnectTimes; SetBackColor(cell, Color.FromArgb(255, (byte)(255 - percent * 2), (byte)(255 - percent * 2))); if (percent < 1e-4) { SetCellText(cell, percent.ToString("F0") + "%"); } else { SetCellText(cell, percent.ToString("F2") + "%"); } } else { SetBackColor(cell, Color.White); SetCellText(cell, "-"); } } if (columnName == "Server") { if (cell.Style.Alignment != DataGridViewContentAlignment.MiddleLeft) { cell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft; } } else { if (cell.Style.Alignment != DataGridViewContentAlignment.MiddleRight) { cell.Style.Alignment = DataGridViewContentAlignment.MiddleRight; } } } if (rowChange) { rowChangeCnt++; } } } catch { } if (ServerDataGrid.SortedColumn != null) { ServerDataGrid.Sort(ServerDataGrid.SortedColumn, (ListSortDirection)((int)ServerDataGrid.SortOrder - 1)); } }
public void RefreshLog() { if (ServerSpeedLogList == null) { return; } int last_rowcount = ServerDataGrid.RowCount; Configuration config = _controller.GetCurrentConfiguration(); if (listOrder.Count > config.configs.Count) { listOrder.RemoveRange(config.configs.Count, listOrder.Count - config.configs.Count); } while (listOrder.Count < config.configs.Count) { listOrder.Add(0); } while (ServerDataGrid.RowCount < config.configs.Count && ServerDataGrid.RowCount < ServerSpeedLogList.Length) { ServerDataGrid.Rows.Add(); int id = ServerDataGrid.RowCount - 1; ServerDataGrid[0, id].Value = id; } if (ServerDataGrid.RowCount > config.configs.Count) { for (int list_index = 0; list_index < ServerDataGrid.RowCount; ++list_index) { DataGridViewCell id_cell = ServerDataGrid[0, list_index]; int id = (int)id_cell.Value; if (id >= config.configs.Count) { ServerDataGrid.Rows.RemoveAt(list_index); --list_index; } } } int displayBeginIndex = ServerDataGrid.FirstDisplayedScrollingRowIndex; int displayEndIndex = displayBeginIndex + ServerDataGrid.DisplayedRowCount(true); try { for (int list_index = (lastRefreshIndex >= ServerDataGrid.RowCount) ? 0 : lastRefreshIndex, rowChangeCnt = 0; list_index < ServerDataGrid.RowCount && rowChangeCnt <= 100; ++list_index) { lastRefreshIndex = list_index + 1; DataGridViewCell id_cell = ServerDataGrid[0, list_index]; int id = (int)id_cell.Value; Server server = config.configs[id]; ServerSpeedLogShow serverSpeedLog = ServerSpeedLogList[id]; listOrder[id] = list_index; rowChange = false; for (int curcol = 0; curcol < ServerDataGrid.Columns.Count; ++curcol) { if (!firstDispley && (ServerDataGrid.SortedColumn == null || ServerDataGrid.SortedColumn.Index != curcol) && (list_index < displayBeginIndex || list_index >= displayEndIndex)) { continue; } DataGridViewCell cell = ServerDataGrid[curcol, list_index]; string columnName = ServerDataGrid.Columns[curcol].Name; // Server if (columnName == "Server") { if (config.index == id) { SetBackColor(cell, Color.Cyan); } else { SetBackColor(cell, Color.White); } SetCellText(cell, server.FriendlyName()); } if (columnName == "Group") { SetCellText(cell, server.group); } // TotalConnectTimes else if (columnName == "TotalConnect") { SetCellText(cell, serverSpeedLog.totalConnectTimes); } // TotalConnecting else if (columnName == "Connecting") { long connections = serverSpeedLog.totalConnectTimes - serverSpeedLog.totalDisconnectTimes; Color[] colList = new Color[5] { Color.White, Color.LightGreen, Color.Yellow, Color.Red, Color.Red }; long[] bytesList = new long[5] { 0, 16, 32, 64, 65536 }; for (int i = 1; i < colList.Length; ++i) { if (connections < bytesList[i]) { SetBackColor(cell, ColorMix(colList[i - 1], colList[i], (double)(connections - bytesList[i - 1]) / (bytesList[i] - bytesList[i - 1]))); break; } } SetCellText(cell, serverSpeedLog.totalConnectTimes - serverSpeedLog.totalDisconnectTimes); } // AvgConnectTime else if (columnName == "AvgLatency") { if (serverSpeedLog.avgConnectTime >= 0) { SetCellText(cell, serverSpeedLog.avgConnectTime / 1000); } else { SetCellText(cell, "-"); } } // AvgDownSpeed else if (columnName == "AvgDownSpeed") { long avgBytes = serverSpeedLog.avgDownloadBytes; string valStr = FormatBytes(avgBytes); Color[] colList = new Color[6] { Color.White, Color.LightGreen, Color.Yellow, Color.Pink, Color.Red, Color.Red }; long[] bytesList = new long[6] { 0, 1024 * 64, 1024 * 512, 1024 * 1024 * 4, 1024 * 1024 * 16, 1024L * 1024 * 1024 * 1024 }; for (int i = 1; i < colList.Length; ++i) { if (avgBytes < bytesList[i]) { SetBackColor(cell, ColorMix(colList[i - 1], colList[i], (double)(avgBytes - bytesList[i - 1]) / (bytesList[i] - bytesList[i - 1]))); break; } } SetCellText(cell, valStr); } // MaxDownSpeed else if (columnName == "MaxDownSpeed") { long maxBytes = serverSpeedLog.maxDownloadBytes; string valStr = FormatBytes(maxBytes); Color[] colList = new Color[6] { Color.White, Color.LightGreen, Color.Yellow, Color.Pink, Color.Red, Color.Red }; long[] bytesList = new long[6] { 0, 1024 * 64, 1024 * 512, 1024 * 1024 * 4, 1024 * 1024 * 16, 1024 * 1024 * 1024 }; for (int i = 1; i < colList.Length; ++i) { if (maxBytes < bytesList[i]) { SetBackColor(cell, ColorMix(colList[i - 1], colList[i], (double)(maxBytes - bytesList[i - 1]) / (bytesList[i] - bytesList[i - 1]))); break; } } SetCellText(cell, valStr); } // AvgUpSpeed else if (columnName == "AvgUpSpeed") { long avgBytes = serverSpeedLog.avgUploadBytes; string valStr = FormatBytes(avgBytes); Color[] colList = new Color[6] { Color.White, Color.LightGreen, Color.Yellow, Color.Pink, Color.Red, Color.Red }; long[] bytesList = new long[6] { 0, 1024 * 64, 1024 * 512, 1024 * 1024 * 4, 1024 * 1024 * 16, 1024L * 1024 * 1024 * 1024 }; for (int i = 1; i < colList.Length; ++i) { if (avgBytes < bytesList[i]) { SetBackColor(cell, ColorMix(colList[i - 1], colList[i], (double)(avgBytes - bytesList[i - 1]) / (bytesList[i] - bytesList[i - 1]))); break; } } SetCellText(cell, valStr); } // MaxUpSpeed else if (columnName == "MaxUpSpeed") { long maxBytes = serverSpeedLog.maxUploadBytes; string valStr = FormatBytes(maxBytes); Color[] colList = new Color[6] { Color.White, Color.LightGreen, Color.Yellow, Color.Pink, Color.Red, Color.Red }; long[] bytesList = new long[6] { 0, 1024 * 64, 1024 * 512, 1024 * 1024 * 4, 1024 * 1024 * 16, 1024 * 1024 * 1024 }; for (int i = 1; i < colList.Length; ++i) { if (maxBytes < bytesList[i]) { SetBackColor(cell, ColorMix(colList[i - 1], colList[i], (double)(maxBytes - bytesList[i - 1]) / (bytesList[i] - bytesList[i - 1]))); break; } } SetCellText(cell, valStr); } // TotalUploadBytes else if (columnName == "Upload") { string valStr = FormatBytes(serverSpeedLog.totalUploadBytes); string fullVal = serverSpeedLog.totalUploadBytes.ToString(); if (cell.ToolTipText != fullVal) { if (fullVal == "0") { SetBackColor(cell, Color.FromArgb(0xf4, 0xff, 0xf4)); } else { SetBackColor(cell, Color.LightGreen); cell.Tag = 8; } } else if (cell.Tag != null) { cell.Tag = (int)cell.Tag - 1; if ((int)cell.Tag == 0) { SetBackColor(cell, Color.FromArgb(0xf4, 0xff, 0xf4)); } } SetCellToolTipText(cell, fullVal); SetCellText(cell, valStr); } // TotalDownloadBytes else if (columnName == "Download") { string valStr = FormatBytes(serverSpeedLog.totalDownloadBytes); string fullVal = serverSpeedLog.totalDownloadBytes.ToString(); if (cell.ToolTipText != fullVal) { if (fullVal == "0") { SetBackColor(cell, Color.FromArgb(0xff, 0xf0, 0xf0)); } else { SetBackColor(cell, Color.LightGreen); cell.Tag = 8; } } else if (cell.Tag != null) { cell.Tag = (int)cell.Tag - 1; if ((int)cell.Tag == 0) { SetBackColor(cell, Color.FromArgb(0xff, 0xf0, 0xf0)); } } SetCellToolTipText(cell, fullVal); SetCellText(cell, valStr); } else if (columnName == "DownloadRaw") { string valStr = FormatBytes(serverSpeedLog.totalDownloadRawBytes); string fullVal = serverSpeedLog.totalDownloadRawBytes.ToString(); SetCellToolTipText(cell, fullVal); SetCellText(cell, valStr); } // ErrorConnectTimes else if (columnName == "ConnectError") { long val = serverSpeedLog.errorConnectTimes + serverSpeedLog.errorDecodeTimes; Color col = Color.FromArgb(255, (byte)Math.Max(0, 255 - val * 2.5), (byte)Math.Max(0, 255 - val * 2.5)); SetBackColor(cell, col); SetCellText(cell, val); } // ErrorTimeoutTimes else if (columnName == "ConnectTimeout") { SetCellText(cell, serverSpeedLog.errorTimeoutTimes); } // ErrorTimeoutTimes else if (columnName == "ConnectEmpty") { long val = serverSpeedLog.errorEmptyTimes; Color col = Color.FromArgb(255, (byte)Math.Max(0, 255 - val * 8), (byte)Math.Max(0, 255 - val * 8)); SetBackColor(cell, col); SetCellText(cell, val); } // ErrorContinurousTimes else if (columnName == "Continuous") { long val = serverSpeedLog.errorContinurousTimes; Color col = Color.FromArgb(255, (byte)Math.Max(0, 255 - val * 8), (byte)Math.Max(0, 255 - val * 8)); SetBackColor(cell, col); SetCellText(cell, val); } // ErrorPersent else if (columnName == "ErrorPercent") { if (serverSpeedLog.errorLogTimes + serverSpeedLog.totalConnectTimes - serverSpeedLog.totalDisconnectTimes > 0) { double percent = (serverSpeedLog.errorConnectTimes + serverSpeedLog.errorTimeoutTimes + serverSpeedLog.errorDecodeTimes) * 100.00 / (serverSpeedLog.errorLogTimes + serverSpeedLog.totalConnectTimes - serverSpeedLog.totalDisconnectTimes); SetBackColor(cell, Color.FromArgb(255, (byte)(255 - percent * 2), (byte)(255 - percent * 2))); SetCellText(cell, percent.ToString("F0") + "%"); } else { SetBackColor(cell, Color.White); SetCellText(cell, "-"); } } } if (rowChange && list_index >= displayBeginIndex && list_index < displayEndIndex) { rowChangeCnt++; } } } catch { } if (ServerDataGrid.SortedColumn != null) { ServerDataGrid.Sort(ServerDataGrid.SortedColumn, (ListSortDirection)((int)ServerDataGrid.SortOrder - 1)); } if (last_rowcount == 0 && config.index >= 0 && config.index < ServerDataGrid.RowCount) { ServerDataGrid[0, config.index].Selected = true; } if (firstDispley) { ServerDataGrid.FirstDisplayedScrollingRowIndex = Math.Max(0, config.index - ServerDataGrid.DisplayedRowCount(true) / 2); firstDispley = false; } }