Пример #1
0
        private static TemplateInfo GetTemplateInfo(string templatesDirectoryPath, string name)
        {
            TemplateInfo templateInfo = null;

            var configPath = PollUtils.PathCombine(templatesDirectoryPath, name, "config.json");

            if (PollUtils.IsFileExists(configPath))
            {
                templateInfo      = Context.UtilsApi.JsonDeserialize <TemplateInfo>(PollUtils.ReadText(configPath));
                templateInfo.Name = name;
            }

            return(templateInfo);
        }
Пример #2
0
        public static string GetListHtml()
        {
            var directoryPath = GetTemplatesDirectoryPath();
            var htmlPath      = PollUtils.PathCombine(directoryPath, "list.html");
            var html          = CacheUtils.Get <string>(htmlPath);

            if (html != null)
            {
                return(html);
            }

            html = PollUtils.ReadText(htmlPath);

            CacheUtils.Insert(htmlPath, html, 24);
            return(html);
        }
Пример #3
0
        private static string CacheGetFileContent(string filePath)
        {
            ObjectCache cache = MemoryCache.Default;

            if (cache[filePath] is string fileContents)
            {
                return(fileContents);
            }

            var policy = new CacheItemPolicy
            {
                SlidingExpiration = new TimeSpan(0, 1, 0, 0)
            };

            policy.ChangeMonitors.Add(new HostFileChangeMonitor(new List <string> {
                filePath
            }));

            fileContents = PollUtils.ReadText(filePath);

            cache.Set(filePath, fileContents, policy);

            return(fileContents);
        }