Пример #1
0
 public bool SaveEncryptionKey()
 {
     try
     {
         GingerCore.GeneralLib.WinCredentialUtil.SetCredentials("Ginger_Sol_" + Solution.Guid, Solution.Name, Solution.EncryptionKey);
         EncryptionHandler.SetCustomKey(Solution.EncryptionKey);
         AddValidationString();
         return(true);
     }
     catch (Exception ex)
     {
         Reporter.ToLog(eLogLevel.DEBUG, ex.Message);
     }
     return(false);
 }
Пример #2
0
        public bool OpenSolution(string solutionFolder, string encryptionKey = null)
        {
            try
            {
                Reporter.ToLog(eLogLevel.INFO, string.Format("Loading the Solution '{0}'", solutionFolder));
                LoadingSolution = true;

                //Cleaning previous Solution load
                Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Cleaning previous Solution items");
                CloseSolution();

                //Load Solution file
                //Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Opening Solution located at: " + solutionFolder);
                string solutionFile = System.IO.Path.Combine(solutionFolder, @"Ginger.Solution.xml");
                Reporter.ToLog(eLogLevel.INFO, string.Format("Loading Solution- Loading Solution File: '{0}'", solutionFile));
                if (System.IO.File.Exists(solutionFile))
                {
                    Reporter.ToLog(eLogLevel.DEBUG, "Loading Solution- Solution File exist");
                }
                else
                {
                    if (!File.Exists(Amdocs.Ginger.IO.PathHelper.GetLongPath(solutionFile)))
                    {
                        //Reporter.ToUser(eUserMsgKey.BeginWithNoSelectSolution);
                        Reporter.ToLog(eLogLevel.ERROR, "Loading Solution- Error: Solution File Not Found");
                        return(false);
                    }
                }

                //Checking if Ginger upgrade is needed
                Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Checking if Ginger Solution items upgrade is needed");
                IEnumerable <string> solutionFiles = Solution.SolutionFiles(solutionFolder);
                SolutionUpgrade.ClearPreviousScans();
                if (SolutionUpgrade.IsGingerUpgradeNeeded(solutionFolder, solutionFiles))
                {
                    Reporter.ToLog(eLogLevel.WARN, "Loading Solution- Error: Current Ginger version can't load the Solution because it includes items from higher Ginger version");
                    return(false);
                }

                Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Loading Solution file xml into object");
                Solution           solution           = SolutionOperations.LoadSolution(solutionFile, true, encryptionKey);
                SolutionOperations solutionOperations = new SolutionOperations(solution);
                solution.SolutionOperations = solutionOperations;

                if (solution == null)
                {
                    Reporter.ToUser(eUserMsgKey.SolutionLoadError, "Failed to load the Solution file");
                    Reporter.ToLog(eLogLevel.ERROR, "Loading Solution- Error: Failed to load the Solution file");
                    return(false);
                }

                EncryptionHandler.SetCustomKey(solution.EncryptionKey);
                if (!solution.SolutionOperations.ValidateKey())
                {
                    if (WorkSpace.Instance.RunningInExecutionMode == false && WorkSpace.Instance.RunningFromUnitTest == false)
                    {
                        if (string.IsNullOrEmpty(solution.EncryptedValidationString))
                        {
                            // To support existing solutions,
                            solution.EncryptionKey             = EncryptionHandler.GetDefaultKey();
                            solution.NeedVariablesReEncryption = true;
                            solution.SolutionOperations.SaveEncryptionKey();
                            solution.SolutionOperations.SaveSolution(false);
                        }
                        else if (!Instance.EventHandler.OpenEncryptionKeyHandler(solution))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        Reporter.ToLog(eLogLevel.ERROR, "Loading Solution- Error: Encryption key validation failed");
                        return(false);
                    }
                }

                Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Creating Items Repository");
                SolutionRepository = GingerSolutionRepository.CreateGingerSolutionRepository();
                SolutionRepository.Open(solutionFolder);

                Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Loading needed Plugins");
                mPluginsManager = new PluginsManager();
                mPluginsManager.SolutionChanged(SolutionRepository);

                Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Doing Source Control Configurations");
                try
                {
                    HandleSolutionLoadSourceControl(solution);
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, "exception occured while doing Solution Source Control Configurations", ex);
                }

                Reporter.ToLog(eLogLevel.INFO, "Loading Solution- Updating Application Functionalities to Work with Loaded Solution");
                ValueExpression.SolutionFolder = solutionFolder;
                BusinessFlow.SolutionVariables = solution.Variables;
                solution.SolutionOperations.SetReportsConfigurations();
                Solution = solution;
                UserProfile.UserProfileOperations.LoadRecentAppAgentMapping();

                if (!RunningInExecutionMode)
                {
                    AppSolutionRecover.DoSolutionAutoSaveAndRecover();
                }

                //Solution items upgrade
                SolutionUpgrade.CheckSolutionItemsUpgrade(solutionFolder, solution.Name, solutionFiles.ToList());

                if (!RunningInExecutionMode && mSolution.NeedVariablesReEncryption)
                {
                    string msg = "Going forward each solution needs to have its own key for encrypting password values\n"
                                 + "Please make a note of Default key updated on Solution details page. This key is mandatory for accessing solution";

                    Reporter.ToUser(eUserMsgKey.SolutionEncryptionKeyUpgrade, msg);
                    Instance.EventHandler.OpenEncryptionKeyHandler(null);
                }

                // No need to add solution to recent if running from CLI
                if (!RunningInExecutionMode)
                {
                    ((UserProfileOperations)UserProfile.UserProfileOperations).AddSolutionToRecent(solution);
                }
                // PlugInsManager = new PluginsManager();
                // mPluginsManager.Init(SolutionRepository);

                Reporter.ToLog(eLogLevel.INFO, string.Format("Finished Loading successfully the Solution '{0}'", solutionFolder));
                return(true);
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, "Loading Solution- Unexpected Error occurred while loading the solution", ex);
                CloseSolution();
                throw ex;
            }
            finally
            {
                LoadingSolution = false;
            }
        }