コード例 #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name = "ModuleID">The ID of the Module being imported</param>
        /// <param name = "Content">The Content being imported</param>
        /// <param name = "Version">The Version of the Module Content being imported</param>
        /// <param name = "UserId">The UserID of the User importing the Content</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------

        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            var xmlDoc     = new XmlDocument();
            var objModCtrl = new ModuleController();
            var objModInfo = objModCtrl.GetModule(ModuleID);

            if (objModInfo != null)
            {
                var objImp = new NBrightInfo(false);
                objImp.FromXmlItem(Content);
                objImp.ModuleId = ModuleID;
                objImp.PortalId = objModInfo.PortalID;
                objImp.ItemID   = -1;           // create new record

                //delete the old setting record.
                var moduleSettings = NBrightBuyUtils.GetSettings(objModInfo.PortalID, ModuleID, "", false);
                if (moduleSettings.ItemID > -1)
                {
                    Delete(moduleSettings.ItemID);
                }

                Update(objImp);

                NBrightBuyUtils.RemoveModCache(ModuleID);
            }
        }
コード例 #2
0
        protected void UpdateData()
        {
            if (CtrlTypeCode != "")
            {
                // read any existing data or create new.
                var objInfo = NBrightBuyUtils.GetSettings(PortalId, ModuleId, CtrlTypeCode, false);

                // populate changed data
                objInfo.ModifiedDate = DateTime.Now;

                //rebuild xml
                objInfo.XMLData = GenXmlFunctions.GetGenXml(RpData);

                objInfo = EventBeforeUpdate(RpData, objInfo);

                objInfo.ItemID = ModCtrl.Update(objInfo);


                EventAfterUpdate(RpData, objInfo);

                // clear any store level cache, might be overkill to clear ALL Store cache,
                // but editing of settings should only happen when changes are being made.
                NBrightBuyUtils.RemoveModCache(-1);
                NBrightBuyUtils.RemoveModCache(ModuleId);
            }
        }
コード例 #3
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   ExportModule implements the IPortable ExportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name = "moduleId">The Id of the module to be exported</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public string ExportModule(int ModuleId)
        {
            var objModCtrl = new ModuleController();
            var xmlOut     = "";

            var objModInfo = objModCtrl.GetModule(ModuleId);

            if (objModInfo != null)
            {
                var portalId       = objModInfo.PortalID;
                var moduleSettings = NBrightBuyUtils.GetSettings(portalId, ModuleId, "", false);

                xmlOut += moduleSettings.ToXmlItem();
            }

            return(xmlOut);
        }
コード例 #4
0
        private void PageLoad()
        {
            try
            {
                var obj = NBrightBuyUtils.GetSettings(PortalId, ModuleId);

                obj.ModuleId = base.ModuleId; // need to pass the moduleid here, becuase it doesn;t exists in url for settings and on new settings it needs it.
                var strOut = NBrightBuyUtils.RazorTemplRender(ModuleConfiguration.DesktopModule.ModuleName + "settings.cshtml", ModuleId, "", obj, "/DesktopModules/NBright/NBrightBuy", "config", Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
                var lit    = new Literal();
                lit.Text = strOut;
                phData.Controls.Add(lit);
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
コード例 #5
0
        private String SaveSettings(HttpContext context)
        {
            try
            {
                var objCtrl = new NBrightBuyController();

                //get uploaded params
                var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);

                var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
                if (Utils.IsNumeric(moduleid))
                {
                    // get DB record
                    var nbi = NBrightBuyUtils.GetSettings(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid));
                    if (nbi.ModuleId == 0) // new setting record
                    {
                        nbi = CreateSettingsInfo(moduleid, nbi);
                    }
                    // get data passed back by ajax
                    var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
                    // update record with ajax data
                    nbi.UpdateAjax(strIn);


                    if (nbi.GetXmlProperty("genxml/hidden/modref") == "")
                    {
                        nbi.SetXmlProperty("genxml/hidden/modref", Utils.GetUniqueKey(10));
                    }
                    if (nbi.TextData == "")
                    {
                        nbi.TextData = "NBrightBuy";
                    }
                    objCtrl.Update(nbi);
                    NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId); // make sure all new settings are used.
                }
                return("");
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                return(ex.ToString());
            }
        }
