Exemple #1
0
        public static bool Save(ProfileFile profile)
        {
            string content = ToJson(profile);

            try
            {
                if (File.Exists(profile.FilePath))
                {
                    string backupPath = profile.FilePath + ".bak";
                    if (File.Exists(backupPath))
                    {
                        File.Delete(backupPath);
                    }

                    File.Move(profile.FilePath, backupPath);
                }

                File.WriteAllText(profile.FilePath, content);
            }
            catch (Exception exception)
            {
                Logger.LogException(exception);
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public static ProfileFile FromJson(string content)
        {
            ProfileFile profileFile =
                JsonConvert.DeserializeObject <ProfileFile>(content, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            return(profileFile);
        }
Exemple #3
0
        public static string ToJson(ProfileFile profileFile)
        {
            string content = JsonConvert.SerializeObject(profileFile, Formatting.Indented,
                                                         new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            return(content);
        }
Exemple #4
0
        public static ProfileFile FromJson(string content)
        {
            ProfileFile profileFile =
                JsonConvert.DeserializeObject <ProfileFile>(content, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            if (profileFile != null && string.IsNullOrEmpty(profileFile.SortKey))
            {
                profileFile.SortKey = "SavedAt";
            }

            return(profileFile);
        }
 public static bool Save(ProfileFile profile)
 {
     return(Save(profile, profile.FilePath));
 }