예제 #1
0
        /// <summary>
        /// Gets the header and footer.
        /// </summary>
        /// <param name="header">The header.</param>
        /// <param name="footer">The footer.</param>
        /// <param name="forCurrentUser">if set to <c>true</c> gets the header and footer for current user.</param>
        public void GetHeaderAndFooter(out string header, out string footer, bool forCurrentUser = false)
        {
            header = string.Empty;
            footer = string.Empty;

            try
            {
                string culture  = CultureHelper.GetCulture();
                string cacheKey = CacheHelper.BuildCacheKey("AppsHeaderFooter", culture, forCurrentUser);

                if (FCMConfig.Data.EnableCache && CacheUtils.Contains(cacheKey))
                {
                    header = (string)CacheUtils.GetItem(cacheKey);
                    footer = (string)CacheUtils.GetItem(cacheKey + "_AdditionalParam");
                }
                else
                {
                    if (forCurrentUser)
                    {
                        header = WebAppsLauncherWS.GetHeaderAndFooter(GetSSOWebAppsLauncherAuthData(), culture, out footer);
                    }
                    else
                    {
                        header = WebAppsLauncherWS.GetAllApplicationsHeaderAndFooter(culture, out footer);
                    }

                    if (FCMConfig.Data.EnableCache)
                    {
                        CacheUtils.Add(cacheKey, header, null,
                                       DateTimeHelper.GetSvcProvDateTimeNow().AddSeconds(FCMConfig.Data.LongCacheDuration), TimeSpan.Zero,
                                       cacheNullObjects: FCMConfig.Data.CacheNullObjects);

                        CacheUtils.Add(cacheKey + "_AdditionalParam", footer, null,
                                       DateTimeHelper.GetSvcProvDateTimeNow().AddSeconds(FCMConfig.Data.LongCacheDuration), TimeSpan.Zero,
                                       cacheNullObjects: FCMConfig.Data.CacheNullObjects);
                    }
                }
            }
            catch (SoapException ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);

                if (!StringUtils.IsNullOrEmptyOrWS(ex.Message) && ex.Message.Contains("00401"))
                {
                    FCMBusiness.ClearSSOCache();
                    GetHeaderAndFooter(out header, out footer);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);
            }
        }
예제 #2
0
        // PUBLIC //

        /// <summary>
        /// Gets the child user.
        /// </summary>
        /// <param name="childUserID">The child user ID.</param>
        public User GetChildUser(long childUserID)
        {
            if (childUserID <= 0)
            {
                return(null);
            }

            string cacheKey = CacheHelper.BuildCacheKey("ChildUser", childUserID);

            try
            {
                User childUser;

                if (FCMConfig.Data.EnableCache && CacheUtils.Contains(cacheKey))
                {
                    childUser = (User)CacheUtils.GetItem(cacheKey);
                }
                else
                {
                    Db_User dbChildUser = DbProvidersWS.GetChildUser(childUserID);
                    childUser = ReadChildUserFromDb(dbChildUser);

                    if (FCMConfig.Data.EnableCache)
                    {
                        CacheUtils.Add(cacheKey, childUser, null, DateTimeHelper.GetSvcProvDateTimeNow().AddSeconds(FCMConfig.Data.LongCacheDuration),
                                       TimeSpan.Zero,
                                       cacheNullObjects: FCMConfig.Data.CacheNullObjects);
                    }
                }

                return(childUser);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevels.Error, string.Format("childUserID:'{0}'", childUserID), ex);
                return(null);
            }
        }
