Menu

[r1586]: / trunk / GoogleContactsSync / ErrorDialog.cs  Maximize  Restore  History

Download this file

129 lines (114 with data), 5.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using Serilog;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GoContactSyncMod
{
public partial class ErrorDialog : Form
{
public ErrorDialog()
{
/* Cannot set Font in designer as there is automatic sorting and Font will be set after AutoScaleDimensions
* This will prevent application to work correctly with high DPI systems. */
Font = new Font("Verdana", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0);
InitializeComponent();
}
public async Task SetErrorText(Exception ex)
{
if (await VersionInformation.IsNewVersionAvailable(CancellationToken.None))
{
richTextBoxError.AppendText(Environment.NewLine);
richTextBoxError.AppendText("NEW VERSION AVAILABLE - ");
var downloadLink = new LinkLabel
{
Text = "DOWNLOAD NOW",
AutoSize = true,
LinkColor = Color.FromArgb(0, 102, 204),
Location = richTextBoxError.GetPositionFromCharIndex(richTextBoxError.TextLength)
};
downloadLink.LinkClicked += OpenDowloadUrl;
richTextBoxError.Controls.Add(downloadLink);
richTextBoxError.AppendText(downloadLink.Text);
richTextBoxError.AppendText(Environment.NewLine);
richTextBoxError.AppendText(Environment.NewLine);
AppendTextWithColor("PLEASE UPDATE TO THE LATEST VERSION!" + Environment.NewLine, Color.Firebrick);
}
AppendTextWithColor("FIRST CHECK IF THIS ERROR HAS ALREADY BEEN REPORTED!", Color.Firebrick);
AppendTextWithColor(Environment.NewLine + "IF THE PROBLEM STILL EXISTS WRITE AN ERROR REPORT ", Color.Firebrick);
var bugsLink = new LinkLabel
{
Text = "HERE!",
AutoSize = true,
LinkColor = Color.FromArgb(0, 102, 204),
Location = richTextBoxError.GetPositionFromCharIndex(richTextBoxError.TextLength)
};
bugsLink.LinkClicked += OpenBugsUrl;
richTextBoxError.Controls.Add(bugsLink);
richTextBoxError.AppendText(Environment.NewLine);
richTextBoxError.AppendText(Environment.NewLine);
richTextBoxError.AppendText("GCSM VERSION: " + VersionInformation.GetGCSMVersion().ToString());
richTextBoxError.AppendText(Environment.NewLine);
richTextBoxError.AppendText("OUTLOOK VERSION: " + VersionInformation.GetOutlookVersion(Synchronizer.OutlookApplication).ToString() + Environment.NewLine);
richTextBoxError.AppendText("OS VERSION: " + VersionInformation.GetWindowsVersion() + Environment.NewLine);
richTextBoxError.AppendText(Environment.NewLine);
richTextBoxError.AppendText("ERROR MESAGE:" + Environment.NewLine + Environment.NewLine);
AppendTextWithColor(ex.Message + Environment.NewLine, Color.Firebrick);
richTextBoxError.AppendText(Environment.NewLine);
richTextBoxError.AppendText("ERROR MESAGE STACK TRACE:" + Environment.NewLine + Environment.NewLine);
if (ex.StackTrace != null)
{
AppendTextWithColor(ex.StackTrace, Color.Firebrick);
}
else
{
AppendTextWithColor("NO STACK TRACE AVAILABLE", Color.Firebrick);
}
var message = richTextBoxError.Text.Replace("\n", "\r\n");
//copy to clipboard
try
{
var thread = new Thread(() => System.Windows.Clipboard.SetDataObject(message, true));
thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
thread.Start();
thread.Join();
}
catch (Exception e)
{
Log.Debug("Message couldn't be copied to clipboard: " + e.Message);
}
}
public string ErrorText => richTextBoxError.Text;
private void AppendTextWithColor(string text, Color color)
{
var start = richTextBoxError.TextLength;
richTextBoxError.AppendText(text);
var end = richTextBoxError.TextLength;
// Textbox may transform chars, so (end-start) != text.Length
richTextBoxError.Select(start, end - start);
{
richTextBoxError.SelectionColor = color;
// could set box.SelectionBackColor, box.SelectionFont too.
}
richTextBoxError.SelectionLength = 0; // clear
}
private void OpenDowloadUrl(object sender, EventArgs e)
{
Process.Start("https://sourceforge.net/projects/googlesyncmod/files/latest/download");
}
private void OpenBugsUrl(object sender, EventArgs e)
{
Process.Start("https://sourceforge.net/p/googlesyncmod/bugs/?source=navbar");
}
private void ErrorDialog_FormClosed(object sender, FormClosedEventArgs e)
{
Visible = false;
}
private void ErrorDialog_Load(object sender, EventArgs e)
{
TopMost = true;
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.