Exemplo n.º 1
0
        public override ClientCommandResponse Excecute()
        {
            if (!FolderClass.HasValue)
            {
                var folder = FolderService.GetFolder(StateManager.Credential, FolderId);
                FolderClass = folder.Type == eFolderType.DefaultContacts ? eFolderClass.Contacts : eFolderClass.Email;
            }
            var response = new ClientAddCommandResponse
            {
                FolderClass = FolderClass.Value,
                ClientId    = ClientId
            };

            switch (FolderClass)
            {
            case eFolderClass.Contacts:
                string serverId;
                var    contact = ((ContactAppData)ApplicationData).Contact;

                var serverAddResponse = ContactService.AddContact(StateManager.Credential, contact, out serverId);
                response.Status   = (eSyncStatus)serverAddResponse;
                response.ServerId = serverId;

                if (response.Status == eSyncStatus.Success)
                {
                    #region Load & Save Collection State

                    var collectionState = StateManager.LoadCollectionState((SyncKey)SyncKey, FolderId) ?? new CollectionState();
                    collectionState.AddItem(new SyncItemState {
                        ServerId = serverId, HashKey = ApplicationData.GenerateHash()
                    });

                    StateManager.SaveCollectionState(SyncKey, collectionState);
                    response.ServerId = serverId;

                    #endregion
                }
                break;

            case eFolderClass.Email:
                break;
            }
            return(response);
        }