Example #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);
            }
        }
Example #2
0
        static private object Deserialize(byte[] responseBytes, Type typeToDeserialize)
        {
            MemoryStream            stream           = new MemoryStream(responseBytes);
            ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer();

            return(customSerializer.Deserialize(stream, null, typeToDeserialize));
        }
Example #3
0
        static private void GetProblemsFromSeed()
        {
            string seedPath = SeedFilePath();

            byte []      seedContents = System.IO.File.ReadAllBytes(seedPath);
            MemoryStream seedStream   = new MemoryStream(seedContents);

            if (seedContents.Length == 0)
            {
                ThinksyPlugin.ShowEmergencyWindow("The seed file is empty! (" + seedPath + ")");
                throw new Exception("The seed file is empty!");
            }
            //Message.Problem.ProblemGetResponse problemGet = Message.Problem.ProblemGetResponse.ParseFrom (seedContents);
            //Message.Problem.ProblemGetResponse problemGet = ProtoBuf.Serializer.Deserialize<Message.Problem.ProblemGetResponse> (seedStream);

            ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer();

            Message.Problem.ProblemGetResponse problemGet =
                customSerializer.Deserialize(seedStream, null, typeof(Message.Problem.ProblemGetResponse))
                as Message.Problem.ProblemGetResponse;


            for (int i = 0; i < problemGet.problems.Count; i++)
            {
                Message.Problem.ProblemData problem = problemGet.problems[i];
                ProblemKeeper.AddProblemsToProblemQueue(problem);
            }
        }
Example #4
0
        public static 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);
            }
        }
        private static void GetProblemsFromSeed()
        {
            string seedPath = SeedFilePath();
            byte [] seedContents = System.IO.File.ReadAllBytes (seedPath);
            MemoryStream seedStream = new MemoryStream (seedContents);
            if (seedContents.Length == 0)
            {
                ThinksyPlugin.ShowEmergencyWindow("The seed file is empty! (" + seedPath + ")");
                throw new Exception ("The seed file is empty!");
            }
            //Message.Problem.ProblemGetResponse problemGet = Message.Problem.ProblemGetResponse.ParseFrom (seedContents);
            //Message.Problem.ProblemGetResponse problemGet = ProtoBuf.Serializer.Deserialize<Message.Problem.ProblemGetResponse> (seedStream);

            ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer ();
            Message.Problem.ProblemGetResponse problemGet =
                customSerializer.Deserialize(seedStream, null, typeof(Message.Problem.ProblemGetResponse))
                    as Message.Problem.ProblemGetResponse;

            for (int i = 0; i < problemGet.problems.Count; i++)
            {
                Message.Problem.ProblemData problem = problemGet.problems[i];
                ProblemKeeper.AddProblemsToProblemQueue(problem);
            }
        }
Example #6
0
 private static object Deserialize(byte[] responseBytes, Type typeToDeserialize)
 {
     MemoryStream stream = new MemoryStream(responseBytes);
     ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer ();
     return customSerializer.Deserialize(stream, null, typeToDeserialize);
 }