mirror of
				https://github.com/Kopano-dev/kopano-ol-extension.git
				synced 2023-10-10 11:37:40 +00:00 
			
		
		
		
	[KOE-168] Added upgrading of existing shared folders
This commit is contained in:
		| @@ -28,6 +28,7 @@ using static Acacia.DebugOptions; | |||||||
| using Acacia.Features.GAB; | using Acacia.Features.GAB; | ||||||
| using Acacia.Features.SyncState; | using Acacia.Features.SyncState; | ||||||
| using System.Windows.Forms; | using System.Windows.Forms; | ||||||
|  | using System.Threading; | ||||||
|  |  | ||||||
| namespace Acacia.Features.SendAs | namespace Acacia.Features.SendAs | ||||||
| { | { | ||||||
| @@ -60,6 +61,9 @@ namespace Acacia.Features.SendAs | |||||||
|                         MailEvents.Respond += MailEvents_Respond; |                         MailEvents.Respond += MailEvents_Respond; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  |                 // Upgrade after accounts are determined | ||||||
|  |                 Watcher.AccountsScanned += CheckUpgrades; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -184,10 +188,6 @@ namespace Acacia.Features.SendAs | |||||||
|                                                MessageBoxIcon.Error |                                                MessageBoxIcon.Error | ||||||
|                                            ); |                                            ); | ||||||
|                         } |                         } | ||||||
|                         else |  | ||||||
|                         { |  | ||||||
|  |  | ||||||
|                         } |  | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -234,13 +234,50 @@ namespace Acacia.Features.SendAs | |||||||
|  |  | ||||||
|         internal void UpdateSendAsAddresses(ZPushAccount zpush, ICollection<SharedFolder> shares) |         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) |             foreach (SharedFolder folder in shares) | ||||||
|             { |             { | ||||||
|                 if (!folder.FlagSendAsOwner) |                 if (!folder.FlagSendAsOwner) | ||||||
|                     continue; |                     continue; | ||||||
|  |  | ||||||
|                 // Resolve it |                 // 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 |         #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 | ||||||
|  |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -113,10 +113,15 @@ namespace Acacia.Features.SharedFolders | |||||||
|             ZPushAccount account = Watcher.Accounts.GetAccount(folder); |             ZPushAccount account = Watcher.Accounts.GetAccount(folder); | ||||||
|             if (account != null) |             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() |         private void ManageFolders() | ||||||
|         { |         { | ||||||
|             ZPushAccount account = Watcher.CurrentZPushAccount(); |             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) |         public SharedFolder GetSharedFolder(IFolder folder) | ||||||
|         { |         { | ||||||
|             if (folder == null) |             if (folder == null) | ||||||
|   | |||||||
| @@ -99,6 +99,12 @@ namespace Acacia.Features.SharedFolders | |||||||
|         private ZPushAccount _initialAccount; |         private ZPushAccount _initialAccount; | ||||||
|         private SharedFolder _initialFolder; |         private SharedFolder _initialFolder; | ||||||
|  |  | ||||||
|  |         public bool SuppressInitialSendAsWarning | ||||||
|  |         { | ||||||
|  |             get; | ||||||
|  |             set; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         public SharedFoldersDialog(FeatureSharedFolders feature, ZPushAccount account, SyncId initial = null) |         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 |             // If this is a shared store, open the account it's a share for, with the request account as the initial | ||||||
| @@ -882,12 +888,19 @@ namespace Acacia.Features.SharedFolders | |||||||
|                 _optionSendAsNodes[0].SharedFolder.SendAsAddress = email; |                 _optionSendAsNodes[0].SharedFolder.SendAsAddress = email; | ||||||
|             } |             } | ||||||
|             else if (checkSendAs.Checked) |             else if (checkSendAs.Checked) | ||||||
|  |             { | ||||||
|  |                 if (SuppressInitialSendAsWarning) | ||||||
|  |                 { | ||||||
|  |                     SuppressInitialSendAsWarning = false; | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|                 { |                 { | ||||||
|                     MessageBox.Show(Properties.Resources.SharedFolders_SendAsFailed_Label, |                     MessageBox.Show(Properties.Resources.SharedFolders_SendAsFailed_Label, | ||||||
|                         Properties.Resources.SharedFolders_SendAsFailed_Title, |                         Properties.Resources.SharedFolders_SendAsFailed_Title, | ||||||
|                         MessageBoxButtons.OK, MessageBoxIcon.Information); |                         MessageBoxButtons.OK, MessageBoxIcon.Information); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|         private void EnableSendAsAddress() |         private void EnableSendAsAddress() | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -1167,7 +1167,7 @@ namespace Acacia.Properties { | |||||||
|         } |         } | ||||||
|          |          | ||||||
|         /// <summary> |         /// <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> |         /// </summary> | ||||||
|         internal static string SharedFolders_SendAsFailed_Label { |         internal static string SharedFolders_SendAsFailed_Label { | ||||||
|             get { |             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> |         /// <summary> | ||||||
|         ///   Looks up a localized string similar to There are unsaved changes. Do you really want to to discard these?. |         ///   Looks up a localized string similar to There are unsaved changes. Do you really want to to discard these?. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|   | |||||||
| @@ -531,9 +531,12 @@ Please contact your system administrator for any required changes.</value> | |||||||
|     <value>Open stores</value> |     <value>Open stores</value> | ||||||
|   </data> |   </data> | ||||||
|   <data name="SharedFolders_SendAsFailed_Label" xml:space="preserve"> |   <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> | ||||||
|   <data name="SharedFolders_SendAsFailed_Title" xml:space="preserve"> |   <data name="SharedFolders_SendAsFailed_Title" xml:space="preserve"> | ||||||
|     <value>Shared Folders</value> |     <value>Shared Folders</value> | ||||||
|   </data> |   </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> | </root> | ||||||
| @@ -266,8 +266,8 @@ namespace Acacia.ZPush | |||||||
|  |  | ||||||
|                 // Need to keep a reference to keep receiving events |                 // Need to keep a reference to keep receiving events | ||||||
|                 _syncObject = addIn.GetSyncObject(); |                 _syncObject = addIn.GetSyncObject(); | ||||||
|                 _syncObject.SyncStart += SyncObject_SyncStart; |                 _syncObject.SyncEnd += SyncObject_SyncPeriodics; | ||||||
|                 _syncObject.SyncEnd += SyncObject_SyncEnd; |                 _syncObject.SyncEnd += SyncObject_SyncOneOffTasks; | ||||||
|                 watcher.AccountDiscovered += Watcher_AccountDiscovered; |                 watcher.AccountDiscovered += Watcher_AccountDiscovered; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -489,7 +489,7 @@ namespace Acacia.ZPush | |||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Invoked when an explicit send and receive is performed, invokes any tasks. |         /// Invoked when an explicit send and receive is performed, invokes any tasks. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         private void SyncObject_SyncStart() |         private void SyncObject_SyncPeriodics() | ||||||
|         { |         { | ||||||
|             // TODO: this checks _started, others don't. Also, this is probably invoked on |             // 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 |             //       start-up, as is AccountDiscoverd. Does that mean tasks are invoked twice | ||||||
| @@ -506,7 +506,7 @@ namespace Acacia.ZPush | |||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Invoked after an explicit send and receive is performed, invokes any tasks. |         /// Invoked after an explicit send and receive is performed, invokes any tasks. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         private void SyncObject_SyncEnd() |         private void SyncObject_SyncOneOffTasks() | ||||||
|         { |         { | ||||||
|             AcaciaTask task; |             AcaciaTask task; | ||||||
|             while (_endTasks.TryDequeue(out task)) |             while (_endTasks.TryDequeue(out task)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user