Example #1
0
        public static AdminSession GetAdminSession(ClearQuestConnectionConfig connConfig)
        {
            string idStr = GenerateSessionIdStr(connConfig);

            lock (s_adminSessionLock)
            {
                if (s_adminSessions.ContainsKey(idStr))
                {
                    return(s_adminSessions[idStr]);
                }

                // create and initialize admin session object
                AdminSession adminSession = CQWrapper.CreateAdminSession();
                TraceManager.TraceInformation("Connecting to CQ Admin Session");
                CQWrapper.AdminLogon(adminSession,
                                     connConfig.User,
                                     connConfig.Password,
                                     connConfig.DBSet);
                TraceManager.TraceInformation("Connected to CQ Admin Session");
                OAdUser cqUser = CQWrapper.GetUser(adminSession, connConfig.User);
                try
                {
                    if (!CQWrapper.IsSuperUser(cqUser))
                    {
                        string errMsg = UtilityMethods.Format(CQResource.CQ_NO_ADMIN_RIGHT,
                                                              connConfig.User ?? string.Empty);
                        TraceManager.TraceError(errMsg);
                        throw new MigrationException(errMsg);
                    }
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    string errMsg = UtilityMethods.Format(CQResource.CQ_NO_ADMIN_RIGHT,
                                                          connConfig.User ?? string.Empty);
                    TraceManager.TraceException(ex);
                    TraceManager.TraceError(errMsg);
                    throw new MigrationException(errMsg);
                }

                s_adminSessions.Add(idStr, adminSession);

                return(adminSession);
            }
        }