/// <summary>
 /// Sync data from the server with an invalid sync request which contains additional element.
 /// </summary>
 /// <param name="syncRequest">The request for sync operation.</param>
 /// <param name="addElement">Additional element insert into normal sync request.</param>
 /// <param name="insertTag">Insert tag shows where the additional element should inserted.</param>
 /// <returns>The sync result which is returned from server.</returns>
 public SendStringResponse InvalidSync(SyncRequest syncRequest, string addElement, string insertTag)
 {
     string syncXmlRequest = syncRequest.GetRequestDataSerializedXML();
     string changedSyncXmlRequest = syncXmlRequest.Insert(syncXmlRequest.IndexOf(insertTag, StringComparison.CurrentCulture), addElement);
     SendStringResponse result = this.activeSyncClient.SendStringRequest(CommandName.Sync, null, changedSyncXmlRequest);
     this.VerifyTransport();
     return result;
 }
 /// <summary>
 /// Sync data from the server.
 /// </summary>
 /// <param name="syncRequest">The request for sync operation.</param>
 /// <returns>The sync result which is returned from server.</returns>
 public SyncStore Sync(SyncRequest syncRequest)
 {
     SyncResponse response = this.activeSyncClient.Sync(syncRequest, true);
     Site.Assert.IsNotNull(response, "If the operation is successful, the response should not be null.");
     SyncStore result = Common.LoadSyncResponse(response);
     this.VerifyTransport();
     this.VerifySyncCommand(result);
     this.VerifyWBXMLCapture();
     return result;
 }
        /// <summary>
        /// Synchronizes the changes in a collection between the client and the server by sending SyncRequest object.
        /// </summary>
        /// <param name="request">A SyncRequest object that contains the request information.</param>
        /// <returns>A SyncStore object.</returns>
        public SyncStore Sync(SyncRequest request)
        {
            SyncResponse response = this.activeSyncClient.Sync(request, true);
            Site.Assert.IsNotNull(response, "If the Sync command executes successfully, the response from server should not be null.");
            SyncStore syncStore = Common.LoadSyncResponse(response);
            this.VerifySyncResponse(response, syncStore);
            this.VerifyWBXMLCapture();

            return syncStore;
        }
 /// <summary>
 /// Sync data from the server
 /// </summary>
 /// <param name="syncRequest">Sync command request.</param>
 /// <param name="isResyncNeeded">A bool value indicates whether need to re-sync when the response contains MoreAvailable element.</param>
 /// <returns>The sync result which is returned from server</returns>
 public SyncStore Sync(SyncRequest syncRequest, bool isResyncNeeded)
 {
     SyncResponse response = this.activeSyncClient.Sync(syncRequest, isResyncNeeded);
     this.VerifySyncResponse(response);
     SyncStore result = Common.LoadSyncResponse(response);
     this.VerifyTransport();
     this.VerifySyncResult(result);
     this.VerifyWBXMLCapture();
     return result;
 }
        /// <summary>
        /// Sync data from the server.
        /// </summary>
        /// <param name="syncRequest">A Sync command request.</param>
        /// <returns>A Sync command response returned from the server.</returns>
        public SyncStore Sync(SyncRequest syncRequest)
        {
            SyncResponse response = this.activeSyncClient.Sync(syncRequest, true);
            Site.Assert.IsNotNull(response, "The Sync response should be returned.");
            this.VerifyTransport();
            this.VerifyWBXMLRequirements();

            SyncStore syncResponse = Common.LoadSyncResponse(response);

            foreach (Request.SyncCollection collection in syncRequest.RequestData.Collections)
            {
                if (collection.SyncKey != "0")
                {
                    this.VerifyMessageSyntax();
                    this.VerifySyncCommandResponse(syncResponse);
                }
            }

            return syncResponse;
        }
        public void MSASCMD_S21_TC05_CommonStatusCode_164()
        {
            Site.Assume.AreNotEqual <string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "Status value 164 is not returned when the MS-ASProtocolVersion header is set to 12.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual <string>("14.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "Status value 164 is not returned when the MS-ASProtocolVersion header is set to 14.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region User calls Sync command with option element

            // Set an unsupported Type element value in the BodyPartPreference node
            Request.Options option = new Request.Options
            {
                Items = new object[]
                {
                    new Request.BodyPartPreference()
                    {
                        // As specified in [MS-ASAIRS] section 2.2.2.22.3, only a value of 2 (HTML) SHOULD be used in the Type element of a BodyPartPreference element.
                        // Then '3' is an unsupported Type element value.
                        Type = 3
                    }
                },
                ItemsElementName = new Request.ItemsChoiceType1[] { Request.ItemsChoiceType1.BodyPartPreference }
            };

            SyncRequest syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User1Information.InboxCollectionId);
            this.Sync(syncRequest);

            syncRequest.RequestData.Collections[0].Options = new Request.Options[] { option };
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            SyncResponse syncResponse = this.Sync(syncRequest);

            #endregion

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5412");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5412
            Site.CaptureRequirementIfAreEqual <int>(
                164,
                int.Parse(syncResponse.ResponseData.Status),
                5412,
                @"[In Common Status Codes] [The meaning of the status value 164 is] The BodyPartPreference node (as specified in [MS-ASAIRS] section 2.2.2.7) has an unsupported Type element (as specified in [MS-ASAIRS] section 2.2.2.22.4) value.<98>");
        }
Пример #7
0
        public async Task PublishAsync(SyncRequest publishRequest)
        {
            var data           = JsonConvert.SerializeObject(publishRequest);
            var deliveryResult = await _producer.ProduceAsync(_kafkaOptions.Topic, new Message <Null, string>
            {
                Value = data
            });

            if (deliveryResult.Status == PersistenceStatus.Persisted ||
                deliveryResult.Status == PersistenceStatus.PossiblyPersisted)
            {
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug($"kafka topic message [{_kafkaOptions.Topic}] has been published.");
                }
            }
            else
            {
                _logger.LogError($"kafka topic message [{_kafkaOptions.Topic}] publish failed.");
            }
        }
Пример #8
0
 /// <summary>
 /// 实例化SyncRequest
 /// </summary>
 private static void InstantiateSyncRequest()
 {
     try
     {
         if (ServerConfigs.Count > 0)
         {
             foreach (var serverConfig in ServerConfigs)
             {
                 SyncRequests.Add(serverConfig.Key, new SyncRequest(serverConfig.Value));
             }
         }
         if (SyncRequests.Count > 0)
         {
             DefaultSyncRequest = SyncRequests.FirstOrDefault().Value;
         }
     }
     catch (Exception ex)
     {
         LogTraceHelper.SendLog(string.Format("Message:{0}\r\n\tStackTrace:{1}", ex.Message, ex.StackTrace), "InstantiateSyncRequest", isDebug: true);
     }
 }
        /// <summary>
        /// Synchronizes changes in a collection between the client and the server.
        /// </summary>
        /// <param name="syncRequest">A SyncRequest object that contains the request information.</param>
        /// <returns>The SyncStore result which is returned from server.</returns>
        public SyncStore Sync(SyncRequest syncRequest)
        {
            SyncResponse syncResponse = this.activeSyncClient.Sync(syncRequest, true);
            Site.Assert.IsNotNull(syncResponse, "The Sync response returned from server should not be null.");

            SyncStore syncStore = Common.LoadSyncResponse(syncResponse);

            if (1 == syncStore.CollectionStatus && syncStore.AddElements.Count != 0)
            {
                foreach (Sync addElement in syncStore.AddElements)
                {
                    this.VerifySyncCommandResponse(addElement);
                }
            }

            // Verify related requirements.
            this.VerifyCommonRequirements();
            this.VerifyWBXMLCapture();

            return syncStore;
        }
Пример #10
0
        /// <summary>
        /// Sync calendars from the server
        /// </summary>
        /// <param name="syncRequest">The request for Sync command</param>
        /// <returns>The Sync response which is returned from server</returns>
        public SyncStore Sync(SyncRequest syncRequest)
        {
            SyncResponse response = this.activeSyncClient.Sync(syncRequest, true);

            this.VerifyTransport();
            this.VerifyWBXMLRequirements();

            SyncStore syncResponse = Common.LoadSyncResponse(response);

            for (int i = syncRequest.RequestData.Collections.Length - 1; i >= 0; i--)
            {
                // Only verify the Sync response related calendar element
                if (syncRequest.RequestData.Collections[i].CollectionId == this.calendarId && syncResponse != null)
                {
                    this.VerifyMessageSyntax();
                    this.VerifySyncCommandResponse(syncResponse);
                }
            }

            return(syncResponse);
        }
