/// <summary> /// Save log file button, opens save dialog to save all logged packets. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnSave_Click(object sender, EventArgs e) { SaveLogDialog.FileName = DateTime.Now.ToString("yyyyMMdd_HHmmss"); if (SaveLogDialog.ShowDialog() == DialogResult.Cancel) { return; } try { using (var stream = SaveLogDialog.OpenFile()) using (var sw = new StreamWriter(stream)) { for (int i = LstPackets.Items.Count - 1; i >= 0; --i) { var palePacket = (PalePacket)LstPackets.Items[i].Tag; var method = palePacket.Received ? "Recv" : "Send"; var time = palePacket.Time.ToString("hh:mm:ss.fff"); var packetStr = HexTool.ToString(palePacket.Packet.GetBuffer()); sw.WriteLine(method + "@" + time + " " + packetStr); } LblCurrentFileName.Text = Path.GetFileName(SaveLogDialog.FileName); } } catch (Exception ex) { MessageBox.Show("Failed to save file (" + ex.Message + ").", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void SaveLog_Click(object sender, EventArgs e) { if (SaveLogDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && SaveLogDialog.FileName.Length > 0) { try { System.IO.StreamWriter file = new System.IO.StreamWriter(SaveLogDialog.FileName); StringBuilder sb = new StringBuilder(); sb.AppendLine(String.Format("Debug log of \"{0}\"", Text)); sb.AppendLine("================="); sb.AppendLine("Friendly text:"); sb.AppendLine(MessageText.Text); sb.AppendLine(""); sb.AppendLine("Exception reason:"); sb.AppendLine(DebugInfoText.Text); sb.AppendLine("================="); sb.AppendLine(String.Format("Date: {0}", DateTime.UtcNow.ToString("MMMM dd, yyyy - hh:mm:ss.fff tt"))); file.WriteLine(sb.ToString()); file.Close(); MessageBox.Show(String.Format("Log saved as \"{0}\" successfully.", SaveLogDialog.FileName), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Can not save the log file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } }
public static Dialog Create(string message) { var dialog = new Dialog { Icon = AppImages.Xf, Title = AppResource.Error_dialog_title, Padding = AppStyles.WindowPadding, Width = 500, Height = 400, }; var container = new TableLayout(1, 3) { Spacing = new Size(0, 10) }; var about = new Label { Text = AboutResource.Save_log_before_termination }; var txtCtrl = new TextArea { ReadOnly = true, Text = message, Wrap = true }; var ok = new Button { Text = CommonResource.Ok }; var export = new LinkButton { Text = AboutResource.Export_log_and_trace }; export.Click += (s, e) => { SaveLogDialog.Show(message); }; container.Add(about, 0, 0, true, false); container.Add(txtCtrl, 0, 1, true, true); var btnRow = new TableLayout(3, 1) { Spacing = new Size(6, 0) }; btnRow.Add(export, 0, 0, false, false); btnRow.Add(null, 1, 0, true, false); btnRow.Add(ok, 2, 0, false, false); container.Add(btnRow, 0, 2, true, false); dialog.Content = container; ok.Click += (s, e) => dialog.Close(); return(dialog); }
private void DefineLayout() { var containingLayout = new TableLayout(1, 3); var filterLayout = new TableLayout(2, 1) { Padding = new Padding(5) }; var exportLayout = new TableLayout(4, 1) { Padding = new Padding(10), Spacing = new Size(10, 0) }; var okBtn = new Button { Text = CommonResource.Ok }; var clearBtn = new LinkButton { Text = LoggingResource.Clear }; _control = new SearchBox { PlaceholderText = LoggingResource.Search_logs, Width = 200 }; filterLayout.Add(null, 0, 0, true, false); filterLayout.Add(_control, 1, 0, false, false); var exportBtn = new LinkButton { Text = LoggingResource.Export_log }; exportLayout.Add(exportBtn, 0, 0, false, false); exportLayout.Add(clearBtn, 1, 0, false, false); exportLayout.Add(null, 2, 0, true, false); exportLayout.Add(okBtn, 3, 0, false, false); exportBtn.Click += (s, e) => { SaveLogDialog.Show(); }; clearBtn.Click += (s, e) => { ToolboxApp.Log.ClearLiveLog(); PopulateGridView(); }; _gridView = new GridView { AllowColumnReordering = false, ShowHeader = true, }; _gridView.Columns.Add(new GridColumn { HeaderText = LoggingResource.Header_time, AutoSize = true, DataCell = new TextBoxCell { Binding = new DelegateBinding <LogItem, string>(i => FormatEventTime(i.EventTime)) }, Editable = false, Sortable = false }); _gridView.Columns.Add(new GridColumn { HeaderText = LoggingResource.Header_severity, AutoSize = true, DataCell = new TextBoxCell { Binding = new DelegateBinding <LogItem, string>(i => i.Severity) }, Editable = false, Sortable = false }); _gridView.Columns.Add(new GridColumn { HeaderText = LoggingResource.Header_description, AutoSize = true, DataCell = new TextBoxCell { Binding = new DelegateBinding <LogItem, string>(i => i.Description) }, Editable = false, Sortable = false }); containingLayout.Add(filterLayout, 0, 0, true, false); containingLayout.Add(_gridView, 0, 1, true, true); containingLayout.Add(exportLayout, 0, 2, false, false); var size = new Size(850, 400); _dialog = new Dialog { Icon = AppImages.Xf, Title = LoggingResource.Dialog_title, Content = containingLayout, ClientSize = size, MinimumSize = size, Maximizable = false, Resizable = true, AbortButton = okBtn }; okBtn.Click += (sender, args) => _dialog.Close(); }
private void SaveLogAsMenuItem_Click(object Sender, EventArgs EventArgs) { SaveLogDialog.ShowDialog(); }