public static IEnumerator CoroutinePostRequest(object parametersObject) { PostRequestParameters parameters = (PostRequestParameters)parametersObject; yield return(GetSingletonInstance().StartCoroutine( CoroutinePostRequest(parameters.recvResult, parameters.serializableRequest, parameters.responseHandler, parameters.url))); }
private static void WriteRequestToCache(PostRequestParameters parameters) { ProtoBuf.IExtensible serializableRequest = parameters.serializableRequest; MemoryStream stream = new MemoryStream(); ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer(); customSerializer.Serialize(stream, serializableRequest); byte[] bytes = stream.ToArray(); string directoryPath = Path.Combine(Application.persistentDataPath, "post_cache/"); //Debug.Log (fileCount); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } string fileCount = (Directory.GetFiles(directoryPath).Length + 1).ToString(); string filePath = Path.Combine(directoryPath, fileCount + ProblemKeeper.SEED_FILE_EXTENSION); System.IO.File.WriteAllBytes(filePath, bytes); SenseixSession.DoFileFlagging(filePath); }
/// <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"); } }
private static void WriteRequestToCache(PostRequestParameters parameters) { ProtoBuf.IExtensible serializableRequest = parameters.serializableRequest; MemoryStream stream = new MemoryStream (); ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer (); customSerializer.Serialize (stream, serializableRequest); byte[] bytes = stream.ToArray(); string directoryPath = Path.Combine (Application.persistentDataPath, "post_cache/"); //Debug.Log (fileCount); if (!Directory.Exists(directoryPath)) Directory.CreateDirectory(directoryPath); string fileCount = (Directory.GetFiles (directoryPath).Length + 1).ToString (); string filePath = Path.Combine (directoryPath, fileCount + ProblemKeeper.SEED_FILE_EXTENSION); System.IO.File.WriteAllBytes (filePath, bytes); SenseixSession.DoFileFlagging(filePath); }
/// <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"); } }