Пример #1
0
        internal static string GetTemplateID(string filePath, TemplateNames nametype)
        {
            Match match = Regex.Match(filePath, "templates(/|\\\\)+#*(.+?)$", RegexOptions.IgnoreCase);

            if (String.IsNullOrEmpty(match.Value))
            {
                throw new Exception("模版页文件名:" + filePath + "不合法");
            }

            string fileName = match.Groups[2].Value;

            if (!fileName.ToLower().EndsWith(".phtml") && nametype == TemplateNames.FileName)
            {
                string id = String.Format("{0}{1}",
                                          match.Groups[1].Value,
                                          match.Groups[2].Value)
                            .Replace('\\', '/');

                return(id.Substring(0, id.LastIndexOf('.')));
            }
            else
            {
                return(MD5.EncodeTo16(Regex.Replace(fileName, "/|\\\\", String.Empty).ToLower()));
            }
        }
Пример #2
0
 public TemplateRegister(DirectoryInfo templateDirectory, TemplateNames nametype)
 {
     this.nametype  = nametype;
     this.directory = templateDirectory;
     if (!this.directory.Exists)
     {
         throw new DirectoryNotFoundException("模版文件夹不存在!");
     }
 }
Пример #3
0
        public void Initialize()
        {
            var templateNames = new TemplateNames();

            LoadTileTypeTemplates(templateNames, "Tiles/", EnumHelper.GetAsList <MainTileType>().Select(x => x.ToString()));
            LoadTileTypeTemplates(templateNames, "Items/", EnumHelper.GetAsList <ItemType>().Select(x => x.ToString()));
            LoadTileTypeTemplates(templateNames, "Areas/", EnumHelper.GetAsList <AreaType>().Select(x => x.ToString()));
            _pool.SetTileTemplates(templateNames);
        }
Пример #4
0
 public TemplateRegister(string directoryPath, TemplateNames nametype)
 {
     this.nametype  = nametype;
     this.directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + directoryPath);
     if (!this.directory.Exists)
     {
         throw new DirectoryNotFoundException("模版文件夹不存在!");
     }
 }