Пример #11
0
        /// <summary>
        /// 用户分享资源
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse ShareUserResource(SyncRequest request)
        {
            ShareResource submitData   = JsonHelper.DecodeJson <ShareResource>(request.Data);
            HttpClient    myHttpClient = new HttpClient();

            myHttpClient.BaseAddress = new Uri(webapi_url); //webapi_url
            string json    = JsonHelper.DeepEncodeJson(submitData);
            var    content = new StringContent(json, Encoding.UTF8);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = myHttpClient.PostAsync("ResourceShare", content).Result;

            if (response.IsSuccessStatusCode)
            {
                return(SyncResponse.GetResponse(request, response.Content.ReadAsStringAsync().Result));
            }
            else
            {
                return(SyncResponse.GetResponse(request, response.IsSuccessStatusCode));
            }
        }
        /// <summary>
        /// Sync data from the server.
        /// </summary>
        /// <param name="syncRequest">A Sync command request.</param>
        /// <returns>A Sync command response returned from the server.</returns>
        public SyncStore Sync(SyncRequest syncRequest)
        {
            SyncResponse response = this.activeSyncClient.Sync(syncRequest, true);

            Site.Assert.IsNotNull(response, "The Sync response should be returned.");
            this.VerifyTransport();
            this.VerifyWBXMLRequirements();

            SyncStore syncResponse = Common.LoadSyncResponse(response);

            foreach (Request.SyncCollection collection in syncRequest.RequestData.Collections)
            {
                if (collection.SyncKey != "0")
                {
                    this.VerifyMessageSyntax();
                    this.VerifySyncCommandResponse(syncResponse);
                }
            }

            return(syncResponse);
        }
Пример #13
0
        /// <summary>
        /// Delete the specified item.
        /// </summary>
        /// <param name="itemsToDelete">The collection of the items to delete.</param>
        private void DeleteCreatedItems(Collection <CreatedItems> itemsToDelete)
        {
            foreach (CreatedItems itemToDelete in itemsToDelete)
            {
                SyncRequest syncRequest = Common.CreateInitialSyncRequest(itemToDelete.CollectionId);
                DataStructures.SyncStore initSyncResult = this.ASRMAdapter.Sync(syncRequest);
                DataStructures.SyncStore result         = this.SyncChanges(initSyncResult.SyncKey, itemToDelete.CollectionId, false);
                int i = 0;
                if (result.AddElements != null)
                {
                    Request.SyncCollectionDelete[] deletes = new Request.SyncCollectionDelete[result.AddElements.Count];
                    foreach (DataStructures.Sync item in result.AddElements)
                    {
                        foreach (string subject in itemToDelete.ItemSubject)
                        {
                            if (item.Email.Subject.Equals(subject))
                            {
                                Request.SyncCollectionDelete delete = new Request.SyncCollectionDelete
                                {
                                    ServerId = item.ServerId
                                };
                                deletes[i] = delete;
                            }
                        }

                        i++;
                    }

                    Request.SyncCollection syncCollection = TestSuiteHelper.CreateSyncCollection(result.SyncKey, itemToDelete.CollectionId);
                    syncCollection.Commands = deletes;

                    syncRequest = Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection });
                    DataStructures.SyncStore deleteResult = this.ASRMAdapter.Sync(syncRequest);
                    this.Site.Assert.AreEqual <byte>(
                        1,
                        deleteResult.CollectionStatus,
                        "The value of 'Status' should be 1 which indicates the Sync command executes successfully.");
                }
            }
        }
Пример #14
0
        /// <summary>
        /// 获取用户教学地图数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse GetUserTeachMapJsonByWhere(SyncRequest request)
        {
            clr_teachmap submitData = JsonHelper.DecodeJson <clr_teachmap>(request.Data);

            using (var db = new fz_wisdomcampusEntities())
            {
                var map = db.clr_teachmap.FirstOrDefault(m => m.UserID == submitData.UserID && m.BookID == submitData.BookID && m.UnitID == submitData.UnitID);
                if (map == null)
                {
                    HttpClient myHttpClient = new HttpClient();
                    myHttpClient.BaseAddress = new Uri(webapi_url); //webapi_url
                    HttpResponseMessage response = myHttpClient.GetAsync("GetTextBookMap?BookID=" + submitData.BookID + "&unitId=" + submitData.UnitID).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        string json = response.Content.ReadAsStringAsync().Result;
                        if (json.IndexOf("\"[") != -1)
                        {
                            json = json.Substring(1, json.Length - 2);
                        }
                        if (json.Length > 2 && json != "null")
                        {
                            json = json.Replace("/", "").Replace("\\", "");
                            return(SyncResponse.GetResponse(request, json));
                        }
                        else
                        {
                            return(SyncResponse.GetResponse(request, ""));
                        }
                    }
                    else
                    {
                        return(SyncResponse.GetResponse(request, null));
                    }
                }
                else
                {
                    return(SyncResponse.GetResponse(request, map.Map));
                }
            }
        }
Пример #15
0
        private static SyncResponse SyncRequestReceived(SyncRequest req)
        {
            Console.Write("Message received from " + req.IpPort + ": ");
            string resp = "Here is your response!";

            if (req.Data != null)
            {
                string dataString = Encoding.UTF8.GetString(req.Data);
                if (Int32.TryParse(dataString, out int seconds))
                {
                    Console.WriteLine(dataString + " [Responding in " + seconds + " seconds]");
                    resp += "  I waited " + seconds + " seconds to send this to you.";
                    Task.Delay((seconds * 1000)).Wait();
                }
                else
                {
                    Console.WriteLine(dataString);
                }
            }
            else
            {
                Console.WriteLine("[null]");
            }

            if (req.Metadata != null && req.Metadata.Count > 0)
            {
                Console.WriteLine("Metadata:");
                foreach (KeyValuePair <object, object> curr in req.Metadata)
                {
                    Console.WriteLine("  " + curr.Key.ToString() + ": " + curr.Value.ToString());
                }
            }

            Dictionary <object, object> retMetadata = new Dictionary <object, object>();

            retMetadata.Add("foo", "bar");
            retMetadata.Add("bar", "baz");

            return(new SyncResponse(req, retMetadata, resp));
        }
Пример #16
0
        public void RequestSync(SyncRequest sync_request)
        {
            WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

            bool user_wants_intervention = KeyboardTools.IsCTRLDown() || !ConfigurationManager.Instance.ConfigurationRecord.SyncTermsAccepted;

            WPFDoEvents.SetHourglassCursor();

            SafeThreadPool.QueueUserWorkItem(o =>
            {
                //
                // Explicitly instruct the sync info collector to perform a swift scan, which DOES NOT include
                // collecting the precise size of every document in every Qiqqa library (which itself is a *significant*
                // file system load when you have any reasonably large libraries like I do.          [GHo]
                //
                // TODO: fetch and cache document filesizes in the background, so we can improve on the accuracy
                // of our numbers in a future call to this method.
                //
                GlobalSyncDetail global_sync_detail = GenerateGlobalSyncDetail(tally_library_storage_size: false);
                WPFDoEvents.InvokeInUIThread(() =>
                {
                    WPFDoEvents.ResetHourglassCursor();

                    SyncControlGridItemSet scgis = new SyncControlGridItemSet(sync_request, global_sync_detail);
                    scgis.AutoTick();

                    if (scgis.CanRunWithoutIntervention() && !user_wants_intervention)
                    {
                        Sync(scgis);
                    }
                    else
                    {
                        SyncControl sync_control = new SyncControl();
                        sync_control.SetSyncParameters(scgis);
                        sync_control.Show();
                    }
                });
            });
        }
Пример #17
0
        /// <summary>
        /// Synchronizes changes in a collection between the client and the server.
        /// </summary>
        /// <param name="syncRequest">A SyncRequest object that contains the request information.</param>
        /// <returns>The SyncStore result which is returned from server.</returns>
        public SyncStore Sync(SyncRequest syncRequest)
        {
            SyncResponse syncResponse = this.activeSyncClient.Sync(syncRequest, true);

            Site.Assert.IsNotNull(syncResponse, "The Sync response returned from server should not be null.");

            SyncStore syncStore = Common.LoadSyncResponse(syncResponse);

            if (1 == syncStore.CollectionStatus && syncStore.AddElements.Count != 0)
            {
                foreach (Sync addElement in syncStore.AddElements)
                {
                    this.VerifySyncCommandResponse(addElement);
                }
            }

            // Verify related requirements.
            this.VerifyCommonRequirements();
            this.VerifyWBXMLCapture();

            return(syncStore);
        }
        public async Task <SyncRequest> CreateSyncRequestAsync(SynchronizationComponent source, SynchronizationComponent target)
        {
            //get
            var synchronizations = await this.synchronizationRepository.GetSynchronizationsAsync();

            var synchronization = synchronizations.Where(x => x.Component == target && x.UserId == userIdentityContext.UserId).FirstOrDefault();

            var request = new SyncRequest
            {
                Component   = source,
                ComponentId = new Guid(settings.ApplicationId),
                UserId      = userIdentityContext.ExternalId,
                LastSync    = synchronization != null ? synchronization.LastSyncAt : new DateTime(),
            };

            //collect collections to send to update
            //modified on || created on > LastSync

            request = await this.GetCollectionsToSyncAsync(request);

            return(request);
        }
