[KOE-168] Added upgrading of existing shared folders

This commit is contained in:
Patrick Simpson 2018-04-13 15:09:53 +03:00
parent 7a6075a6d9
commit 6314010a00
6 changed files with 137 additions and 15 deletions

View File

@ -28,6 +28,7 @@ using static Acacia.DebugOptions;
using Acacia.Features.GAB;
using Acacia.Features.SyncState;
using System.Windows.Forms;
using System.Threading;
namespace Acacia.Features.SendAs
{
@ -60,6 +61,9 @@ namespace Acacia.Features.SendAs
MailEvents.Respond += MailEvents_Respond;
}
}
// Upgrade after accounts are determined
Watcher.AccountsScanned += CheckUpgrades;
}
}
@ -184,10 +188,6 @@ namespace Acacia.Features.SendAs
MessageBoxIcon.Error
);
}
else
{
}
}
}
@ -234,13 +234,50 @@ namespace Acacia.Features.SendAs
internal void UpdateSendAsAddresses(ZPushAccount zpush, ICollection<SharedFolder> shares)
{
UpdateSendAsAddresses(zpush, shares, false);
}
private void UpdateSendAsAddresses(ZPushAccount zpush, ICollection<SharedFolder> shares, bool checkUpgradeFolders)
{
SharedFolder firstFailure = null;
foreach (SharedFolder folder in shares)
{
if (!folder.FlagSendAsOwner)
continue;
// Resolve it
FindSendAsAddress(zpush, folder);
string address = FindSendAsAddress(zpush, folder);
if (checkUpgradeFolders && address == null)
{
// This is an update from an old shared folder. See if it can be resolved
address = UpgradeSharedFolderAddress(zpush, folder);
if (address == null)
{
// Still not resolved, mark a failure for later
if (firstFailure == null)
firstFailure = folder;
}
}
}
if (firstFailure != null)
{
ThisAddIn.Instance.InUI(() =>
{
if (MessageBox.Show(ThisAddIn.Instance.Window,
string.Format(Properties.Resources.SharedFolders_SendAsUpdateFailed_Label, firstFailure.Name),
Properties.Resources.SharedFolders_SendAsFailed_Title,
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning
) == DialogResult.Yes)
{
SharedFoldersDialog dialog = new SharedFoldersDialog(_sharedFolders, zpush, firstFailure.SyncId);
dialog.SuppressInitialSendAsWarning = true;
dialog.ShowDialog();
}
}, false);
}
}
@ -275,5 +312,52 @@ namespace Acacia.Features.SendAs
}
#endregion
#region Upgrading of old send-as folders
private void CheckUpgrades()
{
// To determine the send-as address, we need the GAB. So wait for that to finish updating.
FeatureGAB gab = ThisAddIn.Instance.GetFeature<FeatureGAB>();
if (gab != null)
gab.SyncFinished += CheckUpgradesGabSynced;
}
private string UpgradeSharedFolderAddress(ZPushAccount zpush, SharedFolder folder)
{
string address = FindSendAsAddress(zpush, folder.Store);
if (string.IsNullOrWhiteSpace(address))
return null;
// Store it
folder.SendAsAddress = address;
StoreSyncIdAddress(zpush, folder);
zpush.SetSendAsAddress(folder.BackendId, address);
return address;
}
private void CheckUpgradesGabSynced(GABHandler gab)
{
ThisAddIn.Instance.InUI(() =>
{
ZPushAccount account = gab.ActiveAccount;
ICollection<SharedFolder> shares = _sharedFolders.GetCachedFolders(account);
if (shares == null)
{
using (SharedFoldersManager manager = _sharedFolders.Manage(account))
{
shares = manager.GetCurrentShares(null);
}
}
if (shares != null)
{
UpdateSendAsAddresses(account, shares, true);
}
}, false);
}
#endregion
}
}

View File

