private static List <string> GetTableNameList(bool includeSiteTables, bool includePluginTables) { var tableNames = new List <string>(); if (includeSiteTables) { var pairList = SiteManagerCache.GetSiteInfoKeyValuePairList(); foreach (var pair in pairList) { if (!StringUtils.ContainsIgnoreCase(tableNames, pair.Value.TableName)) { tableNames.Add(pair.Value.TableName); } } } if (includePluginTables) { var pluginTableNames = PluginContentManager.GetContentTableNameList(); foreach (var pluginTableName in pluginTableNames) { if (!StringUtils.ContainsIgnoreCase(tableNames, pluginTableName)) { tableNames.Add(pluginTableName); } } } return(tableNames); }
public IActionResult Save(cms_upload_set dto) { var upload = _uploadSetApp.SaveSite(dto); SiteManagerCache.SetUploadInfo(upload); return(Success("设置成功")); }
public IActionResult Save(cms_ad dto) { dto.insert_id = RequestHelper.AdminInfo().Id; dto = _adApp.Save(dto); SiteManagerCache.AddAdvertising(dto); return(Success("数据保存成功")); }
public IActionResult SaveSite(cms_site dto) { var site = _siteApp.SaveSite(dto); SiteManagerCache.SetSiteInfo(site); return(Success("保存成功")); }
public IActionResult GetUploadSet() { var result = new ResultAdaptDto(); var set = SiteManagerCache.GetUploadInfo(); result.data.Add("uploadSet", set); return(Content(result.ToJson())); }
public static List <int> GetSiteIdList() { var pairList = SiteManagerCache.GetSiteInfoKeyValuePairList(); var list = new List <int>(); foreach (var pair in pairList) { list.Add(pair.Key); } return(list); }
/// <summary> /// 返回渲染后的页面文件 /// </summary> /// <param name="content"></param> /// <param name="template"></param> /// <returns></returns> public (bool genStatus, string contentHtml) GenerateContentHtml(int channelId, int id) { try { Stopwatch watcher = new Stopwatch(); watcher.Start(); var templateModel = ChannelManagerCache.GetContentTemplate(channelId); if (templateModel == null) { return(false, ""); } var content = _contentApp.GetContentInfo(id); if (content == null) { return(false, ""); } //加载模板 先取缓存,没有再初始化一个并且加入缓存 this.Document = RenderDocumentCache.GetRenderDocument(templateModel.id); if (this.Document == null) { string templateFile = Path.Combine(GlobalContext.WebRootPath, templateModel.template_file); this.Document = new TemplateDocument(templateModel.template_content, GlobalContext.WebRootPath, templateFile); RenderDocumentCache.AddRenderDocument(templateModel.id, this.Document); } this.Document.Variables.SetValue("this", this); //站点基本信息 var site = SiteManagerCache.GetSiteInfo(); this.Document.Variables.SetValue("site", site); //设置顶部导航条数据 var navigations = _contentApp.GetChannelTree(); this.Document.Variables.SetValue("navigations", navigations); //获取当前文章信息 this.Document.Variables.SetValue("content", content); string renderHtml = this.Document.GetRenderText(); renderHtml = HtmlPlayerHandler.CreateVideo(renderHtml); watcher.Stop(); string msg = $"渲染内容页耗时:{watcher.ElapsedMilliseconds} ms"; LoggerHelper.Info(msg); return(true, renderHtml); } catch (Exception ex) { LoggerHelper.Exception(ex); } return(false, ""); }
public IActionResult DeleteById(string ids) { if (ids.IsEmpty()) { return(Error("删除失败")); } var idsArray = _adApp.DeleteById(ids); foreach (int adId in idsArray) { SiteManagerCache.RemoveAdvertising(adId); } return(Success("删除成功")); }
public static SiteInfo GetSiteInfoByDirectory(string siteDir) { var list = SiteManagerCache.GetSiteInfoKeyValuePairList(); foreach (var pair in list) { var siteInfo = pair.Value; if (siteInfo == null) { continue; } if (StringUtils.EqualsIgnoreCase(siteInfo.SiteDir, siteDir)) { return(siteInfo); } } return(null); }
public static SiteInfo GetSiteInfoByIsRoot() { var list = SiteManagerCache.GetSiteInfoKeyValuePairList(); foreach (var pair in list) { var siteInfo = pair.Value; if (siteInfo == null) { continue; } if (siteInfo.IsRoot) { return(siteInfo); } } return(null); }
public static SiteInfo GetSiteInfo(int siteId) { if (siteId <= 0) { return(null); } var list = SiteManagerCache.GetSiteInfoKeyValuePairList(); foreach (var pair in list) { var theSiteId = pair.Key; if (theSiteId != siteId) { continue; } var siteInfo = pair.Value; return(siteInfo); } return(null); }
public static List <SiteInfo> GetSiteInfoList() { var pairList = SiteManagerCache.GetSiteInfoKeyValuePairList(); return(pairList.Select(pair => pair.Value).ToList()); }
public static void ClearCache() { SiteManagerCache.Clear(); }
/// <summary> /// 返回渲染后的模板文件 /// </summary> /// <param name="content"></param> /// <param name="template"></param> /// <returns></returns> public void GenerateHomeHtml() { try { Stopwatch watcher = new Stopwatch(); watcher.Start(); var templateModel = TemplateManagerCache.GetHomeTemplate(); if (templateModel.id==0) { throw new Exception("找不到模板"); } //加载模板 先取缓存,没有再初始化一个并且加入缓存 this.Document = RenderDocumentCache.GetRenderDocument(templateModel.id); if (this.Document == null) { string templateFile = Path.Combine(GlobalParamsDto.WebRoot, templateModel.template_file); this.Document = new TemplateDocument(templateModel.template_content, GlobalParamsDto.WebRoot, templateFile); RenderDocumentCache.AddRenderDocument(templateModel.id, this.Document); } //this.LoadTemplate(templateModel.template_content); this.Document.Variables.SetValue("this", this); //站点基本信息 var site = SiteManagerCache.GetSiteInfo(); this.Document.Variables.SetValue("site", site); //设置顶部导航条数据 var navigations = _generateContentApp.GetChannelTree(); this.Document.Variables.SetValue("navigations", navigations); //获取栏目文章模板 ElementCollection<Template> templates = this.Document.GetChildTemplatesByName("channels"); foreach (Template template in templates) { string total = template.Attributes.GetValue("total", "10"); //根据模板块里定义的type属性条件取得新闻数据 var data = _generateContentApp.GetContentSummary(template.Attributes.GetValue("type"),1,int.Parse(total)); //设置变量newsdata的值 template.Variables.SetValue("contents", data); //取得模板块下Id为newslist的标签(也即是在cnblogs_newsdata.html文件中定义的foreach标签) //Tag tag = template.GetChildTagById("newslist"); //if (tag is ForEachTag) //{ // //如果标签为foreach标签则设置其BeforeRender事件用于设置变量表达式{$:#.news.url}的值 // tag.BeforeRender += new System.ComponentModel.CancelEventHandler(Tag_BeforeRender); //} } string contentFilePath = Path.Combine(GlobalParamsDto.WebRoot, "index.html"); using (var filestream = new FileStream(contentFilePath, FileMode.Create, FileAccess.ReadWrite)) { string renderHtml = this.Document.GetRenderText(); using (StreamWriter writer = new StreamWriter(filestream, Encoding.UTF8)) { writer.WriteLine(renderHtml); writer.Flush(); } } watcher.Stop(); string msg = $"渲染首页耗时:{watcher.ElapsedMilliseconds} ms"; LogNHelper.Info(msg); } catch (Exception ex) { LogNHelper.Exception(ex); } }
public ActionResult Index(string action) { var result = new UeditorUploadDto(); try { if (action == "config") { string configPath = $@"ui\plugins\ueditor\config.json"; string serverPath = Path.Combine(GlobalParamsDto.WebRoot, configPath); if (System.IO.File.Exists(serverPath)) { string json = System.IO.File.ReadAllText(serverPath); return(Content(json)); } return(Content("")); } var files = Request.Form.Files; if (files.Count == 0) { result.state = "FAIL"; result.error = "请选择文件"; return(Content(result.ToJson())); } var file = files[0]; var filename = file.FileName; int index = filename.LastIndexOf('.'); string extName = filename.Substring(index + 1); //uploadimage string url = $@"upfiles\images\{DateTime.Now.ToString("yyyyMMdd")}"; var uploadSet = SiteManagerCache.GetUploadInfo(); if (action == "uploadimage") { var imageExt = uploadSet.image_extname.Split(','); if (!imageExt.Contains(extName)) { result.state = "FAIL"; result.error = $"禁止上传图片类型:{extName}"; return(Content(result.ToJson())); } } else if (action == "uploadfile") { var fileExt = uploadSet.attache_extname.Split(','); if (!fileExt.Contains(extName)) { result.state = "FAIL"; result.error = $"禁止上传附件类型:{extName}"; return(Content(result.ToJson())); } if (file.Length > (uploadSet.max_file_size * 1024 * 1024)) { result.state = "FAIL"; result.error = $"上传附件超过{uploadSet.max_file_size}MB限制,禁止上传"; return(Content(result.ToJson())); } url = $@"upfiles\attachments\{DateTime.Now.ToString("yyyyMMdd")}"; } else if (action == "uploadvideo") { var mediaExt = uploadSet.media_extname.Split(','); if (!mediaExt.Contains(extName)) { result.state = "FAIL"; result.error = $"禁止上传视频类型:{extName}"; return(Content(result.ToJson())); } if (file.Length > (uploadSet.max_file_size * 1024 * 1024)) { result.state = "FAIL"; result.error = $"上传视频超过{uploadSet.max_file_size}MB限制,禁止上传"; return(Content(result.ToJson())); } url = $@"upfiles\videos\{DateTime.Now.ToString("yyyyMMdd")}"; } var folder = Path.Combine(GlobalParamsDto.WebRoot, url); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string guidFileName = $"{IdHelper.ObjectId()}.{extName}"; //这个hostingEnv.WebRootPath就是要存的地址可以改下 string newfilename = Path.Combine(folder, guidFileName); using (FileStream fs = System.IO.File.Create(newfilename)) { file.CopyTo(fs); fs.Flush(); } if (action == "uploadimage") { var firstFileInfo = new FileInfo(newfilename); if (firstFileInfo.Length > 200 * 1024) { string compressFileName = $"{IdHelper.ObjectId()}.{extName}"; string compressFile = $@"{folder}\{compressFileName}"; ImageUtilities.CompressImage(newfilename, compressFile, 90, 200); guidFileName = compressFileName; } } result.original = filename; result.title = filename; result.url = $@"\{url}\{guidFileName}"; } catch (Exception e) { LoggerHelper.Exception(e); result.state = "FAIL"; result.error = "内部异常,请联系管理员"; } return(Content(result.ToJson())); }
public IActionResult Ban(int id) { _adApp.Ban(id); SiteManagerCache.RemoveAdvertising(id); return(Success("删除成功")); }
public ActionResult Uploadimg() { var result = new ResultAdaptDto(); //long size = 0; //当设置了开始水印的时候,可以使用nomark来过滤图片不加水印 int nomark = RequestHelper.GetPostInt("nomark"); var files = Request.Form.Files; if (files.Count == 0) { result.status = false; result.message = "没有文件信息"; return(Content(result.ToJson())); } string url = $"/upfiles/images/{DateTime.Now.ToString("yyyyMMdd")}"; var folder = GlobalContext.WebRootPath + url; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var file = files[0]; var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); int index = filename.LastIndexOf('.'); string extName = filename.Substring(index); string guidstr = Guid.NewGuid().ToString("N"); string guidFileName = guidstr + extName; //这个hostingEnv.WebRootPath就是要存的地址可以改下 filename = $"{folder}/{guidFileName}"; using (FileStream fs = System.IO.File.Create(filename)) { file.CopyTo(fs); fs.Flush(); } var firstFileInfo = new FileInfo(filename); if (firstFileInfo.Length > 200 * 1024) { string compressFileName = IdHelper.ObjectId() + extName; string compressFile = $"{folder}/{compressFileName}"; ImageUtilities.CompressImage(filename, compressFile, 90, 200); guidFileName = compressFileName; } if (nomark == 0) { var imageSet = SiteManagerCache.GetUploadInfo(); if (imageSet.open_watermark == 1) { try { string sourcePath = $"{folder}/{guidFileName}"; if (System.IO.File.Exists(sourcePath)) { FileStream fs = new FileStream(sourcePath, FileMode.Open); //把文件读取到字节数组 byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); //实例化一个内存流--->把从文件流中读取的内容[字节数组]放到内存流中去 MemoryStream ms = new MemoryStream(data); Image image = Image.FromStream(ms); if (image.Width > imageSet.image_width && image.Height > imageSet.image_height) { ImageWatermarker marker = new ImageWatermarker(); //图片水印 if (imageSet.watermark_type == 1) { string waterMarkIamge = GlobalContext.WebRootPath + imageSet.watermark_image; if (System.IO.File.Exists(waterMarkIamge)) { marker.AddImageSignPic(image, sourcePath, waterMarkIamge, imageSet.water_postion, imageSet.image_quality, imageSet.image_opacity); } } else { marker.AddWatermarkText(image, sourcePath, imageSet.watermark_word, imageSet.water_postion, imageSet.font_size, imageSet.font_color); } } } } catch (Exception ex) { LoggerHelper.Exception(ex); } } } string imgurl = $"{ url}/{guidFileName}"; result.data.Add("url", imgurl); return(Content(result.ToJson())); }
public static bool IsSiteTable(string tableName) { var pairList = SiteManagerCache.GetSiteInfoKeyValuePairList(); return(pairList.Any(pair => StringUtils.EqualsIgnoreCase(pair.Value.TableName, tableName) || StringUtils.EqualsIgnoreCase(pair.Value.TableName, tableName))); }
/// <summary> /// 返回渲染后的模板文件 /// </summary> /// <param name="content"></param> /// <param name="template"></param> /// <returns></returns> public (bool genStatus, string contentHtml) GenerateChannelHtml(int channelId, int page) { try { //Stopwatch watcher = new Stopwatch(); //watcher.Start(); var channel = _generateContentApp.GetChannel(channelId); if (channel == null) { return(false, null); } var templateModel = TemplateManagerCache.GetChannelTemplate(channel.channel_template); if (templateModel == null) { return(false, null); } //加载模板 先取缓存,没有再初始化一个并且加入缓存 //this.LoadTemplate(templateModel.template_content);"Template/Channel" this.Document = RenderDocumentCache.GetRenderDocument(templateModel.id); if (this.Document == null) { string templateFile = Path.Combine(GlobalParamsDto.WebRoot, templateModel.template_file); this.Document = new TemplateDocument(templateModel.template_content, GlobalParamsDto.WebRoot, templateFile); RenderDocumentCache.AddRenderDocument(templateModel.id, this.Document); } this.Document.Variables.SetValue("this", this); //站点数据 var site = SiteManagerCache.GetSiteInfo(); site.site_title = channel.channel_name; this.Document.Variables.SetValue("site", site); //设置顶部导航条数据 var navigations = _generateContentApp.GetChannelTree(channelId); this.Document.Variables.SetValue("navigations", navigations); //解析文章列表模板设置数据源 Tag element = this.Document.GetChildTagById("contents"); string total = element.Attributes.GetValue("total", "8"); var contents = _generateContentApp.GetContentSummaryPage(channelId, page, int.Parse(total)); //设置变量newsdata的值 this.Document.Variables.SetValue("channel", channel); this.Document.Variables.SetValue("contents", contents.Contents); this.Document.Variables.SetValue("pageHtml", contents.PageHtml); string renderHtml = this.Document.GetRenderText(); //watcher.Stop(); //string msg = $"渲染栏目耗时:{watcher.ElapsedMilliseconds} ms"; //LogNHelper.Info(msg); return(true, renderHtml); } catch (Exception ex) { LogNHelper.Exception(ex); } return(false, null); }
/// <summary> /// 生成静态文档,channelId和contentId都为0的时候生成首页 /// </summary> /// <param name="contentId">文章id</param> /// <param name="channelId">栏目id</param> /// <param name="channelPage">栏目页的分页页面</param> /// <returns></returns> public GenerateResultDto GenerateHtml(int contentId, int channelId, int channelPage) { GenerateResultDto ret = new GenerateResultDto(); try { //获取模板信息 cms_template templateModel = null; ChannelModel channelModel = null; ContentModel contentModel = null; if (channelId == 0 && contentId == 0) { templateModel = TemplateManagerCache.GetHomeTemplate(); RenderMode = 1; } else if (channelId > 0) { channelModel = generateApp.GetChannel(channelId); templateModel = ChannelManagerCache.GetChannelTemplate(channelId); if (channelModel == null) { ret.Message = "栏目数据查找失败"; return(ret); } RenderMode = 2; } else if (contentId > 0) { contentModel = generateApp.GetContentInfo(contentId); channelModel = generateApp.GetChannel(contentModel.channel_id); templateModel = ChannelManagerCache.GetContentTemplate(contentModel.channel_id); if (contentModel == null) { ret.Message = "内容数据查找失败"; return(ret); } RenderMode = 3; } if (templateModel == null || templateModel.id == 0) { throw new Exception("找不到模板"); } //加载模板 先取缓存,没有再初始化一个并且加入缓存 this.Document = RenderDocumentCache.GetRenderDocument(templateModel.id); if (this.Document == null) { string templateFile = Path.Combine(GlobalContext.WebRootPath, templateModel.template_file); this.Document = new TemplateDocument(templateModel.template_content, GlobalContext.WebRootPath, templateFile); RenderDocumentCache.AddRenderDocument(templateModel.id, this.Document); } #region 公用数据 //加入基本信息 this.Document.Variables.SetValue("this", this); //站点基本信息 var site = SiteManagerCache.GetSiteInfo(); this.Document.Variables.SetValue("site", site); //添加所有导航条数据 var channels = generateApp.GetChannelTree(); this.Document.Variables.SetValue("channels", channels); //解析模板中的栏目文章模板 ElementCollection <Template> templateContents = this.Document.GetChildTemplatesByName("contents"); foreach (Template template in templateContents) { //从第几条数据开始 string startNum = template.Attributes.GetValue("startNum", "1"); string total = template.Attributes.GetValue("total", "10"); //根据模板块里定义的type属性条件取得新闻数据 var data = generateApp.GetContentSummary(template.Attributes.GetValue("channelIndex"), int.Parse(startNum), int.Parse(total)); //设置变量newsdata的值 template.Variables.SetValue("contents", data); } //解析模板中的channel标签 ElementCollection <Template> templateChannel = this.Document.GetChildTemplatesByName("channel"); foreach (Template template in templateChannel) { string channelIndex = template.Attributes.GetValue("channelIndex", "#"); //根据模板块里定义的type属性条件取得新闻数据 var channel = ChannelManagerCache.GetChannelByIndex(channelIndex); if (channel != null) { ChannelModel inChannelModel = generateApp.GetChannel(channel.id); //设置变量newsdata的值 template.Variables.SetValue("channel", inChannelModel); } } #endregion //渲染首页 if (RenderMode == 1) { string contentFilePath = Path.Combine(GlobalContext.WebRootPath, "index.html"); using (var filestream = new FileStream(contentFilePath, FileMode.Create, FileAccess.ReadWrite)) { string renderHtml = this.Document.GetRenderText(); using (StreamWriter writer = new StreamWriter(filestream, Encoding.UTF8)) { writer.WriteLine(renderHtml); writer.Flush(); } } ret.Status = true; return(ret); } //栏目数据 if (RenderMode == 2) { //获取当前栏目下的文章列表 //解析文章列表模板设置数据源 添加id为contents 模板 Tag element = this.Document.GetChildTagById("contents"); int total = int.Parse(element.Attributes.GetValue("total", "8")); int startNum = int.Parse(element.Attributes.GetValue("startNum", "1"));//从第几条开始 //跳过多少条数据 int skipNum = (channelPage - 1) * total + (startNum - 1); var channelContents = generateApp.GetContentSummaryByChannelId(channelId, skipNum, total); this.Document.Variables.SetValue("contents", channelContents); this.Document.Variables.SetValue("channel", channelModel); string renderHtml = this.Document.GetRenderText(); ret.Status = true; ret.Html = renderHtml; return(ret); } //文章数据 if (RenderMode == 3) { this.Document.Variables.SetValue("channel", channelModel); this.Document.Variables.SetValue("content", contentModel); //渲染内容数据 string renderHtml = this.Document.GetRenderText(); renderHtml = HtmlPlayerHandler.CreateVideo(renderHtml); ret.Status = true; ret.Html = renderHtml; return(ret); } } catch (Exception ex) { LoggerHelper.Exception(ex); } return(ret); }