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; } } }
private void ProcessChunkBody(CompletionTracker completion, IZPushItem item, ChunkIndex index) { // Process the body foreach (var entry in JSONUtils.Deserialise(item.Body)) { string id = entry.Key; Dictionary <string, object> value = (Dictionary <string, object>)entry.Value; Tasks.Task(completion, _feature, "CreateItem", () => CreateObject(index, id, value)); } }
/// <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); } } }
private void ProcessMessage(CompletionTracker completion, IZPushItem item) { if (!_feature.ProcessMessage) { return; } // Check if the message is for the current sequence ChunkIndex?optionalIndex = ChunkIndex.Parse(item.Subject); if (optionalIndex == null) { Logger.Instance.Trace(this, "Not a chunk: {0}", item.Subject); return; } if (optionalIndex.Value.numberOfChunks != CurrentSequence) { // Try to update the current sequence; this message may indicate that it has changed DetermineSequence(); // If it is still not for the current sequence, it's an old message if (optionalIndex.Value.numberOfChunks != CurrentSequence) { Logger.Instance.Trace(this, "Skipping, wrong sequence: {0}", item.Subject); return; } } ChunkIndex index = optionalIndex.Value; // Check if the message is up to date string lastProcessed = GetChunkStateString(index); if (lastProcessed == item.Location) { Logger.Instance.Trace(this, "Already up to date: {0} - {1}", item.Subject, item.Location); return; } // Process it Logger.Instance.Trace(this, "Processing: {0} - {1} - {2}", item.Subject, item.Location, lastProcessed); _feature?.BeginProcessing(); try { if (_feature.ProcessMessageDeleteExisting) { // Delete the old contacts from this chunk using (ISearch <IItem> search = Contacts.Search <IItem>()) { search.AddField(PROP_SEQUENCE, true).SetOperation(SearchOperation.Equal, index.numberOfChunks); search.AddField(PROP_CHUNK, true).SetOperation(SearchOperation.Equal, index.chunk); foreach (IItem oldItem in search.Search()) { Logger.Instance.Trace(this, "Deleting GAB entry: {0}", oldItem.Subject); oldItem.Delete(); } } } // Create the new contacts ProcessChunkBody(completion, item, index); // Update the state SetChunkStateString(index, item.Location); } finally { _feature?.EndProcessing(); } }