Пример #1
0
        void IPortable.ImportModule(int moduleID, string content, string version, int userID)
        {
            int        portalId      = PortalController.Instance.GetCurrentPortalSettings().PortalId;
            ModuleInfo moduleInfo    = ModuleController.Instance.GetModule(moduleID, Null.NullInteger, true);
            Version    importVersion = new Version(version);
            Version    moduleVersion = new Version(moduleInfo.DesktopModule.Version);

            if (importVersion == moduleVersion)
            {
                XmlNode    xmlCategories = Common.Globals.GetContent(content, "Catalog/Categories");
                SortedList slCategories  = new SortedList(xmlCategories.ChildNodes.Count);
                int        indexID       = Null.NullInteger;

                CategoryController categoriesControler = new CategoryController();

                foreach (XmlNode xmlCategory in xmlCategories)
                {
                    CategoryInfo categoryInfo = new CategoryInfo
                    {
                        PortalID    = portalId,
                        Name        = xmlCategory["Name"].InnerText,
                        SEOName     = xmlCategory["SEOName"].InnerText,
                        Keywords    = xmlCategory["Keywords"].InnerText,
                        Description = xmlCategory["Description"].InnerText,
                        OrderID     = Convert.ToInt32(xmlCategory["OrderId"].InnerText)
                    };
                    indexID = slCategories.IndexOfKey(Convert.ToInt32(xmlCategory["ParentCategoryId"].InnerText));
                    if (indexID != Null.NullInteger)
                    {
                        categoryInfo.ParentCategoryID = (int)slCategories.GetByIndex(indexID);
                    }
                    else
                    {
                        categoryInfo.ParentCategoryID = Null.NullInteger;
                    }
                    categoryInfo.Archived      = Convert.ToBoolean(xmlCategory["Archived"].InnerText);
                    categoryInfo.Message       = xmlCategory["Message"].InnerText;
                    categoryInfo.CreatedByUser = userID.ToString();
                    categoryInfo.CreatedDate   = DateTime.Now;
                    slCategories.Add(Convert.ToInt32(xmlCategory["CategoryId"].InnerText), categoriesControler.AddCategory(categoryInfo));
                }

                XmlNode xmlProducts = Common.Globals.GetContent(content, "Catalog/Products");

                string      value            = Null.NullString;
                CultureInfo invariantCulture = CultureInfo.InvariantCulture;

                foreach (XmlNode xmlProduct in xmlProducts)
                {
                    ProductInfo productInfo = new ProductInfo
                    {
                        PortalID     = portalId,
                        CategoryID   = (int)slCategories[Convert.ToInt32(xmlProduct["CategoryID"].InnerText)],
                        Manufacturer = xmlProduct["Manufacturer"].InnerText,
                        ModelNumber  = xmlProduct["ModelNumber"].InnerText,
                        ModelName    = xmlProduct["ModelName"].InnerText,
                        SEOName      = xmlProduct["SEOName"].InnerText,
                        Keywords     = xmlProduct["Keywords"].InnerText,
                        Summary      = xmlProduct["Summary"].InnerText,
                        RegularPrice = Convert.ToDecimal(xmlProduct["RegularPrice"].InnerText, invariantCulture),
                        UnitCost     = Convert.ToDecimal(xmlProduct["UnitCost"].InnerText, invariantCulture)
                    };
                    if (xmlProduct["Virtual"] != null && Convert.ToBoolean(xmlProduct["Virtual"].InnerText))
                    {
                        string    relativePath = xmlProduct["RelativePath"].InnerText;
                        IFileInfo file         = FileManager.Instance.GetFile(portalId, relativePath);

                        if (file != null)
                        {
                            productInfo.IsVirtual        = true;
                            productInfo.VirtualFileID    = file.FileId;
                            productInfo.AllowedDownloads = Convert.ToInt32(xmlProduct["AllowedDownloads"].InnerText);
                        }
                    }
                    else
                    {
                        productInfo.ProductWeight = Convert.ToDecimal(xmlProduct["ProductWeight"].InnerText, invariantCulture);
                        productInfo.ProductHeight = Convert.ToDecimal(xmlProduct["ProductHeight"].InnerText, invariantCulture);
                        productInfo.ProductLength = Convert.ToDecimal(xmlProduct["ProductLength"].InnerText, invariantCulture);
                        productInfo.ProductWidth  = Convert.ToDecimal(xmlProduct["ProductWidth"].InnerText, invariantCulture);
                    }
                    productInfo.StockQuantity = Convert.ToInt32(xmlProduct["StockQuantity"].InnerText);
                    productInfo.LowThreshold  = Convert.ToInt32(xmlProduct["LowThreshold"].InnerText);
                    productInfo.HighThreshold = Convert.ToInt32(xmlProduct["HighThreshold"].InnerText);
                    productInfo.DeliveryTime  = Convert.ToInt32(xmlProduct["DeliveryTime"].InnerText);
                    productInfo.PurchasePrice = Convert.ToDecimal(xmlProduct["PurchasePrice"].InnerText, invariantCulture);
                    productInfo.Archived      = Convert.ToBoolean(xmlProduct["Archived"].InnerText);
                    if (xmlProduct["RoleName"] != null)
                    {
                        string   roleName = xmlProduct["RoleName"].InnerText;
                        RoleInfo role     = RoleController.Instance.GetRoleByName(portalId, roleName);

                        if (role != null)
                        {
                            productInfo.RoleID = role.RoleID;
                        }
                    }
                    productInfo.Featured = Convert.ToBoolean(xmlProduct["Featured"].InnerText);
                    if (productInfo.Featured)
                    {
                        productInfo.SaleStartDate = Convert.ToDateTime(xmlProduct["SaleStartDate"].InnerText, invariantCulture);
                        productInfo.SaleEndDate   = Convert.ToDateTime(xmlProduct["SaleEndDate"].InnerText, invariantCulture);
                        productInfo.SalePrice     = Convert.ToDecimal(xmlProduct["SalePrice"].InnerText, invariantCulture);
                    }
                    if (xmlProduct["ProductImage"] != null)
                    {
                        value = xmlProduct["ProductImage"].InnerText;
                        if (string.IsNullOrEmpty(value) == false)
                        {
                            if (value.StartsWith("http", StringComparison.InvariantCultureIgnoreCase) == false)
                            {
                                productInfo.ProductImage = value.Replace("[PortalId]", "Portals/" + portalId);
                            }
                            else
                            {
                                productInfo.ProductImage = value;
                            }
                        }
                    }
                    productInfo.Description   = xmlProduct["Description"].InnerText;
                    productInfo.CreatedByUser = userID.ToString();
                    productInfo.CreatedDate   = DateTime.Now;
                    AddProduct(productInfo);
                }
            }
        }
