Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Processes the GAB message(s).
 /// </summary>
 /// <param name="item">If specified, this item has changed. If null, means a global check should be performed</param>
 public void Process(CompletionTracker completion, IZPushItem item)
 {
     using (CompletionTracker.Step step = completion?.Begin())
     {
         try
         {
             if (item == null)
             {
                 if (Folder != null)
                 {
                     ProcessMessages(completion);
                 }
             }
             else
             {
                 ProcessMessage(completion, item);
             }
         }
         catch (Exception e)
         {
             Logger.Instance.Error(this, "Exception in GAB.Process: {0}", e);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Performs a full resync.
        /// </summary>
        /// <param name="completion">The completion tracker, or null.</param>
        /// <param name="accounts">The accounts to resync, or null to resync all</param>
        internal void FullResync(CompletionTracker completion, ZPushAccount[] accounts)
        {
            try
            {
                // TODO: implement per-account resyncing
                Logger.Instance.Trace(this, "FullResync begin: {0}", _processing);
                BeginProcessing();

                // Delete any contacts folders in the local store
                if (DeleteExistingFolder)
                {
                    using (IStore store = ZPushLocalStore.GetInstance(ThisAddIn.Instance))
                    {
                        if (store != null)
                        {
                            using (IFolder root = store.GetRootFolder())
                            {
                                foreach (IFolder folder in root.GetSubFolders <IFolder>().DisposeEnum())
                                {
                                    try
                                    {
                                        if (IsGABContactsFolder(folder, accounts))
                                        {
                                            Logger.Instance.Debug(this, "FullResync: Deleting contacts folder: {0}", folder.Name);
                                            folder.Delete();
                                        }
                                    }
                                    catch (System.Exception e)
                                    {
                                        Logger.Instance.Error(this, "FullResync: Exception deleting contacts folder: {0}", e);
                                    }
                                }
                            }
                        }
                    }
                }

                // Do the resync
                using (completion.Begin())
                {
                    foreach (GABHandler gab in _gabsByDomainName.Values)
                    {
                        // Check if the gab is appropriate for the accounts
                        if (accounts == null || accounts.Contains(gab.ActiveAccount))
                        {
                            completion.Begin();
                            CompletionTracker partCompletion = new CompletionTracker(() =>
                            {
                                OnGabSyncFinished(gab);
                                completion.End();
                            });

                            Logger.Instance.Debug(this, "FullResync: Starting resync: {0}", gab.DisplayName);
                            Tasks.Task(partCompletion, this, "FullResync", () =>
                            {
                                gab.FullResync(partCompletion);
                            });
                        }
                    }
                }
            }
            finally
            {
                EndProcessing();
                Logger.Instance.Trace(this, "FullResync done: {0}", _processing);
            }
        }