[KOE-50] Showing information dialog if password is not available.

This commit is contained in:
Patrick Simpson 2017-02-01 13:15:54 +01:00
parent ef4ee3827a
commit 99e939a5b2
7 changed files with 114 additions and 14 deletions

View File

@ -276,6 +276,7 @@
<Compile Include="Features\SharedFolders\FolderTreeNode.cs" />
<Compile Include="GlobalOptions.cs" />
<Compile Include="Logging.cs" />
<Compile Include="Native\IOleWindow.cs" />
<Compile Include="OutlookConstants.cs" />
<Compile Include="UI\Outlook\OutlookImageList.cs" />
<Compile Include="UI\Outlook\RibbonToggleButton.cs" />

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Acacia.Native
{
[ComImport]
[Guid("00000114-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleWindow
{
void GetWindow(out IntPtr phwnd);
void ContextSensitiveHelp([In, MarshalAs(UnmanagedType.Bool)] bool fEnterMode);
}
}

View File

@ -60,6 +60,24 @@ namespace Acacia.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to The password for account &apos;{0}&apos; is not available. Advanced Z-Push features will not work..
/// </summary>
internal static string AccountNoPassword_Body {
get {
return ResourceManager.GetString("AccountNoPassword_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Password unavailable.
/// </summary>
internal static string AccountNoPassword_Title {
get {
return ResourceManager.GetString("AccountNoPassword_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Support.
/// </summary>

View File

@ -439,4 +439,10 @@
<value>Contacts folder</value>
<comment>Shown when a secondary contact folder is detected, to inform the user that a restart is required</comment>
</data>
<data name="AccountNoPassword_Body" xml:space="preserve">
<value>The password for account '{0}' is not available. Advanced Z-Push features will not work.</value>
</data>
<data name="AccountNoPassword_Title" xml:space="preserve">
<value>Password unavailable</value>
</data>
</root>

View File

@ -32,6 +32,7 @@ using Acacia.UI.Outlook;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Reflection;
using Acacia.Native;
namespace Acacia
{
@ -244,6 +245,41 @@ namespace Acacia
}
}
#region Window handle
private class WindowHandle : IWin32Window
{
private IntPtr hWnd;
public WindowHandle(IntPtr hWnd)
{
this.hWnd = hWnd;
}
public IntPtr Handle
{
get
{
return hWnd;
}
}
}
public IWin32Window Window
{
get
{
var win = Application.ActiveWindow() as IOleWindow;
if (win == null)
return null;
IntPtr hWnd;
win.GetWindow(out hWnd);
return new WindowHandle(hWnd);
}
}
#endregion
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return OutlookUI;

View File

@ -136,6 +136,12 @@ namespace Acacia.ZPush
}
}
[Browsable(false)]
public bool HasPassword
{
get { return Registry.GetValue(_regPath, OutlookConstants.REG_VAL_EAS_PASSWORD, null) != null; }
}
public string StoreID
{
get { return GetStoreId(_regPath); }

View File

@ -141,24 +141,39 @@ namespace Acacia.ZPush
// Register any events
HandleFolderWatchers(account);
// Send an OOF request to get the OOF state and capabilities
Tasks.Task(null, "ZPushCheck: " + account.DisplayName, () =>
if (account.HasPassword)
{
// TODO: if this fails, retry?
ActiveSync.SettingsOOF oof;
using (ZPushConnection connection = new ZPushConnection(account, new System.Threading.CancellationToken(false)))
// Send an OOF request to get the OOF state and capabilities
Tasks.Task(null, "ZPushCheck: " + account.DisplayName, () =>
{
oof = connection.Execute(new ActiveSync.SettingsOOFGet());
}
account.OnConfirmationResponse(oof.RawResponse);
// TODO: if this fails, retry?
ActiveSync.SettingsOOF oof;
using (ZPushConnection connection = new ZPushConnection(account, new System.Threading.CancellationToken(false)))
{
oof = connection.Execute(new ActiveSync.SettingsOOFGet());
}
account.OnConfirmationResponse(oof.RawResponse);
// [ZO-109] Always update the current selection, it might have changed.
Explorer_SelectionChange();
// [ZO-109] Always update the current selection, it might have changed.
Explorer_SelectionChange();
// Notify the OOF feature.
// TODO: this coupling is pretty hideous
ThisAddIn.Instance.GetFeature<FeatureOutOfOffice>()?.OnOOFSettings(account, oof);
});
// Notify the OOF feature.
// TODO: this coupling is pretty hideous
ThisAddIn.Instance.GetFeature<FeatureOutOfOffice>()?.OnOOFSettings(account, oof);
});
}
else
{
ThisAddIn.Instance.InvokeUI(() =>
{
Logger.Instance.Warning(this, "Password not available for account: {0}", account);
System.Windows.Forms.MessageBox.Show(ThisAddIn.Instance.Window,
string.Format(Properties.Resources.AccountNoPassword_Body, account.DisplayName),
Properties.Resources.AccountNoPassword_Title,
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information
);
});
}
}
internal void OnAccountsScanned()