예제 #1
0
        static public IEnumerator SubmitProblemPostCache()
        {
            string directoryPath = Path.Combine(Application.persistentDataPath, "post_cache/");

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            string[] fileNames = Directory.GetFiles(directoryPath);
            foreach (string fileName in fileNames)
            {
                //UnityEngine.Debug.Log("Submitting cache");
                byte[]                     bytes              = System.IO.File.ReadAllBytes(fileName);
                MemoryStream               stream             = new MemoryStream(bytes);
                ThinksyProtosSerializer    customSerializer   = new ThinksyProtosSerializer();
                Problem.ProblemPostRequest problemPostRequest = customSerializer.Deserialize(stream,
                                                                                             null,
                                                                                             typeof(Problem.ProblemPostRequest)) as Problem.ProblemPostRequest;
                for (int i = 0; i < problemPostRequest.problem.Count; i++)
                {
                    Problem.ProblemPost problemPost = problemPostRequest.problem[i];
                    SetPlayerForProblemIfNeeded(ref problemPost);
                    problemPostRequest.problem[i] = (problemPost);
                    //UnityEngine.Debug.Log(problemPostBuilder.PlayerId);
                }

                yield return(GetSingletonInstance().StartCoroutine(
                                 CoroutinePostRequest(problemPostRequest, Response.ParsePostProblemResponse, POST_PROBLEM_URL, false)));

                File.Delete(fileName);
            }
        }
예제 #2
0
        /// <summary>
        /// Posts a list of Problems that have been answered or skipped by the Player to the server. This is mainly
        /// for internal use/developers should not have to worry about this.
        /// </summary>
        static public IEnumerator PostProblems(string PlayerId, Queue problems)
        {
            problems = new Queue(problems);



            Problem.ProblemPostRequest postProblem = new Problem.ProblemPostRequest();

            while (problems.Count > 0)
            {
                Senseix.Message.Problem.ProblemPost addMeProblem = (Senseix.Message.Problem.ProblemPost)problems.Dequeue();
                postProblem.problem.Add(addMeProblem);
            }


            if (SenseixSession.ShouldCacheProblemPosts())
            {
                PostRequestParameters queueParameters = new PostRequestParameters();
                queueParameters.serializableRequest = postProblem;
                queueParameters.responseHandler     = Response.ParsePostProblemResponse;
                queueParameters.url = POST_PROBLEM_URL;
                WriteRequestToCache(queueParameters);
                //UnityEngine.Debug.Log("Cache post");
            }
            else
            {
                //UnityEngine.Debug.Log ("Post Problems request going off to " + POST_PROBLEM_URL);
                for (int i = 0; i < postProblem.problem.Count; i++)
                {
                    Senseix.Message.Problem.ProblemPost problemPost = postProblem.problem[i];
                    SetPlayerForProblemIfNeeded(ref problemPost);
                    postProblem.problem[i] = problemPost;
                    //UnityEngine.Debug.Log(postProblem.problem[0].correct);
                }
                yield return(GetSingletonInstance().StartCoroutine(
                                 CoroutinePostRequest(postProblem, Response.ParsePostProblemResponse, POST_PROBLEM_URL, false)));
                //UnityEngine.Debug.Log("Post post");
            }
        }
예제 #3
0
        /// <summary>
        /// Posts a list of Problems that have been answered or skipped by the Player to the server. This is mainly 
        /// for internal use/developers should not have to worry about this. 
        /// </summary>
        public static IEnumerator PostProblems(string PlayerId, Queue problems)
        {
            problems = new Queue (problems);

            Problem.ProblemPostRequest postProblem = new Problem.ProblemPostRequest();

            while (problems.Count > 0) {
                Senseix.Message.Problem.ProblemPost addMeProblem = (Senseix.Message.Problem.ProblemPost)problems.Dequeue();
                postProblem.problem.Add (addMeProblem);
            }

            if (SenseixSession.ShouldCacheProblemPosts())
            {
                PostRequestParameters queueParameters = new PostRequestParameters();
                queueParameters.serializableRequest = postProblem;
                queueParameters.responseHandler = Response.ParsePostProblemResponse;
                queueParameters.url = POST_PROBLEM_URL;
                WriteRequestToCache(queueParameters);
                //UnityEngine.Debug.Log("Cache post");
            }
            else
            {
                //UnityEngine.Debug.Log ("Post Problems request going off to " + POST_PROBLEM_URL);
                for (int i = 0; i < postProblem.problem.Count; i++)
                {
                    Senseix.Message.Problem.ProblemPost problemPost = postProblem.problem[i];
                    SetPlayerForProblemIfNeeded(ref problemPost);
                    postProblem.problem[i] = problemPost;
                    //UnityEngine.Debug.Log(postProblem.problem[0].correct);
                }
                yield return GetSingletonInstance().StartCoroutine(
                    CoroutinePostRequest (postProblem, Response.ParsePostProblemResponse, POST_PROBLEM_URL, false));
                //UnityEngine.Debug.Log("Post post");
            }
        }