Пример #19
0
        /// <summary>
        /// 更新SelectBook页面操作数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse UpdateInitData(SyncRequest request)
        {
            clr_pageInit submitData = JsonHelper.DecodeJson <clr_pageInit>(request.Data);

            using (var db = new fz_wisdomcampusEntities())
            {
                List <clr_pageInit> list = db.clr_pageInit.Where(p => p.UserID == submitData.UserID && p.AspxName == submitData.AspxName).ToList();
                foreach (var item in list)
                {
                    item.GradeID    = submitData.GradeID;
                    item.ClassID    = submitData.ClassID;
                    item.SubjectID  = submitData.SubjectID;
                    item.EditionID  = submitData.EditionID;
                    item.BookType   = submitData.BookType;
                    item.Stage      = submitData.Stage;
                    item.BookID     = submitData.BookID;
                    item.CreateTime = submitData.CreateTime;
                }
                db.SaveChanges();
                return(SyncResponse.GetResponse(request, true));
            }
        }
        private async Task <SyncRequest> GetCollectionsToSyncAsync(SyncRequest syncRequest)
        {
            syncRequest.Transactions = await this.GetTransactionsToSyncAsync(syncRequest.LastSync);

            syncRequest.Transfers = await this.GetTransfersToSyncAsync(syncRequest.LastSync);

            syncRequest.Accounts = await this.GetAccountsToSyncAsync(syncRequest.LastSync);

            syncRequest.AccountGroups = await this.GetAccountGroupsToSyncAsync(syncRequest.LastSync);

            syncRequest.Users = await this.GetUsersToSyncAsync(syncRequest.LastSync);

            syncRequest.Categories = await this.GetCategoriesToSyncAsync(syncRequest.LastSync);

            syncRequest.Tags = await this.GetTagsToSyncAsync(syncRequest.LastSync);

            syncRequest.ExchangeRates = await this.GetExhangeRatesToSyncAsync();

            syncRequest.Files = await this.GetFilesToSyncAsync(syncRequest.LastSync);

            return(syncRequest);
        }
Пример #21
0
        private SyncResponse UpdateExercises(SyncRequest request)
        {
            clr_exercises submitData = JsonHelper.DecodeJson <clr_exercises>(request.Data);

            using (var db = new fz_wisdomcampusEntities())
            {
                List <clr_exercises> list = db.clr_exercises.Where(e => e.UserID == submitData.UserID).ToList();
                if (list != null)
                {
                    foreach (var item in list)
                    {
                        item.Resources = submitData.Resources;
                    }
                    db.SaveChanges();
                    return(SyncResponse.GetResponse(request, true));
                }
                else
                {
                    return(SyncResponse.GetResponse(request, false));
                }
            }
        }
        public void GetChangesRequest_2ItemsRequested1HasConflict_1IteminChangesRequest()
        {
            // Create non conflicting items
            var conflictItem = new TestItem();
            var item         = new TestItem();


            // Arrange client sync request
            var syncRequest = new SyncRequest <TestItem, Guid> {
                new SyncItem <Guid>(conflictItem), new SyncItem <Guid>(item)
            };

            var             target    = new SyncResult <TestItem, Guid>(_container);
            List <TestItem> conflicts = (List <TestItem>)target.ConflictingItems;

            conflicts.Add(conflictItem);

            target.GetChangesRequest(syncRequest);

            Assert.AreEqual(1, target.ChangesRequest.Count());
            Assert.IsTrue(target.ChangesRequest.Contains(item.Id));
        }
Пример #23
0
        /// <summary>
        /// Update email with invalid data
        /// </summary>
        /// <param name="invalidElement">invalid element send to server</param>
        /// <returns>Update results status code</returns>
        private string UpdateVoiceEmailWithInvalidData(string invalidElement)
        {
            // Switch to user2 mailbox
            this.SwitchUser(this.User2Information, true);

            // Sync changes
            SyncStore initSyncResult   = this.InitializeSync(this.User2Information.InboxCollectionId);
            SyncStore syncChangeResult = this.SyncChanges(initSyncResult.SyncKey, this.User2Information.InboxCollectionId, null);
            string    syncKey          = syncChangeResult.SyncKey;
            string    serverId         = this.User2Information.InboxCollectionId;

            // Create normal Sync change request
            Request.SyncCollectionChange changeData = TestSuiteHelper.CreateSyncChangeData(true, serverId, null, null);
            SyncRequest syncRequest = TestSuiteHelper.CreateSyncChangeRequest(syncKey, this.User2Information.InboxCollectionId, changeData);

            // Calls Sync command to update email with invalid sync request
            string             insertTag = "</ApplicationData>";
            SendStringResponse result    = this.EMAILAdapter.InvalidSync(syncRequest, invalidElement, insertTag);

            // Get status code
            return(TestSuiteHelper.GetStatusCode(result.ResponseDataXML));
        }
Пример #24
0
        /// <summary>
        /// Call Sync command to change a note
        /// </summary>
        /// <param name="syncKey">The sync key</param>
        /// <param name="serverId">The server Id of the note</param>
        /// <param name="changedElements">The changed elements of the note</param>
        /// <returns>Return the sync change result</returns>
        protected SyncStore SyncChange(string syncKey, string serverId, Dictionary <Request.ItemsChoiceType7, object> changedElements)
        {
            Request.SyncCollectionChange change = new Request.SyncCollectionChange
            {
                ServerId        = serverId,
                ApplicationData = new Request.SyncCollectionChangeApplicationData
                {
                    ItemsElementName = new Request.ItemsChoiceType7[changedElements.Count],
                    Items            = new object[changedElements.Count]
                }
            };

            changedElements.Keys.CopyTo(change.ApplicationData.ItemsElementName, 0);
            changedElements.Values.CopyTo(change.ApplicationData.Items, 0);

            List <object> changeData = new List <object> {
                change
            };
            SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(syncKey, this.UserInformation.NotesCollectionId, changeData);

            return(this.NOTEAdapter.Sync(syncRequest, false));
        }
        public void Publish(SyncRequest syncRequest)
        {
            string requestString = JsonHelper.Serialize(syncRequest);

            string path = syncRequest is SendPublishRequest ? "publish" :
                          syncRequest is SendMessageRequest ? "message" : "changes";

            configuration.Entries.Where(entry => !string.IsNullOrEmpty(entry.Url)).ToList().ForEach(nlbEntry =>
            {
                Task.Run(async() =>
                {
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,
                                                                        $"{(nlbEntry.Url.EndsWith('/') ? nlbEntry.Url : nlbEntry.Url + "/")}sapphiresync/{path}");
                    request.Headers.Add("Secret", nlbEntry.Secret);
                    request.Headers.Add("OriginId", configuration.Id);
                    request.Content = new StringContent(requestString);

                    HttpClient client = httpClientFactory.CreateClient();
                    await client.SendAsync(request);
                });
            });
        }
Пример #26
0
        /// <summary>
        /// Builds a initial Sync request by using the specified collection Id.
        /// In order to sync the content of a folder, an initial sync key for the folder MUST be obtained from the server.
        /// The client obtains the key by sending an initial Sync request with a SyncKey element value of zero and the CollectionId element
        /// In general, returns the XML formatted Sync request as follows:
        /// <!--
        /// <?xml version="1.0" encoding="utf-8"?>
        /// <Sync xmlns="AirSync">
        ///   <Collections>
        ///     <Collection>
        ///       <SyncKey>0</SyncKey>
        ///       <CollectionId>5</CollectionId>
        ///     </Collection>
        ///   </Collections>
        /// </Sync>
        /// -->
        /// </summary>
        /// <param name="collectionId">Identify the folder as the collection being synchronized, which can be returned by ActiveSync FolderSync command(Refer to [MS-ASCMD]2.2.3.30.5)</param>
        /// <param name="supported">Specifies which contact and calendar elements in a Sync request are managed by the client and therefore not ghosted.</param>
        /// <returns>Returns the SyncRequest instance</returns>
        internal static SyncRequest InitializeSyncRequest(string collectionId, Request.Supported supported)
        {
            Request.SyncCollection syncCollection = new Request.SyncCollection
            {
                Supported    = supported,
                WindowSize   = "512",
                CollectionId = collectionId,
                SyncKey      = "0"
            };

            List <object> items = new List <object>();
            List <Request.ItemsChoiceType1> itemsElementName = new List <Request.ItemsChoiceType1>
            {
                Request.ItemsChoiceType1.BodyPreference
            };

            items.Add(
                new Request.BodyPreference()
            {
                TruncationSize          = 0,
                TruncationSizeSpecified = false,
                Type             = 2,
                Preview          = 0,
                PreviewSpecified = false,
            });

            Request.Options option = new Request.Options
            {
                Items            = items.ToArray(),
                ItemsElementName = itemsElementName.ToArray()
            };

            syncCollection.Options = new Request.Options[] { option };

            SyncRequest request = Common.CreateSyncRequest(new Request.SyncCollection[] { syncCollection });

            return(request);
        }
