public void MSASCMD_S06_TC01_GetAttachment_Success()
        {
            Site.Assume.AreNotEqual <string>("14.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual <string>("14.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 14.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            Site.Assume.AreNotEqual <string>("16.0", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The GetAttachment command is not supported when the MS-ASProtocolVersion header is set to 16.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Send a mail with normal attachment
            string subject = Common.GenerateResourceName(Site, "NormalAttachment_Subject");
            string body    = Common.GenerateResourceName(Site, "NormalAttachment_Body");
            this.SendEmailWithAttachment(subject, body);
            #endregion

            this.SwitchUser(this.User2Information);
            SyncResponse syncResponse = this.GetMailItem(this.User2Information.InboxCollectionId, subject);
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, subject);

            Response.AttachmentsAttachment[] attachments = this.GetEmailAttachments(syncResponse, subject);
            Site.Assert.IsTrue(attachments != null && attachments.Length == 1, "The email should contain a single attachment.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R5501
            // The attachment name in the sent email is "number1.jpg", so if there is only one attachment in the email and the attachment name is matched, this requirement can be covered.
            Site.CaptureRequirementIfAreEqual <string>(
                "number1.jpg",
                attachments[0].DisplayName,
                5501,
                @"[In GetAttachment] Instead, an Attachment element ([MS-ASAIRS] section 2.2.2.2) is included for each attachment.");

            #region Call GetAttachment command to fetch attachment
            string attachmentFileReference = attachments[0].FileReference;
            IDictionary <CmdParameterName, object> parameters = new Dictionary <CmdParameterName, object>();
            parameters.Add(CmdParameterName.AttachmentName, attachmentFileReference);

            GetAttachmentRequest request = new GetAttachmentRequest();
            request.SetCommandParameters(parameters);
            GetAttachmentResponse response = this.CMDAdapter.GetAttachment(request);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R157
            // The GetAttachment command response data xml only contains the size information of the attachment, if it is not null and includes the size information, this requirement can be covered.
            bool isVerifyR157 = !string.IsNullOrEmpty(response.ResponseDataXML) && Convert.ToInt32(response.ResponseDataXML) > 0;
            Site.CaptureRequirementIfIsTrue(
                isVerifyR157,
                157,
                @"[In GetAttachment] The GetAttachment command retrieves an email attachment from the server.<2>");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R160
            // In ExchangeCommonConfiguration.deployment.ptfconfig, HTTP/HTTPS has been specified, so GetAttachment command is issued within the HTTP POST command.
            Site.CaptureRequirement(
                160,
                @"[In GetAttachment] This command [GetAttachment] is issued within the HTTP POST command.");
            #endregion
        }
Beispiel #2
0
        /// <summary>
        /// Throws if there are errors in the response.
        /// </summary>
        /// <param name="syncResponse">The synchronize response.</param>
        /// <exception cref="System.AggregateException">Command execution exception.</exception>
        private void ThrowIfErrors(SyncResponse syncResponse)
        {
            LinkedList <TodoistException> exceptions = null;

            foreach (var syncStatus in syncResponse.SyncStatus)
            {
                var dynamicStatus = syncStatus.Value;
                var type          = dynamicStatus.GetType();

                // an "ok" string which signals success of the command
                if (type == typeof(string) || dynamicStatus.error_code == null)
                {
                    continue;
                }

                if (exceptions == null)
                {
                    exceptions = new LinkedList <TodoistException>();
                }

                exceptions.AddLast(
                    new TodoistException((int)dynamicStatus.error_code, dynamicStatus.error.ToString(), dynamicStatus));
            }

            if (exceptions?.Any() == true)
            {
                throw new AggregateException(exceptions);
            }
        }
        public void MSASCMD_S21_TC04_CommonStatusCode_105()
        {
            Site.Assume.AreNotEqual <string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The DstFldId element is not supported when the MS-ASProtocolVersion header is set to 12.1. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region User2 sends mail to User1 and do FolderSync in User1's mailbox.
            string subject = this.SendMailAndFolderSync();
            #endregion

            #region Call method Sync to synchronize changes of Inbox folder in User1's mailbox between the client and the server, and get the ServerId of sent email item and the SyncKey
            SyncResponse syncResponseInbox = this.GetMailItem(this.User1Information.InboxCollectionId, subject);
            string       serverId          = TestSuiteBase.FindServerId(syncResponseInbox, "Subject", subject);
            #endregion

            #region Call method MoveItems with the email item's ServerId to move the email item from Inbox folder to recipient information cache.
            Request.MoveItemsMove moveItemsMove = new Request.MoveItemsMove
            {
                DstFldId = this.User1Information.RecipientInformationCacheCollectionId,
                SrcFldId = this.User1Information.InboxCollectionId,
                SrcMsgId = serverId
            };

            MoveItemsRequest  moveItemsRequest  = Common.CreateMoveItemsRequest(new Request.MoveItemsMove[] { moveItemsMove });
            MoveItemsResponse moveItemsResponse = this.CMDAdapter.MoveItems(moveItemsRequest);
            #endregion

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R4821
            Site.CaptureRequirementIfAreEqual <int>(
                105,
                int.Parse(moveItemsResponse.ResponseData.Response[0].Status),
                4821,
                @"[In Common Status Codes] [The meaning of the status value 105 is] The request contains a combination of parameters that is invalid.");
        }
Beispiel #4
0
        public async Task Render()
        {
            await Prepare();

            RenderNode node = manager.GetNodeByName(THIS_NAME);

            long         lastFileChange = new FileInfo(BLEND_FILE).LastWriteTime.Ticks;
            SyncResponse respSync       = null;

            using (FileStream stream = new FileStream(BLEND_FILE, FileMode.Open))
                respSync = await node.SyncFile(SESSION, lastFileChange, stream, Compression.Raw);
            Assert.IsTrue(respSync.Success);


            RenderResponse respRender = await node.Render(new RenderRequest()
            {
                FileID    = lastFileChange,
                SessionID = SESSION,
                TaskID    = "Whatever",
                Version   = BLEND_VERSION,
                Settings  = new Shared.RenderPacketModel()
                {
                    Width   = 640,
                    Height  = 360,
                    Samples = 8
                }
            });

            Assert.IsTrue(respRender.Success);
            File.WriteAllBytes($"{RESULTS_DIRECTORY}/Test.Render.png", respRender.Data);
            Assert.IsTrue(respRender.Data != null && respRender.Data.Length > 0);
            //Check equality
        }
Beispiel #5
0
        /// <summary>
        /// Add a meeting or appointment to server
        /// </summary>
        /// <param name="calendar">the calendar item</param>
        private void SyncAddCalendar(Calendar calendar)
        {
            Request.SyncCollectionAddApplicationData applicationData = SetApplicationDataFromCalendar(calendar);

            this.GetInitialSyncResponse(this.User1Information.CalendarCollectionId);
            Request.SyncCollectionAdd addCalendar = new Request.SyncCollectionAdd
            {
                ClientId        = TestSuiteBase.ClientId,
                ApplicationData = applicationData
            };

            SyncRequest  syncAddCalendarRequest  = TestSuiteBase.CreateSyncAddRequest(this.LastSyncKey, this.User1Information.CalendarCollectionId, addCalendar);
            SyncResponse syncAddCalendarResponse = this.CMDAdapter.Sync(syncAddCalendarRequest);

            // Get data from response
            Response.SyncCollections syncCollections = (Response.SyncCollections)syncAddCalendarResponse.ResponseData.Item;
            Response.SyncCollectionsCollectionResponses syncResponses = null;
            for (int index = 0; index < syncCollections.Collection[0].ItemsElementName.Length; index++)
            {
                if (syncCollections.Collection[0].ItemsElementName[index] == Response.ItemsChoiceType10.Responses)
                {
                    syncResponses = (Response.SyncCollectionsCollectionResponses)syncCollections.Collection[0].Items[index];
                    break;
                }
            }

            Site.Assert.AreEqual(1, syncResponses.Add.Length, "User only upload one calendar item");
            int statusCode = int.Parse(syncResponses.Add[0].Status);

            Site.Assert.AreEqual(1, statusCode, "If upload calendar item successful, server should return status 1");
        }
        public void Sync_Null_Items()
        {
            Mock <ITodoist>        todoist        = new Mock <ITodoist>();
            Mock <ITodoistStorage> todoistStorage = new Mock <ITodoistStorage>();

            ConfigurationSettings configurationSettings = new ConfigurationSettings()
            {
                DatabasePath  = "Todoist",
                TodoistApiUrl = "https://todoist.com/api/v7/sync",
                Token         = "4238b2aba013852a793f55e6bca4825332cda0dd"
            };

            Mock <ItemsViewModel> itemsViewModel = new Mock <ItemsViewModel>(todoist.Object, todoistStorage.Object, configurationSettings)
            {
                CallBase = true
            };

            var          syncToken    = "syncToken";
            var          newSyncToken = "newSyncToken";
            SyncResponse syncResponse = new SyncResponse()
            {
                full_sync  = false,
                sync_token = newSyncToken
            };

            itemsViewModel.Setup(m => m.GetSyncToken()).Returns(syncToken).Verifiable();

            itemsViewModel.Setup(m => m.SyncItems(syncToken)).Returns(syncResponse).Verifiable();

            itemsViewModel.Object.Sync();
        }
Beispiel #7
0
        /// <summary>
        /// 检查备课中的资源
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse CheckPreLessonResource(SyncRequest request)
        {
            Resource submitData = JsonHelper.DecodeJson <Resource>(request.Data);
            UserInfo userDate   = JsonHelper.DecodeJson <UserInfo>(request.Data);

            string[] resourceArr = submitData.ResourceID.Split(',');

            bool result = false;

            foreach (var item in resourceArr)
            {
                using (var db = new fz_wisdomcampusEntities())
                {
                    IList <clr_preLesson> preLessonlist = db.clr_preLesson.Where(p => p.PreLessonContent.Contains(item) && p.UserID == userDate.UserID).ToList();
                    if (preLessonlist != null && preLessonlist.Count != 0)
                    {
                        result = true;
                    }
                    IList <clr_teachmap> maplist = db.clr_teachmap.Where(m => m.Map.Contains(item) && m.UserID == userDate.UserID).ToList();
                    if (maplist != null && maplist.Count != 0)
                    {
                        result = true;
                    }
                }
            }
            return(SyncResponse.GetResponse(request, result));
        }
        private void BroadcastDisconnect()
        {
            var response = new SyncResponse(SyncResponse.ResponseTypes.Disconnect);

            response.Data = new { Reason = "Admin stopped server." };
            this.Broadcast(response.ToString());
        }
Beispiel #9
0
        /// <summary>
        /// This method is used to check the Add element in Sync response.
        /// </summary>
        /// <param name="syncKey">The sync key</param>
        /// <param name="collectionId">Folder's collectionID</param>
        /// <param name="subject">The subject of item which is expected to add</param>
        /// <returns>The boolean value which indicates the Add element is found in Sync response or not</returns>
        private bool CheckAddInSyncResponse(string syncKey, string collectionId, string subject)
        {
            SyncResponse syncResponse = syncKey != null
                ? this.SyncChanges(syncKey, collectionId)
                : this.SyncChanges(collectionId);

            Response.SyncCollectionsCollectionCommands commands = this.GetCommandsFromSyncResponse(syncResponse);

            if (commands == null || commands.Add == null)
            {
                return(false);
            }
            else
            {
                Site.Assert.IsNotNull(commands.Add, "The Add element in Sync response for collection ID: {0} should not be null", collectionId);
            }

            foreach (Response.SyncCollectionsCollectionCommandsAdd add in commands.Add)
            {
                Site.Assert.IsNotNull(add, "The Add element in Sync response for collection ID: {0} should not be null", collectionId);
                for (int i = 0; i < add.ApplicationData.Items.Length; i++)
                {
                    if (add.ApplicationData.ItemsElementName[i] == Response.ItemsChoiceType8.Subject1)
                    {
                        if (subject.Equals(add.ApplicationData.Items[i].ToString()))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #10
0
        /// <summary>
        /// 获取资源地址
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse GetResourceUrlByFileID(SyncRequest request)
        {
            UserResource submitData   = JsonHelper.DecodeJson <UserResource>(request.Data);
            HttpClient   myHttpClient = new HttpClient();

            myHttpClient.BaseAddress = new Uri(webapi_url); //webapi_url
            HttpResponseMessage response = myHttpClient.GetAsync("ResourcePreview?id=" + submitData.FileID).Result;

            if (response.IsSuccessStatusCode)
            {
                string json = response.Content.ReadAsStringAsync().Result;
                if (json.IndexOf("http") != -1)
                {
                    return(SyncResponse.GetResponse(request, json));
                }
                else
                {
                    return(SyncResponse.GetResponse(request, false));
                }
            }
            else
            {
                return(SyncResponse.GetResponse(request, null));
            }
        }
Beispiel #11
0
        public void MSASCMD_S10_TC04_MoveItems_Status2()
        {
            #region User2 sends mail to User1 and does FolderSync in User1's mailbox.
            string subject = this.SendMailAndFolderSync();
            #endregion

            #region Call method Sync to synchronize changes of Inbox folder in User1's mailbox between the client and the server.
            SyncResponse syncResponse = this.GetMailItem(this.User1Information.InboxCollectionId, subject);
            string       serverId     = TestSuiteBase.FindServerId(syncResponse, "Subject", subject);
            #endregion

            #region Call method MoveItems with the email item's ServerId to move the email item from Inbox folder to an invalid destination folder.
            MoveItemsRequest  moveItemsRequest  = TestSuiteBase.CreateMoveItemsRequest(serverId, this.User1Information.InboxCollectionId, "Invalid DstFldId");
            MoveItemsResponse moveItemsResponse = this.CMDAdapter.MoveItems(moveItemsRequest);

            this.CheckMoveItemsResponse(moveItemsResponse, 1);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R4212
            Site.CaptureRequirementIfAreEqual <int>(
                2,
                int.Parse(moveItemsResponse.ResponseData.Response[0].Status),
                4212,
                @"[In Status(MoveItems)] [When the scope is Item], [the cause of the status value 2 is] The destination folder collection ID (CollectionId element value) is not recognized by the server, possibly because the source folder has been deleted.");
            #endregion
        }
Beispiel #12
0
        public void MSASCMD_S10_TC05_MoveItems_Status4()
        {
            #region User2 sends mail to User1 and does FolderSync in User1's mailbox.
            string subject = this.SendMailAndFolderSync();
            #endregion

            #region Call method Sync to synchronize changes of Inbox folder in User1's mailbox between the client and the server.
            SyncResponse syncResponse = this.GetMailItem(this.User1Information.InboxCollectionId, subject);
            string       serverId     = TestSuiteBase.FindServerId(syncResponse, "Subject", subject);
            #endregion

            #region Call method MoveItems with the email item's ServerId to move the email item from Inbox folder to Inbox folder.
            MoveItemsRequest  moveItemsRequest  = TestSuiteBase.CreateMoveItemsRequest(serverId, this.User1Information.InboxCollectionId, this.User1Information.InboxCollectionId);
            MoveItemsResponse moveItemsResponse = this.CMDAdapter.MoveItems(moveItemsRequest);

            this.CheckMoveItemsResponse(moveItemsResponse, 1);

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R4219
            Site.CaptureRequirementIfAreEqual <int>(
                4,
                int.Parse(moveItemsResponse.ResponseData.Response[0].Status),
                4219,
                @"[In Status(MoveItems)] [When the scope is Item], [the cause of the status value 4 is] The client supplied a destination folder that is the same as the source.");
            #endregion
        }
Beispiel #13
0
        private static void SendAndWait()
        {
            string userInput = InputString("Data:", null, false);
            int    timeoutMs = InputInteger("Timeout (milliseconds):", 5000, true, false);
            Dictionary <object, object> metadata = new Dictionary <object, object>();

            metadata.Add("foo", "bar");

            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                SyncResponse resp = _Client.SendAndWait(timeoutMs, userInput, metadata);
                stopwatch.Stop();
                if (resp.Metadata != null && resp.Metadata.Count > 0)
                {
                    Console.WriteLine("Metadata:");
                    foreach (KeyValuePair <object, object> curr in resp.Metadata)
                    {
                        Console.WriteLine("  " + curr.Key.ToString() + ": " + curr.Value.ToString());
                    }
                }

                Console.WriteLine("Response: " + Encoding.UTF8.GetString(resp.Data));
                Console.WriteLine("Server responded in {0} ms/{1} ticks.", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.ToString());
            }
        }
Beispiel #14
0
        private static void SendAndWaitEmpty()
        {
            int timeoutMs = InputInteger("Timeout (milliseconds):", 5000, true, false);

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

            dict.Add("foo", "bar");

            try
            {
                SyncResponse resp = _Client.SendAndWait(timeoutMs, "", dict);
                if (resp.Metadata != null && resp.Metadata.Count > 0)
                {
                    Console.WriteLine("Metadata:");
                    foreach (KeyValuePair <object, object> curr in resp.Metadata)
                    {
                        Console.WriteLine("  " + curr.Key.ToString() + ": " + curr.Value.ToString());
                    }
                }

                Console.WriteLine("Response: " + Encoding.UTF8.GetString(resp.Data));
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.ToString());
            }
        }
        private void FailRegistration(UserContext context, string message)
        {
            var response = new SyncResponse(SyncResponse.ResponseTypes.Connect);

            response.Data = new { Success = false, Message = message };
            this.Reply(context, response);
        }
Beispiel #16
0
        public async Task SyncCompressed()
        {
            await BasicConnect();

            RenderNode node = manager.GetNodeByName(THIS_NAME);

            long lastFileChange = new FileInfo(BLEND_FILE).LastWriteTime.Ticks;

            SyncResponse resp = null;

            using (MemoryStream str = new MemoryStream())
                using (GZipStream zip = new GZipStream(str, CompressionMode.Compress))
                    using (FileStream stream = new FileStream(BLEND_FILE, FileMode.Open))
                    {
                        byte[] buffer = new byte[4096];
                        int    read   = 0;
                        while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            zip.Write(buffer, 0, read);
                        }

                        str.Seek(0, SeekOrigin.Begin);
                        resp = await node.SyncFile(SESSION, lastFileChange, str, Compression.GZip);
                    }
            Assert.IsTrue(resp.Success);
        }
Beispiel #17
0
        private static void ServerTask()
        {
            for (int i = 0; i < _NumIterations; i++)
            {
                int waitVal = _Random.Next(0, 12);
                Task.Delay(waitVal).Wait();
                if (waitVal % 3 == 0)
                {
                    Console.WriteLine("[server] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Sending large message");
                    _Server.Send(_ClientIpPort, _DataLargeBytes);
                }
                else if (waitVal % 2 == 0)
                {
                    Console.WriteLine("[server] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Sending small message");
                    _Server.Send(_ClientIpPort, _DataSmallBytes);
                }
                else
                {
                    Console.WriteLine("[server] " + (i + 1).ToString() + "/" + _NumIterations.ToString() + " Send and wait small message");
                    try
                    {
                        SyncResponse syncResponse = _Server.SendAndWait(_ClientIpPort, _SendAndWaitInterval, _DataSmallBytes);
                        Console.WriteLine("[server] Sync response received");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("[server] Sync response not received: " + e.Message);
                    }
                }
            }

            Console.WriteLine("[server] Finished");
        }
        private void HandleCameraSyncProposal(UserContext context, SyncCommand command)
        {
            // Client requests OTHER clients to sync to his camera
            // Re-send data to clients
            var users = command.Data.Users.ToObject <List <User> >();
            //var users = (List<User>)JsonConvert.DeserializeObject<List<User>>(command.Data.Users.ToString());

            var response = new SyncResponse(SyncResponse.ResponseTypes.ProposeSyncCameras);

            response.Data = command.Data;
            var responseString = response.ToString();

            foreach (var user in users)
            {
                var conn = FindConnection(user);
                if (conn != null && conn.ClientAddress == context.ClientAddress.ToString())
                {
                    continue;                                                                         // skip requesting user
                }
                if (conn != null)
                {
                    conn.Context.Send(responseString);
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// 获取基础数据地址
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse GetUrlStr(SyncRequest request)
        {
            UrlModel submitData = JsonHelper.DecodeJson <UrlModel>(request.Data);
            string   url        = ConfigurationManager.AppSettings[submitData.Type].ToString();

            return(SyncResponse.GetResponse(request, url));
        }
Beispiel #20
0
        private SyncResponse DeletePreLessonResource(SyncRequest request)
        {
            PreLessonContent preLessonContent = new PreLessonContent();
            clr_preLesson    submitData       = JsonHelper.DecodeJson <clr_preLesson>(request.Data);
            PreLessonBtn     submitDataBtn    = JsonHelper.DecodeJson <PreLessonBtn>(request.Data);

            using (var db = new fz_wisdomcampusEntities())
            {
                List <clr_preLesson> prelessonList = db.clr_preLesson.Where(p => p.UserID == submitData.UserID).ToList();
                foreach (var prelesson in prelessonList)
                {
                    preLessonContent = JsonHelper.DecodeJson <PreLessonContent>(prelesson.PreLessonContent);
                    for (int i = preLessonContent.btns.Count - 1; i >= 0; i--)
                    {
                        if (submitDataBtn.sourceUrl.IndexOf(preLessonContent.btns[i].sourceUrl) != -1)
                        {
                            preLessonContent.btns.Remove(preLessonContent.btns[i]);
                        }
                    }
                    string jsonContent = JsonHelper.DeepEncodeJson(preLessonContent);
                    prelesson.PreLessonContent = jsonContent;
                    prelesson.CreateDate       = DateTime.Now;
                    db.SaveChanges();
                }
                return(SyncResponse.GetResponse(request, true));
            }
        }
Beispiel #21
0
        private static void SendAndWait()
        {
            string ipPort    = InputString("IP:port:", lastIpPort, false);
            string userInput = InputString("Data:", null, false);
            int    timeoutMs = InputInteger("Timeout (milliseconds):", 5000, true, false);

            try
            {
                SyncResponse resp = server.SendAndWait(ipPort, timeoutMs, userInput);
                if (resp.Metadata != null && resp.Metadata.Count > 0)
                {
                    Console.WriteLine("Metadata:");
                    foreach (KeyValuePair <object, object> curr in resp.Metadata)
                    {
                        Console.WriteLine("  " + curr.Key.ToString() + ": " + curr.Value.ToString());
                    }
                }

                Console.WriteLine("Response: " + Encoding.UTF8.GetString(resp.Data));
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.ToString());
            }
        }
Beispiel #22
0
        /// <summary>
        /// 保存用户最后的操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private SyncResponse SavsUserFinallyOperationRecord(SyncRequest request)
        {
            clr_pageInit submitData = JsonHelper.DecodeJson <clr_pageInit>(request.Data);

            using (var db = new fz_wisdomcampusEntities())
            {
                clr_pageInit page = db.clr_pageInit.FirstOrDefault(p => p.UserID == submitData.UserID && p.AspxName == "Common");
                if (page != null)
                {
                    page.BookType  = submitData.BookType;
                    page.Stage     = submitData.Stage;
                    page.GradeID   = submitData.GradeID;
                    page.SubjectID = submitData.SubjectID;
                    page.EditionID = submitData.EditionID;
                    page.BookID    = submitData.BookID;
                    page.UnitID    = submitData.UnitID;
                    page.PageNum   = submitData.PageNum;
                    db.SaveChanges();
                }
                else
                {
                    submitData.PageInitID = Guid.NewGuid().ToString();
                    submitData.CreateTime = DateTime.Now;
                    submitData.AspxName   = "Common";
                    db.clr_pageInit.Add(submitData);
                    db.SaveChanges();
                }
                return(SyncResponse.GetResponse(request, true));
            }
        }
Beispiel #23
0
        public JsonResult <SyncResponse> Get()
        {
            var products = GenerateProducts();
            var response = new SyncResponse(Header, products, DateTime.Now.ToUnixTimestamp());

            return(Json(response));
        }
Beispiel #24
0
        public void MSASCMD_S17_TC02_SmartForward_Fail()
        {
            Site.Assume.AreNotEqual <string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "The AccountID element is not supported 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), "The AccountID element is not supported when the MS-ASProtocolVersion header is set to 14.0. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");
            #region Call SendMail command to send one plain text email messages to user2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            #region Call Sync command to sync user2 mailbox changes
            this.SwitchUser(this.User2Information);
            SyncResponse syncChangeResponse = this.GetMailItem(this.User2Information.InboxCollectionId, emailSubject);
            string       originalServerId   = TestSuiteBase.FindServerId(syncChangeResponse, "Subject", emailSubject);
            #endregion

            #region Record user name, folder collectionId and item subject that are used in this case
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);
            #endregion

            #region Call SmartForward command to forward messages without retrieving the full, original message from the server
            // Create invalid SmartForward request
            SmartForwardRequest smartForwardRequest = new SmartForwardRequest
            {
                RequestData = new Request.SmartForward
                {
                    ClientId = System.Guid.NewGuid().ToString(),
                    Source   = new Request.Source
                    {
                        FolderId = this.User2Information.InboxCollectionId,
                        ItemId   = originalServerId
                    },
                    Mime      = string.Empty,
                    AccountId = "InvalidValueAccountID"
                }
            };

            smartForwardRequest.SetCommandParameters(new Dictionary <CmdParameterName, object>
            {
                {
                    CmdParameterName.CollectionId, this.User2Information.InboxCollectionId
                },
                {
                    CmdParameterName.ItemId, "5:" + originalServerId
                }
            });

            SmartForwardResponse smartForwardResponse = this.CMDAdapter.SmartForward(smartForwardRequest);
            #endregion

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R4408
            // If SmartForward operation failed, server will return Status element in response, then MS-ASCMD_4408 is verified.
            Site.CaptureRequirementIfIsNotNull(
                smartForwardResponse.ResponseData.Status,
                4408,
                @"[In Status(SmartForward and SmartReply)] If the SmartForward command request [or SmartReply command request] fails, the Status element contains a code that indicates the type of failure.");
        }
        internal byte[] CreateCalendarEvent(string clientId, string syncKey, out string newSyncKey, string folderId, Event theEvent, IList <Event> exceptionalEvents, IList <string> deletedOccurrences, UserSmtpAddress userSmtpAddress)
        {
            SyncRequest  syncRequest  = EasRequestGenerator.CreateSyncRequestForCreateCalendarEvent(syncKey, clientId, folderId, theEvent, exceptionalEvents, deletedOccurrences, userSmtpAddress);
            SyncResponse syncResponse = this.SyncCreation(clientId, syncRequest);

            newSyncKey = syncResponse.Collections[0].SyncKey;
            return(EasMailbox.GetEntryId(syncResponse.AddResponses[0].ServerId));
        }
Beispiel #26
0
 public void Sync(SyncResponse syncResponse)
 {
     foreach (var objectData in syncResponse.objects)
     {
         var workspaceObject = new WorkspaceObject(this, syncResponse, objectData);
         this.workspaceObjectById[workspaceObject.Id] = workspaceObject;
     }
 }
Beispiel #27
0
        public void MSASCMD_S17_TC07_SmartForward_ReplaceMime()
        {
            Site.Assume.AreNotEqual <string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "ReplaceMime is not support when MS-ASProtocolVersion header is set to 12.1.MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion.");

            #region Call SendMail command to send plain text email messages to user2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            string emailBody    = Common.GenerateResourceName(Site, "NormalAttachment_Body");
            this.SendEmailWithAttachment(emailSubject, emailBody);
            #endregion

            #region Call Sync command to sync user2 mailbox changes
            this.SwitchUser(this.User2Information);
            SyncResponse syncChangeResponse = this.GetMailItem(this.User2Information.InboxCollectionId, emailSubject);
            string       originalServerID   = TestSuiteBase.FindServerId(syncChangeResponse, "Subject", emailSubject);
            string       originalContent    = TestSuiteBase.GetDataFromResponseBodyElement(syncChangeResponse, originalServerID);
            Response.AttachmentsAttachment[] originalAttachments = this.GetEmailAttachments(syncChangeResponse, emailSubject);
            Site.Assert.IsTrue(originalAttachments != null && originalAttachments.Length == 1, "The email should contain a single attachment.");

            #endregion

            #region Record user name, folder collectionId and item subject that are used in this case
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);
            #endregion

            #region Call SmartForward command to forward messages with ReplaceMime.
            string forwardSubject = string.Format("FW:{0}", emailSubject);
            SmartForwardRequest smartForwardRequest = this.CreateDefaultForwardRequest(originalServerID, forwardSubject, this.User2Information.InboxCollectionId);
            smartForwardRequest.RequestData.ReplaceMime = string.Empty;
            SmartForwardResponse smartForwardResponse = this.CMDAdapter.SmartForward(smartForwardRequest);
            #endregion

            #region After user2 forwarded email to user3, sync user3 mailbox changes
            this.SwitchUser(this.User3Information);
            SyncResponse syncForwardResult   = this.GetMailItem(this.User3Information.InboxCollectionId, forwardSubject);
            string       forwardItemServerID = TestSuiteBase.FindServerId(syncForwardResult, "Subject", forwardSubject);
            string       forwardItemContent  = TestSuiteBase.GetDataFromResponseBodyElement(syncForwardResult, forwardItemServerID);
            Response.AttachmentsAttachment[] forwardAttachments = this.GetEmailAttachments(syncForwardResult, forwardSubject);
            #endregion

            #region Record user name, folder collectionId and item subject that are used in this case
            TestSuiteBase.RecordCaseRelativeItems(this.User3Information, this.User3Information.InboxCollectionId, forwardSubject);
            #endregion

            // Compare original content with forward content
            bool isContained = forwardItemContent.Contains(originalContent);

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

            Site.Assert.IsNull(
                forwardAttachments,
                @"The attachment should not be returned");

            Site.CaptureRequirementIfIsFalse(
                isContained,
                3775,
                @"[In ReplaceMime] When the ReplaceMime element is present, the server MUST not include the body or attachments of the original message being forwarded.");
        }
        public void MSASCMD_S18_TC02_SmartReply_Success()
        {
            #region Call SendMail command to send one plain text email to user2.
            string emailSubject = Common.GenerateResourceName(Site, "subject");
            this.SendPlainTextEmail(null, emailSubject, this.User1Information.UserName, this.User2Information.UserName, null);
            #endregion

            #region Call Sync command to sync user2 mailbox changes
            this.SwitchUser(this.User2Information);
            SyncResponse syncChangeResponse = this.GetMailItem(this.User2Information.InboxCollectionId, emailSubject);
            string       originalServerId   = TestSuiteBase.FindServerId(syncChangeResponse, "Subject", emailSubject);
            #endregion

            #region Record user name, folder collectionId and item subject that are useed in this case
            TestSuiteBase.RecordCaseRelativeItems(this.User2Information, this.User2Information.InboxCollectionId, emailSubject);
            #endregion

            #region Call SmartReply command to reply to messages without retrieving the full, original message from the server
            string            smartReplySubject = string.Format("REPLY: {0}", emailSubject);
            SmartReplyRequest smartReplyRequest = this.CreateDefaultReplyRequest(smartReplySubject, originalServerId);

            SmartReplyResponse smartReplyResponse = this.CMDAdapter.SmartReply(smartReplyRequest);

            #endregion

            #region Call Sync command to sync user1 mailbox changes
            this.SwitchUser(this.User1Information);
            this.GetMailItem(this.User1Information.InboxCollectionId, smartReplySubject);
            #endregion

            #region Record user name, folder collectionId and item subject that are useed in this case
            TestSuiteBase.RecordCaseRelativeItems(this.User1Information, this.User1Information.InboxCollectionId, smartReplySubject);
            #endregion

            #region Verify Requirements MS-ASCMD_R605, MS-ASCMD_R5776
            // Add the debug information
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R605");

            // Verify MS-ASCMD requirement: MS-ASCMD_R605
            // If the message was sent successfully, the server won't return any XML data, then MS-ASCMD_R605 is verified.
            Site.CaptureRequirementIfAreEqual <string>(
                string.Empty,
                smartReplyResponse.ResponseDataXML,
                605,
                @"[In SmartReply] If the message was sent successfully, the server returns an empty response.");

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

            // Verify MS-ASCMD requirement: MS-ASCMD_R5776
            // If the message was sent successfully, the server won't return any XML data, then MS-ASCMD_R776 is verified.
            Site.CaptureRequirementIfAreEqual <string>(
                string.Empty,
                smartReplyResponse.ResponseDataXML,
                5776,
                @"[In Status(SmartForward and SmartReply)] If the [SmartForward command request or] SmartReply command request succeeds, no XML body is returned in the response.");
            #endregion
        }
Beispiel #29
0
        /// <summary>
        /// Sync data from the server.
        /// </summary>
        /// <param name="syncRequest">The request for Sync command.</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 command is successful, the response should not be null.");
            SyncStore result = Common.LoadSyncResponse(response);

            return(result);
        }
        /// <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 bool value indicate whether need to re-sync when the response contains MoreAvailable.</param>
        /// <returns>Sync command response</returns>
        public SyncResponse Sync(SyncRequest request, bool isResyncNeeded = true)
        {
            SyncResponse response = this.activeSyncClient.Sync(request, isResyncNeeded);

            this.VerifyTransportRequirements();
            this.VerifyWBXMLCapture(CommandName.Sync, response);
            this.VerifySyncCommand(response);
            return(response);
        }
        /// <summary>
        /// Convert the instance of SendStringResponse to SyncResponse.
        /// </summary>
        /// <param name="syncResponseString">The SendStringResponse instance to convert.</param>
        /// <returns>The instance of SyncResponse.</returns>
        public static SyncResponse ConvertSyncResponseFromSendString(ActiveSyncResponseBase<object> syncResponseString)
        {
            SyncResponse syncResponse = new SyncResponse
            {
                ResponseDataXML = syncResponseString.ResponseDataXML,
                Headers = syncResponseString.Headers
            };

            syncResponse.DeserializeResponseData();

            return syncResponse;
        }
 private void HandleUserlist(SyncResponse response)
 {
     var users = (List<User>) JsonConvert.DeserializeObject<List<User>>(response.Data.Users.ToString());
     _dispatcher.Invoke(() => this.UpdateUsers(users));
 }
        private void HandleStateUpdate(SyncResponse response)
        {
            _state = (SyncState) JsonConvert.DeserializeObject<SyncState>(response.Data.State.ToString());
            Debug.WriteLine(">> Received state update: " + _state);

            // Save state
            SaveState(_state);

            // Copy settings that come from the server
            OfftrackHistory.OfftrackLimit = _state.OfftrackLimit;

            this.OnStateUpdated();
        }
 private void HandleServerDisconnect(SyncResponse response)
 {
     string reason = "Unknown reason.";
     if (response.Data != null && response.Data.Reason != null)
     {
         reason = (string) response.Data.Reason;
     }
     this.HandleDisconnect(reason);
 }
        /// <summary>
        /// Get the body of an email.
        /// </summary>
        /// <param name="syncResponse">A Sync command response.</param>
        /// <param name="emailSubject">The email subject.</param>
        /// <returns>The body part of the email.</returns>
        private static Response.Body GetMailBody(SyncResponse syncResponse, string emailSubject)
        {
            Response.Body mailBody = null;
            Response.SyncCollectionsCollectionCommandsAddApplicationData applicationData = TestSuiteBase.GetAddApplicationData(syncResponse, Response.ItemsChoiceType8.Subject1, emailSubject);
            for (int i = 0; i < applicationData.ItemsElementName.Length; i++)
            {
                if (applicationData.ItemsElementName[i] == Response.ItemsChoiceType8.Body)
                {
                    mailBody = applicationData.Items[i] as Response.Body;
                    break;
                }
            }

            return mailBody;
        }
        /// <summary>
        /// Get an object related to a specified ItemsChoiceType10 value.
        /// </summary>
        /// <param name="syncResponse">A Sync response.</param>
        /// <param name="element">An element of ItemsChoiceType10 type, which specifies which object in the Sync response to be retrieved.</param>
        /// <returns>The object to be retrieved, if it exists in the Sync response; otherwise, return null.</returns>
        protected static object GetCollectionItem(SyncResponse syncResponse, Response.ItemsChoiceType10 element)
        {
            if (syncResponse.ResponseData.Item != null)
            {
                Response.SyncCollectionsCollection syncCollection = ((Response.SyncCollections)syncResponse.ResponseData.Item).Collection[0];

                for (int i = 0; i < syncCollection.ItemsElementName.Length; i++)
                {
                    if (syncCollection.ItemsElementName[i] == element)
                    {
                        return syncCollection.Items[i];
                    }
                }
            }

            return null;
        }
        /// <summary>
        /// This method is used to search serverId from SyncResponse.
        /// </summary>
        /// <param name="responseSync">An instance of the SyncResponse.</param>
        /// <param name="field">The value of the item name.</param>
        /// <param name="fieldValue">The value of item.</param>
        /// <returns>The collection of serverIds</returns>
        protected static Collection<string> FindServerIdList(SyncResponse responseSync, string field, string fieldValue)
        {
            Response.SyncCollections syncCollections = (Response.SyncCollections)responseSync.ResponseData.Item;
            if (syncCollections == null)
            {
                return null;
            }

            Response.SyncCollectionsCollectionCommands commands = null;
            for (int index = 0; index < syncCollections.Collection[0].ItemsElementName.Length; index++)
            {
                if (syncCollections.Collection[0].ItemsElementName[index] == Response.ItemsChoiceType10.Commands)
                {
                    commands = (Response.SyncCollectionsCollectionCommands)syncCollections.Collection[0].Items[index];
                    break;
                }
            }

            Collection<string> serverId = new Collection<string>();
            foreach (Response.SyncCollectionsCollectionCommandsAdd add in commands.Add)
            {
                for (int itemIndex = 0; itemIndex < add.ApplicationData.ItemsElementName.Length; itemIndex++)
                {
                    if (add.ApplicationData.ItemsElementName[itemIndex].ToString().Contains(field) && add.ApplicationData.Items[itemIndex].ToString().Contains(fieldValue))
                    {
                        serverId.Add(add.ServerId);
                        break;
                    }
                }
            }

            return serverId;
        }
Beispiel #38
0
        private void BroadcastState()
        {
            // Copy settings that clients require
            _state.OfftrackLimit = Properties.Settings.Default.OfftrackLimit;

            var response = new SyncResponse(SyncResponse.ResponseTypes.UpdateState);
            response.Data = new { State = _state };
            Debug.WriteLine(">> Broadcasting state: " + response);

            this.Broadcast(response.ToString());
        }
        /// <summary>
        /// Get the attachments of an email.
        /// </summary>
        /// <param name="syncResponse">The Sync command response.</param>
        /// <param name="subject">The email subject.</param>
        /// <returns>The attachments of the email.</returns>
        protected Response.AttachmentsAttachment[] GetEmailAttachments(SyncResponse syncResponse, string subject)
        {
            Response.AttachmentsAttachment[] attachments = null;

            // Get the application data of the email, to which the attachments belong.
            Response.SyncCollectionsCollectionCommandsAddApplicationData addData = TestSuiteBase.GetAddApplicationData(syncResponse, Response.ItemsChoiceType8.Subject1, subject);
            Site.Assert.IsNotNull(addData, string.Format("The email with subject '{0}' should exist.", subject));

            for (int i = 0; i < addData.ItemsElementName.Length; i++)
            {
                if (addData.ItemsElementName[i] == Response.ItemsChoiceType8.Attachments)
                {
                    Response.Attachments attachmentCollection = addData.Items[i] as Response.Attachments;
                    if (attachmentCollection != null)
                    {
                        attachments = new Response.AttachmentsAttachment[attachmentCollection.Items.Length];
                        for (int j = 0; j < attachmentCollection.Items.Length; j++)
                        {
                            attachments[j] = attachmentCollection.Items[j] as Response.AttachmentsAttachment;
                        }
                    }

                    break;
                }
            }
            return attachments;
        }
 public static SyncResponse Ping()
 {
     var response = new SyncResponse(SyncResponse.ResponseTypes.Ping);
     return response;
 }
        /// <summary>
        /// Get the value of ConversationId element from SyncResponse
        /// </summary>
        /// <param name="syncResponse">An instance of the SyncResponse.</param>
        /// <param name="serverId">The value of the ServerId element.</param>
        /// <returns>The value of the ConversationId element</returns>
        private static string GetConverstationIdFromSyncResposne(SyncResponse syncResponse, string serverId)
        {
            int index = 0;
            foreach (Response.ItemsChoiceType10 item in ((Response.SyncCollections)syncResponse.ResponseData.Item).Collection[0].ItemsElementName)
            {
                if (item == Response.ItemsChoiceType10.Commands)
                {
                    Response.SyncCollectionsCollectionCommands commands = ((Response.SyncCollections)syncResponse.ResponseData.Item).Collection[0].Items[index] as Response.SyncCollectionsCollectionCommands;
                    foreach (Response.SyncCollectionsCollectionCommandsAdd add in commands.Add)
                    {
                        if (add.ServerId.Equals(serverId))
                        {
                            for (int j = 0; j < add.ApplicationData.ItemsElementName.Length; j++)
                            {
                                if (add.ApplicationData.ItemsElementName[j] == Response.ItemsChoiceType8.ConversationId)
                                {
                                    return add.ApplicationData.Items[j].ToString();
                                }
                            }
                        }
                    }
                }

                index++;
            }

            return string.Empty;
        }
        /// <summary>
        /// This method is used to verify the Sync response related requirements.
        /// </summary>
        /// <param name="syncResponse">Sync command response.</param>
        private void VerifySyncCommand(SyncResponse syncResponse)
        {
            Site.Assert.IsTrue(this.activeSyncClient.ValidationResult, "The schema validation result should be true.");
            Site.Assert.IsNotNull(syncResponse.ResponseData, "The Sync element should not be null.");

            #region Capture code for Sync
            // Add the debug information.
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R4558");

            // If the schema validation result is true and Sync is not null, this requirement can be verified.
            Site.CaptureRequirement(
                4558,
                @"[In Sync] The Sync element is a required element in Sync command requests and responses that identifies the body of the HTTP POST as containing a Sync command (section 2.2.2.20).");

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

            // If the schema validation result is true and Sync is not null, this requirement can be verified.
            Site.CaptureRequirement(
                2795,
                @"[In Sync] None [Element Sync in Sync command response has no parent element.]");

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

            // If the schema validation result is true and Sync is not null, this requirement can be verified.
            Site.CaptureRequirement(
                2796,
                @"[In Sync] Element Sync in Sync command response, the child elements are Collections (section 2.2.3.31.2), Limit (section 2.2.3.92), Status (section 2.2.3.167.16).");

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

            // If the schema validation result is true and Sync is not null, this requirement can be verified.
            Site.CaptureRequirement(
                2797,
                @"[In Sync] Element Sync in Sync command response, the data type is container.");

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

            // If the schema validation result is true and Sync is not null, this requirement can be verified.
            Site.CaptureRequirement(
                2798,
                @"[In Sync] Element Sync in Sync command response, the number allowed is 1...1 (required).");

            this.VerifyContainerDataType();
            #endregion

            #region Capture code for Status
            if (!string.IsNullOrEmpty(syncResponse.ResponseData.Status))
            {
                // Add the debug information.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5585");

                // If the schema validation result is true and Status(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    5585,
                    @"[In Status(Sync)] Element Status in Sync command response, the parent element is Sync (section 2.2.3.170).");

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

                // If the schema validation result is true and Status(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    5586,
                    @"[In Status(Sync)] None [Element Status in Sync command response has no child element.]");

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

                // If the schema validation result is true and Status(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    5587,
                    @"[In Status(Sync)] Element Status in Sync command response, the data type is unsignedByte.");

                this.VerifyIntegerDataType();

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

                // If the schema validation result is true and Status(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    5588,
                    @"[In Status(Sync)] Element Status in Sync command response, the number allowed is 0…1 (optional).");
            }
            #endregion

            if (!string.IsNullOrEmpty(syncResponse.ResponseData.Status) && (syncResponse.ResponseData.Status == "14" || syncResponse.ResponseData.Status == "15"))
            {
                Site.Assert.IsNotNull((string)syncResponse.ResponseData.Item, "The Limit element should not be null when the Status is 14 or 15.");

                #region Capture code for Limit
                // Add the debug information.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1828");

                // If the schema validation result is true and Limit is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1828,
                    @"[In Limit] Element Limit in Sync command response (section 2.2.2.20), the parent element is Sync (section 2.2.3.170).");

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

                // If the schema validation result is true and Limit is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1829,
                    @"[In Limit] None [Element Limit in Sync command response (section 2.2.2.20) has no child element.]");

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

                // If the schema validation result is true and Limit is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1830,
                    @"[In Limit] Element Limit in Sync command response (section 2.2.2.20), the data type is integer ([MS-ASDTYPE] section 2.6).");

                this.VerifyIntegerDataType();

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

                // If the schema validation result is true and Limit is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1831,
                    @"[In Limit] Element Limit in Sync command response (section 2.2.2.20), the number allowed is 0...1 (optional).");
                #endregion
            }
            else if ((SyncCollections)syncResponse.ResponseData.Item != null)
            {
                SyncCollections syncCollections = (SyncCollections)syncResponse.ResponseData.Item;

                #region Capture code for Collections
                // Add the debug information.
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1415");

                // If the schema validation result is true and Collections(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1415,
                    @"[In Collections(Sync)] Element Commands in Sync command response, the parent element is Sync.");

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

                // If the schema validation result is true and Collections(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1416,
                    @"[In Collections(Sync)] Element Commands in Sync command response, the child element is Collection.");

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

                // If the schema validation result is true and Collections(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1417,
                    @"[In Collections(Sync)] Element Commands in Sync command response, the data type is container.");

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

                // If the schema validation result is true and Collections(Sync) is not null, this requirement can be verified.
                Site.CaptureRequirement(
                    1418,
                    @"[In Collections(Sync)] Element Commands in Sync command response, the number allowed is 0...1 (optional).");

                this.VerifyContainerDataType();
                #endregion

                #region Capture code for Collection
                if (syncCollections.Collection != null && syncCollections.Collection.Length > 0)
                {
                    // Add the debug information.
                    Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1363");

                    // If the schema validation result is true and Collection(Sync) is not null, this requirement can be verified.
                    Site.CaptureRequirement(
                        1363,
                        @"[In Collection(Sync)] Element Collection in Sync command response, the parent element is Collections.");

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

                    // If the schema validation result is true and Collection(Sync) is not null, this requirement can be verified.
                    Site.CaptureRequirement(
                        1364,
                        @"[In Collection(Sync)] Element Collection in Sync command response, the child elements are Class, SyncKey, CollectionId, Status (section 2.2.3.167.16), MoreAvailable (section 2.2.3.110), Commands, Responses (section 2.2.3.145).");

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

                    // If the schema validation result is true and Collection(Sync) is not null, this requirement can be verified.
                    Site.CaptureRequirement(
                        1365,
                        @"[In Collection(Sync)] Element Collection in Sync command response, the data type is container.");

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

                    // If the schema validation result is true and Collection(Sync) is not null, this requirement can be verified.
                    Site.CaptureRequirement(
                        1366,
                        @"[In Collection(Sync)] Element Collection in Sync command response, the number allowed is 0…N (optional).");

                    this.VerifyContainerDataType();

                    foreach (SyncCollectionsCollection collection in syncCollections.Collection)
                    {
                        if (collection.ItemsElementName != null && collection.ItemsElementName.Length > 0)
                        {
                            bool hasStatus = false;
                            bool hasSyncKey = false;
                            bool hasCollectionId = false;

                            for (int j = 0; j < collection.ItemsElementName.Length; j++)
                            {
                                #region Capture code for Status
                                if (collection.ItemsElementName[j] == ItemsChoiceType10.Status && collection.Items[j] != null)
                                {
                                    hasStatus = true;

                                    Common.VerifyActualValues("Status(Sync)", AdapterHelper.ValidStatus(new string[] { "1", "3", "4", "5", "6", "7", "8", "9", "12", "13", "14", "15", "16" }), collection.Items[j].ToString(), this.Site);

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

                                    // Verify MS-ASCMD requirement: MS-ASCMD_R4420
                                    // If above Common.VerifyActualValues method is not failed, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        4420,
                                        @"[In Status(Sync)] The following table lists the status codes [1,3,4,5,6,7,8,9,12,13,14,15,16] for the Sync command (section 2.2.2.20). For information about the scope of the status value and for status values common to all ActiveSync commands, see section 2.2.4.");

                                    this.VerifyStatusElementForSync();
                                }
                                #endregion

                                #region Capture code for SyncKey
                                if (collection.ItemsElementName[j] == ItemsChoiceType10.SyncKey && collection.Items[j] != null)
                                {
                                    hasSyncKey = true;

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

                                    // If the schema validation result is true and SyncKey(Sync) is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        2839,
                                        @"[In SyncKey(Sync)] Element SyncKey in Sync command response, the parent element is Collection (section 2.2.3.29.2),");

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

                                    // If the schema validation result is true and SyncKey(Sync) is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        2840,
                                        @"[In SyncKey(Sync)] None [Element SyncKey in Sync command response has no child element.]");

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

                                    // If the schema validation result is true and SyncKey(Sync) is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        2841,
                                        @"[In SyncKey(Sync)] Element SyncKey in Sync command response, the data type is string.");

                                    this.VerifyStringDataType();
                                }
                                #endregion

                                #region Capture code for CollectionId
                                if (collection.ItemsElementName[j] == ItemsChoiceType10.CollectionId && collection.Items[j] != null)
                                {
                                    hasCollectionId = true;

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

                                    // If the schema validation result is true and CollectionId(Sync) is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1400,
                                        @"[In CollectionId(Sync)] Element CollectionId in Sync command response, the parent element is Collection (section 2.2.3.29.2).");

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

                                    // If the schema validation result is true and CollectionId(Sync) is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1401,
                                        @"[In CollectionId(Sync)] None [Element CollectionId in Sync command response has no child element.]");

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

                                    // If the schema validation result is true and CollectionId(Sync) is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1402,
                                        @"[In CollectionId(Sync)] Element CollectionId in Sync command response, the data type is string.");

                                    this.VerifyStringDataType();

                                    // Add the debug information.
                                    Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R5862, the length of CollectionId element is {0}", ((string)collection.Items[j]).Length);

                                    // Verify MS-ASCMD requirement: MS-ASCMD_R5862
                                    Site.CaptureRequirementIfIsTrue(
                                        ((string)collection.Items[j]).Length <= 64,
                                        5862,
                                        @"[In CollectionId(Sync)] The CollectionId element value is not larger than 64 characters in length.");
                                }
                                #endregion

                                #region Capture code for MoreAvailable
                                if (collection.ItemsElementName[j] == ItemsChoiceType10.MoreAvailable)
                                {
                                    // Add the debug information.
                                    Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1951");

                                    // If the schema validation result is true and MoreAvailable is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1951,
                                        @"[In MoreAvailable] Element MoreAvailable in Sync command response (section 2.2.2.20), the parent element is Collection (section 2.2.3.29.2).");

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

                                    // If the schema validation result is true and MoreAvailable is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1952,
                                        @"[In MoreAvailable] None [Element MoreAvailable in Sync command response (section 2.2.2.20) has no child element.]");

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

                                    // If the schema validation result is true and MoreAvailable is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1953,
                                        @"[In MoreAvailable] None [Element MoreAvailable in Sync command response (section 2.2.2.20) has no data type.]");

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

                                    // If the schema validation result is true and MoreAvailable is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1954,
                                        @"[In MoreAvailable] Element MoreAvailable in Sync command response (section 2.2.2.20), the number allowed is 0...1 (optional).");

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

                                    // Verify MS-ASCMD requirement: MS-ASCMD_R3448
                                    Site.CaptureRequirementIfIsTrue(
                                        string.IsNullOrEmpty((string)collection.Items[j]),
                                        3448,
                                        @"[In MoreAvailable] The MoreAvailable element is an empty tag element, meaning it has no value or data type.");
                                }
                                #endregion

                                #region Capture code for Commands
                                if (collection.ItemsElementName[j] == ItemsChoiceType10.Commands && collection.Items[j] != null)
                                {
                                    SyncCollectionsCollectionCommands commands = (SyncCollectionsCollectionCommands)collection.Items[j];

                                    bool hasAddCommand = commands.Add != null && commands.Add.Length > 0;
                                    bool hasDeleteCommand = commands.Delete != null && commands.Delete.Length > 0;
                                    bool hasChangeCommand = commands.Change != null && commands.Change.Length > 0;
                                    bool hasSoftDeleteCommand = commands.SoftDelete != null && commands.SoftDelete.Length > 0;

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

                                    // Verify MS-ASCMD requirement: MS-ASCMD_R2053
                                    Site.CaptureRequirementIfIsTrue(
                                        hasAddCommand || hasDeleteCommand || hasChangeCommand || hasSoftDeleteCommand,
                                        2053,
                                        @"[In Commands] If it [Commands] is present, it MUST include at least one operation.");

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

                                    // If the schema validation result is true and Commands is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1423,
                                        @"[In Commands] Element Commands in Sync command response, the parent element is Collection.");

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

                                    // If the schema validation result is true and Commands is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1425,
                                        @"[In Commands] Element Commands in Sync command response, the child elements are Add, Delete, Change, SoftDelete (section 2.2.3.162).");

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

                                    // If the schema validation result is true and Commands is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1426,
                                        @"[In Commands] Element Commands in Sync command response, the data type is  container.");

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

                                    // If the schema validation result is true and Commands is not null, this requirement can be verified.
                                    Site.CaptureRequirement(
                                        1427,
                                        @"[In Commands] Element Commands in Sync command response, the number allowed is 0...1 (optional).");

                                    this.VerifyContainerDataType();

                                    #region Capture code for SoftDelete
                                    if (hasSoftDeleteCommand)
                                    {
                                        // Add the debug information.
                                        Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2655");

                                        // If the schema validation result is true and SoftDelete is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            2655,
                                            @"[In SoftDelete] Element SoftDelete in Sync command response (section 2.2.2.20),the parent element is Commands (section 2.2.3.32).");

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

                                        // If the schema validation result is true and SoftDelete is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            2656,
                                            @"[In SoftDelete] Element SoftDelete in Sync command response (section 2.2.2.20), the child element is ServerId (section 2.2.3.156.6).");

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

                                        // If the schema validation result is true and SoftDelete is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            2657,
                                            @"[In SoftDelete] Element SoftDelete in Sync command response (section 2.2.2.20), the data type is container ([MS-ASDTYPE] section 2.2).");

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

                                        // If the schema validation result is true and SoftDelete is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            2658,
                                            @"[In SoftDelete] Element SoftDelete in Sync command response (section 2.2.2.20), the number allowed is 0...N (optional).");

                                        this.VerifyContainerDataType();

                                        foreach (SyncCollectionsCollectionCommandsSoftDelete softDelete in commands.SoftDelete)
                                        {
                                            Site.Assert.IsNotNull(softDelete.ServerId, "The ServerId element in Sync command response should not be null.");

                                            this.VerifyServerIdElementForSync(softDelete.ServerId);
                                        }
                                    }
                                    #endregion

                                    #region Capture code for Delete
                                    if (hasDeleteCommand)
                                    {
                                        // Add the debug information.
                                        Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1490");

                                        // If the schema validation result is true and Delete(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1490,
                                            @"[In Delete(Sync)] Element Delete in Sync command response, the parent element is Commands.");

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

                                        // If the schema validation result is true and Delete(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1491,
                                            @"[In Delete(Sync)] Element Delete in Sync command response, the child element is ServerId, Class (section 2.2.3.27.5).");

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

                                        // If the schema validation result is true and Delete(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1492,
                                            @"[In Delete(Sync)] Element Delete in Sync command response, the data type is  container.");

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

                                        // If the schema validation result is true and Delete(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1493,
                                            @"[In Delete(Sync)] Element Delete in Sync command response, the number allowed is 0...N (optional).");

                                        this.VerifyContainerDataType();

                                        foreach (SyncCollectionsCollectionCommandsDelete delete in commands.Delete)
                                        {
                                            Site.Assert.IsNotNull(delete.ServerId, "The ServerId element in Sync command response should not be null.");

                                            this.VerifyServerIdElementForSync(delete.ServerId);
                                        }
                                    }
                                    #endregion

                                    #region Capture code for Add
                                    if (hasAddCommand)
                                    {
                                        // Add the debug information.
                                        Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1039");

                                        // If the schema validation result is true and Add(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1039,
                                            @"[In Add(Sync)] Element Add in Sync command response, the parent element is Commands.");

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

                                        // If the schema validation result is true and Add(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1040,
                                            @"[In Add(Sync)] Element Add in Sync command response, the child elements are ServerId (section 2.2.3.156.7), ApplicationData (section 2.2.3.11).");

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

                                        // If the schema validation result is true and Add(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1041,
                                            @"[In Add(Sync)] Element Add in Sync command response, the data type is container.");

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

                                        // If the schema validation result is true and Add(Sync) is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1042,
                                            @"[In Add(Sync)] Element Add in Sync command response, the number allowed is 0...N (optional).");

                                        this.VerifyContainerDataType();

                                        foreach (SyncCollectionsCollectionCommandsAdd add in commands.Add)
                                        {
                                            Site.Assert.IsNotNull(add.ServerId, "The ServerId element in Sync command response should not be null.");

                                            this.VerifyServerIdElementForSync(add.ServerId);

                                            Site.Assert.IsNotNull(add.ApplicationData, "The ApplicationData element in Sync command should not be null.");

                                            this.VerifyApplicationDataForSyncAddChange();
                                        }
                                    }
                                    #endregion

                                    #region Capture code for Change
                                    if (hasChangeCommand)
                                    {
                                        // Add the debug information.
                                        Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R1147");

                                        // If the schema validation result is true and Change is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1147,
                                            @"[In Change] Element Change in Sync command response, the parent element is Commands.");

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

                                        // If the schema validation result is true and Change is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1148,
                                            @"[In Change] Element Change in Sync command response, the child elements are ServerId, ApplicationData, Class (section 2.2.3.27.5).");

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

                                        // If the schema validation result is true and Change is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1149,
                                            @"[In Change] Element Change in Sync command response, the data type is container.");

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

                                        // If the schema validation result is true and Change is not null, this requirement can be verified.
                                        Site.CaptureRequirement(
                                            1150,
                                            @"[In Change] Element Change in Sync command response, the number allowed is 0...N (optional).");

                                        this.VerifyContainerDataType();

                                        foreach (SyncCollectionsCollectionCommandsChange change in commands.Change)
                                        {
                                            Site.Assert.IsNotNull(change.ServerId, "The ServerId element in Sync command response should not be null.");

                                            this.VerifyServerIdElementForSync(change.ServerId);

                                            Site.Assert.IsNotNull(change.ApplicationData, "The ApplicationData element in Sync command should not be null.");

                                            this.VerifyApplicationDataForSyncAddChange();
                                        }
                                    }
                                    #endregion
                                }
                                #endregion

                                XmlDocument xmlDoc = new XmlDocument();
                                xmlDoc.LoadXml(syncResponse.ResponseDataXML);

                                if (xmlDoc.DocumentElement.HasChildNodes)
                                {
                                    #region Capture code for Change
                                    XmlNodeList changeNodes = xmlDoc.DocumentElement.GetElementsByTagName("Change");

                                    if (changeNodes != null && changeNodes.Count > 0)
                                    {
                                        // Add the debug information.
                                        Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R3836");

                                        // Verify MS-ASCMD requirement: MS-ASCMD_R3836
                                        Site.CaptureRequirement(
                                            3836,
                                            @"[In Responses] If [ Responses element is ] present, it MUST include at least one child element.");
                                    }
                                    #endregion

                                    #region Capture code for Responses/Response
                                    XmlNodeList responsesNodes = xmlDoc.DocumentElement.GetElementsByTagName("Responses");
                                    XmlNodeList responseNodes = xmlDoc.DocumentElement.GetElementsByTagName("Response");

                                    if (responsesNodes != null && responsesNodes.Count > 0)
                                    {
                                        foreach (XmlNode responsesNode in responsesNodes)
                                        {
                                            if (responsesNode.ParentNode.Name.Equals("Collection", StringComparison.CurrentCultureIgnoreCase) && responsesNode.ParentNode.ParentNode != null && responsesNode.ParentNode.ParentNode.Name.Equals("Collections", StringComparison.CurrentCultureIgnoreCase) && responsesNode.ParentNode.ParentNode.ParentNode != null && responsesNode.ParentNode.ParentNode.ParentNode.Name.Equals("Sync", StringComparison.CurrentCultureIgnoreCase))
                                            {
                                                // Add the debug information.
                                                Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASCMD_R2504");

                                                // If the schema validation result is true and Responses is not null, this requirement can be verified.
                                                Site.CaptureRequirement(
                                                    2504,
                                                    @"[In Responses] Element Responses in Sync command response (section 2.2.2.20), the parent element is Collection (section 2.2.3.29.2).");

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

                                                // If the schema validation result is true and Responses is not null, this requirement can be verified.
                                                Site.CaptureRequirement(
                                                    2506,
                                                    @"[In Responses] Element Responses in Sync command response (section 2.2.2.19), the data  type is container ([MS-ASDTYPE] section 2.2).");

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

                                                // If the schema validation result is true and Responses is not null, this requirement can be verified.
                                                Site.CaptureRequirement(
                                                    2507,
                                                    @"[In Responses] Element Responses in Sync command response (section 2.2.2.19), the number allowed is 0...1 (optional).");

                                                this.VerifyContainerDataType();

                                                this.VerifyElementsForResponses(responsesNode as XmlElement);
                                            }
                                        }
                                    }

                                    if (responseNodes != null && responseNodes.Count > 0)
                                    {
                                        foreach (XmlNode responseNode in responseNodes)
                                        {
                                            if (responseNode.ParentNode.Name.Equals("Collection", StringComparison.CurrentCultureIgnoreCase) && responseNode.ParentNode.ParentNode != null && responseNode.ParentNode.ParentNode.Name.Equals("Collections", StringComparison.CurrentCultureIgnoreCase) && responseNode.ParentNode.ParentNode.ParentNode != null && responseNode.ParentNode.ParentNode.ParentNode.Name.Equals("Sync", StringComparison.CurrentCultureIgnoreCase))
                                            {
                                                this.VerifyElementsForResponses(responseNode as XmlElement);
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }

                            Site.Assert.IsTrue(hasStatus, "The Status in Collection should not be null.");
                            Site.Assert.IsTrue(hasSyncKey, "The SyncKey in Collection should not be null.");

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

                            // If the schema validation result is true and SyncKey(Sync) is not null, this requirement can be verified.
                            Site.CaptureRequirement(
                                4596,
                                @"[In SyncKey(Sync)] The SyncKey element is a required child element of the Collection element in Sync command requests and responses that contains a value that is used by the server to mark the synchronization state of a collection.");

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

                            // If the schema validation result is true and SyncKey(Sync) is not null, this requirement can be verified.
                            Site.CaptureRequirement(
                                2842,
                                @"[In SyncKey(Sync)] Element SyncKey in Sync command response, the number allowed is 1…1 (required).");

                            Site.Assert.IsTrue(hasCollectionId, "The CollectionId in Collection should not be null.");

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

                            // If the schema validation result is true and CollectionId(Sync) is not null, this requirement can be verified.
                            Site.CaptureRequirement(
                                2033,
                                @"[In CollectionId(Sync)] The CollectionId element is a required child element of the Collection element in Sync command requests and responses that specifies the server ID of the folder to be synchronized.");

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

                            // If the schema validation result is true and CollectionId(Sync) is not null, this requirement can be verified.
                            Site.CaptureRequirement(
                                1403,
                                @"[In CollectionId(Sync)] Element CollectionId in Sync command response, the number allowed is 1…1 (required).");
                        }
                    }
                }
                #endregion
            }
        }
