Example #1
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);
        }
Example #2
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);
        }
Example #3
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());
        }
Example #4
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);
 }
Example #5
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 ());
        }