示例#1
0
        /// <summary>
        /// 设置模块实例
        /// </summary>
        /// <param name="moduleInfo">模块对象</param>
        /// <returns>模块基类</returns>
        public static ModuleBase SetModuleBase(ModuleInfo moduleInfo)
        {
            ModuleBase desktopModule = new ModuleBase();

            if (moduleInfo.ModuleDefID > 0)
            {
                // 重构,是否需要缓存?
                ModuleDefInfo moduleDef = Spaces.GetModuleDefById(moduleInfo.ModuleDefID);
                try
                {
                    Type type = Type.GetType(moduleDef.BussinessController, false, true);
                    desktopModule = (ModuleBase)Activator.CreateInstance(type);
                }
                catch (Exception ex)
                {
                    string a = ex.Message;
                }
                desktopModule.ModuleDef = moduleDef;                //貌似不需要,重构?
            }
            desktopModule.Module   = moduleInfo;
            desktopModule.ModuleID = moduleInfo.ModuleID;
            if (moduleInfo.ModuleType == ModuleType.Local)
            {
                string path           = BaseConfigs.GetForumPath + "space/modules/" + moduleInfo.ModuleUrl;
                string modulefilepath = Utils.GetMapPath(path);
                try
                {
                    desktopModule.UserPrefCollection = ModuleXmlHelper.LoadUserPrefs(modulefilepath);
                    desktopModule.ModulePref         = ModuleXmlHelper.LoadModulePref(modulefilepath);
                    desktopModule.ModuleContent      = ModuleXmlHelper.LoadContent(modulefilepath);
                }
                catch (Exception ex)
                {
                    desktopModule.UserPrefCollection        = new UserPrefCollection <UserPref>();
                    desktopModule.ModulePref                = new ModulePref();
                    desktopModule.ModuleContent             = new ModuleContent();
                    desktopModule.ModuleContent.ContentHtml = ex.Message;
                    desktopModule.ModuleContent.Type        = ModuleContentType.HtmlInline;
                }
                if (desktopModule.UserPrefCollection == null)
                {
                    desktopModule.UserPrefCollection = new UserPrefCollection <UserPref>();
                }
                if (desktopModule.ModulePref == null)
                {
                    desktopModule.ModulePref = new ModulePref();
                }

                if (desktopModule.ModuleContent == null)
                {
                    desktopModule.ModuleContent             = new ModuleContent();
                    desktopModule.ModuleContent.ContentHtml = "模块" + path + "不存在";
                    desktopModule.ModuleContent.Type        = ModuleContentType.HtmlInline;
                }
            }
            return(desktopModule);
        }
示例#2
0
        public ifr()
        {
            HttpContext.Current.Response.ContentType = "text/html";
//			if (ForumUtils.IsCrossSitePost(DNTRequest.GetUrlReferrer(), DNTRequest.GetHost()))
//				return;

//			if (userid < 1)
//				return;
            string     url        = DNTRequest.GetQueryString("url");
            int        mid        = DNTRequest.GetQueryInt("mid", 0);
            int        uid        = DNTRequest.GetQueryInt("uid", 0);
            ModuleInfo moduleinfo = Spaces.GetModuleById(mid, uid);

            if (moduleinfo == null)
            {
                return;
            }
            if (url != moduleinfo.ModuleUrl)
            {
                return;
            }
            UserPrefsSaved ups = new UserPrefsSaved(moduleinfo.UserPref);

            string        path           = BaseConfigs.GetForumPath + "space/modules/" + url;
            string        modulefilepath = Utils.GetMapPath(path);
            ModulePref    mp             = ModuleXmlHelper.LoadModulePref(modulefilepath);
            ModuleContent mc             = ModuleXmlHelper.LoadContent(modulefilepath);

#if NET1
            UserPrefCollection upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath);
#else
            UserPrefCollection <UserPref> upc = ModuleXmlHelper.LoadUserPrefs(modulefilepath);
#endif

            StringBuilder registScript = new StringBuilder("<script type=\"text/javascript\">");
            foreach (UserPref up in upc)
            {
                string userprefvalue = ups.GetValueByName(up.Name);
                userprefvalue = userprefvalue == string.Empty ? up.DefaultValue : userprefvalue;
                registScript.AppendFormat(PREF_SCRIPT_FORMAT, mid, up.Name, userprefvalue);
            }
            registScript.Append(ModuleXmlHelper.GetModuleRequireScript(mp, mc.Type == ModuleContentType.HtmlInline));
            registScript.Append("</script>");
            string html = string.Format(IFRAME_HTML, registScript.ToString(), mc.ContentHtml, BaseConfigs.GetForumPath);
            html = html.Replace("__MODULE_ID__", mid.ToString()).Replace("_IG_", "_DS_");


            HttpContext.Current.Response.Write(html);
            HttpContext.Current.Response.End();
        }