Пример #1
0
        private void SaveToFile(OfflineStorageSessions sessionToStore)
        {
            AllStorageSessions loadedSessions;
            string             getSessions = PlayerPrefs.GetString("offlineSessions", "");

            //if null store make new and store
            if (getSessions.Equals(""))
            {
                Debug.Log("get sessions is null (good for first one)");
                loadedSessions = new AllStorageSessions();
                loadedSessions.allSessions.Add(sessionToStore);           //now one element in list
                string jsonSessions = JsonUtility.ToJson(loadedSessions); //this MAY need to be redone for AllStorageSessions?
                PlayerPrefs.SetString("offlineSessions", jsonSessions);
            }
            else
            {
                //if not null, load into List, add to list, then store
                Debug.Log("get sessions is not null - good for second");
                loadedSessions = JsonUtility.FromJson <AllStorageSessions>(getSessions);
                loadedSessions.allSessions.Add(sessionToStore);
                string jsonSessions = JsonUtility.ToJson(loadedSessions);
                PlayerPrefs.SetString("offlineSessions", jsonSessions);
                Debug.Log("the json: " + jsonSessions);
            }
        }
Пример #2
0
        public void UploadCache()
        {
            //load into list --> run through list trying to upload
            Debug.Log("in UploadCache");
            AllStorageSessions loadedSessions = new AllStorageSessions();
            string             jsonSession    = PlayerPrefs.GetString("offlineSessions", "");

            if (jsonSession.Equals(""))
            {
                return; //nothing to upload
            }
            else
            {
                loadedSessions = JsonUtility.FromJson <AllStorageSessions>(jsonSession);
                //now run through and upload
                Debug.Log("trying to upload");
                for (int i = loadedSessions.allSessions.Count - 1; i >= 0; i--)
                {
                    OfflineStorageSessions  uploadSession = loadedSessions.allSessions[i];
                    FizzyoRequestReturnType uploadStatus  = UploadSession(uploadSession);
                    if (uploadStatus == FizzyoRequestReturnType.SUCCESS)
                    {
                        //remove from queue -- maybe unnecessary
                        loadedSessions.allSessions.RemoveAt(i);
                    }
                    else
                    {                                                             //send the whole array and store it again
                        string jsonSessions = JsonUtility.ToJson(loadedSessions); //this MAY need to be redone for AllStorageSessions?
                        PlayerPrefs.SetString("offlineSessions", jsonSessions);
                        return;
                    }
                }
                //if we haven't returned, then everthing has been uploaded by now
                PlayerPrefs.SetString("offlineSessions", ""); //so reset queue
            } Debug.Log("player prefs should now be null " + PlayerPrefs.GetString("offlineSessions", "") + "?");
        }