Пример #2
0
        string IPortable.ExportModule(int moduleID)
        {
            int portalId = PortalController.Instance.GetCurrentPortalSettings().PortalId;

            // Export categories
            CategoryController  categoriesControler = new CategoryController();
            List <CategoryInfo> alCategories        = categoriesControler.GetCategories(portalId, true, -3);

            if (alCategories.Count > 0)
            {
                StringBuilder strXML = new StringBuilder();

                XmlWriterSettings settings = new XmlWriterSettings
                {
                    Indent             = true,
                    OmitXmlDeclaration = true
                };
                using (XmlWriter writer = XmlWriter.Create(strXML, settings))
                {
                    writer.WriteStartElement("Catalog");
                    writer.WriteStartElement("Categories");
                    foreach (CategoryInfo categoryInfo in alCategories)
                    {
                        writer.WriteStartElement("Category");
                        writer.WriteElementString("CategoryId", categoryInfo.CategoryID.ToString());
                        writer.WriteElementString("Name", categoryInfo.Name);
                        writer.WriteElementString("SEOName", categoryInfo.SEOName);
                        writer.WriteElementString("Keywords", categoryInfo.Keywords);
                        writer.WriteElementString("Description", categoryInfo.Description);
                        writer.WriteElementString("OrderId", categoryInfo.OrderID.ToString());
                        writer.WriteElementString("ParentCategoryId", categoryInfo.ParentCategoryID.ToString());
                        writer.WriteElementString("Archived", categoryInfo.Archived.ToString());
                        writer.WriteElementString("Message", categoryInfo.Message);
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();

                    // Export Products
                    List <ProductInfo> alProducts = GetPortalAllProducts(portalId);

                    if (alProducts.Count > 0)
                    {
                        CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                        string      strProductImage  = Null.NullString;

                        writer.WriteStartElement("Products");
                        foreach (ProductInfo productInfo in alProducts)
                        {
                            writer.WriteStartElement("Product");
                            writer.WriteElementString("CategoryID", productInfo.CategoryID.ToString());
                            writer.WriteElementString("Manufacturer", productInfo.Manufacturer);
                            writer.WriteElementString("ModelNumber", productInfo.ModelNumber);
                            writer.WriteElementString("ModelName", productInfo.ModelName);
                            writer.WriteElementString("SEOName", productInfo.SEOName);
                            writer.WriteElementString("Keywords", productInfo.Keywords);
                            writer.WriteElementString("Summary", productInfo.Summary);
                            writer.WriteElementString("RegularPrice", productInfo.RegularPrice.ToString("0.00", invariantCulture));
                            writer.WriteElementString("UnitCost", productInfo.UnitCost.ToString("0.00", invariantCulture));
                            if (productInfo.IsVirtual)
                            {
                                IFileInfo file = FileManager.Instance.GetFile(productInfo.VirtualFileID);

                                if (file != null)
                                {
                                    writer.WriteElementString("Virtual", productInfo.IsVirtual.ToString());
                                    writer.WriteElementString("RelativePath", file.RelativePath);
                                    writer.WriteElementString("AllowedDownloads", productInfo.AllowedDownloads.ToString());
                                }
                            }
                            else
                            {
                                writer.WriteElementString("ProductWeight", productInfo.ProductWeight.ToString("0.00", invariantCulture));
                                writer.WriteElementString("ProductHeight", productInfo.ProductHeight.ToString("0.00", invariantCulture));
                                writer.WriteElementString("ProductLength", productInfo.ProductLength.ToString("0.00", invariantCulture));
                                writer.WriteElementString("ProductWidth", productInfo.ProductWidth.ToString("0.00", invariantCulture));
                            }
                            writer.WriteElementString("StockQuantity", productInfo.StockQuantity.ToString());
                            writer.WriteElementString("LowThreshold", productInfo.LowThreshold.ToString());
                            writer.WriteElementString("HighThreshold", productInfo.HighThreshold.ToString());
                            writer.WriteElementString("DeliveryTime", productInfo.DeliveryTime.ToString());
                            writer.WriteElementString("PurchasePrice", productInfo.PurchasePrice.ToString("0.00", invariantCulture));
                            writer.WriteElementString("Archived", productInfo.Archived.ToString());
                            if (productInfo.RoleID > 0)
                            {
                                RoleInfo role = RoleController.Instance.GetRoleById(portalId, productInfo.RoleID);

                                if (role != null)
                                {
                                    writer.WriteElementString("RoleName", role.RoleName);
                                }
                            }
                            writer.WriteElementString("Featured", productInfo.Featured.ToString());
                            if (productInfo.Featured)
                            {
                                writer.WriteElementString("SaleStartDate", productInfo.SaleStartDate.ToString(invariantCulture));
                                writer.WriteElementString("SaleEndDate", productInfo.SaleEndDate.ToString(invariantCulture));
                                writer.WriteElementString("SalePrice", productInfo.SalePrice.ToString("0.00", invariantCulture));
                            }
                            if (string.IsNullOrEmpty(productInfo.ProductImage) == false)
                            {
                                if (!productInfo.ProductImage.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    strProductImage = productInfo.ProductImage.Replace("Portals/" + portalId, "[PortalId]");
                                }
                                writer.WriteElementString("ProductImage", strProductImage);
                            }
                            writer.WriteElementString("Description", productInfo.Description);
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                    writer.Close();
                }
                return(strXML.ToString());
            }

            return(string.Empty);
        }