Esempio n. 1
0
        public void Write(DataList data)
        {
            /* try
             * {
             *   if (Program.UserDataManager.UserData == null)
             *   {
             *       DataList userList = Program.DataPool.userData;
             *       Program.UserDataManager.UserData = new UserData((string)userList.Get("address"), (string)userList.Get("username"));
             *   }
             * }
             * catch (Exception e)
             * {
             *   Console.WriteLine("Saving class failed.");
             *   throw e;
             * }*/
            string jsonUser = Json.FromList(DataList.ToList(data));

            try
            {
                Directory.CreateDirectory(UserDataManager.writeDirectory);
                File.WriteAllText(UserDataManager.FileDirectory(), jsonUser);
            }
            catch (Exception e)
            {
                Console.WriteLine("USERDATAMANAGER" + e.Message);
            }
        }
Esempio n. 2
0
        public void Read(out DataList data)
        {
            string        userJson;
            List <object> dataList = null;

            try
            {
                if (Directory.Exists(UserDataManager.FileDirectory()))
                {
                    Directory.Delete(UserDataManager.FileDirectory());
                }
                Directory.CreateDirectory(UserDataManager.writeDirectory);
                userJson = File.ReadAllText(UserDataManager.FileDirectory());
                data     = DataList.FromList(Json.ToList(userJson));
            }
            catch (FileNotFoundException e)
            {
                data = null;
                return;
            }
        }