Пример #27
0
        public async Task <SyncResponse> Sync(SyncRequest request)
        {
            var now  = DateTime.UtcNow;
            var user = await GetUserAsync(request);

            foreach (var itemId in request.GainedItems)
            {
                var info = await _dbContext.TryGetItemStorageAsync(user.UserId, itemId);

                if (info != null)
                {
                    _dbContext.ItemStorage.Update(info);
                }
                else
                {
                    info = new ItemStorage {
                        ItemId = itemId, UserId = user.UserId, DateNotified = now
                    };
                    _dbContext.ItemStorage.Add(info);
                }
            }

            foreach (var itemId in request.LostItems)
            {
                var info = await _dbContext.TryGetItemStorageAsync(user.UserId, itemId);

                if (info != null)
                {
                    _dbContext.ItemStorage.Remove(info);
                }
            }

            user.LastSync = DateTime.UtcNow;

            await _dbContext.SaveChangesAsync();

            return(new SyncResponse());
        }
        public void Sync()
        {
            try
            {
                var predicate = Predicates.Field <Statistic>(f => f.Synced, Operator.Eq, null);

                GetList(predicate).ToList().ForEach(item =>
                {
                    var syncRequest = new SyncRequest
                    {
                        License     = AppLicenseController.Instance.ActiveLicense.Key,
                        FingerPrint = SecurityUtility.GetMd5Hash(AppConfigUtility.FingerPrint),
                        TimeStamp   = item.TimeStamp,
                        Action      = item.Action,
                        Value       = item.Value.FromJSON <Dictionary <string, string> >()
                    };

                    WebServiceUtility.PostAsync(AppConfigUtility.SyncStatisticUrl, syncRequest.ToJSON());
                    WebServiceUtility.PostAsyncOnComplete += response =>
                    {
                        if (response.Success)
                        {
                            item.Synced = DateTime.Now;
                            Save(item);
                        }
                        else
                        {
                            throw new Exception(response.Message);
                        }
                    };
                });
            }
            catch (Exception ex)
            {
                LogUtility.Log(LogUtility.LogType.SystemError, MethodBase.GetCurrentMethod().Name, ex.Message);
                throw;
            }
        }
Пример #29
0
        /// <summary>
        /// Sync items in the specified folder.
        /// </summary>
        /// <param name="collectionId">The CollectionId of the folder.</param>
        /// <param name="conversationMode">The value of ConversationMode element.</param>
        /// <returns>A SyncStore instance that contains the result.</returns>
        protected SyncStore CallSyncCommand(string collectionId, bool conversationMode)
        {
            // Call initial Sync command.
            SyncRequest syncRequest = Common.CreateInitialSyncRequest(collectionId);

            SyncStore syncStore = this.CONAdapter.Sync(syncRequest);

            // Verify Sync command response.
            Site.Assert.AreEqual <byte>(
                1,
                syncStore.CollectionStatus,
                "If the Sync command executes successfully, the Status in response should be 1.");

            if (conversationMode && Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site) != "12.1")
            {
                syncRequest = TestSuiteHelper.GetSyncRequest(collectionId, syncStore.SyncKey, null, null, true);
            }
            else
            {
                syncRequest = TestSuiteHelper.GetSyncRequest(collectionId, syncStore.SyncKey, null, null, false);
            }

            syncStore = this.CONAdapter.Sync(syncRequest);

            // Verify Sync command response.
            Site.Assert.AreEqual <byte>(
                1,
                syncStore.CollectionStatus,
                "If the Sync command executes successfully, the Status in response should be 1.");

            bool checkSyncStore = syncStore.AddElements != null && syncStore.AddElements.Count != 0;

            Site.Assert.IsTrue(checkSyncStore, "The items should be gotten from the Sync command response.");

            this.LatestSyncKey = syncStore.SyncKey;

            return(syncStore);
        }
Пример #30
0
        private static SyncResponse ClientSyncRequestReceived(SyncRequest req)
        {
            try
            {
                string md5 = BytesToHex(Md5(req.Data));
                if (!md5.Equals(_DataLargeMd5) && !md5.Equals(_DataSmallMd5))
                {
                    Interlocked.Increment(ref _Failure);
                    Console.WriteLine("[client] [sync] Data MD5 validation failed");
                }
                else
                {
                    Interlocked.Increment(ref _Success);
                    // Console.WriteLine("[client] [sync] Data MD5 validation success: " + md5);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            return(new SyncResponse(req, new byte[0]));
        }
        public async Task SynchroniseAsync(SyncRequest syncRequest)
        {
            await this.UpdateUsersAsync(syncRequest.Users);

            await this.UpdateTagsAsync(syncRequest.Tags);

            await this.UpdateCategoriesAsync(syncRequest.Categories);

            await this.UpdateAccountGroupsAsync(syncRequest.AccountGroups);

            await this.UpdateAccountsAsync(syncRequest.Accounts);

            await this.UpdateFilesAsync(syncRequest.Files);

            _tags = (await this.tagRepository.GetAsync()).ToDictionary(x => x.ExternalId, x => x.Id);
            await this.UpdateTransactionsAsync(syncRequest.Transactions);

            await this.UpdateTransfersAsync(syncRequest.Transfers);

            await this.UpdateExchangeRatesAsync(syncRequest.ExchangeRates);

            await this.UpdateLastSyncDateAsync(syncRequest);
        }
        private async Task UpdateLastSyncDateAsync(SyncRequest syncRequest)
        {
            var userId     = (await this.userRepository.GetFirstUserAsync()).Id;
            var syncObject = await this.synchronizationRepository.GetSynchronizationAsync(syncRequest.Component, syncRequest.ComponentId, userId);// syncRequest.UserId)

            if (syncObject != null)
            {
                syncObject.LastSyncAt = DateTime.UtcNow;
                await this.synchronizationRepository.UpdateAsync(syncObject);
            }
            else
            {
                syncObject = new Synchronization
                {
                    LastSyncAt  = DateTime.UtcNow,
                    Component   = syncRequest.Component,
                    ComponentId = syncRequest.ComponentId,
                    UserId      = userId,
                };

                await this.synchronizationRepository.AddSynchronizationAsync(syncObject);
            }
        }
        private async Task UpdateLastSyncDateAsync(SyncRequest syncRequest)
        {
            var userId     = this.userIdentityContext.UserId;
            var syncObject = await this.synchronizationRepository.GetSynchronizationAsync(syncRequest.Component, syncRequest.ComponentId.ToString(), userId);

            if (syncObject != null)
            {
                syncObject.LastSyncAt = DateTime.UtcNow;
                await this.synchronizationRepository.UpdateAsync(syncObject);
            }
            else
            {
                syncObject = new Synchronization
                {
                    LastSyncAt  = DateTime.UtcNow,
                    Component   = syncRequest.Component,
                    ComponentId = syncRequest.ComponentId.ToString(),
                    UserId      = userId,
                };

                await this.synchronizationRepository.AddSynchronizationAsync(syncObject);
            }
        }
Пример #34
0
        /// <summary>
        /// 获取校本资源数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse GetSchoolResourceList(SyncRequest request)
        {
            UserResource  submitData = JsonHelper.DecodeJson <UserResource>(request.Data);
            PageParameter parameter  = JsonHelper.DecodeJson <PageParameter>(request.Data);

            HttpClient myHttpClient = new HttpClient();

            myHttpClient.BaseAddress = new Uri(webapi_url); //webapi_url
            string type;

            if (submitData.ResourceStyle == "0")
            {
                type = "null";
            }
            else
            {
                type = submitData.ResourceStyle;
            }
            HttpResponseMessage response = myHttpClient.GetAsync("GetSchoolResourceList?PageIndex=" + parameter.PageIndex + "&PageSize=" + parameter.PageSize + "&SubjectID=" + submitData.SubjectID + "&Catalogs=" + submitData.Catalogs + "&ResourceStyle=" + type).Result;

            if (response.IsSuccessStatusCode)
            {
                string json = response.Content.ReadAsStringAsync().Result;
                if (json.Length > 2)
                {
                    return(SyncResponse.GetResponse(request, json));
                }
                else
                {
                    return(SyncResponse.GetResponse(request, null));
                }
            }
            else
            {
                return(SyncResponse.GetResponse(request, null));
            }
        }
Пример #35
0
        /// <summary>
        /// Sync changes between client and server
        /// </summary>
        /// <param name="collectionId">Specify the folder collection Id which needs to be synced.</param>
        /// <returns>Return the sync response</returns>
        public SyncStore SyncChanges(string collectionId)
        {
            SyncStore syncResponse;

            int retryCount = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site));
            int waitTime   = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site));
            int counter    = 0;

            do
            {
                Thread.Sleep(waitTime);

                // Sync to get the SyncKey
                SyncStore initializeSyncResponse = this.InitializeSync(collectionId, null);

                // Get the server changes through sync command
                SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(collectionId, initializeSyncResponse.SyncKey, true);
                syncResponse = this.CALAdapter.Sync(syncRequest);
                if (syncResponse != null)
                {
                    if (syncResponse.CollectionStatus == 1)
                    {
                        break;
                    }
                }

                counter++;
            }while (counter < retryCount);

            // Verify sync response
            Site.Assert.AreEqual <byte>(
                1,
                syncResponse.CollectionStatus,
                "If the Sync command executes successfully, the Status in response should be 1.");

            return(syncResponse);
        }
