Пример #1
0
        public static string TryToGetReliableSetting(ModuleInfo module, string settingName)
        {
            if (module.ModuleSettings.ContainsKey(settingName))
                return module.ModuleSettings[settingName].ToString();

            // if not found, it could be a caching issue
            var settings = new ModuleController().GetModuleSettings(module.ModuleID);
            return settings.ContainsKey(settingName) ? settings[settingName].ToString() : null;
        }
Пример #2
0
        /// <summary>
        /// Loads the module settings.
        /// </summary>
        /// <param name="portalSettings">The portal settings.</param>
        /// <param name="currentSettings">The current settings.</param>
        /// <param name="key">The module key.</param>
        /// <param name="moduleId">The module id.</param>
        /// <param name="portalRoles">The portal roles.</param>
        /// <returns>
        /// Returns the filled Module Settings
        /// </returns>
        internal static EditorProviderSettings LoadModuleSettings(PortalSettings portalSettings, EditorProviderSettings currentSettings, string key, int moduleId, ArrayList portalRoles)
        {
            var hshModSet = new ModuleController().GetModuleSettings(moduleId);

            var roleController = new RoleController();

            var roles = new ArrayList();

            // Import all Editor config settings
            foreach (PropertyInfo info in
                GetEditorConfigProperties()
                    .Where(
                        info =>
                        !string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, info.Name)])
                        || info.Name.Equals("CodeMirror") || info.Name.Equals("WordCount")))
            {
                switch (info.PropertyType.Name)
                {
                    case "String":
                        info.SetValue(currentSettings.Config, hshModSet[string.Format("{0}{1}", key, info.Name)], null);
                        break;
                    case "Int32":
                        info.SetValue(
                            currentSettings.Config,
                            int.Parse((string)hshModSet[string.Format("{0}{1}", key, info.Name)]),
                            null);
                        break;
                    case "Decimal":
                        info.SetValue(
                            currentSettings.Config,
                            decimal.Parse((string)hshModSet[string.Format("{0}{1}", key, info.Name)]),
                            null);
                        break;
                    case "Boolean":
                        info.SetValue(
                            currentSettings.Config,
                            bool.Parse((string)hshModSet[string.Format("{0}{1}", key, info.Name)]),
                            null);
                        break;
                }

                switch (info.Name)
                {
                    case "ToolbarLocation":
                        info.SetValue(
                            currentSettings.Config,
                            (ToolBarLocation)
                            Enum.Parse(
                                typeof(ToolBarLocation), (string)hshModSet[string.Format("{0}{1}", key, info.Name)]),
                            null);
                        break;
                    case "DefaultLinkType":
                        info.SetValue(
                            currentSettings.Config,
                            (LinkType)
                            Enum.Parse(typeof(LinkType), (string)hshModSet[string.Format("{0}{1}", key, info.Name)]),
                            null);
                        break;
                    case "EnterMode":
                    case "ShiftEnterMode":
                        info.SetValue(
                            currentSettings.Config,
                            (EnterModus)
                            Enum.Parse(typeof(EnterModus), (string)hshModSet[string.Format("{0}{1}", key, info.Name)]),
                            null);
                        break;
                    case "ContentsLangDirection":
                        info.SetValue(
                            currentSettings.Config,
                            (LanguageDirection)
                            Enum.Parse(
                                typeof(LanguageDirection), (string)hshModSet[string.Format("{0}{1}", key, info.Name)]),
                            null);
                        break;
                    case "CodeMirror":
                        foreach (var codeMirrorInfo in
                            typeof(CodeMirror).GetProperties()
                                              .Where(codeMirrorInfo => !codeMirrorInfo.Name.Equals("Theme")))
                        {
                            switch (codeMirrorInfo.PropertyType.Name)
                            {
                                case "String":
                                    if (hshModSet.ContainsKey(string.Format("{0}{1}", key, codeMirrorInfo.Name)))
                                    {
                                        codeMirrorInfo.SetValue(
                                            currentSettings.Config.CodeMirror,
                                            hshModSet[string.Format("{0}{1}", key, codeMirrorInfo.Name)],
                                            null);
                                    }

                                    break;
                                case "Boolean":
                                    if (hshModSet.ContainsKey(string.Format("{0}{1}", key, codeMirrorInfo.Name)))
                                    {
                                        codeMirrorInfo.SetValue(
                                            currentSettings.Config.CodeMirror,
                                            bool.Parse(
                                                (string)hshModSet[string.Format("{0}{1}", key, codeMirrorInfo.Name)]),
                                            null);
                                    }

                                    break;
                            }
                        }

                        break;
                    case "WordCount":
                        foreach (var wordCountInfo in typeof(WordCountConfig).GetProperties())
                        {
                            switch (wordCountInfo.PropertyType.Name)
                            {
                                case "String":
                                    if (hshModSet.ContainsKey(string.Format("{0}{1}", key, wordCountInfo.Name)))
                                    {
                                        wordCountInfo.SetValue(
                                            currentSettings.Config.WordCount,
                                            hshModSet[string.Format("{0}{1}", key, wordCountInfo.Name)],
                                            null);
                                    }

                                    break;
                                case "Boolean":
                                    if (hshModSet.ContainsKey(string.Format("{0}{1}", key, wordCountInfo.Name)))
                                    {
                                        wordCountInfo.SetValue(
                                            currentSettings.Config.WordCount,
                                            bool.Parse(
                                                (string)hshModSet[string.Format("{0}{1}", key, wordCountInfo.Name)]),
                                            null);
                                    }

                                    break;
                            }
                        }

                        break;
                }
            }

            /////////////////

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.SKIN)]))
            {
                currentSettings.Config.Skin = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.SKIN)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CODEMIRRORTHEME)]))
            {
                currentSettings.Config.CodeMirror.Theme = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CODEMIRRORTHEME)];
            }

            List<ToolbarRoles> listToolbarRoles = (from RoleInfo objRole in portalRoles
                                                   where
                                                       !string.IsNullOrEmpty(
                                                           (string)
                                                           hshModSet[string.Format("{0}{2}#{1}", key, objRole.RoleID, SettingConstants.TOOLB)])
                                                   let sToolbar =
                                                       (string)
                                                       hshModSet[string.Format("{0}{2}#{1}", key, objRole.RoleID, SettingConstants.TOOLB)]
                                                   select
                                                       new ToolbarRoles { RoleId = objRole.RoleID, Toolbar = sToolbar })
                .ToList();

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{2}#{1}", key, "-1", SettingConstants.TOOLB)]))
            {
                string sToolbar = (string)hshModSet[string.Format("{0}{2}#{1}", key, "-1", SettingConstants.TOOLB)];

                listToolbarRoles.Add(new ToolbarRoles { RoleId = -1, Toolbar = sToolbar });
            }

            currentSettings.ToolBarRoles = listToolbarRoles;

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.ROLES)]))
            {
                string sRoles = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.ROLES)];

                currentSettings.BrowserRoles = sRoles;

                string[] rolesA = sRoles.Split(';');

                foreach (string sRoleName in rolesA)
                {
                    if (Utility.IsNumeric(sRoleName))
                    {
                        RoleInfo roleInfo = roleController.GetRole(
                            int.Parse(sRoleName), portalSettings.PortalId);

                        if (roleInfo != null)
                        {
                            roles.Add(roleInfo.RoleName);
                        }
                    }
                    else
                    {
                        roles.Add(sRoleName);
                    }
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.BROWSER)]))
            {
                currentSettings.Browser = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.BROWSER)];

                switch (currentSettings.Browser)
                {
                    case "ckfinder":
                        foreach (string sRoleName in roles)
                        {
                            if (PortalSecurity.IsInRoles(sRoleName))
                            {
                                currentSettings.BrowserMode = Browser.CKFinder;

                                break;
                            }

                            currentSettings.BrowserMode = Browser.None;
                        }

                        break;
                    case "standard":
                        foreach (string sRoleName in roles)
                        {
                            if (PortalSecurity.IsInRoles(sRoleName))
                            {
                                currentSettings.BrowserMode = Browser.StandardBrowser;

                                break;
                            }

                            currentSettings.BrowserMode = Browser.None;
                        }

                        break;
                    case "none":
                        currentSettings.BrowserMode = Browser.None;
                        break;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.INJECTJS)]))
            {
                bool bResult;
                if (bool.TryParse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.INJECTJS)], out bResult))
                {
                    currentSettings.InjectSyntaxJs = bResult;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.WIDTH)]))
            {
                currentSettings.Config.Width = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.WIDTH)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.HEIGHT)]))
            {
                currentSettings.Config.Height = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.HEIGHT)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.BLANKTEXT)]))
            {
                currentSettings.BlankText = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.BLANKTEXT)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.STYLES)]))
            {
                currentSettings.Config.StylesSet = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.STYLES)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CSS)]))
            {
                currentSettings.Config.ContentsCss = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CSS)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.TEMPLATEFILES)]))
            {
                currentSettings.Config.Templates_Files = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.TEMPLATEFILES)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CUSTOMJSFILE)]))
            {
                currentSettings.CustomJsFile = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CUSTOMJSFILE)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CONFIG)]))
            {
                currentSettings.Config.CustomConfig = (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.CONFIG)];
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.FILELISTPAGESIZE)]))
            {
                currentSettings.FileListPageSize = int.Parse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.FILELISTPAGESIZE)]);
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.FILELISTVIEWMODE)]))
            {
                currentSettings.FileListViewMode =
                    (FileListView)
                    Enum.Parse(typeof(FileListView), (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.FILELISTVIEWMODE)]);
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.DEFAULTLINKMODE)]))
            {
                currentSettings.DefaultLinkMode =
                    (LinkMode)
                    Enum.Parse(typeof(LinkMode), (string)hshModSet[string.Format("{0}{1}", key, SettingConstants.DEFAULTLINKMODE)]);
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.USEANCHORSELECTOR)]))
            {
                bool bResult;
                if (bool.TryParse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.USEANCHORSELECTOR)], out bResult))
                {
                    currentSettings.UseAnchorSelector = bResult;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.SHOWPAGELINKSTABFIRST)]))
            {
                bool bResult;
                if (bool.TryParse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.SHOWPAGELINKSTABFIRST)], out bResult))
                {
                    currentSettings.ShowPageLinksTabFirst = bResult;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.OVERRIDEFILEONUPLOAD)]))
            {
                bool bResult;
                if (bool.TryParse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.OVERRIDEFILEONUPLOAD)], out bResult))
                {
                    currentSettings.OverrideFileOnUpload = bResult;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.SUBDIRS)]))
            {
                bool bResult;
                if (bool.TryParse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.SUBDIRS)], out bResult))
                {
                    currentSettings.SubDirs = bResult;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.BROWSERROOTDIRID)]))
            {
                try
                {
                    currentSettings.BrowserRootDirId = int.Parse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.BROWSERROOTDIRID)]);
                }
                catch (Exception)
                {
                    currentSettings.BrowserRootDirId = -1;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.UPLOADDIRID)]))
            {
                try
                {
                    currentSettings.UploadDirId = int.Parse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.UPLOADDIRID)]);
                }
                catch (Exception)
                {
                    currentSettings.UploadDirId = -1;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.RESIZEWIDTH)]))
            {
                try
                {
                    currentSettings.ResizeWidth = int.Parse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.RESIZEWIDTH)]);
                }
                catch (Exception)
                {
                    currentSettings.ResizeWidth = -1;
                }
            }

            if (!string.IsNullOrEmpty((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.RESIZEHEIGHT)]))
            {
                try
                {
                    currentSettings.ResizeHeight = int.Parse((string)hshModSet[string.Format("{0}{1}", key, SettingConstants.RESIZEHEIGHT)]);
                }
                catch (Exception)
                {
                    currentSettings.ResizeHeight = -1;
                }
            }

            return currentSettings;
        }