Cleaner solution for export problems which are denied/failed.

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

View file

@ -141,6 +141,13 @@ namespace GreenshotOfficePlugin {
} }
} }
/// <summary>
/// Export the capture to outlook
/// </summary>
/// <param name="manuallyInitiated"></param>
/// <param name="surface"></param>
/// <param name="captureDetails"></param>
/// <returns></returns>
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
// Outlook logic // Outlook logic

View file

@ -363,25 +363,8 @@ namespace Greenshot.Interop.Office {
break; break;
} }
// So not save, otherwise the email is always stored in Draft folder.. (newMail.Save();) // So not save, otherwise the email is always stored in Draft folder.. (newMail.Save();)
do { newMail.Display(false);
try { newMail.GetInspector().Activate();
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;
}
}
// Not rejected OR pressed cancel
throw ex;
}
} while (true);
if (newItem != null) { if (newItem != null) {
newItem.Dispose(); newItem.Dispose();

View file

@ -55,6 +55,11 @@ namespace Greenshot.Interop {
/// </summary> /// </summary>
private Type _InterceptType; private Type _InterceptType;
/// <summary>
/// The humanly readable target name
/// </summary>
private string _TargetName;
#endregion #endregion
[DllImport("ole32.dll")] [DllImport("ole32.dll")]
static extern int ProgIDFromCLSID([In] ref Guid clsid, [MarshalAs(UnmanagedType.LPWStr)] out string lplpszProgID); static extern int ProgIDFromCLSID([In] ref Guid clsid, [MarshalAs(UnmanagedType.LPWStr)] out string lplpszProgID);
@ -126,7 +131,7 @@ namespace Greenshot.Interop {
if (comObject != null) { if (comObject != null) {
if (comObject is IDispatch) { if (comObject is IDispatch) {
COMWrapper wrapper = new COMWrapper(comObject, type); COMWrapper wrapper = new COMWrapper(comObject, type, progIDAttribute.Value);
return (T)wrapper.GetTransparentProxy(); return (T)wrapper.GetTransparentProxy();
} else { } else {
return (T)comObject; return (T)comObject;
@ -275,7 +280,7 @@ namespace Greenshot.Interop {
} }
if (comObject != null) { if (comObject != null) {
if (comObject is IDispatch) { if (comObject is IDispatch) {
COMWrapper wrapper = new COMWrapper(comObject, type); COMWrapper wrapper = new COMWrapper(comObject, type, progIDAttribute.Value);
return (T)wrapper.GetTransparentProxy(); return (T)wrapper.GetTransparentProxy();
} else { } else {
return (T)comObject; return (T)comObject;
@ -290,7 +295,7 @@ namespace Greenshot.Interop {
/// <param name="comObject">An object to intercept</param> /// <param name="comObject">An object to intercept</param>
/// <param name="type">Interface which defines the method and properties to intercept</param> /// <param name="type">Interface which defines the method and properties to intercept</param>
/// <returns>Transparent proxy to the real proxy for the object</returns> /// <returns>Transparent proxy to the real proxy for the object</returns>
private static object Wrap(object comObject, Type type) { private static object Wrap(object comObject, Type type, string targetName) {
if (null == comObject) { if (null == comObject) {
throw new ArgumentNullException("comObject"); throw new ArgumentNullException("comObject");
} }
@ -298,7 +303,7 @@ namespace Greenshot.Interop {
throw new ArgumentNullException("type"); throw new ArgumentNullException("type");
} }
COMWrapper wrapper = new COMWrapper(comObject, type); COMWrapper wrapper = new COMWrapper(comObject, type, targetName);
return wrapper.GetTransparentProxy(); return wrapper.GetTransparentProxy();
} }
@ -311,10 +316,11 @@ namespace Greenshot.Interop {
/// <param name="type"> /// <param name="type">
/// The interface type to impersonate. /// The interface type to impersonate.
/// </param> /// </param>
private COMWrapper(object comObject, Type type) : base(type) { private COMWrapper(object comObject, Type type, string targetName) : base(type) {
this._COMObject = comObject; this._COMObject = comObject;
this._COMType = comObject.GetType(); this._COMType = comObject.GetType();
this._InterceptType = type; this._InterceptType = type;
this._TargetName = targetName;
} }
#endregion #endregion
@ -452,7 +458,7 @@ namespace Greenshot.Interop {
throw new ArgumentException("wrapper proxy was no COMWrapper"); throw new ArgumentException("wrapper proxy was no COMWrapper");
} }
if (oldWrapper._InterceptType.IsAssignableFrom(newType)) { if (oldWrapper._InterceptType.IsAssignableFrom(newType)) {
COMWrapper newWrapper = new COMWrapper(oldWrapper._COMObject, newType); COMWrapper newWrapper = new COMWrapper(oldWrapper._COMObject, newType, oldWrapper._TargetName);
return (T)newWrapper.GetTransparentProxy(); return (T)newWrapper.GetTransparentProxy();
} }
throw new InvalidCastException(string.Format("{0} is not assignable from {1}", oldWrapper._InterceptType, newType)); throw new InvalidCastException(string.Format("{0} is not assignable from {1}", oldWrapper._InterceptType, newType));
@ -661,11 +667,17 @@ namespace Greenshot.Interop {
} catch (Exception ex) { } catch (Exception ex) {
// Test for rejected // Test for rejected
COMException comEx = ex as COMException; COMException comEx = ex as COMException;
if (comEx != null && comEx.ErrorCode == RPC_E_CALL_REJECTED) { if (comEx == null) {
ComProgIdAttribute progIDAttribute = ComProgIdAttribute.GetAttribute(_InterceptType); comEx = ex.InnerException as COMException;
string destinationName = ""; }
if (progIDAttribute != null) { if (comEx != null && (comEx.ErrorCode == RPC_E_CALL_REJECTED || comEx.ErrorCode == COMWrapper.RPC_E_FAIL)) {
destinationName = progIDAttribute.Value + " "; string destinationName = _TargetName;
// Try to find a "catchy" name for the rejecting application
if (destinationName != null && destinationName.Contains(".")) {
destinationName = destinationName.Substring(0, destinationName.IndexOf("."));
}
if (destinationName == null) {
destinationName = _InterceptType.FullName;
} }
DialogResult result = MessageBox.Show(PluginUtils.Host.GreenshotForm, Language.GetFormattedString("com_rejected", destinationName), Language.GetString("com_rejected_title"), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); 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) { if (result == DialogResult.OK) {
@ -682,7 +694,7 @@ namespace Greenshot.Interop {
if (returnType.IsInterface) { if (returnType.IsInterface) {
// Wrap the returned value in an intercepting COM wrapper // Wrap the returned value in an intercepting COM wrapper
if (Marshal.IsComObject(returnValue)) { if (Marshal.IsComObject(returnValue)) {
returnValue = COMWrapper.Wrap(returnValue, returnType); returnValue = COMWrapper.Wrap(returnValue, returnType, _TargetName);
} }
} else if (returnType.IsEnum) { } else if (returnType.IsEnum) {
// Convert to proper Enum type // Convert to proper Enum type
@ -722,7 +734,7 @@ namespace Greenshot.Interop {
} }
if (null == wrapper) { if (null == wrapper) {
wrapper = new COMWrapper(arg, byValType); wrapper = new COMWrapper(arg, byValType, _TargetName);
} }
arg = wrapper.GetTransparentProxy(); arg = wrapper.GetTransparentProxy();
} }