Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
        /// <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);
            }
        }
Exemple #3
0
 private void SaveLogAsMenuItem_Click(object Sender, EventArgs EventArgs)
 {
     SaveLogDialog.ShowDialog();
 }