コード例 #6
0
        private String GetSettings(HttpContext context, bool clearCache = false)
        {
            try
            {
                var strOut = "";
                //get uploaded params
                var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);

                var moduleid      = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
                var razortemplate = ajaxInfo.GetXmlProperty("genxml/hidden/razortemplate");
                var themefolder   = ajaxInfo.GetXmlProperty("genxml/dropdownlist/themefolder");
                var controlpath   = ajaxInfo.GetXmlProperty("genxml/hidden/controlpath");
                if (controlpath == "")
                {
                    controlpath = "/DesktopModules/NBright/NBrightBuy";
                }
                if (razortemplate == "")
                {
                    return("");                     // assume no settings requirted
                }
                if (moduleid == "")
                {
                    moduleid = "-1";
                }

                // do edit field data if a itemid has been selected
                var obj = NBrightBuyUtils.GetSettings(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid));
                obj.ModuleId = Convert.ToInt32(moduleid); // assign for new records
                strOut       = NBrightBuyUtils.RazorTemplRender(razortemplate, obj.ModuleId, "settings", obj, controlpath, themefolder, _uilang, null);

                return(strOut);
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                return(ex.ToString());
            }
        }
コード例 #7
0
        private void PageLoad()
        {
            try
            {
                // load the notificationmessage if with have a placeholder control to display it.
                var ctrlMsg = this.FindControl("notifymsg");
                if (ctrlMsg != null)
                {
                    var msg = NBrightBuyUtils.GetNotfiyMessage(ModuleId);
                    var l   = new Literal {
                        Text = msg
                    };
                    ctrlMsg.Controls.Add(l);
                }

                if (CtrlTypeCode != "")
                {
                    // display the detail
                    var l = new List <NBrightInfo>();
                    var moduleSettings = NBrightBuyUtils.GetSettings(PortalId, ModuleId, CtrlTypeCode, false);
                    moduleSettings = EventBeforeRender(moduleSettings);
                    l.Add(moduleSettings);
                    RpData.DataSource = l;
                    RpData.DataBind();

                    //if new setting, save theme and reload, so we get theme settings displayed.
                    if (moduleSettings.ItemID == -1)
                    {
                        UpdateData();
                        Response.Redirect(Request.Url.AbsoluteUri, true);
                    }
                }
            }
            catch (Exception exc)             //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
コード例 #8
0
        private void PageLoad()
        {
            try
            {
                var obj = NBrightBuyUtils.GetSettings(PortalId, ModuleId);
                obj.ModuleId = base.ModuleId; // need to pass the moduleid here, becuase it doesn;t exists in url for settings and on new settings it needs it.

                // check the moduleref is unique, if not the module have been copied, so create new moduleref
                var objCtrl   = new NBrightBuyController();
                var moduleKey = obj.GetXmlProperty("genxml/hidden/modref");
                if (!String.IsNullOrEmpty(moduleKey))
                {
                    var modl = objCtrl.GetDataListCount(PortalId, -1, "SETTINGS", " and [XMLData].value('(genxml/hidden/modref)[1]','nvarchar(max)') = '" + moduleKey + "'", "", "", false, false);
                    if (modl > 1)
                    {
                        // we have multiple refs, reset this one.
                        obj.SetXmlProperty("genxml/hidden/modref", Utils.GetUniqueKey(10));
                        objCtrl.Update(obj);
                    }
                }


                if (String.IsNullOrEmpty(SettingsTemplate))
                {
                    SettingsTemplate = ModuleConfiguration.DesktopModule.ModuleName + "settings.cshtml";                                         // default to name of module
                }
                var strOut = NBrightBuyUtils.RazorTemplRender(SettingsTemplate, ModuleId, "", obj, ControlPath, "config", Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
                var lit    = new Literal();
                lit.Text = strOut;
                phData.Controls.Add(lit);
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
コード例 #9
0
ファイル: ModSettings.cs プロジェクト: valadas/Open-Store
        private void BuildSettingsDic(System.Collections.Hashtable modSettings)
        {
            var nbbSettings = NBrightBuyUtils.GetSettings(PortalSettings.Current.PortalId, Moduleid);

            _settingsDic = new Dictionary <string, string>();
            // this function will build the Settings that is passed to the templating system.
            var strCacheKey = PortalSettings.Current.PortalId.ToString("") + "*" + Moduleid.ToString("") + "*SettingsDic";
            var obj         = NBrightBuyUtils.GetModCache(strCacheKey);

            if (obj != null)
            {
                _settingsDic = (Dictionary <string, string>)obj;
            }
            if (_settingsDic.Count == 0 || StoreSettings.Current.DebugMode)
            {
                if (!_settingsDic.ContainsKey("tabid"))
                {
                    _settingsDic.Add("tabid", PortalSettings.Current.ActiveTab.TabID.ToString(""));
                }

                // add store settings (we keep store settings at module level, because these can be overwritten by the module)
                var storesettings = StoreSettings.Current.Settings(); // assign to var, so it doesn;t causes error if site settings change during loop.
                foreach (var item in storesettings)
                {
                    if (_settingsDic.ContainsKey(item.Key))
                    {
                        _settingsDic[item.Key] = item.Value;
                    }
                    else
                    {
                        _settingsDic.Add(item.Key, item.Value);
                    }
                }


                // add normal DNN Setting
                foreach (string name in modSettings.Keys)
                {
                    if (!_settingsDic.ContainsKey(name))
                    {
                        _settingsDic.Add(name, modSettings[name].ToString());
                    }
                }

                // add nbbSettings Settings
                AddToSettingDic(nbbSettings, "genxml/hidden/*");
                AddToSettingDic(nbbSettings, "genxml/textbox/*");
                AddToSettingDic(nbbSettings, "genxml/checkbox/*");
                AddToSettingDic(nbbSettings, "genxml/dropdownlist/*");
                AddToSettingDic(nbbSettings, "genxml/radiobuttonlist/*");


                // redo the moduleid key, on imported module settings this could be wrong.
                if (_settingsDic.ContainsKey("moduleid"))
                {
                    _settingsDic["moduleid"] = Moduleid.ToString("");
                }
                else
                {
                    _settingsDic.Add("moduleid", Moduleid.ToString(""));
                }

                NBrightBuyUtils.SetModCache(Moduleid, strCacheKey, _settingsDic);
            }
            else
            {
                _settingsDic = (Dictionary <string, string>)obj;
            }

            // redo the edit langauge for backoffice.
            if (_settingsDic != null)
            {
                if (_settingsDic.ContainsKey("editlanguage"))
                {
                    _settingsDic["editlanguage"] = StoreSettings.Current.EditLanguage;
                }
                else
                {
                    _settingsDic.Add("editlanguage", StoreSettings.Current.EditLanguage);
                }
            }
        }
コード例 #10
0
        public static List <UrlRule> GetRules(int portalId)
        {
            object padlock = new object();

            lock (padlock)
            {
                List <UrlRule> rules    = new List <UrlRule>();
                List <UrlRule> catrules = new List <UrlRule>();

                #if DEBUG
                decimal speed;
                string  mess;
                var     stopwatch = new System.Diagnostics.Stopwatch();
                stopwatch.Start();
                #endif

                var purgeResult    = UrlRulesCaching.PurgeExpiredItems(portalId);
                var portalCacheKey = UrlRulesCaching.GeneratePortalCacheKey(portalId, null);
                var portalRules    = UrlRulesCaching.GetCache(portalId, portalCacheKey, purgeResult.ValidCacheItems);
                if (portalRules != null && portalRules.Count > 0)
                {
                    #if DEBUG
                    stopwatch.Stop();
                    speed = stopwatch.Elapsed.Milliseconds;
                    mess  = $"PortalId: {portalId}. Time elapsed: {stopwatch.Elapsed.Milliseconds}ms. All Cached. PurgedItems: {purgeResult.PurgedItemCount}. Speed: {speed}";
                    Logger.Error(mess);
                    #endif
                    return(portalRules);
                }

                Dictionary <string, Locale> dicLocales = LocaleController.Instance.GetLocales(portalId);

                var objCtrl = new NBrightBuyController();

                var storesettings = new StoreSettings(portalId);

                ModuleController mc  = new ModuleController();
                var modules          = mc.GetModulesByDefinition(portalId, "NBS_ProductDisplay").OfType <ModuleInfo>();
                var modulesOldModule = mc.GetModulesByDefinition(portalId, "NBS_ProductView").OfType <ModuleInfo>();
                modules = modules.Concat(modulesOldModule);

                // ------- Category URL ---------------

                #region "Category Url"

                // Not using the module loop!!
                // becuase tabs that are defined in the url are dealt with by open url rewriter, so we only need use the default tab which is defined by the store settings.

                foreach (KeyValuePair <string, Locale> key in dicLocales)
                {
                    try
                    {
                        string cultureCode     = key.Value.Code;
                        string ruleCultureCode = (dicLocales.Count > 1 ? cultureCode : null);

                        var grpCatCtrl = new GrpCatController(cultureCode, portalId);

                        // get all products in portal, with lang data
                        var catitems = objCtrl.GetList(portalId, -1, "CATEGORY");

                        foreach (var catData in catitems)
                        {
                            var catDataLang = objCtrl.GetDataLang(catData.ItemID, cultureCode);

                            if (catDataLang != null && !catData.GetXmlPropertyBool("genxml/checkbox/chkishidden"))
                            {
                                var            catCacheKey   = portalCacheKey + "_" + catDataLang.ItemID + "_" + cultureCode;
                                List <UrlRule> categoryRules = UrlRulesCaching.GetCache(portalId, catCacheKey, purgeResult.ValidCacheItems);
                                if (categoryRules != null && categoryRules.Count > 0)
                                {
                                    rules.AddRange(categoryRules);
                                }
                                else
                                {
                                    catrules = new List <UrlRule>();

                                    var caturlname   = catDataLang.GUIDKey;
                                    var SEOName      = catDataLang.GetXmlProperty("genxml/textbox/txtseoname");
                                    var categoryName = catDataLang.GetXmlProperty("genxml/textbox/txtcategoryname");

                                    var newcatUrl = grpCatCtrl.GetBreadCrumb(catData.ItemID, 0, "/", false);

                                    var url = newcatUrl;
                                    if (!string.IsNullOrEmpty(url))
                                    {
                                        // ------- Category URL ---------------

                                        var rule = new UrlRule
                                        {
                                            CultureCode = ruleCultureCode,
                                            TabId       = storesettings.ProductListTabId,
                                            Parameters  = "catref=" + caturlname,
                                            Url         = url
                                        };
                                        var reducedRules =
                                            rules.Where(r => r.CultureCode == rule.CultureCode && r.TabId == rule.TabId)
                                            .ToList();
                                        bool ruleExist = reducedRules.Any(r => r.Parameters == rule.Parameters);
                                        if (!ruleExist)
                                        {
                                            if (reducedRules.Any(r => r.Url == rule.Url)) // if duplicate url
                                            {
                                                rule.Url = catData.ItemID + "-" + url;
                                            }
                                            rules.Add(rule);
                                            catrules.Add(rule);
                                        }

                                        var proditems = objCtrl.GetList(catData.PortalId, -1, "CATXREF", " and NB1.XRefItemId = " + catData.ItemID.ToString(""));
                                        var l2        = objCtrl.GetList(catData.PortalId, -1, "CATCASCADE", " and NB1.XRefItemId = " + catData.ItemID.ToString(""));
                                        proditems.AddRange(l2);

                                        var pageurl  = "";
                                        var pageurl1 = rule.Url;
                                        // do paging for category (on all product modules.)
                                        foreach (var module in modules)
                                        {
                                            // ------- Paging URL ---------------
                                            var modsetting        = NBrightBuyUtils.GetSettings(portalId, module.ModuleID);
                                            var pagesize          = modsetting.GetXmlPropertyInt("genxml/textbox/pagesize");
                                            var staticlist        = modsetting.GetXmlPropertyBool("genxml/checkbox/staticlist");
                                            var defaultcatid      = modsetting.GetXmlPropertyBool("genxml/dropdownlist/defaultpropertyid");
                                            var defaultpropertyid = modsetting.GetXmlPropertyBool("genxml/dropdownlist/defaultcatid");
                                            if (pagesize > 0)
                                            {
                                                if (module.TabID != storesettings.ProductListTabId || staticlist)
                                                {
                                                    // on the non-default product list tab, add the moduleid, so we dont; get duplicates.
                                                    // NOTE: this only supports defaut paging url for 1 module on the defaut product list page. Other modules will have moduleid added to the url.

                                                    //pageurl = module.ModuleID + "-" + pageurl1;

                                                    //IGNORE NON DEFAULT MODULES.
                                                }
                                                else
                                                {
                                                    pageurl = pageurl1;


                                                    var pagetotal = Convert.ToInt32((proditems.Count / pagesize) + 1);
                                                    for (int i = 1; i <= pagetotal; i++)
                                                    {
                                                        rule = new UrlRule
                                                        {
                                                            CultureCode = ruleCultureCode,
                                                            TabId       = module.TabID,
                                                            Parameters  = "catref=" + caturlname + "&page=" + i + "&pagemid=" + module.ModuleID,
                                                            Url         = pageurl + "-" + i
                                                        };
                                                        ruleExist = reducedRules.Any(r => r.Parameters == rule.Parameters);
                                                        if (!ruleExist)
                                                        {
                                                            if (reducedRules.Any(r => r.Url == rule.Url)) // if duplicate url
                                                            {
                                                                rule.Url = module.ModuleID + "-" + rule.Url;
                                                            }
                                                            rules.Add(rule);
                                                            catrules.Add(rule);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        // ------- Product URL ---------------
                                        foreach (var xrefData in proditems)
                                        {
                                            //var product = new ProductData(xrefData.ParentItemId, cultureCode, false);
                                            var prdData = objCtrl.GetData(xrefData.ParentItemId, cultureCode);

                                            var pref = prdData.GetXmlProperty("genxml/textbox/txtproductref");

                                            string produrl = prdData.GetXmlProperty("genxml/lang/genxml/textbox/txtseoname");
                                            ;
                                            if (string.IsNullOrEmpty(produrl))
                                            {
                                                produrl = prdData.GetXmlProperty("genxml/lang/genxml/textbox/txtproductname");
                                            }
                                            if (string.IsNullOrEmpty(produrl))
                                            {
                                                produrl = pref;
                                            }
                                            if (string.IsNullOrEmpty(produrl))
                                            {
                                                produrl = prdData.ItemID.ToString("");
                                            }
                                            //if (catref != "") produrl = catref + "-" + produrl;
                                            //if (catref != "") produrl = catref + "-" + produrl;
                                            produrl = newcatUrl + "/" + Utils.UrlFriendly(produrl);
                                            var prodrule = new UrlRule
                                            {
                                                CultureCode = ruleCultureCode,
                                                TabId       = storesettings.ProductDetailTabId,
                                                Parameters  = "catref=" + catDataLang.GUIDKey + "&ref=" + prdData.GUIDKey,
                                                Url         = produrl
                                            };
                                            reducedRules =
                                                rules.Where(
                                                    r => r.CultureCode == prodrule.CultureCode && r.TabId == prodrule.TabId)
                                                .ToList();
                                            ruleExist = reducedRules.Any(r => r.Parameters == prodrule.Parameters);
                                            if (!ruleExist)
                                            {
                                                if (reducedRules.Any(r => r.Url == prodrule.Url)) // if duplicate url
                                                {
                                                    prodrule.Url = prdData.ItemID + "-" + produrl;
                                                }
                                                rules.Add(prodrule);
                                                catrules.Add(prodrule);
                                            }
                                        }
                                    }
                                    UrlRulesCaching.SetCache(portalId, catCacheKey, new TimeSpan(1, 0, 0, 0), catrules);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Failed to generate url for module NBS", ex);
                    }
                }

                #endregion


                UrlRulesCaching.SetCache(portalId, portalCacheKey, new TimeSpan(1, 0, 0, 0), rules);


                #if DEBUG
                stopwatch.Stop();
                mess = $"PortalId: {portalId}. Time elapsed: {stopwatch.Elapsed.Milliseconds}ms. Module Count: {modules.Count()}. PurgedItems: {purgeResult.PurgedItemCount}";
                Logger.Error(mess);
                Console.WriteLine(mess);
                #endif


                return(rules);
            }
        }