Пример #36
0
        /// <summary>
        /// Add a meeting to the server.
        /// </summary>
        /// <param name="calendarCollectionId">The collectionId of the folder which the item should be added.</param>
        /// <param name="elementsToValueMap">The key and value pairs of common meeting properties.</param>
        private void SyncAddMeeting(string calendarCollectionId, Dictionary <Request.ItemsChoiceType8, object> elementsToValueMap)
        {
            Request.SyncCollectionAddApplicationData applicationData = new Request.SyncCollectionAddApplicationData
            {
                Items            = new object[elementsToValueMap.Count],
                ItemsElementName = new Request.ItemsChoiceType8[elementsToValueMap.Count]
            };

            if (elementsToValueMap.Count > 0)
            {
                elementsToValueMap.Values.CopyTo(applicationData.Items, 0);
                elementsToValueMap.Keys.CopyTo(applicationData.ItemsElementName, 0);
            }

            string      iniSyncKey     = this.GetInitialSyncKey(calendarCollectionId);
            SyncRequest syncAddRequest = TestSuiteHelper.CreateSyncAddRequest(iniSyncKey, calendarCollectionId, applicationData);

            SyncStore syncAddResponse = this.ASAIRSAdapter.Sync(syncAddRequest);

            Site.Assert.AreEqual <int>(
                1,
                int.Parse(syncAddResponse.AddResponses[0].Status),
                "The sync add operation should be successful.");
        }
Пример #37
0
        public void MSASCMD_S19_TC36_Sync_Fetch()
        {
            #region Send a MIME-formatted email to User2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            this.SwitchUser(this.User2Information);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);
            SyncResponse syncResponse = this.CheckEmail(this.User2Information.InboxCollectionId, emailSubject, null);

            #region Fetch the email.
            Request.SyncCollectionFetch appDataFetch = new Request.SyncCollectionFetch
            {
                ServerId = TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject)
            };

            Request.SyncCollection collection = new Request.SyncCollection
            {
                SyncKey = this.LastSyncKey,
                GetChanges = true,
                GetChangesSpecified = true,
                CollectionId = this.User2Information.InboxCollectionId,
                Commands = new object[] { appDataFetch }
            };

            Request.Sync syncRequestData = new Request.Sync { Collections = new Request.SyncCollection[] { collection } };

            SyncRequest syncRequestForFetch = new SyncRequest { RequestData = syncRequestData };
            syncResponse = this.Sync(syncRequestForFetch);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            Response.SyncCollectionsCollectionResponses collectionResponse = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;
            Site.Assert.IsNotNull(collectionResponse, "The responses element should exist in the Sync response.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5433");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5433
            Site.CaptureRequirementIfIsNotNull(
                collectionResponse.Fetch,
                5433,
                @"[In Responses] Element Responses in Sync command response (section 2.2.2.19), the child elements is [Add (section 2.2.3.7.2),] Fetch (section 2.2.3.63.2) (If the operation succeeded.)");
            #endregion
        }
Пример #38
0
        public void MSASCMD_S19_TC41_Sync_MoreThanOneConflicts()
        {
            Request.Options option = new Request.Options
            {
                Items = new object[] { (byte)1, (byte)1 },
                ItemsElementName =
                    new Request.ItemsChoiceType1[] { Request.ItemsChoiceType1.Conflict, Request.ItemsChoiceType1.Conflict }
            };

            Request.SyncCollection collection = new Request.SyncCollection
            {
                Options = new Request.Options[] { option },
                SyncKey = "0",
                CollectionId = this.User1Information.ContactsCollectionId
            };

            Request.Sync syncRequestData = new Request.Sync { Collections = new Request.SyncCollection[] { collection } };

            SyncRequest syncRequest = new SyncRequest { RequestData = syncRequestData };
            SyncResponse syncResponse = this.Sync(syncRequest);

            if (Common.IsRequirementEnabled(2075, this.Site))
            {
                // Add the debug information
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2075");

                // Verify MS-ASCMD requirement: MS-ASCMD_R2075
                Site.CaptureRequirementIfAreEqual<uint>(
                    1,
                    Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)),
                    2075,
                    @"[In Appendix A: Product Behavior] The implementation does not return a protocol status error in response to such a command request [more than one Conflict element as the child of an Options element]. (Exchange 2007 and above follow this behavior.)");
            }
        }
Пример #39
0
        public void MSASCMD_S19_TC52_Sync_Status8()
        {
            #region Send a MIME-formatted email to User2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            this.SwitchUser(this.User2Information);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);
            SyncResponse syncResponse = this.CheckEmail(this.User2Information.InboxCollectionId, emailSubject, null);
            string itemServerId = TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject);

            #region Delete the email form Inbox of User2.
            SyncRequest syncRequest = TestSuiteBase.CreateSyncDeleteRequest(this.LastSyncKey, this.User2Information.InboxCollectionId, itemServerId);
            syncRequest.RequestData.Collections[0].DeletesAsMoves = false;
            syncRequest.RequestData.Collections[0].DeletesAsMovesSpecified = true;
            syncResponse = this.Sync(syncRequest);
            #endregion

            #region Fetch the email.
            Request.SyncCollectionFetch appDataFetch = new Request.SyncCollectionFetch
            {
                ServerId = itemServerId
            };

            Request.SyncCollection collection = new Request.SyncCollection
            {
                SyncKey = this.LastSyncKey,
                GetChanges = true,
                GetChangesSpecified = true,
                CollectionId = this.User2Information.InboxCollectionId,
                Commands = new object[] { appDataFetch }
            };

            Request.Sync syncRequestData = new Request.Sync { Collections = new Request.SyncCollection[] { collection } };

            SyncRequest syncRequestForFetch = new SyncRequest { RequestData = syncRequestData };
            syncResponse = this.Sync(syncRequestForFetch);
            Response.SyncCollectionsCollectionResponses collectionResponse = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Responses) as Response.SyncCollectionsCollectionResponses;

            this.Site.CaptureRequirementIfAreEqual<int>(
                8,
                int.Parse(collectionResponse.Fetch.Status),
                4447,
                @"[In Status(Sync)] [When the scope is Item], [the cause of the status value 8 is] The client issued a fetch [or change] operation that has a CollectionId (section 2.2.3.30.5) value that is no longer valid on the server (for example, the item was deleted).");

            #endregion
        }
