Example #1
0
        static SiteSettings()
        {
            XElement xe = XElement.Load(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/content/config/sitesetting.xml");

            resource = new Resource()
            {
                Host = new Resource_Host()
                {
            #if DEBUG
                    Domain_Portal = xe.Element("host").Element("domain")
                        .Element("portal").Element("test").Value,
                    Domain_Admin = xe.Element("host").Element("domain")
                        .Element("admin").Element("test").Value,
            #else
                    Domain_Portal = xe.Element("host").Element("domain")
                        .Element("portal").Element("standard").Value,
                    Domain_Admin = xe.Element("host").Element("domain")
                        .Element("admin").Element("standard").Value,
            #endif
                    IP_Admin = xe.Element("host").Element("domain")
                        .Element("admin").Element("ip").Value,
                    IP_Portal = xe.Element("host").Element("domain")
                        .Element("portal").Element("ip").Value,
                    SiteName = xe.Element("host").Element("name").Value
                },
                Setting = xe.Element("host").Element("setting").Elements()
                        .ToDictionary(
                            xn => { return xn.Name.ToString(); },
                            xn => { return xn.Value; }),
                Company = xe.Element("host").Element("company").Elements()
                    .ToDictionary(
                        xn => { return xn.Name.ToString(); },
                        xn => { return xn.Value; }),
                seo = new SEOSettings()
                {
                    Default = new SEOSettingItem()
                    {
                        title = xe.Element("seo").Element("default").Attribute("title").Value,
                        keywords = xe.Element("seo").Element("default").Attribute("keyword").Value,
                        description = xe.Element("seo").Element("default").Attribute("description").Value
                    },
                    PageSet = xe.Element("seo").Elements("item")
                    .ToDictionary(
                        xn =>
                        {
                            return xn.Attribute("name").Value;
                        },
                        xn =>
                        {
                            SEOSettingItem item = new SEOSettingItem();
                            item.title = xn.Attribute("title").Value;
                            if (xn.Attribute("keyword") != null)
                            {
                                item.keywords = xn.Attribute("keyword").Value;
                            }
                            else
                            {
                                item.keywords = string.Empty;
                            }
                            if (xn.Attribute("description") != null)
                            {
                                item.description = xn.Attribute("description").Value;
                            }
                            else
                            {
                                item.description = string.Empty;
                            }
                            return item;
                        })
                }
            };
        }
Example #2
0
        static SiteResource()
        {
            XElement xe = XElement.Load(AppDomain.CurrentDomain.SetupInformation.ApplicationBase+"/content/config/sitesetting.xml");
            string costrankSet = ConfigurationManager.AppSettings["costrank"];
            if (!string.IsNullOrEmpty(costrankSet))
            {
                Int32.TryParse(costrankSet, out costrank);
            }
            resource = new Resource()
            {
                Host = new Resource_Host()
                {
                    Domain = xe.Element("host").Element("domain").Value,
                    SiteName = xe.Element("host").Element("name").Value
                },
                Scope = xe.Element("host").Element("scope").Elements()
                        .ToDictionary(
                            xn=>{ return xn.Attribute("domain").Value;},
                            xn => { return xn.Attribute("name").Value; }),
                Setting = xe.Element("host").Element("setting").Elements()
                        .ToDictionary(
                            xn => { return xn.Name.ToString(); },
                            xn => { return xn.Value; }),
                Company = xe.Element("host").Element("company").Elements()
                    .ToDictionary(
                        xn => { return xn.Name.ToString(); },
                        xn => { return xn.Value; }),
                seo = new SEOSettings()
                {
                    Default = new SEOSettingItem()
                    {
                        title = xe.Element("seo").Element("default").Attribute("title").Value,
                        keywords = xe.Element("seo").Element("default").Attribute("keyword").Value,
                        description = xe.Element("seo").Element("default").Attribute("description").Value
                    },
                    PageSet = xe.Element("seo").Elements("item")
                    .ToDictionary(
                        xn =>
                        {
                            return xn.Attribute("name").Value;
                        },
                        xn =>
                        {
                            SEOSettingItem item = new SEOSettingItem();
                            item.title = xn.Attribute("title").Value;
                            item.keywords = xn.Attribute("keyword").Value;
                            item.description = xn.Attribute("description").Value;
                            return item;
                        })
                },
                Comminession = xe.Element("commission").Elements("item").Select(
                    c => new CommissionItem()
                    {
                        Name = c.Attribute("name").Value,
                        Order = Int32.Parse(c.Attribute("order").Value),
                        point = decimal.Parse(c.Attribute("point").Value),
                        value = c.Attribute("value").Value
                    }).ToList(),
                Articles = new Articles()
                {
                    AboutUs = new ArticleGroup()
                    {
                        Title = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "4").Attribute("title").Value,
                        Items = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "4").Elements("item")
                            .Select(c => new ArticleItem()
                            {
                                Id = c.Attribute("id").Value,
                                Title = c.Attribute("name").Value,
                                Content = c.Attribute("file").Value
                            }).ToList()
                    },
                    Cooperation = new ArticleGroup()
                    {
                        Title = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "3").Attribute("title").Value,
                        Items = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "3").Elements("item")
                            .Select(c => new ArticleItem()
                            {
                                Id = c.Attribute("id").Value,
                                Title = c.Attribute("name").Value,
                                Content = c.Attribute("file").Value
                            }).ToList()
                    },
                    ShoppingGuide = new ArticleGroup()
                    {
                        Title = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "2").Attribute("title").Value,
                        Items = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "2").Elements("item")
                            .Select(c => new ArticleItem()
                            {
                                Id = c.Attribute("id").Value,
                                Title = c.Attribute("name").Value,
                                Content = c.Attribute("file").Value
                            }).ToList()
                    },
                    Delivery = new ArticleGroup()
                    {
                        Title = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "1").Attribute("title").Value,
                        Items = xe.Element("articles").Elements("group").FirstOrDefault(c => c.Attribute("key").Value == "1").Elements("item")
                            .Select(c => new ArticleItem()
                            {
                                Id = c.Attribute("id").Value,
                                Title = c.Attribute("name").Value,
                                Content = c.Attribute("file").Value
                            }).ToList()
                    }
                },
                Block = xe.Element("advertisement").Elements("block")
                    .Select(c => new BlockGroup()
                    {
                        Key = c.Attribute("key").Value,
                        Items = c.Elements("item").Select(
                            e => new BlockItem()
                            {
                                alt = e.Attribute("alt").Value,
                                description = e.Attribute("description").Value,
                                href = e.Attribute("href").Value,
                                img = e.Attribute("img").Value,
                                price = e.Element("price") == null ? "" : e.Element("price").Value,
                                product = e.Element("product") == null ? "" : e.Element("product").Value,
                            }).ToList()
                    }).ToList()
            };

            #region LoadArticleContent
            resource.Articles.AboutUs.Items.ForEach(
                c => {
                    try
                    {
                        string filePath = c.Content;
                        if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                        {
                            using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                            {
                                c.Content = sr.ReadToEnd();
                            }
                        }
                    }
                    catch
                    {
                        c.Content = "";
                    }
                });
            resource.Articles.Cooperation.Items.ForEach(
                c =>
                {
                    try
                    {
                        string filePath = c.Content;
                        if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                        {
                            using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                            {
                                c.Content = sr.ReadToEnd();
                            }
                        }
                    }
                    catch
                    {
                        c.Content = "";
                    }
                });
            resource.Articles.Delivery.Items.ForEach(
                c =>
                {
                    try
                    {
                        string filePath = c.Content;
                        if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                        {
                            using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                            {
                                c.Content = sr.ReadToEnd();
                            }
                        }
                    }
                    catch
                    {
                        c.Content = "";
                    }
                });
            resource.Articles.ShoppingGuide.Items.ForEach(
                c =>
                {
                    try
                    {
                        string filePath = c.Content;
                        if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                        {
                            using (StreamReader sr = new StreamReader(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + filePath))
                            {
                                c.Content = sr.ReadToEnd();
                            }
                        }
                    }
                    catch
                    {
                        c.Content = "";
                    }
                });
            #endregion
        }