Beispiel #43
0
        /// <summary>
        /// Load SyncResponse to SyncStore.
        /// </summary>
        /// <param name="response">A SyncResponse instance.</param>
        /// <returns>The SyncStore instance.</returns>
        public static DataStructures.SyncStore LoadSyncResponse(SyncResponse response)
        {
            DataStructures.SyncStore result = new DataStructures.SyncStore();
            if (string.IsNullOrEmpty(response.ResponseData.Status))
            {
                result.StatusSpecified = false;
            }
            else
            {
                result.StatusSpecified = true;
            }

            if (result.StatusSpecified)
            {
                result.Status = Convert.ToInt32(response.ResponseData.Status);
            }

            if (response.ResponseData.Item == null)
            {
                return result;
            }

            Response.SyncCollectionsCollection collection = ((Response.SyncCollections)response.ResponseData.Item).Collection[0];
            for (int i = 0; i < collection.ItemsElementName.Length; i++)
            {
                switch (collection.ItemsElementName[i])
                {
                    case Response.ItemsChoiceType10.CollectionId:
                        result.CollectionId = collection.Items[i].ToString();
                        break;
                    case Response.ItemsChoiceType10.SyncKey:
                        result.SyncKey = collection.Items[i].ToString();
                        break;
                    case Response.ItemsChoiceType10.Status:
                        result.CollectionStatus = Convert.ToByte(collection.Items[i]);
                        break;
                    case Response.ItemsChoiceType10.Commands:
                        Response.SyncCollectionsCollectionCommands commands = collection.Items[i] as Response.SyncCollectionsCollectionCommands;
                        if (commands != null)
                        {
                            LoadAddElements(commands, result.AddElements);
                            LoadChangeElements(commands, result.ChangeElements);
                            LoadDeleteElements(commands, result.DeleteElements);
                        }

                        break;
                    case Response.ItemsChoiceType10.Responses:
                        Response.SyncCollectionsCollectionResponses responses = collection.Items[i] as Response.SyncCollectionsCollectionResponses;
                        if (responses != null)
                        {
                            if (responses.Add != null)
                            {
                                foreach (Response.SyncCollectionsCollectionResponsesAdd add in responses.Add)
                                {
                                    result.AddResponses.Add(add);
                                }
                            }

                            if (responses.Change != null)
                            {
                                foreach (Response.SyncCollectionsCollectionResponsesChange change in responses.Change)
                                {
                                    result.ChangeResponses.Add(change);
                                }
                            }
                        }

                        break;
                }
            }

            return result;
        }
