예제 #1
0
        /// <summary>
        /// Makes the current user the owner of this session
        /// </summary>
        public static void AssignCurrentUser(User thisUser)
        {
            if (Session == null) Session = new SessionData();
            Session.CurrentUser = thisUser;
            ServerData.StorageRemoteDir = "uploads/" + thisUser.Key + "/";

            SaveCurrentData();
        }
예제 #2
0
        /// <summary>
        /// Attempts to load existing data stored in a local file.
        /// </summary>
        /// <returns>true if successful, false if a request to the server is needed</returns>
        public static async Task<bool> TryLoadExistingData()
        {
            if (Rand == null) Rand = new Random();

            try
            {
                if ((await Root.CheckExistsAsync("offline.json")) == ExistenceCheckResult.FileExists)
                {
                    IFile json = await Root.GetFileAsync("offline.json");

                    var binder = new TypeNameSerializationBinder("SpeechingShared.{0}, SpeechingShared");
                    Session = JsonConvert.DeserializeObject<SessionData>(await json.ReadAllTextAsync(),
                        new JsonSerializerSettings
                        {
                            TypeNameHandling = TypeNameHandling.Auto,
                            Binder = binder
                        });
                    ServerData.StorageRemoteDir = "uploads/" + Session.CurrentUser.Key + "/";
                    return true;
                }
            }
            catch (Exception e)
            {
                Io.PrintToConsole(e.Message);
            }

            Session = new SessionData();
            return false;
        }