Пример #5
0
        public CmsTemplate(IMemoryCacheWrapper cache, TemplateNames names)
        {
            this.cache = cache;
            var opt = new Options
            {
                EnabledCompress = Settings.TPL_USE_COMPRESS,
                EnabledCache    = true,
                UrlQueryShared  = true,
                HttpItemShared  = true,
                Names           = names,
            };

            registry = new TemplateRegistry(createContainer(), opt);
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="names"></param>
        public CmsTemplate(IMemoryCacheWrapper cache, TemplateNames names)
        {
            this._cache = cache;
            var opt = new Options
            {
                EnabledCompress = Settings.TPL_USE_COMPRESS,
                // 非正式环境关闭模板缓存
                EnabledCache   = Cms.OfficialEnvironment && Settings.TPL_USE_CACHE,
                UrlQueryShared = true,
                HttpItemShared = true,
                Names          = names
            };

            _registry = new TemplateRegistry(CreateContainer(), opt);
        }
Пример #7
0
        private void LoadTemplate(TemplateNames template)
        {
            switch (template)
            {
            case TemplateNames.SingleImageAd:
                TemplateName = TemplateNames.SingleImageAd;
                Title        = new List <string>()
                {
                    "Default Title"
                };
                AdCopy = new List <string>()
                {
                    "Default Text"
                };
                CampaignObjective = "LeadGeneration";
                break;

            case TemplateNames.MultiImageCarouselAd:
                TemplateName = TemplateNames.MultiImageCarouselAd;
                Title        = new List <string>()
                {
                    "Default Title 1", "Default Title 2", "Default Title 3"
                };
                AdCopy = new List <string>()
                {
                    "Default Text1", "Default Text2", "Default Text3"
                };
                CampaignObjective = "Conversions";
                break;

            case TemplateNames.MultiImageSliderAd:
                TemplateName = TemplateNames.MultiImageSliderAd;
                Title        = new List <string>()
                {
                    "Default Title 1", "Default Title 2", "Default Title 3"
                };
                AdCopy = new List <string>()
                {
                    "Default Text1", "Default Text2", "Default Text3"
                };
                CampaignObjective = "Impressions";
                break;

            default:
                break;
            }
        }
Пример #8
0
        private void LoadTileTypeTemplates(TemplateNames templateNames, string typeClass, IEnumerable <string> mainTypes)
        {
            var allTiles = LoadTiles(typeClass);

            foreach (var mainType in mainTypes)
            {
                var tileTypeGameObjects = allTiles
                                          .Where(x => x.NameContains(mainType.ToString()))
                                          .ToList();

                if (tileTypeGameObjects.Count == 0)
                {
                    Debug.LogWarning("No tiles available for " + mainType);
                }

                templateNames.Add(mainType.ToUpper(), GetSubtypes(tileTypeGameObjects, typeClass));
            }
        }
Пример #9
0
        //递归方式注册模板
        private static void RegisterTemplates(DirectoryInfo dir, TemplateNames nametype)
        {
            Regex allowExt = new Regex("(.html|.phtml)$", RegexOptions.IgnoreCase);

            foreach (FileInfo file in dir.GetFiles())
            {
                if (allowExt.IsMatch(file.Extension))
                {
                    TemplateCache.RegisterTemplate(TemplateUtility.GetTemplateID(file.FullName, nametype), file.FullName);
                }
            }
            foreach (DirectoryInfo _dir in dir.GetDirectories())
            {
                //如果文件夹是可见的
                if ((_dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                {
                    RegisterTemplates(_dir, nametype);
                }
            }
        }
Пример #10
0
 //递归方式注册模板
 private static void RegisterTemplates(DirectoryInfo dir, TemplateNames nametype)
 {
     // tml 为模板文件,防止可以被直接浏览
     Regex allowExt = new Regex("(.html|.tml|.phtml)$", RegexOptions.IgnoreCase);
     foreach (FileInfo file in dir.GetFiles())
     {
         if (allowExt.IsMatch(file.Extension))
         {
             TemplateCache.RegisterTemplate(TemplateUtility.GetTemplateId(file.FullName, nametype), file.FullName);
         }
     }
     foreach (DirectoryInfo _dir in dir.GetDirectories())
     {
         //如果文件夹是可见的
         if ((_dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
         {
             RegisterTemplates(_dir, nametype);
         }
     }
 }
Пример #11
0
        internal static string GetTemplateId(string filePath, TemplateNames nameType)
        {
            Match match = Regex.Match(filePath, "templates(/|\\\\)+#*(.+?)$", RegexOptions.IgnoreCase);

            if (String.IsNullOrEmpty(match.Value))
            {
                throw new Exception("模版页文件名:" + filePath + "不合法");
            }
            string fileName      = match.Groups[2].Value;
            String lowerFileName = fileName.ToLower();

            if (lowerFileName.EndsWith(".html") || nameType == TemplateNames.ID)
            {
                //return MD5.EncodeTo16(Regex.Replace(fileName, "/|\\\\", String.Empty).ToLower());
            }

            string id = $"{match.Groups[1].Value}{match.Groups[2].Value}"
                        .Replace('\\', '/');

            return(id.Substring(0, id.LastIndexOf('.')).ToLower());
        }
Пример #12
0
        internal static string GetTemplateId(string filePath, TemplateNames nametype)
        {
            Match match = Regex.Match(filePath, "templates(/|\\\\)+#*(.+?)$", RegexOptions.IgnoreCase);
            if (String.IsNullOrEmpty(match.Value)) throw new Exception("模版页文件名:" + filePath + "不合法");

            string fileName = match.Groups[2].Value;
            if (!fileName.ToLower().EndsWith(".phtml") && nametype == TemplateNames.FileName)
            {
                string id = String.Format("{0}{1}",
                    match.Groups[1].Value,
                    match.Groups[2].Value)
                    .Replace('\\', '/');

                return id.Substring(0, id.LastIndexOf('.'));
            }
            else
            {
                return MD5.EncodeTo16(Regex.Replace(fileName, "/|\\\\", String.Empty).ToLower());
            }
        }
Пример #13
0
 public Template(TemplateNames template = TemplateNames.SingleImageAd)
 {
     LoadTemplate(template);
 }
Пример #14
0
 public TemplateRegister(DirectoryInfo templateDirectory, TemplateNames nametype)
 {
     this.nametype = nametype;
     this.directory = templateDirectory;
     if (!this.directory.Exists) throw new DirectoryNotFoundException("模版文件夹不存在!");
 }
Пример #15
0
 public TemplateRegister(string directoryPath, TemplateNames nametype)
 {
     this.nametype = nametype;
     this.directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + directoryPath);
     if (!this.directory.Exists) throw new DirectoryNotFoundException("模版文件夹不存在!");
 }