예제 #3
0
        // PRIVATE //

        /// <summary>
        /// Gets all roles.
        /// </summary>
        private static List <Role> GetAllRoles()
        {
            try
            {
                List <Role> roles    = null;
                string      culture  = CultureHelper.GetCulture();
                string      cacheKey = CacheHelper.BuildCacheKey("Roles", culture);

                if (FCMConfig.Data.EnableCache && CacheUtils.Contains(cacheKey))
                {
                    roles = (List <Role>)CacheUtils.GetItem(cacheKey);
                }
                else
                {
                    SSOAuth_Role[] rolesDataList = SSOAuthWS.GetAllRoles(culture);

                    if (rolesDataList != null && rolesDataList.Length > 0)
                    {
                        roles = new List <Role>(rolesDataList.Length);

                        foreach (SSOAuth_Role roleData in rolesDataList)
                        {
                            if (roleData == null)
                            {
                                continue;
                            }

                            Role role = null;

                            if (ReadRole(ref role, roleData))
                            {
                                roles.Add(role);
                            }
                        }
                    }

                    if (FCMConfig.Data.EnableCache)
                    {
                        CacheUtils.Add(cacheKey, roles, null, DateTimeHelper.GetSvcProvDateTimeNow().AddSeconds(FCMConfig.Data.LongCacheDuration),
                                       TimeSpan.Zero,
                                       cacheNullObjects: FCMConfig.Data.CacheNullObjects);
                    }
                }

                return(roles);
            }
            catch (SoapException ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);

                if (!StringUtils.IsNullOrEmptyOrWS(ex.Message) && ex.Message.Contains("00401"))
                {
                    FCMBusiness.ClearSSOCache();
                    return(GetAllRoles());
                }

                return(null);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);
                return(null);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the applications.
        /// </summary>
        public List <Application> GetApplications()
        {
            //return null;

            try
            {
                List <Application> applications = null;
                string             culture      = CultureHelper.GetCulture();
                string             cacheKey     = CacheHelper.BuildCacheKey("Applications", culture);

                if (FCMConfig.Data.EnableCache && CacheUtils.Contains(cacheKey))
                {
                    applications = (List <Application>)CacheUtils.GetItem(cacheKey);
                }
                else
                {
                    SSOAuth_ApplicationData[] applicationsDataList = SSOAuthWS.GetAllApplicationsData(culture);

                    if (applicationsDataList != null && applicationsDataList.Length > 0)
                    {
                        applications = new List <Application>(applicationsDataList.Length);

                        foreach (SSOAuth_ApplicationData applicationData in applicationsDataList)
                        {
                            if (applicationData == null)
                            {
                                continue;
                            }

                            Application application = null;

                            if (ReadApplication(ref application, applicationData, GetAllRoles()))
                            {
                                applications.Add(application);
                            }
                        }
                    }

                    if (FCMConfig.Data.EnableCache)
                    {
                        CacheUtils.Add(cacheKey, applications, null,
                                       DateTimeHelper.GetSvcProvDateTimeNow().AddSeconds(FCMConfig.Data.LongCacheDuration), TimeSpan.Zero,
                                       cacheNullObjects: FCMConfig.Data.CacheNullObjects);
                    }
                }

                return(applications);
            }
            catch (SoapException ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);

                if (!StringUtils.IsNullOrEmptyOrWS(ex.Message) && ex.Message.Contains("00401"))
                {
                    FCMBusiness.ClearSSOCache();
                    return(GetApplications());
                }

                return(null);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevels.Error, exception: ex);
                return(null);
            }
        }
예제 #5
0
        // PUBLIC //

        /// <summary>
        /// Gets the application.
        /// </summary>
        /// <param name="applicationID">The application ID.</param>
        /// <param name="applicationName">Name of the application.</param>
        public Application GetApplication(string applicationID, string applicationName)
        {
            if (StringUtils.IsNullOrEmptyOrWS(applicationID) &&
                StringUtils.IsNullOrEmptyOrWS(applicationName))
            {
                return(null);
            }

            try
            {
                Application application = null;
                string      culture     = CultureHelper.GetCulture();
                string      cacheKey    = CacheHelper.BuildCacheKey("Application", culture, applicationID, applicationName);

                if (FCMConfig.Data.EnableCache && CacheUtils.Contains(cacheKey))
                {
                    application = (Application)CacheUtils.GetItem(cacheKey);
                }
                else
                {
                    List <Application> applications = GetApplications();

                    if (applications != null && applications.Count > 0)
                    {
                        application = new Application();

                        foreach (Application existingApplication in applications)
                        {
                            if (!StringUtils.IsNullOrEmptyOrWS(applicationID))
                            {
                                if (existingApplication.ApplicationID.ToLower() == applicationID.ToLower())
                                {
                                    application = existingApplication;
                                    break;
                                }
                            }
                            else
                            {
                                if (existingApplication.Name.ToLower() == applicationName.ToLower() ||
                                    (existingApplication.IsAdmin && applicationName == "$ADMIN"))
                                {
                                    application = existingApplication;
                                    break;
                                }
                            }
                        }
                    }

                    if (FCMConfig.Data.EnableCache)
                    {
                        CacheUtils.Add(cacheKey, application, null,
                                       DateTimeHelper.GetSvcProvDateTimeNow().AddSeconds(FCMConfig.Data.LongCacheDuration), TimeSpan.Zero,
                                       cacheNullObjects: FCMConfig.Data.CacheNullObjects);
                    }
                }

                return(application);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevels.Error, string.Format("applicationID:'{0}', applicationName:'{1}'", applicationID, applicationName), ex);
                return(null);
            }
        }