Beispiel #1
0
        public HttpResponseMessage BeginSession(JObject request)
        {
            var resp = Request.CreateResponse(HttpStatusCode.OK, string.Empty);

            ValidateRequest(request, false);

            if (_userService.GetSessionId((string)request["username"]) != null)
            {
                ThrowSafeException("Session In Progress", 1, HttpStatusCode.ServiceUnavailable);
            }

            string sessionId = Guid.NewGuid().ToString();

            _syncSessionDbConnectionProvider.SessionStart(sessionId);

            using (ISyncableStore store = _userService.GetSyncableStore(_username))
                using (IDbConnection connection = _syncSessionDbConnectionProvider.GetSyncSessionDbConnection(sessionId))
                {
                    var json = new SyncServerSession(store, connection).BeginSession(request);
                    json.Add(new JProperty("sessionID", sessionId));

                    _userService.SetSessionId(_username, sessionId);

                    resp.Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
                }

            return(resp);
        }
Beispiel #2
0
        public HttpResponseMessage PutItemDataBatch(JObject request)
        {
            var resp = Request.CreateResponse(HttpStatusCode.OK, string.Empty);

            ValidateRequest(request);

            using (ISyncableStore store = _userService.GetSyncableStore(_username))
                using (IDbConnection connection = _syncSessionDbConnectionProvider.GetSyncSessionDbConnection(_userService.GetSessionId(_username)))
                {
                    JObject json = new SyncServerSession(store, connection).PutItemDataBatch(request);
                    resp.Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
                }

            return(resp);
        }