@ -113,10 +113,15 @@ namespace Acacia.Features.SharedFolders
ZPushAccount account = Watcher.Accounts.GetAccount(folder);
if (account != null)
{
new SharedFoldersDialog(this, account, folder.SyncId).ShowDialog();
ManageFolder(account, folder.SyncId);
}
}
public void ManageFolder(ZPushAccount account, SyncId folderId)
{
new SharedFoldersDialog(this, account, folderId).ShowDialog();
}
private void ManageFolders()
{
ZPushAccount account = Watcher.CurrentZPushAccount();
@ -174,6 +179,14 @@ namespace Acacia.Features.SharedFolders
}
}
public ICollection<SharedFolder> GetCachedFolders(ZPushAccount zpush)
{
Dictionary<SyncId, SharedFolder> shared = zpush.GetFeatureData<Dictionary<SyncId, SharedFolder>>(this, KEY_SHARES);
if (shared == null)
return null;
return shared.Values;
}
public SharedFolder GetSharedFolder(IFolder folder)
{
if (folder == null)

View File

@ -99,6 +99,12 @@ namespace Acacia.Features.SharedFolders
private ZPushAccount _initialAccount;
private SharedFolder _initialFolder;
public bool SuppressInitialSendAsWarning
{
get;
set;
}
public SharedFoldersDialog(FeatureSharedFolders feature, ZPushAccount account, SyncId initial = null)
{
// If this is a shared store, open the account it's a share for, with the request account as the initial
@ -883,9 +889,16 @@ namespace Acacia.Features.SharedFolders
}
else if (checkSendAs.Checked)
{
MessageBox.Show(Properties.Resources.SharedFolders_SendAsFailed_Label,
Properties.Resources.SharedFolders_SendAsFailed_Title,
MessageBoxButtons.OK, MessageBoxIcon.Information);
if (SuppressInitialSendAsWarning)
{
SuppressInitialSendAsWarning = false;
}
else
{
MessageBox.Show(Properties.Resources.SharedFolders_SendAsFailed_Label,
Properties.Resources.SharedFolders_SendAsFailed_Title,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

View File

@ -1167,7 +1167,7 @@ namespace Acacia.Properties {
}
/// <summary>
/// Looks up a localized string similar to Unable to determine the email address for the folder. Send-as will only work if you specify the email address manually..
/// Looks up a localized string similar to Unable to determine the send-as email address for the folder. Send-as will only work if you specify the email address manually..
/// </summary>
internal static string SharedFolders_SendAsFailed_Label {
get {
@ -1184,6 +1184,15 @@ namespace Acacia.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Unable to determine the send-as email address for the existing shared folder {0}. Send-as will only work if you specify the email address manually. Would you like to open the Shared Folders dialog?.
/// </summary>
internal static string SharedFolders_SendAsUpdateFailed_Label {
get {
return ResourceManager.GetString("SharedFolders_SendAsUpdateFailed_Label", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to There are unsaved changes. Do you really want to to discard these?.
/// </summary>

View File

@ -531,9 +531,12 @@ Please contact your system administrator for any required changes.</value>
<value>Open stores</value>
</data>
<data name="SharedFolders_SendAsFailed_Label" xml:space="preserve">
<value>Unable to determine the email address for the folder. Send-as will only work if you specify the email address manually.</value>
<value>Unable to determine the send-as email address for the folder. Send-as will only work if you specify the email address manually.</value>
</data>
<data name="SharedFolders_SendAsFailed_Title" xml:space="preserve">
<value>Shared Folders</value>
</data>
<data name="SharedFolders_SendAsUpdateFailed_Label" xml:space="preserve">
<value>Unable to determine the send-as email address for the existing shared folder {0}. Send-as will only work if you specify the email address manually. Would you like to open the Shared Folders dialog?</value>
</data>
</root>

View File

@ -266,8 +266,8 @@ namespace Acacia.ZPush
// Need to keep a reference to keep receiving events
_syncObject = addIn.GetSyncObject();
_syncObject.SyncStart += SyncObject_SyncStart;
_syncObject.SyncEnd += SyncObject_SyncEnd;
_syncObject.SyncEnd += SyncObject_SyncPeriodics;
_syncObject.SyncEnd += SyncObject_SyncOneOffTasks;
watcher.AccountDiscovered += Watcher_AccountDiscovered;
}
}
@ -489,7 +489,7 @@ namespace Acacia.ZPush
/// <summary>
/// Invoked when an explicit send and receive is performed, invokes any tasks.
/// </summary>
private void SyncObject_SyncStart()
private void SyncObject_SyncPeriodics()
{
// TODO: this checks _started, others don't. Also, this is probably invoked on
// start-up, as is AccountDiscoverd. Does that mean tasks are invoked twice
@ -506,7 +506,7 @@ namespace Acacia.ZPush
/// <summary>
/// Invoked after an explicit send and receive is performed, invokes any tasks.
/// </summary>
private void SyncObject_SyncEnd()
private void SyncObject_SyncOneOffTasks()
{
AcaciaTask task;
while (_endTasks.TryDequeue(out task))