Exemplo n.º 1
0
        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;
            }
        }