Beispiel #44
0
 private void Reply(UserContext context, SyncResponse response)
 {
     context.Send(response.ToString());
 }
Beispiel #45
0
        private void BroadcastUserlist()
        {
            var users = this.State.Users.ToList(); // _users.Where(u => u.IsRegistered).ToList();
            
            var response = new SyncResponse(SyncResponse.ResponseTypes.UserList);
            response.Data = new { Users = users };
            this.Broadcast(response.ToString());

            this.OnUpdateConnections();
        }
        /// <summary>
        /// Get element value from Sync response
        /// </summary>
        /// <param name="syncResponse">The Sync response</param>
        /// <param name="serverId">The specified serverId</param>
        /// <param name="elementType">The element type</param>
        /// <returns>The element value</returns>
        protected static object GetElementValueFromSyncResponse(SyncResponse syncResponse, string serverId, Response.ItemsChoiceType8 elementType)
        {
            Response.SyncCollections syncCollections = (Response.SyncCollections)syncResponse.ResponseData.Item;
            Response.SyncCollectionsCollectionCommands commands = null;
            for (int index = 0; index < syncCollections.Collection[0].ItemsElementName.Length; index++)
            {
                if (syncCollections.Collection[0].ItemsElementName[index] == Response.ItemsChoiceType10.Commands)
                {
                    commands = (Response.SyncCollectionsCollectionCommands)syncCollections.Collection[0].Items[index];
                    break;
                }
            }

            foreach (Response.SyncCollectionsCollectionCommandsAdd add in commands.Add)
            {
                if (add.ServerId == serverId)
                {
                    for (int itemIndex = 0; itemIndex < add.ApplicationData.ItemsElementName.Length; itemIndex++)
                    {
                        if (add.ApplicationData.ItemsElementName[itemIndex] == elementType)
                        {
                            return add.ApplicationData.Items[itemIndex];
                        }
                    }
                }
            }

            return null;
        }
