Beispiel #1
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);
        }
Beispiel #2
0
        public static void InitApp()
        {
            // Add event handler for handling non-UI thread exceptions.
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(StandAloneThreadExceptionHandler);

            Reporter.WorkSpaceReporter = new GingerWorkSpaceReporter();

            if (Environment.GetCommandLineArgs().Count() > 1)
            {
                // When running from unit test there are args, so we set a flag in GingerAutomator to make sure Ginger will Launch
                // and will not try to process the args for RunSet auto run
                if (RunningFromUnitTest)
                {
                    // do nothing for now, but later on we might want to process and check auto run too
                }
                else
                {
                    // This Ginger is running with run set config will do the run and close Ginger
                    WorkSpace.RunningInExecutionMode = true;
                    Reporter.ReportAllAlsoToConsole  = true; //needed so all reportering will be added to Consol
                    //Reporter.AppLogLevel = eAppReporterLoggingLevel.Debug;//needed so all reportering will be added to Log file
                }
            }

            string phase = string.Empty;

            RepositoryItemHelper.RepositoryItemFactory = new RepositoryItemFactory();

            //Helper.RuntimeObjectFactory = new RuntimeObjectFactory();

            AutomateTabGingerRunner = new GingerRunner(eExecutedFrom.Automation);

            WorkSpaceEventHandler WSEH = new WorkSpaceEventHandler();

            WorkSpace.Init(WSEH);

            WorkSpace.Instance.BetaFeatures = BetaFeatures.LoadUserPref();
            WorkSpace.Instance.BetaFeatures.PropertyChanged += BetaFeatureChanged;

            AutomateBusinessFlowEvent += App_AutomateBusinessFlowEvent;

            if (WorkSpace.Instance.BetaFeatures.ShowDebugConsole)
            {
                DebugConsoleWindow.Show();
                WorkSpace.Instance.BetaFeatures.DisplayStatus();
            }

            Reporter.ToLog(eLogLevel.INFO, "######################## Application version " + App.AppVersion + " Started ! ########################");

            AppSplashWindow.LoadingInfo("Init Application");
            WorkSpace.AppVersion = App.AppShortVersion;
            // We init the classes dictionary for the Repository Serializer only once
            InitClassTypesDictionary();

            // TODO: need to add a switch what we get from old ginger based on magic key

            phase = "Loading User Profile";
            Reporter.ToLog(eLogLevel.DEBUG, phase);
            AppSplashWindow.LoadingInfo(phase);
            WorkSpace.UserProfile = UserProfile.LoadUserProfile();

            phase = "Configuring User Type";
            Reporter.ToLog(eLogLevel.DEBUG, phase);
            AppSplashWindow.LoadingInfo(phase);
            WorkSpace.UserProfile.LoadUserTypeHelper();


            phase = "Loading User Selected Resource Dictionaries";
            Reporter.ToLog(eLogLevel.DEBUG, phase);
            AppSplashWindow.LoadingInfo(phase);
            if (WorkSpace.UserProfile != null)
            {
                LoadApplicationDictionaries(Amdocs.Ginger.Core.eSkinDicsType.Default, WorkSpace.UserProfile.TerminologyDictionaryType);
            }
            else
            {
                LoadApplicationDictionaries(Amdocs.Ginger.Core.eSkinDicsType.Default, GingerCore.eTerminologyType.Default);
            }

            Reporter.ToLog(eLogLevel.DEBUG, "Loading user messages pool");
            UserMsgsPool.LoadUserMsgsPool();
            StatusMsgsPool.LoadStatusMsgsPool();

            Reporter.ToLog(eLogLevel.DEBUG, "Init the Centralized Auto Log");
            AutoLogProxy.Init(App.AppVersion);

            Reporter.ToLog(eLogLevel.DEBUG, "Initializing the Source control");
            AppSplashWindow.LoadingInfo(phase);

            phase = "Loading the Main Window";
            Reporter.ToLog(eLogLevel.DEBUG, phase);
            AppSplashWindow.LoadingInfo(phase);
            MainWindow = new Ginger.MainWindow();
            MainWindow.Show();
            MainWindow.Init();

            // If we have command line params process them and do not load MainWindow
            if (WorkSpace.RunningInExecutionMode == true)
            {
                HandleAutoRunMode();
            }

            //AppSplashWindow.LoadingInfo("Ready!");
            App.AppSplashWindow = null;

            AutoLogProxy.LogAppOpened();

            if ((WorkSpace.UserProfile.Solution != null) && (WorkSpace.UserProfile.Solution.ExecutionLoggerConfigurationSetList != null))
            {
            }

            // Register our own Ginger tool tip handler
            //--Canceling customize tooltip for now due to many issues and no real added value

            phase = "Application was loaded and ready";
            Reporter.ToLog(eLogLevel.INFO, phase);
            mIsReady = true;
        }