private void RegisterGABAccount(ZPushAccount account, IFolder folder) { // Determine the domain name string domain = account.Account.DomainName; // Could already be registered if there are multiple accounts on the same domain GABHandler gab; if (!_gabsByDomainName.TryGetValue(domain, out gab)) { // Create the handler gab = new GABHandler(this, (f) => CreateGABContacts(domain), (f) => DisposeGABContacts(f)); _gabsByDomainName.Add(domain, gab); } else { Logger.Instance.Debug(this, "GAB handler already registered: {0} on {1}", folder, folder.StoreDisplayName); } // Register the account with the GAB gab.AddAccount(account, folder); // The folder has become available, check the GAB messages DoProcess(account, gab, null); // And watch for any new messages Watcher.WatchItems <IZPushItem>(folder, (item) => DoProcess(account, gab, item), false); }
private void DoProcess(ZPushAccount account, GABHandler gab, IZPushItem item) { // Multiple accounts - and therefore multiple folders - may use the same GAB. // One process the items from the first associated account if (account != gab.ActiveAccount) { Logger.Instance.Trace(this, "Ignoring GAB message: {0} - {1}", account, item); return; } ++_processing; Logger.Instance.Trace(this, "Processing GAB message: {0} - {1}", account, _processing); CompletionTracker completion = new CompletionTracker(() => OnGabSyncFinished(gab)); using (completion.Begin()) { try { gab.Process(completion, item); // TODO: this will probably run while still processing, use completion tracker DoEmptyDeletedItems(); } finally { Logger.Instance.Trace(this, "Processed GAB message: {0} - {1}", account, _processing); --_processing; } } }
public void OnGabSyncFinished(GABHandler gab) { SyncFinished?.Invoke(gab); }