Beispiel #47
0
 private void BroadcastDisconnect()
 {
     var response = new SyncResponse(SyncResponse.ResponseTypes.Disconnect);
     response.Data = new {Reason = "Admin stopped server."};
     this.Broadcast(response.ToString());
 }
 /// <summary>
 /// Get data from sync response BODY element
 /// </summary>
 /// <param name="syncResponse">An instance of the SyncResponse</param>
 /// <param name="serverId">The value of the ServerId element.</param>
 /// <returns>The value of BODY element.</returns>
 protected static string GetDataFromResponseBodyElement(SyncResponse syncResponse, string serverId)
 {
     Response.Body body = (Response.Body)TestSuiteBase.GetElementValueFromSyncResponse(syncResponse, serverId, Response.ItemsChoiceType8.Body);
     return body.Data;
 }
        /// <summary>
        /// This method is used to search serverId from SyncResponse.
        /// </summary>
        /// <param name="responseSync">An instance of the SyncResponse.</param>
        /// <param name="field">The name of the field.</param>
        /// <param name="fieldValue">The value of item.</param>
        /// <returns>The server ID of the specified item.</returns>
        protected static string FindServerId(SyncResponse responseSync, string field, string fieldValue)
        {
            Response.SyncCollections syncCollections = (Response.SyncCollections)responseSync.ResponseData.Item;
            if (syncCollections == null)
            {
                return null;
            }

            Response.SyncCollectionsCollectionCommands commands = null;
            for (int index = 0; index < syncCollections.Collection[0].ItemsElementName.Length; index++)
            {
                if (syncCollections.Collection[0].ItemsElementName[index] == Response.ItemsChoiceType10.Commands)
                {
                    commands = (Response.SyncCollectionsCollectionCommands)syncCollections.Collection[0].Items[index];
                    break;
                }
            }

            if (commands == null || commands.Add == null)
            {
                return null;
            }

            foreach (Response.SyncCollectionsCollectionCommandsAdd add in commands.Add)
            {
                for (int itemIndex = 0; itemIndex < add.ApplicationData.ItemsElementName.Length; itemIndex++)
                {
                    if (add.ApplicationData.ItemsElementName[itemIndex].ToString().Contains(field) && add.ApplicationData.Items[itemIndex].ToString().ToLower().Replace(" ", "") == fieldValue.ToLower().Replace(" ", ""))
                    {
                        return add.ServerId;
                    }
                }
            }

            return null;
        }
