示例#1
0
        static private object Deserialize(byte[] responseBytes, Type typeToDeserialize)
        {
            MemoryStream            stream           = new MemoryStream(responseBytes);
            ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer();

            return(customSerializer.Deserialize(stream, null, typeToDeserialize));
        }
示例#2
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);
            }
        }
示例#3
0
        public static WWW SetUpRecvResult(ProtoBuf.IExtensible serializableRequest, string url, bool isGet)
        {
            byte[] bytes;
            Dictionary <string, string> mods = new Dictionary <string, string>();

            mods.Add("X-Auth-Token", SenseixSession.GetAuthToken());
            mods.Add("X-Access-Token", SenseixSession.GetAccessToken());
            mods.Add("Content-Type", "application/protobuf");

            MemoryStream            requestMessageStream = new MemoryStream();
            ThinksyProtosSerializer serializer           = new ThinksyProtosSerializer();

            //UnityEngine.Debug.Log ("Serializing request");
            serializer.Serialize(requestMessageStream, serializableRequest);
            bytes = requestMessageStream.ToArray();
            requestMessageStream.Close();

            WWW recvResult;

            if (!isGet)
            {
                //UnityEngine.Debug.Log("POST");
                recvResult = new WWW(url, bytes, mods);
            }
            else
            {
                //UnityEngine.Debug.Log("GET");
                recvResult = new WWW(url, null, mods);
            }

            return(recvResult);
        }
示例#4
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);
            }
        }
示例#5
0
        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);
        }
示例#6
0
        static private void ReplaceSeed(Message.Problem.ProblemGetResponse reply)
        {
            Logger.BasicLog("Replacing seed file.");
            MemoryStream            stream           = new MemoryStream();
            ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer();

            customSerializer.Serialize(stream, reply);

            byte[] replacementBytes = stream.ToArray();
            try
            {
                FileStream newFile = System.IO.File.Create(PlayerSeedPath());
                SenseixSession.DoFileFlagging(PlayerSeedPath());
                newFile.Close();
            }
            catch
            {
                ThinksyPlugin.ShowEmergencyWindow("An error occurred while creating a seedfile in " + PlayerSeedPath());
            }
            stream.Close();
            System.IO.File.WriteAllBytes(SeedFilePath(), replacementBytes);
            SenseixSession.DoFileFlagging(SeedFilePath());
        }
示例#7
0
 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);
 }
示例#8
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);
            }
        }
示例#9
0
        public static WWW SetUpRecvResult(ProtoBuf.IExtensible serializableRequest, string url, bool isGet)
        {
            byte[] bytes;
            Dictionary<string, string> mods = new Dictionary<string, string>();
            mods.Add ("X-Auth-Token", SenseixSession.GetAuthToken ());
            mods.Add ("X-Access-Token", SenseixSession.GetAccessToken());
            mods.Add("Content-Type", "application/protobuf");

            MemoryStream requestMessageStream = new MemoryStream ();
            ThinksyProtosSerializer serializer = new ThinksyProtosSerializer ();
            //UnityEngine.Debug.Log ("Serializing request");
            serializer.Serialize(requestMessageStream, serializableRequest);
            bytes = requestMessageStream.ToArray();
            requestMessageStream.Close();

            WWW recvResult;
            if (!isGet)
            {
                //UnityEngine.Debug.Log("POST");
                recvResult = new WWW (url, bytes, mods);
            }
            else
            {
                //UnityEngine.Debug.Log("GET");
                recvResult = new WWW (url, null, mods);
            }

            return recvResult;
        }
        private static void ReplaceSeed(Message.Problem.ProblemGetResponse reply)
        {
            Logger.BasicLog ("Replacing seed file.");
            MemoryStream stream = new MemoryStream ();
            ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer ();
            customSerializer.Serialize (stream, reply);

            byte[] replacementBytes = stream.ToArray();
            try
            {
                FileStream newFile = System.IO.File.Create (PlayerSeedPath ());
                SenseixSession.DoFileFlagging(PlayerSeedPath());
                newFile.Close ();
            }
            catch
            {
                ThinksyPlugin.ShowEmergencyWindow("An error occurred while creating a seedfile in " + PlayerSeedPath());
            }
            stream.Close ();
            System.IO.File.WriteAllBytes (SeedFilePath(), replacementBytes);
            SenseixSession.DoFileFlagging (SeedFilePath ());
        }
        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);
            }
        }
示例#12
0
 private static object Deserialize(byte[] responseBytes, Type typeToDeserialize)
 {
     MemoryStream stream = new MemoryStream(responseBytes);
     ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer ();
     return customSerializer.Deserialize(stream, null, typeToDeserialize);
 }