Fixed #3590372 by showing a MessageBox where the problem is displayed and the user can re-try.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2322 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-11-28 16:27:34 +00:00
commit c517787d23
3 changed files with 30 additions and 32 deletions

View file

@ -181,8 +181,7 @@ namespace GreenshotOfficePlugin {
return ShowPickerMenu(false, surface, captureDetails, destinations);
}
} else {
OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC);
exportInformation.ExportMade = true;
exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC);
}
}
ProcessExport(exportInformation, surface);

View file

@ -28,6 +28,9 @@ using Microsoft.Win32;
using Greenshot.Interop;
using Greenshot.Interop.IE;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using GreenshotPlugin.Core;
namespace Greenshot.Interop.Office {
/// <summary>
@ -360,36 +363,26 @@ namespace Greenshot.Interop.Office {
break;
}
// So not save, otherwise the email is always stored in Draft folder.. (newMail.Save();)
try {
newMail.Display(false);
newMail.GetInspector().Activate();
} catch (Exception ex) {
LOG.Warn("Problem displaying the new email, retrying to display it. Problem:", ex);
Thread retryDisplayEmail = new Thread(delegate() {
int retries = 10;
int retryInXSeconds = 5;
while (retries-- > 0) {
Thread.Sleep(retryInXSeconds * 1000);
try {
newMail.Display(false);
newMail.GetInspector().Activate();
LOG.InfoFormat("Managed to display the message.");
return;
} catch (Exception displayEx) {
LOG.WarnFormat("Error displaying message: {0}, retrying to show email in {1} seconds... Retries left: {2}", displayEx, retryInXSeconds, retries);
do {
try {
newMail.Display(false);
newMail.GetInspector().Activate();
break;
} catch (Exception ex) {
// Test for rejected
LOG.Warn("Problem displaying the new email, retrying to display it. Problem:", ex);
COMException comEx = ex.InnerException as COMException;
if (comEx != null && (comEx.ErrorCode == COMWrapper.RPC_E_CALL_REJECTED || comEx.ErrorCode == COMWrapper.RPC_E_FAIL)) {
DialogResult result = MessageBox.Show(PluginUtils.Host.GreenshotForm, Language.GetFormattedString("com_rejected", "Outlook "), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.OK) {
continue;
}
}
LOG.WarnFormat("Retry failed, saving message to draft.");
try {
newMail.Save();
} catch (Exception saveEx) {
LOG.WarnFormat("Saving message to draft failed: {0}", saveEx);
}
});
retryDisplayEmail.Name = "Retry to display email";
retryDisplayEmail.IsBackground = true;
retryDisplayEmail.Start();
}
// Not rejected OR pressed cancel
throw ex;
}
} while (true);
if (newItem != null) {
newItem.Dispose();
}

View file

@ -35,7 +35,8 @@ namespace Greenshot.Interop {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(COMWrapper));
private const int MK_E_UNAVAILABLE = -2147221021;
private const int CO_E_CLASSSTRING = -2147221005;
private const int RPC_E_CALL_REJECTED = unchecked((int)0x80010001);
public const int RPC_E_CALL_REJECTED = unchecked((int)0x80010001);
public const int RPC_E_FAIL = unchecked((int)0x80004005);
#region Private Data
@ -661,7 +662,12 @@ namespace Greenshot.Interop {
// Test for rejected
COMException comEx = ex as COMException;
if (comEx != null && comEx.ErrorCode == RPC_E_CALL_REJECTED) {
DialogResult result = MessageBox.Show(Language.GetString("com_rejected"), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
ComProgIdAttribute progIDAttribute = ComProgIdAttribute.GetAttribute(_InterceptType);
string destinationName = "";
if (progIDAttribute != null) {
destinationName = progIDAttribute.Value + " ";
}
DialogResult result = MessageBox.Show(PluginUtils.Host.GreenshotForm, Language.GetFormattedString("com_rejected", destinationName), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.OK) {
continue;
}