Beispiel #50
0
        private void RegisterUser(UserContext context, SyncCommand command)
        {
            // Client is trying to register
            // Find his connection and link it to a new user
            var conn = FindConnection(context);
            if (conn != null)
            {
                if (!conn.IsRegistered)
                {
                    var id = (int)command.Data.Id;
                    var ssid = (long)command.Data.Ssid;
                    var name = command.Data.Name.ToString();
                    var shortname = command.Data.ShortName.ToString();
                    var password = command.Data.Password.ToString();

                    // Check password
                    if (password == _password)
                    {
                        // Check subsession ID
                        if (ssid == _subSessionId)
                        {
                            // Check name length
                            if (!string.IsNullOrWhiteSpace(name) && name.Length >= MIN_NAME_LENGTH)
                            {
                                
                                // Try to find previously connected user
                                var user = this.State.Users.FromId(id);
                                if (user == null)
                                {
                                    // New user
                                    user = new User();
                                    user.CustId = id;
                                    this.State.Users.Add(user);

                                    UserColors.SetColor(user);
                                }

                                if (!user.IsConnected)
                                {
                                    user.Name = name;
                                    user.ShortName = shortname;
                                    user.IsRegistered = true;
                                    user.IsConnected = true;
                                    user.IsHost = id == _adminId;

                                    // Link him to his connection
                                    conn.User = user;

                                    this.OnLog("User registered: " + name);

                                    var response = new SyncResponse(SyncResponse.ResponseTypes.Connect);
                                    response.Data = new { Success = true, User = user };

                                    this.Reply(context, response);
                                    this.BroadcastUserlist();
                                    this.SendState(context);
                                }
                                else
                                {
                                    this.OnLog("Already connected: " + name);
                                    this.FailRegistration(context, "You are already connected.");
                                }
                            }
                            else
                            {
                                this.OnLog("Name too short: " + name);
                                this.FailRegistration(context,
                                    string.Format("Please choose a name with a minimum of {0} characters.", MIN_NAME_LENGTH));
                            }
                        }
                        else
                        {
                            this.OnLog("Incorrect session ID.");
                            this.FailRegistration(context, "Incorrect subsession ID: you must join the same session as the server host.");
                        }
                    }
                    else
                    {
                        this.OnLog("Incorrect password attempt: " + password);
                        this.FailRegistration(context, "Incorrect password.");
                    }
                }
                else
                {
                    this.OnLog("Already registered: " + conn.Username);
                    this.FailRegistration(context, "You are already registered.");
                }
            }
            else
            {
                this.OnLog("Unknown client tried to register: " + context.ClientAddress);
                this.FailRegistration(context, "Unknown client.");
            }
        }
        /// <summary>
        /// Get the application data of an item specified by field.
        /// </summary>
        /// <param name="syncResponse">The Sync command response.</param>
        /// <param name="field">The element name of the item.</param>
        /// <param name="fieldValue">The value of the item</param>
        /// <returns>If the item exists, return its application data; otherwise, return null.</returns>
        protected static Response.SyncCollectionsCollectionCommandsAddApplicationData GetAddApplicationData(SyncResponse syncResponse, Response.ItemsChoiceType8 field, string fieldValue)
        {
            Response.SyncCollectionsCollectionCommandsAddApplicationData addData = null;

            Response.SyncCollectionsCollectionCommands commands = TestSuiteBase.GetCollectionItem(syncResponse, Response.ItemsChoiceType10.Commands) as Response.SyncCollectionsCollectionCommands;
            if (commands != null)
            {
                foreach (Response.SyncCollectionsCollectionCommandsAdd item in commands.Add)
                {
                    for (int i = 0; i < item.ApplicationData.ItemsElementName.Length; i++)
                    {
                        if (item.ApplicationData.ItemsElementName[i] == field &&
                            item.ApplicationData.Items[i].ToString() == fieldValue)
                        {
                            addData = item.ApplicationData;
                            break;
                        }
                    }
                }
            }

            return addData;
        }