Пример #40
0
        public void MSASCMD_S19_TC34_Sync_DeletesAsMovesIsTrue()
        {
            #region Send a MIME-formatted email to User2.
            string emailSubject1 = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject1, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            this.SwitchUser(this.User2Information);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject1);

            // Check DeletedItems folder
            SyncRequest syncRequest = TestSuiteBase.CreateEmptySyncRequest(this.User2Information.DeletedItemsCollectionId);
            this.Sync(syncRequest);
            syncRequest.RequestData.Collections[0].SyncKey = this.LastSyncKey;
            SyncResponse syncResponse = this.Sync(syncRequest);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject1), "The email should not be found in the DeletedItems folder.");

            // Check Inbox folder
            syncResponse = this.CheckEmail(this.User2Information.InboxCollectionId, emailSubject1, null);
            string serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject1);
            Site.Assert.IsNotNull(serverId, "The email should be found in the inbox folder.");

            #region Delete the email with DeletesAsMoves set to true from the Inbox folder.
            Request.SyncCollection collection = new Request.SyncCollection
            {
                SyncKey = this.LastSyncKey,
                CollectionId = this.User2Information.InboxCollectionId,
                Commands = new object[] { new Request.SyncCollectionDelete { ServerId = serverId } },
                DeletesAsMoves = true,
                DeletesAsMovesSpecified = true
            };

            Request.Sync syncRequestData = new Request.Sync { Collections = new Request.SyncCollection[] { collection } };

            SyncRequest syncRequestDelete = new SyncRequest { RequestData = syncRequestData };
            syncResponse = this.Sync(syncRequestDelete);
            Site.Assert.AreEqual<uint>(1, Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)), "The Sync delete operation should be successful.");
            #endregion

            #region Verify if the email has been deleted from the Inbox folder and placed into the DeletedItems folder.
            // Check Inbox folder.
            syncResponse = this.SyncChanges(this.User2Information.InboxCollectionId, false);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject1), "The email deleted should not be found in the Inbox folder.");
            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject1);

            // Check DeletedItems folder
            this.CheckEmail(this.User2Information.DeletedItemsCollectionId, emailSubject1, null);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.DeletedItemsCollectionId, emailSubject1);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2160");

            // Verify MS-ASCMD requirement: MS-ASCMD_R2160
            // When the Assert statements above are passed, it means the deleted email is moved from the inbox folder to Deleted Items folder, then this requirement can be  captured directly.
            Site.CaptureRequirement(
                2160,
                @"[In DeletesAsMoves] A value of 1 (TRUE), which is the default, indicates that any deleted items are moved to the Deleted Items folder.");
            #endregion

            #region Send a MIME-formatted email to User2.
            this.SwitchUser(this.User1Information);
            string emailSubject2 = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject2, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            this.SwitchUser(this.User2Information);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject1);

            // Check DeletedItems folder
            syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject2), "The email should not be found in the DeletedItems folder.");

            // Check Inbox folder
            syncResponse = this.CheckEmail(this.User2Information.InboxCollectionId, emailSubject2, null);
            serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject2);
            Site.Assert.IsNotNull(serverId, "The email should be found in the inbox folder.");

            #region Delete the email and DeletesAsMoves is not present in the request
            collection = new Request.SyncCollection
            {
                SyncKey = this.LastSyncKey,
                CollectionId = this.User2Information.InboxCollectionId,
                Commands = new object[] { new Request.SyncCollectionDelete { ServerId = serverId } }
            };

            syncRequestData = new Request.Sync { Collections = new Request.SyncCollection[] { collection } };

            syncRequestDelete = new SyncRequest { RequestData = syncRequestData };
            syncResponse = this.Sync(syncRequestDelete);
            Site.Assert.AreEqual<uint>(1, Convert.ToUInt32(TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Status)), "The Sync delete operation should be successful.");

            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject1);
            #endregion

            #region Verify if the second email has been deleted from the Inbox folder and placed into the DeletedItems folder.
            // Check Inbox folder
            syncResponse = this.SyncChanges(this.User2Information.InboxCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject2), "The deleted email should not be found in the Inbox folder.");

            // Check DeletedItems folder
            syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNotNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject2), "The deleted email should be found in the DeletedItems folder.");

            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject1);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.DeletedItemsCollectionId, emailSubject1, emailSubject2);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5874");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5874
            // When the Assert statements above are passed, it means the deleted email is moved from the inbox folder to Deleted Items folder, then this requirement can be  captured directly.
            Site.CaptureRequirement(
                5874,
                @"[In DeletesAsMoves] If element DeleteAsMoves is empty, the delete items are moved to the Deleted Items folder.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5875");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5875
            // When the Assert statements above are passed, it means the deleted email is moved from the inbox folder to Deleted Items folder, then this requirement can be  captured directly.
            Site.CaptureRequirement(
                5875,
                @"[In DeletesAsMoves] If element DeleteAsMoves is not present, the delete items are moved to the Deleted Items folder.");
            #endregion
        }
Пример #41
0
        public void MSASCMD_S19_TC05_Sync_Status4()
        {
            SyncRequest syncRequest = new SyncRequest();
            SyncResponse syncResponse = this.Sync(syncRequest);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4430");

            // Verify MS-ASCMD requirement: MS-ASCMD_R4430
            Site.CaptureRequirementIfAreEqual<int>(
                4,
                int.Parse(syncResponse.ResponseData.Status),
                4430,
                @"[In Status(Sync)] [When the scope is Item], [the cause the status value 4 is] There was a semantic error in the synchronization request.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4431");

            // Verify MS-ASCMD requirement: MS-ASCMD_R4431
            Site.CaptureRequirementIfAreEqual<int>(
                4,
                int.Parse(syncResponse.ResponseData.Status),
                4431,
                @"[In Status(Sync)] [When the scope is Item], [the cause of the status value 4 is] The client is issuing a request that does not comply with the specification requirements.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5778");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5778
            Site.CaptureRequirementIfAreEqual<int>(
                4,
                int.Parse(syncResponse.ResponseData.Status),
                5778,
                @"[In Status(Sync)] [When the scope is Global], [the cause the status value 4 is] There was a semantic error in the synchronization request.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5779");

            // Verify MS-ASCMD requirement: MS-ASCMD_R5779
            Site.CaptureRequirementIfAreEqual<int>(
                4,
                int.Parse(syncResponse.ResponseData.Status),
                5779,
                @"[In Status(Sync)] [When the scope is Global], [the cause of the status value 4 is] The client is issuing a request that does not comply with the specification requirements.");

            #region Add a contact item to the recipient information cache.
            string contactFileAS = Common.GenerateResourceName(Site, "FileAS");
            Request.SyncCollectionAdd addData = this.CreateAddContactCommand("FirstName", "MiddleName", "LastName", contactFileAS, null);
            syncRequest = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.RecipientInformationCacheCollectionId, addData);
            syncResponse = this.Sync(syncRequest);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R756");

            // Verify MS-ASCMD requirement: MS-ASCMD_R756
            Site.CaptureRequirementIfAreEqual<int>(
                4,
                int.Parse(syncResponse.ResponseData.Status),
                756,
                @"[In Add(Sync)] If a client attempts to add an item to the recipient information cache, a Status element with a value of 4 is returned as a child of the Sync element.");
            #endregion
        }
Пример #42
0
        public void MSASCMD_S19_TC06_Sync_Status13()
        {
            SyncResponse syncResponse = this.Sync(TestSuiteBase.CreateEmptySyncRequest(this.User1Information.InboxCollectionId));
            Site.Assert.AreEqual<string>("1", this.GetStatusCode(syncResponse.ResponseDataXML), "The Status value of the Sync command should be 1, when the RequestData element in the Sync command request is not null.");

            // Synchronize the changes with a request, of which the request data are null.
            SyncRequest syncRequest = new SyncRequest { RequestData = null };
            syncResponse = this.Sync(syncRequest, false);

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4456");

            // Verify MS-ASCMD requirement: MS-ASCMD_R4456
            Site.CaptureRequirementIfAreEqual<int>(
                13,
                int.Parse(syncResponse.ResponseData.Status),
                4456,
                @"[In Status(Sync)] [When the scope is Item], [the cause of the status value 13 is] An empty or partial Sync command request is received and the cached set of notify-able collections is missing.");
        }
