Ejemplo n.º 1
0
        public static void PluginSave(HttpContext context)
        {
            if (NBrightBuyUtils.CheckRights())
            {
                var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
                var itemid   = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
                if (Utils.IsNumeric(itemid))
                {
                    var objCtrl      = new NBrightBuyController();
                    var info         = objCtrl.GetData(Convert.ToInt32(itemid));
                    var pluginRecord = new PluginRecord(info);
                    var modelXml     = Utils.UnCode(ajaxInfo.GetXmlProperty("genxml/hidden/xmlupdatemodeldata"));

                    ajaxInfo.RemoveXmlNode("genxml/hidden/xmlupdatemodeldata");
                    pluginRecord.Info().XMLData = ajaxInfo.XMLData;

                    // check for unique ctrl ref
                    var ctrlref  = pluginRecord.Info().GetXmlProperty("genxml/textbox/ctrl");
                    var ctrltest = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PLUGIN", ctrlref);
                    if (ctrltest != null)
                    {
                        if (ctrltest.ItemID != pluginRecord.Info().ItemID)
                        {
                            pluginRecord.Info().SetXmlProperty("genxml/textbox/ctrl", pluginRecord.Info().GetXmlProperty("genxml/textbox/ctrl") + Utils.GetUniqueKey());
                        }
                    }

                    // make sure index is in correct format, (FLOAT) for SQL
                    pluginRecord.Info().SetXmlProperty("genxml/hidden/index", (pluginRecord.Info().GetXmlPropertyInt("genxml/hidden/index").ToString()), TypeCode.Double);
                    pluginRecord.Info().RemoveXmlNode("genxml/hidden/itemid");
                    pluginRecord.Info().RemoveXmlNode("genxml/hidden/editlanguage");
                    pluginRecord.Info().RemoveXmlNode("genxml/hidden/uilang1");
                    pluginRecord.Info().GUIDKey = pluginRecord.Info().GetXmlProperty("genxml/textbox/ctrl");

                    pluginRecord.UpdateModels(modelXml, Utils.GetCurrentCulture());
                    objCtrl.Update(pluginRecord.Info());

                    // remove save GetData cache
                    DataCache.ClearCache();

                    //load entity typecode to DB idx settings.
                    NBrightBuyUtils.RegisterEnityTypeToDataBase();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Search filesystem for any new plugins that have been added. Removed any deleted ones.
        /// </summary>
        public static void UpdateSystemPlugins()
        {
            // Add new plugins
            var updated             = false;
            var deleted             = false;
            var pluginfoldermappath = System.Web.Hosting.HostingEnvironment.MapPath(StoreSettings.NBrightBuyPath() + "/Plugins");

            if (pluginfoldermappath != null && Directory.Exists(pluginfoldermappath))
            {
                var objCtrl = new NBrightBuyController();
                var flist   = Directory.GetFiles(pluginfoldermappath, "*.xml");
                foreach (var f in flist)
                {
                    if (f.EndsWith(".xml"))
                    {
                        var datain = File.ReadAllText(f);
                        try
                        {
                            var nbi = new NBrightInfo();
                            nbi.XMLData = datain;
                            // check if we are injecting multiple
                            var nodlist = nbi.XMLDoc.SelectNodes("genxml");
                            if (nodlist != null && nodlist.Count > 0)
                            {
                                foreach (XmlNode nod in nodlist)
                                {
                                    var nbi2 = new NBrightInfo();
                                    nbi2.XMLData      = nod.OuterXml;
                                    nbi2.ItemID       = -1;
                                    nbi2.GUIDKey      = nbi.GetXmlProperty("genxml/textbox/ctrl");
                                    nbi2.PortalId     = 99999;
                                    nbi2.Lang         = "";
                                    nbi2.ParentItemId = 0;
                                    nbi2.ModuleId     = -1;
                                    nbi2.XrefItemId   = 0;
                                    nbi2.UserId       = 0;
                                    nbi2.TypeCode     = "PLUGIN";

                                    // check if record exists (should NOT) but lets replace if it does.
                                    var existingrecord = objCtrl.GetByGuidKey(-1, -1, "PLUGIN", nbi2.GUIDKey);
                                    if (existingrecord != null)
                                    {
                                        nbi2.ItemID = existingrecord.ItemID;
                                        if (nbi2.GetXmlPropertyBool("genxml/delete"))
                                        {
                                            var sysrecord = objCtrl.GetByGuidKey(99999, -1, "PLUGIN", nbi2.GUIDKey);
                                            objCtrl.Delete(existingrecord.ItemID);
                                            objCtrl.Delete(sysrecord.ItemID);
                                            File.Delete(f);
                                            deleted = true;
                                        }
                                        else
                                        {
                                            objCtrl.Update(nbi2);
                                            updated = true;
                                        }
                                    }
                                    else
                                    {
                                        objCtrl.Update(nbi2);
                                        updated = true;
                                    }
                                }
                            }
                            if (updated)
                            {
                                File.Delete(f);
                                //load entity typecode to DB idx settings.
                                NBrightBuyUtils.RegisterEnityTypeToDataBase();
                            }
                        }
                        catch (Exception)
                        {
                            // data might not be XML complient (ignore)
                        }
                    }
                }
            }

            if (updated || deleted)
            {
                if (updated)
                {
                    CopySystemPluginsToPortal();
                }
                if (deleted)
                {
                    DotNetNuke.Common.Utilities.DataCache.ClearCache();
                }
                ClearPluginCache(PortalSettings.Current.PortalId);
            }
        }