Beispiel #52
0
 private void FailRegistration(UserContext context, string message)
 {
     var response = new SyncResponse(SyncResponse.ResponseTypes.Connect);
     response.Data = new { Success = false, Message = message};
     this.Reply(context, response);
 }
 /// <summary>
 /// Check whether an element of ItemsChoiceType10 type appears in a Sync response.
 /// </summary>
 /// <param name="syncResponse">A Sync response.</param>
 /// <param name="element">The element to be checked.</param>
 /// <returns>Return true, if the element exists in the Sync response; otherwise, return false.</returns>
 private static bool CheckElementOfItemsChoiceType10(SyncResponse syncResponse, Response.ItemsChoiceType10 element)
 {
     if (TestSuiteBase.GetCollectionItem(syncResponse, element) != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Beispiel #54
0
        private void HandleCameraSyncProposal(UserContext context, SyncCommand command)
        {
            // Client requests OTHER clients to sync to his camera
            // Re-send data to clients
            var users = command.Data.Users.ToObject<List<User>>();
            //var users = (List<User>)JsonConvert.DeserializeObject<List<User>>(command.Data.Users.ToString());

            var response = new SyncResponse(SyncResponse.ResponseTypes.ProposeSyncCameras);
            response.Data = command.Data;
            var responseString = response.ToString();

            foreach (var user in users)
            {
                var conn = FindConnection(user);
                if (conn != null && conn.ClientAddress == context.ClientAddress.ToString()) continue; // skip requesting user
                if (conn != null)
                {
                    conn.Context.Send(responseString);
                }
            }
        }
        private void HandleCameraSyncProposal(SyncResponse response)
        {
            // Other admin proposed YOU to sync to HIS camera
            try
            {
                var camera =
                    (CameraDetails)
                        JsonConvert.DeserializeObject<CameraDetails>(response.Data.CameraDetails.ToString());
                var adminId = (int) response.Data.ProposingAdmin;
                var admin = SyncManager.Instance.Users.FromId(adminId);

                // Invoke on dispatcher to not block response handling thread
                App.Instance.Dispatcher.Invoke(() =>
                {
                    if ((bool) response.Data.Force 
                        || App.Instance.MainModel.ShowDialog(new ConfirmCameraSyncWindow(admin, camera)).GetValueOrDefault())
                    {
                        CameraControl.ChangeCamera(camera);
                    }
                });
            }
            catch (Exception ex)
            {
                App.Instance.LogError("Handling Camera Sync. Response: " + response, ex);
            }
        }
Beispiel #56
0
 private void SendState(UserContext context)
 {
     // Re-send the state if connected
     var conn = this.FindConnection(context);
     if (conn != null && conn.IsRegistered)
     {
         var response = new SyncResponse(SyncResponse.ResponseTypes.UpdateState);
         response.Data = new { State = _state };
         context.Send(response.ToString());
     }
 }
        private void HandleRegistration(UserContext context, SyncResponse response, TaskCompletionSource<ConnectionResult> tcs)
        {
            if (response.Data.Success.Value)
            {
                // Registered successfully
                _status = ConnectionStatus.Connected;

                this.RaiseConnected();

                _user = (User) JsonConvert.DeserializeObject<User>(response.Data.User.ToString());
                //_user.Context = context;

                tcs.SetResult(new ConnectionResult());
            }
            else
            {
                // Failed
                this.ResetStatus();
                tcs.SetResult(new ConnectionResult(response.Data.Message.Value));
            }
        }
        /// <summary>
        /// This method is used to retrieve the Commands element in Sync response.
        /// </summary>
        /// <param name="syncResponse">The response of sync command.</param>
        /// <returns>The commands element in the response of sync command.</returns>
        private Response.SyncCollectionsCollectionCommands GetCommandsFromSyncResponse(SyncResponse syncResponse)
        {
            if (syncResponse.ResponseData.Item == null)
            {
                return null;
            }

            Response.SyncCollections syncCollections = (Response.SyncCollections)syncResponse.ResponseData.Item;

            Site.Assert.AreEqual<int>(1, syncCollections.Collection.Length, "There should be one Collection element in Sync response.");
            Site.Assert.IsNotNull(syncCollections.Collection[0], "The Collection element in Sync response should be not null.");

            for (int i = 0; i < syncCollections.Collection[0].ItemsElementName.Length; i++)
            {
                if (Response.ItemsChoiceType10.Commands == syncCollections.Collection[0].ItemsElementName[i])
                {
                    Site.Assert.IsNotNull(syncCollections.Collection[0].Items[i], "The Commands element in Sync response should be not null.");
                    return (Response.SyncCollectionsCollectionCommands)syncCollections.Collection[0].Items[i];
                }
            }

            return null;
        }