Ejemplo n.º 1
0
        public static UserProfile LoadUserProfile()
        {
            if (General.isDesignMode())
            {
                return(null);
            }

            string   InstallationConfigurationPath = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("Ginger.exe", "Ginger.InstallationConfiguration.Json");
            DateTime InstallationDT = File.GetLastWriteTime(InstallationConfigurationPath);

            string  UserConfigJsonString = string.Empty;
            JObject UserConfigJsonObj    = null;
            Dictionary <string, string> UserConfigdictObj = null;

            if (System.IO.File.Exists(InstallationConfigurationPath))
            {
                UserConfigJsonString = System.IO.File.ReadAllText(InstallationConfigurationPath);
                UserConfigJsonObj    = JObject.Parse(UserConfigJsonString);
                UserConfigdictObj    = UserConfigJsonObj.ToObject <Dictionary <string, string> >();
            }

            if (File.Exists(UserProfileFilePath))
            {
                try
                {
                    DateTime UserProfileDT = File.GetLastWriteTime(UserProfileFilePath);
                    Reporter.ToLog(eAppReporterLogLevel.INFO, string.Format("Loading existing User Profile at '{0}'", UserProfileFilePath));
                    string      userProfileTxt = File.ReadAllText(UserProfileFilePath);
                    UserProfile up             = (UserProfile)NewRepositorySerializer.DeserializeFromText(userProfileTxt);
                    up.FilePath = UserProfileFilePath;
                    if (DateTime.Compare(UserProfileDT, InstallationDT) < 0)
                    {
                        if (UserConfigdictObj != null)
                        {
                            up.AddUserConfigProperties(UserConfigdictObj);
                        }
                    }
                    return(up);
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eAppReporterLogLevel.ERROR, string.Format("Failed to load the existing User Profile at '{0}'", UserProfileFilePath), ex);
                }
            }

            Reporter.ToLog(eAppReporterLogLevel.INFO, "Creating new User Profile");

            UserProfile up2 = new UserProfile();

            up2.LoadDefaults();
            if (UserConfigdictObj != null)
            {
                up2.AddUserConfigProperties(UserConfigdictObj);
            }

            return(up2);
        }
Ejemplo n.º 2
0
        public static UserProfile LoadUserProfile()
        {
            if (General.isDesignMode())
            {
                return(null);
            }

            string   UserProfilePath = getUserProfileFileName();
            string   InstallationConfigurationPath = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("Ginger.exe", "Ginger.InstallationConfiguration.Json");
            DateTime InstallationDT = File.GetLastWriteTime(InstallationConfigurationPath);
            DateTime UserProfileDT  = File.GetLastWriteTime(UserProfilePath);

            string  UserConfigJsonString = string.Empty;
            JObject UserConfigJsonObj    = null;
            Dictionary <string, string> UserConfigdictObj = null;

            if (System.IO.File.Exists(InstallationConfigurationPath))
            {
                UserConfigJsonString = System.IO.File.ReadAllText(InstallationConfigurationPath);
                UserConfigJsonObj    = JObject.Parse(UserConfigJsonString);
                UserConfigdictObj    = UserConfigJsonObj.ToObject <Dictionary <string, string> >();
            }

            if (File.Exists(UserProfilePath))
            {
                try
                {
                    UserProfile up = (UserProfile)RepositoryItem.LoadFromFile(typeof(UserProfile), UserProfilePath);
                    if (DateTime.Compare(UserProfileDT, InstallationDT) < 0)
                    {
                        if (UserConfigdictObj != null)
                        {
                            up.AddUserConfigProperties(UserConfigdictObj);
                        }
                    }
                    return(up);
                }
                catch (Exception e)
                {
                    Reporter.ToUser(eUserMsgKeys.UserProfileLoadError, e.Message);
                }
            }

            UserProfile up2 = new UserProfile();

            up2.LoadDefaults();
            if (UserConfigdictObj != null)
            {
                up2.AddUserConfigProperties(UserConfigdictObj);
            }
            up2.ValidateProfile();
            return(up2);
        }
Ejemplo n.º 3
0
        public static UserProfile LoadUserProfile()
        {
            if (General.isDesignMode())
            {
                return(null);
            }

            string InstallationConfigurationPath = Assembly.GetExecutingAssembly().Location.Replace(Path.GetFileName(Assembly.GetExecutingAssembly().Location), "Ginger.InstallationConfiguration.Json");

            string  UserConfigJsonString = string.Empty;
            JObject UserConfigJsonObj    = null;
            Dictionary <string, string> UserConfigdictObj = null;

            if (System.IO.File.Exists(InstallationConfigurationPath))
            {
                UserConfigJsonString = System.IO.File.ReadAllText(InstallationConfigurationPath);
                UserConfigJsonObj    = JObject.Parse(UserConfigJsonString);
                UserConfigdictObj    = UserConfigJsonObj.ToObject <Dictionary <string, string> >();
            }

            if (File.Exists(UserProfileFilePath))
            {
                try
                {
                    DateTime UserProfileDT = File.GetLastWriteTime(UserProfileFilePath);
                    Reporter.ToLog(eLogLevel.INFO, string.Format("Loading existing User Profile at '{0}'", UserProfileFilePath));
                    string      userProfileTxt = File.ReadAllText(UserProfileFilePath);
                    UserProfile up             = (UserProfile)NewRepositorySerializer.DeserializeFromText(userProfileTxt);
                    up.FilePath = UserProfileFilePath;
                    if (UserConfigdictObj != null &&
                        DateTime.Compare(UserProfileDT, File.GetLastWriteTime(InstallationConfigurationPath)) < 0)
                    {
                        up.AddUserConfigProperties(UserConfigdictObj);
                    }
                    return(up);
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, string.Format("Failed to load the existing User Profile at '{0}'", UserProfileFilePath), ex);
                    try
                    {
                        //create backup to the user profile so user won't lose all of it configs in case he went back to old Ginger version
                        //TODO- allow recover from newer User Profile version in code instead creating new user profile
                        Reporter.ToLog(eLogLevel.INFO, "Creating backup copy for the User Profile file");
                        File.Copy(UserProfileFilePath, UserProfileFilePath.Replace("Ginger.UserProfile.xml", "Ginger.UserProfile-Backup.xml"), true);
                    }
                    catch (Exception ex2)
                    {
                        Reporter.ToLog(eLogLevel.ERROR, "Failed to create backup copy for the User Profile file", ex2);
                    }
                }
            }

            Reporter.ToLog(eLogLevel.INFO, "Creating new User Profile");
            UserProfile up2 = new UserProfile();

            up2.LoadDefaults();
            if (UserConfigdictObj != null)
            {
                up2.AddUserConfigProperties(UserConfigdictObj);
            }

            return(up2);
        }