private static void CreateProvider()
        {
            lock (lockobjectCreateProvider)
            {
                _providerList = new Dictionary <string, EntityTypeInterface>();

                var pluginData = new PluginData(PortalSettings.Current.PortalId);
                var l          = pluginData.GetEntityTypeProviders(false);

                foreach (var p in l)
                {
                    var          prov   = p.Value;
                    ObjectHandle handle = null;
                    handle = Activator.CreateInstance(prov.GetXmlProperty("genxml/textbox/assembly"),
                                                      prov.GetXmlProperty("genxml/textbox/namespaceclass"));
                    var objProvider = (EntityTypeInterface)handle.Unwrap();
                    var ctrlkey     = prov.GetXmlProperty("genxml/textbox/ctrl");
                    if (!_providerList.ContainsKey(ctrlkey))
                    {
                        if (!_providerList.ContainsKey(ctrlkey))
                        {
                            _providerList.Add(ctrlkey, objProvider);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void DoExportDocs()
        {
            var fileMapPathList = new List <string>();

            var l = ModCtrl.GetList(PortalId, -1, "PRD");

            foreach (var i in l)
            {
                var nodlist = i.XMLDoc.SelectNodes("genxml/docs/*");
                if (nodlist != null)
                {
                    foreach (XmlNode nod in nodlist)
                    {
                        var fname = nod.SelectSingleNode("./hidden/docpath");
                        if (fname != null && fname.InnerText != "")
                        {
                            fileMapPathList.Add(fname.InnerText);
                        }
                    }
                }
            }


            // export any entitytype provider data
            // This is data created by plugins into the NBS data tables.
            var pluginData = new PluginData(PortalSettings.Current.PortalId);
            var provList   = pluginData.GetEntityTypeProviders();

            foreach (var prov in provList)
            {
                var entityprov = EntityTypeInterface.Instance(prov.Key);
                if (entityprov != null)
                {
                    var provl = ModCtrl.GetList(PortalId, -1, entityprov.GetEntityTypeCode());
                    foreach (var i in provl)
                    {
                        var nodlist = i.XMLDoc.SelectNodes("genxml/docs/*");
                        if (nodlist != null)
                        {
                            foreach (XmlNode nod in nodlist)
                            {
                                var fname = nod.SelectSingleNode("./hidden/docpath");
                                if (fname != null && fname.InnerText != "")
                                {
                                    fileMapPathList.Add(fname.InnerText);
                                }
                            }
                        }
                    }
                }
            }


            DnnUtils.Zip(StoreSettings.Current.FolderUploadsMapPath + "\\exportdocs.zip", fileMapPathList);

            Utils.ForceDocDownload(StoreSettings.Current.FolderUploadsMapPath + "\\exportdocs.zip", PortalSettings.PortalAlias.HTTPAlias + "_exportdocs.zip", Response);
        }
        // dynamically create provider
        private static void CreateProvider()
        {
            _providerList = new Dictionary<string, EntityTypeInterface>();

            var pluginData = new PluginData(PortalSettings.Current.PortalId);
            var l = pluginData.GetEntityTypeProviders();

            foreach (var p in l)
            {
                var prov = p.Value;
                ObjectHandle handle = null;
                handle = Activator.CreateInstance(prov.GetXmlProperty("genxml/textbox/assembly"),
                prov.GetXmlProperty("genxml/textbox/namespaceclass"));
                var objProvider = (EntityTypeInterface)handle.Unwrap();
                var ctrlkey = prov.GetXmlProperty("genxml/textbox/ctrl");
                if (!_providerList.ContainsKey(ctrlkey))
                {
                    _providerList.Add(ctrlkey, objProvider);
                }
            }
        }
Beispiel #4
0
        private void ImportRecord(XmlDocument xmlFile, String typeCode, Boolean updaterecordsbyref = true)
        {
            var nodList = xmlFile.SelectNodes("root/item[./typecode='" + typeCode + "']");

            if (nodList != null)
            {
                foreach (XmlNode nod in nodList)
                {
                    var nbi = new NBrightInfo();
                    nbi.FromXmlItem(nod.OuterXml);
                    var olditemid = nbi.ItemID;

                    // check to see if we have a new record or updating a existing one, use the ref field to find out.
                    nbi.ItemID = -1;
                    if (nbi.PortalId >= 0)
                    {
                        nbi.PortalId = PortalId;                    // shared products have -1 portalid
                    }
                    if (typeCode == "PRD" && updaterecordsbyref)
                    {
                        var itemref = nbi.GetXmlProperty("genxml/textbox/txtproductref");
                        if (itemref != "")
                        {
                            var l = ModCtrl.GetList(nbi.PortalId, -1, "PRD", " and NB1.XmlData.value('(genxml/textbox/txtproductref)[1]','nvarchar(max)') = '" + itemref.Replace("'", "''") + "' ");
                            if (l.Count > 0)
                            {
                                nbi.ItemID = l[0].ItemID;
                            }
                        }
                    }
                    if (typeCode == "PRDLANG")
                    {
                        if (_recordXref.ContainsKey(nbi.ParentItemId))
                        {
                            var l = ModCtrl.GetList(nbi.PortalId, -1, "PRDLANG", " and NB1.parentitemid = '" + _recordXref[nbi.ParentItemId].ToString("") + "' and NB1.Lang = '" + nbi.Lang + "'");
                            if (l.Count > 0)
                            {
                                nbi.ItemID = l[0].ItemID;
                            }
                            nbi.ParentItemId = _recordXref[nbi.ParentItemId];
                        }
                    }



                    // import any entitytype provider data
                    // This is data created by plugins into the NBS data tables.
                    var pluginData = new PluginData(PortalSettings.Current.PortalId);
                    var provList   = pluginData.GetEntityTypeProviders();
                    foreach (var prov in provList)
                    {
                        var entityprov = EntityTypeInterface.Instance(prov.Key);
                        if (entityprov != null)
                        {
                            if (typeCode == entityprov.GetEntityTypeCode() && updaterecordsbyref)
                            {
                                var itemref = nbi.GetXmlProperty("genxml/textbox/txtproductref");
                                if (itemref != "")
                                {
                                    var l = ModCtrl.GetList(nbi.PortalId, -1, entityprov.GetEntityTypeCode(), " and NB3.ProductRef = '" + itemref.Replace("'", "''") + "' ");
                                    if (l.Count > 0)
                                    {
                                        nbi.ItemID = l[0].ItemID;
                                    }
                                }
                            }
                            if (typeCode == entityprov.GetEntityTypeCodeLang())
                            {
                                if (_recordXref.ContainsKey(nbi.ParentItemId))
                                {
                                    var l = ModCtrl.GetList(nbi.PortalId, -1, entityprov.GetEntityTypeCodeLang(), " and NB1.parentitemid = '" + _recordXref[nbi.ParentItemId].ToString("") + "' and NB1.Lang = '" + nbi.Lang + "'");
                                    if (l.Count > 0)
                                    {
                                        nbi.ItemID = l[0].ItemID;
                                    }
                                    nbi.ParentItemId = _recordXref[nbi.ParentItemId];
                                }
                            }
                        }
                    }


                    if ((typeCode == "PRDXREF" || typeCode == "CATXREF" || typeCode == "CATCASCADE"))
                    {
                        if (_recordXref.ContainsKey(nbi.XrefItemId))
                        {
                            nbi.XrefItemId = _recordXref[nbi.XrefItemId];
                        }
                        if (_recordXref.ContainsKey(nbi.ParentItemId))
                        {
                            nbi.ParentItemId = _recordXref[nbi.ParentItemId];
                        }

                        var l = ModCtrl.GetList(nbi.PortalId, -1, typeCode, " AND nb1.XrefItemId = " + nbi.XrefItemId + " AND nb1.ParentItemId=" + nbi.ParentItemId);
                        if (l.Count > 0)
                        {
                            return;
                        }
                    }

                    if (typeCode == "USERPRDXREF")
                    {
                        var u = UserController.GetUserByName(nbi.PortalId, nbi.TextData);
                        if (u != null)
                        {
                            if (_recordXref.ContainsKey(nbi.ParentItemId))
                            {
                                nbi.ParentItemId = _recordXref[nbi.ParentItemId];
                            }
                            if (_recordXref.ContainsKey(nbi.XrefItemId))
                            {
                                nbi.UserId = u.UserID;
                            }

                            var l = ModCtrl.GetList(nbi.PortalId, -1, "USERPRDXREF", " AND nb1.UserId = " + nbi.UserId + " AND nb1.ParentItemId=" + nbi.ParentItemId);
                            if (l.Count > 0)
                            {
                                return;
                            }
                        }
                    }


                    if (typeCode == "CATEGORY" && updaterecordsbyref)
                    {
                        var itemref = nbi.GetXmlProperty("genxml/textbox/txtcategoryref");
                        if (itemref != "")
                        {
                            var l = ModCtrl.GetList(nbi.PortalId, -1, "CATEGORY", " and [XMLData].value('(genxml/textbox/txtcategoryref)[1]','nvarchar(max)') = '" + itemref.Replace("'", "''") + "' ");
                            if (l.Count > 0)
                            {
                                nbi.ItemID = l[0].ItemID;
                            }
                        }
                    }
                    if (typeCode == "CATEGORYLANG")
                    {
                        if (_recordXref.ContainsKey(nbi.ParentItemId))
                        {
                            var l = ModCtrl.GetList(nbi.PortalId, -1, "CATEGORYLANG", " and NB1.parentitemid = '" + _recordXref[nbi.ParentItemId].ToString("") + "' and NB1.Lang = '" + nbi.Lang + "'");
                            if (l.Count > 0)
                            {
                                nbi.ItemID = l[0].ItemID;
                            }
                            nbi.ParentItemId = _recordXref[nbi.ParentItemId];
                        }
                    }
                    if (typeCode == "GROUP" && updaterecordsbyref)
                    {
                        var itemref = nbi.GetXmlProperty("genxml/textbox/groupref");
                        if (itemref != "")
                        {
                            var l = ModCtrl.GetList(nbi.PortalId, -1, "GROUP", " and [XMLData].value('(genxml/textbox/groupref)[1]','nvarchar(max)') = '" + itemref.Replace("'", "''") + "' ");
                            if (l.Count > 0)
                            {
                                nbi.ItemID = l[0].ItemID;
                            }
                        }
                    }
                    if (typeCode == "GROUPLANG")
                    {
                        if (_recordXref.ContainsKey(nbi.ParentItemId))
                        {
                            var l = ModCtrl.GetList(nbi.PortalId, -1, "GROUPLANG", " and NB1.parentitemid = '" + _recordXref[nbi.ParentItemId].ToString("") + "' and NB1.Lang = '" + nbi.Lang + "'");
                            if (l.Count > 0)
                            {
                                nbi.ItemID = l[0].ItemID;
                            }
                            nbi.ParentItemId = _recordXref[nbi.ParentItemId];
                        }
                    }
                    if (typeCode == "SETTINGS") // the setting exported are only the portal settings, not module.  So always update and don;t create new.
                    {
                        var l = ModCtrl.GetList(nbi.PortalId, 0, "SETTINGS", " and NB1.GUIDKey = 'NBrightBuySettings' ");
                        if (l.Count > 0)
                        {
                            nbi.ItemID = l[0].ItemID;
                        }
                    }
                    //NOTE: if ORDERS are imported, we expect those to ALWAYS be new records, we don't want to delete any validate orders in this import.

                    // NOTE: we expect the records to be done in typecode order so we know parent and xref itemids.

                    var newitemid = ModCtrl.Update(nbi);
                    if (newitemid > 0)
                    {
                        _recordXref.Add(olditemid, newitemid);
                    }
                    if (typeCode == "PRD" && !_productList.ContainsKey(newitemid))
                    {
                        _productList.Add(newitemid, typeCode);
                    }

                    // Add any provider data types
                    foreach (var prov in provList)
                    {
                        var entityprov = EntityTypeInterface.Instance(prov.Key);
                        if (entityprov != null)
                        {
                            if (typeCode == entityprov.GetEntityTypeCode())
                            {
                                _productList.Add(newitemid, typeCode);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        private void DoImport(NBrightInfo nbi)
        {
            var fname = StoreSettings.Current.FolderUploadsMapPath + "\\" + nbi.GetXmlProperty("genxml/hidden/hiddatafile");

            if (System.IO.File.Exists(fname))
            {
                var xmlFile = new XmlDocument();
                xmlFile.Load(fname);

                if (GenXmlFunctions.GetField(rpData, "importproducts") == "True")
                {
                    ImportRecord(xmlFile, "PRD");
                    ImportRecord(xmlFile, "PRDLANG");

                    // import any entitytype provider data
                    // This is data created by plugins into the NBS data tables.
                    var pluginData = new PluginData(PortalSettings.Current.PortalId);
                    var provList   = pluginData.GetEntityTypeProviders();
                    foreach (var prov in provList)
                    {
                        var entityprov = EntityTypeInterface.Instance(prov.Key);
                        if (entityprov != null)
                        {
                            ImportRecord(xmlFile, entityprov.GetEntityTypeCode());
                            ImportRecord(xmlFile, entityprov.GetEntityTypeCodeLang());
                        }
                    }

                    ImportRecord(xmlFile, "PRDXREF");
                    ImportRecord(xmlFile, "USERPRDXREF");
                }

                if (GenXmlFunctions.GetField(rpData, "importcategories") == "True")
                {
                    ImportRecord(xmlFile, "CATEGORY");
                    ImportRecord(xmlFile, "CATEGORYLANG");
                }

                if (GenXmlFunctions.GetField(rpData, "importcategories") == "True" && GenXmlFunctions.GetField(rpData, "importproducts") == "True")
                {
                    ImportRecord(xmlFile, "CATCASCADE");
                    ImportRecord(xmlFile, "CATXREF");
                }

                if (GenXmlFunctions.GetField(rpData, "importproperties") == "True")
                {
                    ImportRecord(xmlFile, "GROUP");
                    ImportRecord(xmlFile, "GROUPLANG");
                }

                if (GenXmlFunctions.GetField(rpData, "importsettings") == "True")
                {
                    ImportRecord(xmlFile, "SETTINGS");
                }

                if (GenXmlFunctions.GetField(rpData, "importorders") == "True")
                {
                    ImportRecord(xmlFile, "ORDER");
                }

                RelinkNewIds();
            }
        }
Beispiel #6
0
        private void DoExport()
        {
            FixUniqueRef("PRD", "genxml/textbox/txtproductref");
            FixUniqueRef("GROUP", "genxml/textbox/groupref");
            FixUniqueRef("CATEGORY", "genxml/textbox/txtcategoryref");

            var strXml      = new StringBuilder("<root>");
            var objCtrlUser = new UserController();

            if (GenXmlFunctions.GetField(rpData, "exportproducts") == "True")
            {
                // export any entitytype provider data
                // This is data created by plugins into the NBS data tables.
                var pluginData = new PluginData(PortalSettings.Current.PortalId);
                var provList   = pluginData.GetEntityTypeProviders();
                foreach (var prov in provList)
                {
                    var entityprov = EntityTypeInterface.Instance(prov.Key);
                    if (entityprov != null)
                    {
                        var provl = ModCtrl.GetList(PortalId, -1, entityprov.GetEntityTypeCode());
                        foreach (var i in provl)
                        {
                            strXml.Append(i.ToXmlItem());
                        }

                        provl = ModCtrl.GetList(PortalId, -1, entityprov.GetEntityTypeCodeLang());
                        foreach (var i in provl)
                        {
                            strXml.Append(i.ToXmlItem());
                        }
                    }
                }

                var l = ModCtrl.GetList(PortalId, -1, "PRD");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }

                l = ModCtrl.GetList(PortalId, -1, "PRDLANG");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }

                l = ModCtrl.GetList(PortalId, -1, "PRDXREF");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }

                l = ModCtrl.GetList(PortalId, -1, "USERPRDXREF");
                foreach (var i in l)
                {
                    var u = objCtrlUser.GetUser(i.PortalId, i.UserId);
                    if (u != null)
                    {
                        i.TextData = u.Username;
                        strXml.Append(i.ToXmlItem());
                    }
                }
            }

            if (GenXmlFunctions.GetField(rpData, "exportcategories") == "True")
            {
                var l = ModCtrl.GetList(PortalId, -1, "CATEGORY");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }

                l = ModCtrl.GetList(PortalId, -1, "CATEGORYLANG");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }
            }

            if (GenXmlFunctions.GetField(rpData, "exportcategories") == "True" && GenXmlFunctions.GetField(rpData, "exportproducts") == "True")
            {
                var l = ModCtrl.GetList(PortalId, -1, "CATCASCADE");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }
                l = ModCtrl.GetList(PortalId, -1, "CATXREF");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }
            }

            if (GenXmlFunctions.GetField(rpData, "exportproperties") == "True")
            {
                var l = ModCtrl.GetList(PortalId, -1, "GROUP");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }

                l = ModCtrl.GetList(PortalId, -1, "GROUPLANG");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }
            }

            if (GenXmlFunctions.GetField(rpData, "exportsettings") == "True")
            {
                var l = ModCtrl.GetList(PortalId, 0, "SETTINGS");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }
            }

            if (GenXmlFunctions.GetField(rpData, "exportorders") == "True")
            {
                var l = ModCtrl.GetList(PortalId, -1, "ORDER");
                foreach (var i in l)
                {
                    strXml.Append(i.ToXmlItem());
                }
            }

            strXml.Append("</root>");

            var doc = new XmlDocument();

            doc.LoadXml(strXml.ToString());
            doc.Save(StoreSettings.Current.FolderUploadsMapPath + "\\export.xml");

            Utils.ForceDocDownload(StoreSettings.Current.FolderUploadsMapPath + "\\export.xml", PortalSettings.PortalAlias.HTTPAlias + "_export.xml", Response);
        }