Beispiel #1
0
        public void Initialize(ThemeFolderLookup themeFolderLookup, string defaultTheme, string physicalApplicationPath)
        {
            Dictionary <string, Dictionary <string, string> > lookup    = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, Dictionary <string, string> > languages = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, Dictionary <string, string> > countries = new Dictionary <string, Dictionary <string, string> >();

            foreach (string theme in themeFolderLookup.ThemeNames)
            {
                lookup.Add(theme, new Dictionary <string, string>());
                languages.Add(theme, new Dictionary <string, string>());
                countries.Add(theme, new Dictionary <string, string>());

                ReadFromXml(themeFolderLookup, theme, "contents.xml", physicalApplicationPath, lookup);
                ReadFromXml(themeFolderLookup, theme, "contents.scripts.xml", physicalApplicationPath, lookup);
                ReadFromXml(themeFolderLookup, theme, "contents.emails.xml", physicalApplicationPath, lookup);
                ReadFromXml(themeFolderLookup, theme, "contents.countries.xml", physicalApplicationPath, countries);
                ReadFromXml(themeFolderLookup, theme, "contents.languages.xml", physicalApplicationPath, languages);
            }

            _DefaultTheme = defaultTheme;
            _Content      = lookup;

            // do language conversion
            Dictionary <string, List <Language> > languageLookup = new Dictionary <string, List <Language> >();

            foreach (var item in languages)
            {
                languageLookup[item.Key] = new List <Language>();
                foreach (var kvp in item.Value)
                {
                    languageLookup[item.Key].Add(new Language(kvp.Key, kvp.Value));
                }
            }
            _Languages = languageLookup;

            // do country conversion
            Dictionary <string, List <Country> > countryLookup = new Dictionary <string, List <Country> >();

            foreach (var item in countries)
            {
                countryLookup[item.Key] = new List <Country>();
                foreach (var kvp in item.Value)
                {
                    countryLookup[item.Key].Add(new Country(kvp.Key, kvp.Value));
                }
            }
            _Countries = countryLookup;
        }
