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