コード例 #1
0
        public bool UpdateSession(string user, string id, CodeCursor codeCursor)
        {
            var element = this.codeSessions.FirstOrDefault(cs => cs.Id == id);

            if (element == null)
            {
                return(false);
            }

            element.CodeHighlights.Add(codeCursor);

            return(true);
        }
コード例 #2
0
        public bool UpdateSession(string user, string id, CodeCursor codeCursor)
        {
            var e = this.GetCodeSessionById(id);

            if (e == null)
            {
                return(false);
            }

            e.CodeHighlights.Add(codeCursor);
            this.AddToUpdateQueue(id);

            return(true);
        }
コード例 #3
0
        public virtual void TestUpdate()
        {
            const string Old = "Hello World!";
            const string New = "Nope";

            CodeSession cs = new CodeSession()
            {
                Owner = User,
                Code  = Old
            };
            var id = cs.Id;

            this.codeSessionsRepository.CreateNewSession(cs);

            // update code text

            this.codeSessionsRepository.UpdateSession(User, id, New);

            var result      = this.codeSessionsRepository.GetUserOwnedSessions(User);
            var onlySession = result.First(s => s.Id == id);

            Assert.AreEqual(New, onlySession.Code);

            // update highlight

            var highlightOne = new CodeCursor()
            {
                HighlightFrom = new CodeCursor.CursorPoint()
                {
                    Ch = 0, Line = 0
                },
                HighlightTo = new CodeCursor.CursorPoint()
                {
                    Ch = 2, Line = 0
                }
            };

            this.codeSessionsRepository.UpdateSession(User, id, highlightOne);

            result      = this.codeSessionsRepository.GetUserOwnedSessions(User);
            onlySession = result.First(s => s.Id == id);

            Assert.AreEqual(1, onlySession.CodeHighlights.Count);
            Assert.AreEqual(2, onlySession.CodeHighlights.First().HighlightTo.Ch);

            // update highlight erase
            this.codeSessionsRepository.UpdateSessionEraseHighlights(User, id);

            result      = this.codeSessionsRepository.GetUserOwnedSessions(User);
            onlySession = result.First(s => s.Id == id);

            Assert.AreEqual(0, onlySession.CodeHighlights.Count);

            // update syntax
            const string NewSyntax = "nothing";

            this.codeSessionsRepository.UpdateSessionSyntax(User, id, NewSyntax);

            result      = this.codeSessionsRepository.GetUserOwnedSessions(User);
            onlySession = result.First(s => s.Id == id);

            Assert.AreEqual(NewSyntax, onlySession.CodeSyntax);

            // update user in control
            const string NewUser = "******";

            this.codeSessionsRepository.UpdateSessionUserInControl(User, id, NewUser);

            result      = this.codeSessionsRepository.GetUserOwnedSessions(User);
            onlySession = result.First(s => s.Id == id);

            Assert.AreEqual(NewUser, onlySession.UserInControl);
            Assert.AreEqual(User, onlySession.Owner);
        }
コード例 #4
0
ファイル: CodeController.cs プロジェクト: bodva/codescreen.me
        public ActionResult PutCodeCursor(string id, [FromBody] CodeCursor codeCursor)
        {
            string user = this.userRepository.GetCurrentUserId();

            return(this.codeSessionsRepository.UpdateSession(user, id, codeCursor) ? Ok() : StatusCode(500));
        }
コード例 #5
0
ファイル: CodeHub.cs プロジェクト: fdevelop/codescreen.me
 public async Task SetCodeHighlight(string user, string sessionId, CodeCursor codeCursor)
 {
     this.codeSessionsRepository.UpdateSession(user, sessionId, codeCursor);
     await Clients.All.SendAsync("SetCodeHighlight", user, sessionId, codeCursor);
 }