Пример #43
0
        /// <summary>
        /// Synchronizes changes in a collection between the client and the server.
        /// </summary>
        /// <param name="request">A SyncRequest object that contains the request information.</param>
        /// <param name="isResyncNeeded">A boolean value indicate whether need to re-sync when the response contains MoreAvailable.</param>
        /// <returns>The Sync command response.</returns>
        protected SyncResponse Sync(SyncRequest request, bool isResyncNeeded = true)
        {
            SyncResponse response = this.CMDAdapter.Sync(request, isResyncNeeded);

            // Get the SyncKey returned in the last Sync command response.
            if (response != null
                && response.ResponseData != null
                && response.ResponseData.Item != null)
            {
                Response.SyncCollections syncCollections = response.ResponseData.Item as Response.SyncCollections;
                if (syncCollections != null)
                {
                    foreach (Response.SyncCollectionsCollection syncCollection in syncCollections.Collection)
                    {
                        for (int i = 0; i < syncCollection.ItemsElementName.Length; i++)
                        {
                            if (syncCollection.ItemsElementName[i] == Response.ItemsChoiceType10.SyncKey)
                            {
                                this.LastSyncKey = syncCollection.Items[i] as string;
                            }
                        }
                    }
                }
            }
            else
            {
                this.LastSyncKey = null;
            }

            return response;
        }
        /// <summary>
        /// Find an email with specific subject.
        /// </summary>
        /// <param name="syncRequest">A SyncRequest object that contains the request information.</param>
        /// <param name="subject">The subject of the email to find.</param>
        /// <param name="isRetryNeeded">A boolean indicating whether need retry.</param>
        /// <returns>The email with specific subject.</returns>
        public Sync SyncEmail(SyncRequest syncRequest, string subject, bool isRetryNeeded)
        {
            Sync syncResult = this.activeSyncClient.SyncEmail(syncRequest, subject, isRetryNeeded);
            Site.Assert.IsNotNull(syncResult, "If the Sync command executes successfully, the response from server should not be null.");

            return syncResult;
        }
        public void MSASCAL_S01_TC33_DeletePropertyOfException()
        {
            Site.Assume.IsTrue(Common.IsRequirementEnabled(2242, this.Site), "Exchange 2007 does not support deleting elements of a recurring calendar item in an Exception element.");
            Site.Assume.AreNotEqual<string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The recurring calendar item cannot be created when protocol version is set to 16.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Call Sync command to add a calendar to the server, and sync calendars from the server.

            Dictionary<Request.ItemsChoiceType8, object> calendarItem = new Dictionary<Request.ItemsChoiceType8, object>();

            DateTime exceptionStartTime = this.StartTime.AddDays(3);

            // Set Calendar StartTime, EndTime elements
            calendarItem.Add(Request.ItemsChoiceType8.StartTime, this.StartTime.ToString("yyyyMMddTHHmmssZ"));
            calendarItem.Add(Request.ItemsChoiceType8.EndTime, this.EndTime.ToString("yyyyMMddTHHmmssZ"));

            // Set Calendar Recurrence element including Occurrence sub-element
            byte recurrenceType = byte.Parse("0");
            Request.Recurrence recurrence = this.CreateCalendarRecurrence(recurrenceType, 6, 1);

            // Set Calendar Exceptions element
            Request.Exceptions exceptions = new Request.Exceptions { Exception = new Request.ExceptionsException[] { } };
            List<Request.ExceptionsException> exceptionList = new List<Request.ExceptionsException>();

            // Set ExceptionStartTime element in exception
            Request.ExceptionsException exception = TestSuiteHelper.CreateExceptionRequired(exceptionStartTime.ToString("yyyyMMddTHHmmssZ"));

            exception.Subject = "Calendar Exception";
            exception.Location = "Room 666";
            exceptionList.Add(exception);
            exceptions.Exception = exceptionList.ToArray();

            calendarItem.Add(Request.ItemsChoiceType8.Recurrence, recurrence);
            calendarItem.Add(Request.ItemsChoiceType8.Exceptions, exceptions);
            calendarItem.Add(Request.ItemsChoiceType8.Location, this.Location);

            string emailAddress = Common.GetMailAddress(this.User2Information.UserName, this.User2Information.UserDomain);
            calendarItem.Add(Request.ItemsChoiceType8.Attendees, TestSuiteHelper.CreateAttendeesRequired(new string[] { emailAddress }, new string[] { this.User2Information.UserName }));
            calendarItem.Add(Request.ItemsChoiceType8.MeetingStatus, (byte)1);
            if (!this.IsActiveSyncProtocolVersion121)
            {
                calendarItem.Add(Request.ItemsChoiceType8.ResponseRequested, true);
                calendarItem.Add(Request.ItemsChoiceType8.DisallowNewTimeProposal, true);
            }

            string subject = Common.GenerateResourceName(Site, "subject");
            calendarItem.Add(Request.ItemsChoiceType8.Subject, subject);

            this.AddSyncCalendar(calendarItem);

            SyncItem calendar = this.GetChangeItem(this.User1Information.CalendarCollectionId, subject);

            Site.Assert.IsNotNull(calendar.Calendar, "The calendar with subject {0} should exist in server.", subject);
            this.RecordCaseRelativeItems(this.User1Information.UserName, this.User1Information.CalendarCollectionId, subject);
            #endregion

            #region Call Sync command to delete the Location property of the exception to change the calendar, and sync calendars from the server.

            SyncStore syncResponse1 = this.InitializeSync(this.User1Information.CalendarCollectionId, null);
            SyncRequest syncRequest = TestSuiteHelper.CreateSyncRequest(this.User1Information.CalendarCollectionId, syncResponse1.SyncKey, true);
            SyncStore syncResponse2 = this.CALAdapter.Sync(syncRequest);

            // Delete Location property of the Exception
            Dictionary<Request.ItemsChoiceType7, object> changeItem = new Dictionary<Request.ItemsChoiceType7, object>();
            exception.Location = null;
            changeItem.Add(Request.ItemsChoiceType7.Exceptions, exceptions);
            changeItem.Add(Request.ItemsChoiceType7.Recurrence, recurrence);
            changeItem.Add(Request.ItemsChoiceType7.Subject, subject);
            Request.SyncCollectionChangeApplicationData syncChangeData = new Request.SyncCollectionChangeApplicationData
            {
                ItemsElementName = changeItem.Keys.ToArray<Request.ItemsChoiceType7>(),
                Items = changeItem.Values.ToArray<object>()
            };

            Request.SyncCollectionChange syncChange = new Request.SyncCollectionChange
            {
                ApplicationData = syncChangeData,
                ServerId = calendar.ServerId
            };

            SyncRequest syncChangeRequest = new SyncRequest
            {
                RequestData = new Request.Sync { Collections = new Request.SyncCollection[1] }
            };

            syncChangeRequest.RequestData.Collections[0] = new Request.SyncCollection
            {
                Commands = new object[] { syncChange },
                SyncKey = syncResponse2.SyncKey,
                CollectionId = this.User1Information.CalendarCollectionId
            };

            // If an element in a recurring calendar item has been deleted in an Exception element, sends an empty tag
            // for this element to remove the inherited value from the server.
            string syncXmlRequest = syncChangeRequest.GetRequestDataSerializedXML();
            string changedSyncXmlRequest = syncXmlRequest.Insert(syncXmlRequest.IndexOf("</Exception>", StringComparison.CurrentCulture), "<Location />");
            SendStringResponse result = this.CALAdapter.SendStringRequest(changedSyncXmlRequest);

            #endregion

            #region Call Sync command to get the changed calendar.

            SyncStore initializeSyncResponse = this.InitializeSync(this.User1Information.CalendarCollectionId, null);
            syncRequest = TestSuiteHelper.CreateSyncRequest(this.User1Information.CalendarCollectionId, initializeSyncResponse.SyncKey, true);
            result = this.CALAdapter.SendStringRequest(syncRequest.GetRequestDataSerializedXML());

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(result.ResponseDataXML);
            XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(doc.NameTable);
            nameSpaceManager.AddNamespace("e", "AirSync");
            XmlNodeList nodes = doc.SelectNodes("//e:Collections/e:Collection/e:Commands/e:Add/e:ApplicationData", nameSpaceManager);
            bool isEmptyLocationContained = false;
            foreach (XmlNode node in nodes)
            {
                bool isFound = false;
                XmlNodeList subNodes = node.ChildNodes;
                foreach (XmlNode subNode in subNodes)
                {
                    if (subNode.Name.Equals("Subject") && subNode.InnerText != null && subNode.InnerText.Equals(subject))
                    {
                        isFound = true;
                    }
                    if (isFound && subNode.Name.Equals("Exceptions"))
                    {
                        isEmptyLocationContained = subNode.InnerXml.Contains("<Location />");
                        break;
                    }
                }
                if (isEmptyLocationContained)
                {
                    break;
                }
            }

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCAL_R2242");

            // Verify MS-ASCAL requirement: MS-ASCAL_R2242
            Site.CaptureRequirementIfIsTrue(
                isEmptyLocationContained,
                2242,
                @"[In Appendix B: Product Behavior]  If an element in a recurring calendar item has been deleted in an Exception element (section 2.2.2.19), the client sends an empty tag for this element to remove the inherited value from the implementation. (Exchange 2010 and above follow this behavior.)");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCAL_R539");

            // Verify MS-ASCAL requirement: MS-ASCAL_R539
            Site.CaptureRequirementIfIsTrue(
                isEmptyLocationContained,
                539,
                @"[In Sync Command Response] If one or more properties of an exception for recurring calendar item (that is, any child elements of the Exception element (section 2.2.2.19)) have been deleted, the server MUST transmit an empty element in the Sync command response to indicate that this property is not inherited from the recurrence.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCAL_R543");

            // Verify MS-ASCAL requirement: MS-ASCAL_R543
            Site.CaptureRequirementIfIsTrue(
                isEmptyLocationContained,
                543,
                @"[In Indicating Deleted Elements in Exceptions] If an element of a recurring calendar item has been deleted in an Exception element (section 2.2.2.19), the server MUST send an empty tag for this element in the Sync command response ([MS-ASCMD] section 2.2.2.19).");

            #endregion
        }