Beispiel #2
0
        private void ReadFromXml(ThemeFolderLookup themeFolderLookup, string theme, string fileName
                                 , string physicalApplicationPath, Dictionary <string, Dictionary <string, string> > lookup)
        {
            XAttribute key;
            string     xmlFilePath;

            if (themeFolderLookup.TryGetVirtualThemePath(theme, fileName, out xmlFilePath))
            {
                XDocument document = XDocument.Load(Path.Combine(
                                                        physicalApplicationPath
                                                        , xmlFilePath.Remove(0, 2).Replace("/", @"\")) // make relative...
                                                    );

                foreach (XElement xElement in document.Descendants("content"))
                {
                    key = xElement.Attribute("key");
                    if (key != null)
                    {
                        lookup[theme][key.Value] = xElement.Value;
                    }
                }
            }
        }
Beispiel #3
0
        public void Refresh(string applicationRootPath)
        {
            Dictionary <string, ThemeFolderLookup>     themeFolderLookups         = new Dictionary <string, ThemeFolderLookup>();
            Dictionary <string, SitemapLookup>         sitemapLookups             = new Dictionary <string, SitemapLookup>();
            Dictionary <string, StaticContentLookup>   staticContentLookups       = new Dictionary <string, StaticContentLookup>();
            Dictionary <string, IApplicationThemeInfo> applicationThemeInfoLookup = new Dictionary <string, IApplicationThemeInfo>();

            List <string> applicationGroups = new List <string>();
            DirectoryInfo directoryInfo     = new DirectoryInfo(applicationRootPath + @"\Themes");

            applicationGroups = (from c in directoryInfo.GetDirectories()
                                 select c.Name.ToLowerInvariant()).ToList();

            ThemeFolderLookup   themeFolderLookup;
            SitemapLookup       sitemapLookup;
            StaticContentLookup staticContentLookup;

            string sitemapConfigFilePath;

            Dictionary <string, SitemapItem> dnsSitemapItems;
            Dictionary <string, Tuple <SitemapItem, string> > defaultDnsSitemapItems;
            SitemapItem defaultThemeSitemapItem;
            string      defaultDomainName;

            foreach (string applicationGroup in applicationGroups)
            {
                sitemapConfigFilePath = applicationRootPath + @"\Themes\" + applicationGroup + @"\sitemap.config";

                if (!File.Exists(sitemapConfigFilePath))
                {
                    throw new ConfigurationErrorsException("File " + sitemapConfigFilePath + " not found. Please provide a sitemap file for application " + applicationGroup);
                }

                sitemapLookup = new SitemapLookup();
                sitemapLookup.Initialize(sitemapConfigFilePath);

                if (string.IsNullOrWhiteSpace(sitemapLookup.DefaultTheme))
                {
                    throw new ConfigurationErrorsException("Please provide a default theme within the sitemap.config file for application " + applicationGroup);
                }

                themeFolderLookup = new ThemeFolderLookup();
                themeFolderLookup.Initialize(applicationRootPath, applicationGroup, sitemapLookup.DefaultTheme, sitemapLookup.GetDnsLookup());

                staticContentLookup = new StaticContentLookup();
                staticContentLookup.Initialize(themeFolderLookup, sitemapLookup.DefaultTheme, applicationRootPath);

                dnsSitemapItems        = sitemapLookup.GetDnsSitemapItems();
                defaultDnsSitemapItems = new Dictionary <string, Tuple <SitemapItem, string> >();

                foreach (string domainName in dnsSitemapItems.Keys)
                {
                    if (dnsSitemapItems[domainName].IsDefault)
                    {
                        defaultDnsSitemapItems[dnsSitemapItems[domainName].ApplicationName.ToLowerInvariant()] = new Tuple <SitemapItem, string>(dnsSitemapItems[domainName], domainName.ToLowerInvariant().TrimEnd('/') + "/");;
                    }
                }
                foreach (string domainName in dnsSitemapItems.Keys)
                {
                    defaultThemeSitemapItem = defaultDnsSitemapItems[dnsSitemapItems[domainName].ApplicationName.ToLowerInvariant()].Item1;
                    defaultDomainName       = defaultDnsSitemapItems[dnsSitemapItems[domainName].ApplicationName.ToLowerInvariant()].Item2;

                    ApplicationThemeInfoImages applicationThemeInfoImages = new ApplicationThemeInfoImages();
                    applicationThemeInfoImages.ImageFolderServerPath = dnsSitemapItems[domainName].HasImageFolderServerPath
              ? dnsSitemapItems[domainName].ImageFolderServerPath.TrimEnd('\\') + @"\"
              : applicationRootPath.TrimEnd('\\') + @"\Themes\" + applicationGroup + @"\" + dnsSitemapItems[domainName].Name + @"\images\";
                    applicationThemeInfoImages.ImageFolderRootUrl = dnsSitemapItems[domainName].HasImageFolderRootUrl
            ? dnsSitemapItems[domainName].ImageFolderRootUrl
            : (defaultDomainName.StartsWith("http://") ? defaultDomainName : "http://" + defaultDomainName)
                                                                    + "themes/" + applicationGroup + "/" + dnsSitemapItems[domainName].Name + "/images/";

                    applicationThemeInfoImages.DefaultThemeImageFolderServerPath = defaultThemeSitemapItem.HasImageFolderServerPath
            ? defaultThemeSitemapItem.ImageFolderServerPath.TrimEnd('\\') + @"\"
            : applicationRootPath.TrimEnd('\\') + @"\Themes\" + applicationGroup + @"\" + defaultThemeSitemapItem.Name + @"\images\";

                    applicationThemeInfoImages.DefaultThemeImageFolderRootUrl = defaultThemeSitemapItem.HasImageFolderRootUrl
            ? defaultThemeSitemapItem.ImageFolderRootUrl
            : (defaultDomainName.StartsWith("http://") ? defaultDomainName : "http://" + defaultDomainName)
                                                                                + "themes/" + applicationGroup + "/" + dnsSitemapItems[domainName].Name + "/images/";

                    applicationThemeInfoLookup[domainName] = new ApplicationThemeInfo()
                    {
                        ApplicationGroup = dnsSitemapItems[domainName].ApplicationGroup,
                        ApplicationId    = int.MinValue,
                        ApplicationName  = dnsSitemapItems[domainName].ApplicationName,
                        DomainName       = domainName,
                        ThemeName        = dnsSitemapItems[domainName].Name,
                        IsDefault        = dnsSitemapItems[domainName].IsDefault,
                        DefaultThemeName = defaultThemeSitemapItem.Name,
                        Images           = applicationThemeInfoImages,
                    };
                }

                themeFolderLookups.Add(applicationGroup, themeFolderLookup);
                sitemapLookups.Add(applicationGroup, sitemapLookup);
                staticContentLookups.Add(applicationGroup, staticContentLookup);
            }

            _ApplicationThemeInfoLookup = applicationThemeInfoLookup;
            _ThemeFolderLookups         = themeFolderLookups;
            _SitemapLookups             = sitemapLookups;
            _ApplicationGroups          = applicationGroups;
            _StaticContentLookups       = staticContentLookups;
        }