private void PlaySystemQueueCallback(object obj) { // trace callback TraceHelper.AddMessage(String.Format("Play System Queue Callback: {0}", obj == null ? "null" : "success")); // if the operation was successful, continue the refresh cycle if (obj != null) { // dequeue the current record (which removes it from the queue) RequestQueue.RequestRecord record = RequestQueue.DequeueRequestRecord(RequestQueue.SystemQueue); // parse out request record info and trace the details string typename; string reqtype; string id; string name; RequestQueue.RetrieveRequestInfo(record, out typename, out reqtype, out id, out name); TraceHelper.AddMessage(String.Format("Request details: {0} {1} {2} (id {3})", reqtype, typename, name, id)); // don't need to process the object since the folder will be refreshed at the end // of the cycle anyway // since the operation was successful, continue to drain the queue PlayQueue(RequestQueue.SystemQueue); } else { // refresh cycle interrupted - still need to signal the SyncComplete event if it was set if (SyncComplete != null) SyncComplete(this, new SyncCompleteEventArgs(SyncCompleteArg)); } }
private static void RetrieveRequestInfo(RequestQueue.RequestRecord req, out string typename, out string reqtype, out string id, out string name) { typename = req.BodyTypeName; reqtype = ""; id = ""; name = ""; switch (req.ReqType) { case RequestQueue.RequestRecord.RequestType.Delete: reqtype = "Delete"; id = ((ClientEntity)req.Body).ID.ToString(); name = ((ClientEntity)req.Body).Name; break; case RequestQueue.RequestRecord.RequestType.Insert: reqtype = "Insert"; id = ((ClientEntity)req.Body).ID.ToString(); name = ((ClientEntity)req.Body).Name; break; case RequestQueue.RequestRecord.RequestType.Update: reqtype = "Update"; switch (req.BodyTypeName) { case "Tag": name = ((List <Tag>)req.Body)[0].Name; id = ((List <Tag>)req.Body)[0].ID.ToString(); break; case "Item": name = ((List <Item>)req.Body)[0].Name; id = ((List <Item>)req.Body)[0].ID.ToString(); break; case "Folder": name = ((List <Folder>)req.Body)[0].Name; id = ((List <Folder>)req.Body)[0].ID.ToString(); break; default: name = "(unrecognized entity)"; break; } break; default: reqtype = "Unrecognized"; break; } }
public void PlayQueue(string queueName) { // if user hasn't been set, we cannot sync with the service if (User == null) return; // peek at the first record RequestQueue.RequestRecord record = RequestQueue.GetRequestRecord(queueName); // if the record is null, this means we've processed all the pending changes if (record == null) { // if we were playing the user queue (and are now done), start playing the system queue if (queueName == RequestQueue.UserQueue) { // prepare the system queue for playing (this will catch any FolderID / ItemID discrepancies between server and client $ClientSettings) RequestQueue.PrepareSystemQueueForPlaying(); PlayQueue(RequestQueue.SystemQueue); } else { // retrieve the Service's (now authoritative) data GetUserData(); } return; } // get type name for the record string typename = record.BodyTypeName; // trace playing record TraceHelper.AddMessage(String.Format("Play Queue: {0} {1}", record.ReqType, typename)); PlayQueueCallbackDelegate callbackDelegate = null; switch (queueName) { case RequestQueue.UserQueue: callbackDelegate = new PlayQueueCallbackDelegate(PlayUserQueueCallback); break; case RequestQueue.SystemQueue: callbackDelegate = new PlayQueueCallbackDelegate(PlaySystemQueueCallback); break; default: TraceHelper.AddMessage("PlayQueue: unrecognized queue name " + queueName); return; } // invoke the appropriate web service call based on the record type switch (record.ReqType) { case RequestQueue.RequestRecord.RequestType.Delete: switch (typename) { case "Tag": WebServiceHelper.DeleteTag( User, (Tag)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; case "Item": WebServiceHelper.DeleteItem( User, (Item)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; case "Folder": WebServiceHelper.DeleteFolder( User, (Folder)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; } break; case RequestQueue.RequestRecord.RequestType.Insert: switch (typename) { case "Tag": WebServiceHelper.CreateTag( User, (Tag)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; case "Item": WebServiceHelper.CreateItem( User, (Item)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; case "Folder": WebServiceHelper.CreateFolder( User, (Folder)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; } break; case RequestQueue.RequestRecord.RequestType.Update: switch (typename) { case "Tag": WebServiceHelper.UpdateTag( User, (List<Tag>)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; case "Item": WebServiceHelper.UpdateItem( User, (List<Item>)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; case "Folder": WebServiceHelper.UpdateFolder( User, (List<Folder>)record.Body, callbackDelegate, new NetworkOperationInProgressCallbackDelegate(NetworkOperationInProgressCallback)); break; } break; default: return; } }