Пример #1
0
        public Approval Signup(String parentEmail, String token)
        {
            JObject approvalRequest = new JObject();

            approvalRequest.Add("user", new JObject());
            (approvalRequest["user"] as JObject).Add("token", new JObject());
            approvalRequest["user"]["token"] = token;
            approvalRequest.Add("parent", new JObject());
            (approvalRequest["parent"] as JObject).Add("email", parentEmail);

            try{
                string   jsonResponse = connection.Post("/approval", approvalRequest.ToString());
                Approval approval     = JsonConvert.DeserializeObject <Approval>(jsonResponse);
                if (Approval.StatusEnum.REJECTED == approval.Status)
                {
                    OnRevoke?.Invoke();
                    return(null);
                }
                else
                {
                    ConnectUser(token);
                    return(approval);
                }
            }catch (WebException exception) {
                HandleSignupWebException(exception);
                return(null);
            }
        }
Пример #2
0
        private void HandleApprovalStatusChangedEvent(ApprovalStatusChangedEvent evt)
        {
            switch (evt.Entity.Status)
            {
            case Approval.StatusEnum.APPROVED:
                OnResume?.Invoke();
                break;

            case Approval.StatusEnum.REJECTED:
                OnRevoke?.Invoke();
                socket.CloseConnection();
                break;
            }
        }
Пример #3
0
        private void HandleConnectUserWebException(WebException exception)
        {
            if ("Unable to read data from the transport connection: Connection timed out.".Equals(exception.Message) || exception.Response == null)
            {
                //assume that there is no internet
                StartOfflineWorkflow();
                // but keep trying to connect anyway as long as we've not yet hit the maxretrycount
                reconnectTryCount++;

                if (reconnectTryCount < maxRetryCount)
                {
                    ConnectUser(usertoken);
                }

                return;
            }


            var resp = new StreamReader(exception.Response.GetResponseStream()).ReadToEnd();

            GameSessionException gameSessionException = JsonConvert.DeserializeObject <GameSessionException>(resp);

            switch (gameSessionException.exceptionType)
            {
            case "com.saferize.core.entities.appusagesession.ApprovalPendingException":
                OnPause?.Invoke();
                break;

            case "com.saferize.core.entities.appusagesession.ApprovalRejectedException":
                OnRevoke?.Invoke();
                break;

            case "com.saferize.core.entities.appusagesession.UsageTimerTimeIsUpException":
                OnTimeIsUp?.Invoke();
                break;

            case "com.saferize.core.entities.appusagesession.IllegalApprovalStateException":
                break;

            case "com.saferize.core.entities.approval.ApprovalNotFoundException":
                break;

            case "com.saferize.core.entities.app.IllegalAppStateException":
                break;

            case "com.saferize.core.security.PrincipalNotFoundException":
                break;
            }
        }