Пример #46
0
        public void MSASCMD_S19_TC35_Sync_DeletesAsMovesIsFalse()
        {
            #region Send a MIME-formatted email to User2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            this.SwitchUser(this.User2Information);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);

            SyncResponse syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject), "The email should not be found in the DeletedItems folder.");

            syncResponse = this.GetMailItem(this.User2Information.InboxCollectionId, emailSubject);
            Site.Assert.IsNotNull(syncResponse.ResponseData.Item, "The items returned in the Sync command response should not be null.");

            string serverId = TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject);
            Site.Assert.IsTrue(!string.IsNullOrEmpty(serverId), "The email should be found in the Inbox folder.");

            #region Delete the added email item.
            Request.SyncCollectionDelete appDataDelete = new Request.SyncCollectionDelete { ServerId = serverId };

            Request.SyncCollection collection = new Request.SyncCollection
            {
                SyncKey = this.LastSyncKey,
                GetChanges = true,
                CollectionId = this.User2Information.InboxCollectionId,
                Commands = new object[] { appDataDelete },
                DeletesAsMoves = false,
                DeletesAsMovesSpecified = true
            };

            Request.Sync syncRequestData = new Request.Sync { Collections = new Request.SyncCollection[] { collection } };

            SyncRequest syncRequestDelete = new SyncRequest { RequestData = syncRequestData };
            this.Sync(syncRequestDelete);
            #endregion

            #region Verify if the email has been deleted from the Inbox folder and not placed into the DeletedItems folder.
            syncResponse = this.SyncChanges(this.User2Information.InboxCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject), "The email deleted should not be found in the Inbox folder.");
            TestSuiteBase.RemoveRecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);

            syncResponse = this.SyncChanges(this.User2Information.DeletedItemsCollectionId);
            Site.Assert.IsNull(TestSuiteBase.FindServerId(syncResponse, "Subject", emailSubject), "The email deleted should not be found in the DeletedItems folder.");

            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2158");

            // Verify MS-ASCMD requirement: MS-ASCMD_R2158
            // If the deleted email can not be found in both Inbox and Deleted Items folder, this requirement can be captured directly.
            Site.CaptureRequirement(
                2158,
                @"[In DeletesAsMoves] If the DeletesAsMoves element is set to false, the deletion is permanent.");
            #endregion
        }
        /// <summary>
        /// Build a Sync command request.
        /// </summary>
        /// <param name="syncKey">The current sync key.</param>
        /// <param name="collectionId">The collection id which to sync with.</param>
        /// <param name="commands">The sync commands.</param>
        /// <param name="bodyPreferences">The bodyPreference in the options element.</param>
        /// <param name="bodyPartPreferences">The bodyPartPreference in the options element.</param>
        /// <returns>A Sync command request.</returns>
        internal static SyncRequest CreateSyncRequest(string syncKey, string collectionId, object[] commands, Request.BodyPreference[] bodyPreferences, Request.BodyPartPreference[] bodyPartPreferences)
        {
            SyncRequest request = new SyncRequest
            {
                RequestData =
                {
                    Collections = new Request.SyncCollection[]
                    {
                        new Request.SyncCollection()
                        {
                            SyncKey = syncKey,
                            CollectionId = collectionId
                        }
                    }
                }
            };

            request.RequestData.Collections[0].Commands = commands;

            List<object> items = new List<object>();
            List<Request.ItemsChoiceType1> itemsElementName = new List<Request.ItemsChoiceType1>();

            if (bodyPreferences != null)
            {
                foreach (Request.BodyPreference bodyPreference in bodyPreferences)
                {
                    items.Add(bodyPreference);
                    itemsElementName.Add(Request.ItemsChoiceType1.BodyPreference);

                    // Include the MIMESupport element in request to retrieve the MIME body
                    if (bodyPreference.Type == 4)
                    {
                        items.Add((byte)2);
                        itemsElementName.Add(Request.ItemsChoiceType1.MIMESupport);
                    }
                }
            }

            if (bodyPartPreferences != null)
            {
                foreach (Request.BodyPartPreference bodyPartPreference in bodyPartPreferences)
                {
                    items.Add(bodyPartPreference);
                    itemsElementName.Add(Request.ItemsChoiceType1.BodyPartPreference);
                }
            }

            if (items.Count > 0)
            {
                request.RequestData.Collections[0].Options = new Request.Options[]
                {
                    new Request.Options()
                    {
                        ItemsElementName = itemsElementName.ToArray(),
                        Items = items.ToArray()
                    }
                };
            }

            return request;
        }
Пример #48
0
 /// <summary>
 /// Creates an empty Sync request
 /// </summary>
 /// <returns>A SyncRequest instance</returns>
 public static SyncRequest CreateSyncRequest()
 {
     SyncRequest requestTemp = new SyncRequest { RequestData = new Request.Sync() };
     return requestTemp;
 }
        /// <summary>
        /// Synchronizes the changes in a collection between the client and the server by sending SyncRequest object.
        /// </summary>
        /// <param name="syncRequest">A SyncRequest object that contains the request information.</param>
        /// <returns>A SyncStore object.</returns>
        public SyncStore Sync(SyncRequest syncRequest)
        {
            SyncResponse response = this.activeSyncClient.Sync(syncRequest, true);
            Site.Assert.IsNotNull(response, "If the Sync command executes successfully, the response from server should not be null.");

            SyncStore syncResult = Common.LoadSyncResponse(response);
            return syncResult;
        }
Пример #50
0
 /// <summary>
 ///  Creates a Sync request using the specified SyncCollection array
 /// </summary>
 /// <param name="syncCollections">Specified SyncCollection array</param>
 /// <returns>A SyncRequest instance</returns>
 public static SyncRequest CreateSyncRequest(Request.SyncCollection[] syncCollections)
 {
     SyncRequest requestTemp = new SyncRequest();
     Request.Sync requestData = new Request.Sync();
     requestTemp.RequestData = requestData;
     requestTemp.RequestData.Collections = syncCollections;
     return requestTemp;
 }
Пример #51
0
        /// <summary>
        /// Call Sync command to change a task.
        /// </summary>
        /// <param name="syncKey">The sync key.</param>
        /// <param name="serverId">The server Id of the task.</param>
        /// <param name="changedElements">The changed elements of the task.</param>
        /// <returns>Return the sync change result.</returns>
        protected SyncStore SyncChangeTask(string syncKey, string serverId, Dictionary<Request.ItemsChoiceType7, object> changedElements)
        {
            Request.SyncCollectionChange change = new Request.SyncCollectionChange
            {
                ServerId = serverId,
                ApplicationData = new Request.SyncCollectionChangeApplicationData
                {
                    Items = changedElements.Values.ToArray<object>(),
                    ItemsElementName = changedElements.Keys.ToArray<Request.ItemsChoiceType7>()
                }
            };

            SyncRequest syncRequest = new SyncRequest
            {
                RequestData = new Request.Sync { Collections = new Request.SyncCollection[1] }
            };
            syncRequest.RequestData.Collections[0] = new Request.SyncCollection
            {
                Commands = new object[] { change },
                SyncKey = syncKey,
                CollectionId = this.UserInformation.TasksCollectionId
            };
            SyncStore syncResponse = this.TASKAdapter.Sync(syncRequest);

            return syncResponse;
        }
Пример #52
0
        /// <summary>
        /// Call sync command to update properties of an existing calendar item.
        /// </summary>
        /// <param name="serverId">Server Id of the calendar item.</param>
        /// <param name="collectionId">Collection Id of the folder that calendar item is contained in.</param>
        /// <param name="syncKey">Sync key value.</param>
        /// <param name="items">The dictionary store calendar item's element name and element value, which will be changed.</param>
        /// <returns>Return Sync Change response.</returns>
        public SyncStore UpdateCalendarProperty(string serverId, string collectionId, string syncKey, Dictionary<Request.ItemsChoiceType7, object> items)
        {
            Request.SyncCollectionChangeApplicationData syncChangeData = new Request.SyncCollectionChangeApplicationData
            {
                ItemsElementName = items.Keys.ToArray<Request.ItemsChoiceType7>(),
                Items = items.Values.ToArray<object>()
            };

            Request.SyncCollectionChange syncChange = new Request.SyncCollectionChange
            {
                ApplicationData = syncChangeData,
                ServerId = serverId
            };

            SyncRequest syncChangeRequest = new SyncRequest
            {
                RequestData = new Request.Sync { Collections = new Request.SyncCollection[1] }
            };

            syncChangeRequest.RequestData.Collections[0] = new Request.SyncCollection
            {
                Commands = new object[] { syncChange },
                SyncKey = syncKey,
                CollectionId = collectionId
            };

            SyncStore syncChanageResponse = this.CALAdapter.Sync(syncChangeRequest);
            return syncChanageResponse;
        }
        /// <summary>
        /// Find an email with specific subject.
        /// </summary>
        /// <param name="syncRequest">A SyncRequest object that contains the request information.</param>
        /// <param name="subject">The subject of the email to find.</param>
        /// <param name="isRetryNeeded">A boolean whether need retry.</param>
        /// <returns>The email with specific subject.</returns>
        public Sync SyncEmail(SyncRequest syncRequest, string subject, bool isRetryNeeded)
        {
            Sync syncResult = this.activeSyncClient.SyncEmail(syncRequest, subject, isRetryNeeded);

            // Verify related requirements.
            this.VerifyCommonRequirements();
            this.VerifyWBXMLCapture();

            // If the email should be gotten, then verify the related requirements.
            if (isRetryNeeded)
            {
                this.VerifySyncCommandResponse(syncResult);
            }

            return syncResult;
        }