private static void Application_Error(object sender, EventArgs e) { try { var ex = HttpContext.Current.Server.GetLastError(); if (ex.InnerException != null) { ex = ex.InnerException; } HttpContext.Current.Server.ClearError(); if (ex.HResult == -2147467259) // 文件名不存在 { PageUtils.RedirectToErrorPage(ex.Message); } else { var logId = LogUtils.AddSystemErrorLog(ex, "Application Error"); if (logId > 0) { PageUtils.RedirectToErrorPage(logId); } else { PageUtils.RedirectToErrorPage(ex.Message); } } } catch { // ignored } }
public NameValueCollection CreateSiteByOnlineTemplateName(int siteId, bool isImportContents, bool isImportTableStyles, string onlineTemplateName, bool isUseTables, string userKeyPrefix, string administratorName) { var cacheTotalCountKey = userKeyPrefix + CacheTotalCount; var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount; var cacheMessageKey = userKeyPrefix + CacheMessage; CacheUtils.Insert(cacheTotalCountKey, "4"); //存储需要的页面总数 CacheUtils.Insert(cacheCurrentCountKey, "0"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息 //返回“运行结果”、“错误信息”及“执行JS脚本”的字符串数组 NameValueCollection retval; try { CacheUtils.Insert(cacheCurrentCountKey, "1"); CacheUtils.Insert(cacheMessageKey, "开始下载模板压缩包,可能需要几分钟,请耐心等待..."); var filePath = PathUtility.GetSiteTemplatesPath($"T_{onlineTemplateName}.zip"); FileUtils.DeleteFileIfExists(filePath); var downloadUrl = OnlineTemplateManager.GetDownloadUrl(onlineTemplateName); WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath); CacheUtils.Insert(cacheCurrentCountKey, "2"); CacheUtils.Insert(cacheMessageKey, "模板压缩包下载成功,开始解压缩,可能需要几分钟,请耐心等待..."); var siteTemplateDir = $"T_{onlineTemplateName}"; var directoryPath = PathUtility.GetSiteTemplatesPath(siteTemplateDir); DirectoryUtils.DeleteDirectoryIfExists(directoryPath); ZipUtils.UnpackFiles(filePath, directoryPath); CacheUtils.Insert(cacheCurrentCountKey, "3"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, "站点模板下载成功,正在导入数据..."); //存储消息 SiteTemplateManager.Instance.ImportSiteTemplateToEmptySite(siteId, siteTemplateDir, isUseTables, isImportContents, isImportTableStyles, administratorName); CreateManager.CreateAll(siteId); CacheUtils.Insert(cacheCurrentCountKey, "4"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, "创建成功!"); //存储消息 var siteInfo = SiteManager.GetSiteInfo(siteId); retval = AjaxManager.GetWaitingTaskNameValueCollection($"站点 <strong>{siteInfo.SiteName}<strong> 创建成功!", string.Empty, $"top.location.href='{PageInitialization.GetRedirectUrl()}';"); } catch (Exception ex) { retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty); LogUtils.AddSystemErrorLog(ex); } CacheUtils.Remove(cacheTotalCountKey); //取消存储需要的页面总数 CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数 CacheUtils.Remove(cacheMessageKey); //取消存储消息 CacheUtils.ClearAll(); return(retval); }
public static string GetStlErrorMessage(string elementName, string stlContent, Exception ex) { LogUtils.AddSystemErrorLog(ex, StringUtils.HtmlEncode(stlContent)); return($@" <!-- {elementName} error: {ex.Message} stl: {stlContent} -->"); }
public async Task Execute(int siteId) { var pendingTaskCount = 0; try { pendingTaskCount = await ExecuteTaskAsync(siteId); } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex, "CreateHub"); } Clients.Client(Context.ConnectionId).next(pendingTaskCount); }
public HttpResponseMessage GetFile(int siteId, int fileTemplateId) { try { var pageIndex = TranslateUtils.ToInt(HttpContext.Current.Request.QueryString["pageIndex"]); var response = GetResponseMessage(VisualInfo.GetInstance(siteId, 0, 0, fileTemplateId, pageIndex, 0)); return(response ?? Request.CreateResponse(HttpStatusCode.NotFound)); } catch (Exception ex) { var logId = LogUtils.AddSystemErrorLog(ex); PageUtils.RedirectToErrorPage(logId); } return(Request.CreateResponse(HttpStatusCode.NotFound)); }
private static PluginInfo ActivePlugin(string directoryName) { PackageMetadata metadata = null; string errorMessage; try { metadata = PackageUtils.GetPackageMetadataFromPlugins(directoryName, out errorMessage); var dllDirectoryPath = PathUtils.GetPluginDllDirectoryPath(directoryName); if (string.IsNullOrEmpty(dllDirectoryPath)) { throw new Exception($"插件可执行文件 {directoryName}.dll 不存在"); } //foreach (var filePath in DirectoryUtils.GetFilePaths(DirectoryUtils.GetDirectoryPath(metadata.ExecuteFilePath))) //{ // if (!StringUtils.EqualsIgnoreCase(PathUtils.GetExtension(filePath), ".dll")) continue; // var fileName = PathUtils.GetFileName(filePath); // if (StringUtils.EqualsIgnoreCase(fileName, PathUtils.GetFileName(metadata.ExecuteFilePath))) continue; // if (FileUtils.IsFileExists(PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, "Bin", fileName))) continue; // Assembly.Load(File.ReadAllBytes(filePath)); //} //var assembly = Assembly.Load(File.ReadAllBytes(metadata.ExecuteFilePath)); //metadata.GetDependencyGroups() CopyDllsToBin(metadata.Id, dllDirectoryPath); //var assembly = Assembly.Load(File.ReadAllBytes(PathUtils.Combine(WebConfigUtils.PhysicalApplicationPath, "Bin", PathUtils.GetFileName(metadata.ExecuteFilePath)))); var assembly = Assembly.Load(metadata.Id); // load the dll from bin directory var type = assembly.GetTypes().First(o => o.IsClass && !o.IsAbstract && o.IsSubclassOf(typeof(PluginBase))); return(ActiveAndAdd(metadata, type)); } catch (Exception ex) { errorMessage = ex.Message; LogUtils.AddSystemErrorLog(ex, $"插件加载:{directoryName}"); } return(new PluginInfo(directoryName, metadata, errorMessage)); }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } if (!string.IsNullOrEmpty(Request.Form["translateCollection"])) { try { var translateType = ETranslateContentTypeUtils.GetEnumType(RblTranslateType.SelectedValue); foreach (var channelId in _idsDictionary.Keys) { var contentIdArrayList = _idsDictionary[channelId]; if (contentIdArrayList != null) { contentIdArrayList.Reverse(); if (contentIdArrayList.Count > 0) { foreach (var contentId in contentIdArrayList) { ContentUtility.Translate(SiteInfo, channelId, contentId, Request.Form["translateCollection"], translateType, Body.AdminName); Body.AddSiteLog(SiteInfo.Id, channelId, contentId, "转移内容", string.Empty); } } } } SuccessMessage("内容转移成功!"); AddWaitAndRedirectScript(_returnUrl); } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex); FailMessage(ex, "内容转移失败!"); } } else { FailMessage("请选择需要转移到的栏目!"); } }
public NameValueCollection Backup(int siteId, string backupType, string userKeyPrefix) { //返回“运行结果”和“错误信息”的字符串数组 NameValueCollection retval; try { var eBackupType = EBackupTypeUtils.GetEnumType(backupType); var siteInfo = SiteManager.GetSiteInfo(siteId); var filePath = PathUtility.GetBackupFilePath(siteInfo, eBackupType); DirectoryUtils.CreateDirectoryIfNotExists(filePath); FileUtils.DeleteFileIfExists(filePath); if (eBackupType == EBackupType.Templates) { BackupUtility.BackupTemplates(siteId, filePath); } else if (eBackupType == EBackupType.ChannelsAndContents) { BackupUtility.BackupChannelsAndContents(siteId, filePath); } else if (eBackupType == EBackupType.Files) { BackupUtility.BackupFiles(siteId, filePath); } else if (eBackupType == EBackupType.Site) { BackupUtility.BackupSite(siteId, filePath); } string resultString = $"任务完成,备份地址:<br /><strong> {filePath} </strong> <a href='{ApiRouteActionsDownload.GetUrl(PageUtility.InnerApiUrl, filePath)}'><img src='{SiteServerAssets.GetIconUrl("download.gif")}' />下载</a>。"; retval = AjaxManager.GetWaitingTaskNameValueCollection(resultString, string.Empty, string.Empty); } catch (Exception ex) { retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty); LogUtils.AddSystemErrorLog(ex); } return(retval); }
public NameValueCollection CreateSiteBySiteTemplateDir(int siteId, bool isImportContents, bool isImportTableStyles, string siteTemplateDir, bool isUseTables, string userKeyPrefix, string administratorName) { var cacheTotalCountKey = userKeyPrefix + CacheTotalCount; var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount; var cacheMessageKey = userKeyPrefix + CacheMessage; CacheUtils.Insert(cacheTotalCountKey, "3"); //存储需要的页面总数 CacheUtils.Insert(cacheCurrentCountKey, "0"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息 //返回“运行结果”、“错误信息”及“执行JS脚本”的字符串数组 NameValueCollection retval; try { CacheUtils.Insert(cacheCurrentCountKey, "1"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, "正在创建站点..."); //存储消息 var siteInfo = SiteManager.GetSiteInfo(siteId); CacheUtils.Insert(cacheCurrentCountKey, "2"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, "正在导入数据..."); //存储消息 SiteTemplateManager.Instance.ImportSiteTemplateToEmptySite(siteId, siteTemplateDir, isUseTables, isImportContents, isImportTableStyles, administratorName); CreateManager.CreateAll(siteId); CacheUtils.Insert(cacheCurrentCountKey, "3"); //存储当前的页面总数 CacheUtils.Insert(cacheMessageKey, "创建成功!"); //存储消息 retval = AjaxManager.GetWaitingTaskNameValueCollection( $"站点 <strong>{siteInfo.SiteName}<strong> 创建成功!", string.Empty, $"top.location.href='{PageInitialization.GetRedirectUrl()}';"); } catch (Exception ex) { retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty); LogUtils.AddSystemErrorLog(ex); } CacheUtils.Remove(cacheTotalCountKey); //取消存储需要的页面总数 CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数 CacheUtils.Remove(cacheMessageKey); //取消存储消息 CacheUtils.ClearAll(); return(retval); }
private static async Task CreateContentsAsync(int siteId, int channelId) { var siteInfo = SiteManager.GetSiteInfo(siteId); var nodeInfo = ChannelManager.GetChannelInfo(siteId, channelId); var tableName = ChannelManager.GetTableName(siteInfo, nodeInfo); var orderByString = ETaxisTypeUtils.GetContentOrderByString(ETaxisType.OrderByTaxisDesc); var contentIdList = Content.GetContentIdListChecked(tableName, channelId, orderByString); foreach (var contentId in contentIdList) { try { await CreateContentAsync(siteInfo, tableName, channelId, contentId); } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex, "CreateContent"); } } }
private static SortedList <string, PluginInfo> Load() { Environment = new PluginEnvironment(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.AdminDirectory, WebConfigUtils.PhysicalApplicationPath); var dict = new SortedList <string, PluginInfo>(); Thread.Sleep(2000); try { var pluginsPath = PathUtils.PluginsPath; if (!Directory.Exists(pluginsPath)) { return(dict); } var directoryNames = DirectoryUtils.GetDirectoryNames(pluginsPath); foreach (var directoryName in directoryNames) { if (StringUtils.StartsWith(directoryName, ".") || StringUtils.EqualsIgnoreCase(directoryName, "packages")) { continue; } var pluginInfo = ActivePlugin(directoryName); if (pluginInfo != null) { dict[directoryName] = pluginInfo; } } #if DEBUG PluginDebugger.Instance.Run(); #endif } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex, "载入插件时报错"); } return(dict); }
public async Task GetTasks(int siteId) { try { if (siteId > 0) { var summary = CreateTaskManager.Instance.GetTaskSummary(siteId); Clients.Client(Context.ConnectionId).show(true, summary.Tasks, summary.ChannelsCount, summary.ContentsCount, summary.FilesCount); await Execute(siteId); } else { Clients.Client(Context.ConnectionId).show(false, null, 0, 0, 0, 0); } } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex, "CreateHub"); } }
public NameValueCollection Recovery(int siteId, bool isDeleteChannels, bool isDeleteTemplates, bool isDeleteFiles, bool isZip, string path, bool isOverride, bool isUseTable, string userKeyPrefix, Request request) { //返回“运行结果”和“错误信息”的字符串数组 NameValueCollection retval; try { BackupUtility.RecoverySite(siteId, isDeleteChannels, isDeleteTemplates, isDeleteFiles, isZip, PageUtils.UrlDecode(path), isOverride, isUseTable, request.AdminName); request.AddSiteLog(siteId, "恢复备份数据", request.AdminName); retval = AjaxManager.GetWaitingTaskNameValueCollection("数据恢复成功!", string.Empty, string.Empty); //retval = new string[] { "数据恢复成功!", string.Empty, string.Empty }; } catch (Exception ex) { //retval = new string[] { string.Empty, ex.Message, string.Empty }; retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty); LogUtils.AddSystemErrorLog(ex); } return(retval); }
public void Delete_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } try { var channelIdList = TranslateUtils.StringCollectionToIntList(Body.GetQueryString("ChannelIDCollection")); channelIdList.Sort(); channelIdList.Reverse(); var channelIdArrayList = new List <int>(); foreach (var channelId in channelIdList) { if (channelId == SiteId) { continue; } if (HasChannelPermissions(channelId, ConfigManager.Permissions.Channel.ChannelDelete)) { channelIdArrayList.Add(channelId); } } var builder = new StringBuilder(); foreach (var channelId in channelIdArrayList) { builder.Append(ChannelManager.GetChannelName(SiteId, channelId)).Append(","); } if (builder.Length > 0) { builder.Length -= 1; } if (_deleteContents) { SuccessMessage(bool.Parse(RblRetainFiles.SelectedValue) == false ? "成功删除内容以及生成页面!" : "成功删除内容,生成页面未被删除!"); foreach (var channelId in channelIdArrayList) { var tableName = ChannelManager.GetTableName(SiteInfo, channelId); var contentIdList = DataProvider.ContentDao.GetContentIdList(tableName, channelId); DirectoryUtility.DeleteContents(SiteInfo, channelId, contentIdList); DataProvider.ContentDao.TrashContents(SiteId, tableName, contentIdList); } Body.AddSiteLog(SiteId, "清空栏目下的内容", $"栏目:{builder}"); } else { if (bool.Parse(RblRetainFiles.SelectedValue) == false) { DirectoryUtility.DeleteChannels(SiteInfo, channelIdArrayList); SuccessMessage("成功删除栏目以及相关生成页面!"); } else { SuccessMessage("成功删除栏目,相关生成页面未被删除!"); } foreach (var channelId in channelIdArrayList) { var tableName = ChannelManager.GetTableName(SiteInfo, channelId); DataProvider.ContentDao.TrashContentsByChannelId(SiteId, tableName, channelId); DataProvider.ChannelDao.Delete(SiteId, channelId); } Body.AddSiteLog(SiteId, "删除栏目", $"栏目:{builder}"); } AddWaitAndRedirectScript(ReturnUrl); } catch (Exception ex) { FailMessage(ex, _deleteContents ? "删除内容失败!" : "删除栏目失败!"); LogUtils.AddSystemErrorLog(ex); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack) { return; } var targetChannelId = TranslateUtils.ToInt(DdlChannelIdTo.SelectedValue); var targetSiteId = TranslateUtils.ToInt(DdlSiteId.SelectedValue); var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); bool isChecked; int checkedLevel; if (targetSiteInfo.Additional.CheckContentLevel == 0 || AdminUtility.HasChannelPermissions(Body.AdminName, targetSiteId, targetChannelId, ConfigManager.Permissions.Channel.ContentAdd, ConfigManager.Permissions.Channel.ContentCheck)) { isChecked = true; checkedLevel = 0; } else { var userCheckLevel = 0; var ownHighestLevel = false; if (AdminUtility.HasChannelPermissions(Body.AdminName, targetSiteId, targetChannelId, ConfigManager.Permissions.Channel.ContentCheckLevel1)) { userCheckLevel = 1; if (AdminUtility.HasChannelPermissions(Body.AdminName, targetSiteId, targetChannelId, ConfigManager.Permissions.Channel.ContentCheckLevel2)) { userCheckLevel = 2; if (AdminUtility.HasChannelPermissions(Body.AdminName, targetSiteId, targetChannelId, ConfigManager.Permissions.Channel.ContentCheckLevel3)) { userCheckLevel = 3; if (AdminUtility.HasChannelPermissions(Body.AdminName, targetSiteId, targetChannelId, ConfigManager.Permissions.Channel.ContentCheckLevel4)) { userCheckLevel = 4; if (AdminUtility.HasChannelPermissions(Body.AdminName, targetSiteId, targetChannelId, ConfigManager.Permissions.Channel.ContentCheckLevel5)) { userCheckLevel = 5; } } } } } if (userCheckLevel >= targetSiteInfo.Additional.CheckContentLevel) { ownHighestLevel = true; } if (ownHighestLevel) { isChecked = true; checkedLevel = 0; } else { isChecked = false; checkedLevel = userCheckLevel; } } try { var translateType = ETranslateTypeUtils.GetEnumType(DdlTranslateType.SelectedValue); var channelIdStrArrayList = ControlUtils.GetSelectedListControlValueArrayList(LbChannelIdFrom); var channelIdList = new List <int>(); //需要转移的栏目ID foreach (string channelIdStr in channelIdStrArrayList) { var channelId = int.Parse(channelIdStr); if (translateType != ETranslateType.Content) //需要转移栏目 { if (!ChannelManager.IsAncestorOrSelf(SiteId, channelId, targetChannelId)) { channelIdList.Add(channelId); } } if (translateType == ETranslateType.Content) //转移内容 { TranslateContent(targetSiteInfo, channelId, targetChannelId, isChecked, checkedLevel); } } if (translateType != ETranslateType.Content) //需要转移栏目 { var channelIdListToTranslate = new List <int>(channelIdList); foreach (var channelId in channelIdList) { var subChannelIdArrayList = DataProvider.ChannelDao.GetIdListForDescendant(channelId); if (subChannelIdArrayList != null && subChannelIdArrayList.Count > 0) { foreach (int channelIdToDelete in subChannelIdArrayList) { if (channelIdListToTranslate.Contains(channelIdToDelete)) { channelIdListToTranslate.Remove(channelIdToDelete); } } } } var nodeInfoList = new List <ChannelInfo>(); foreach (int channelId in channelIdListToTranslate) { var nodeInfo = ChannelManager.GetChannelInfo(SiteId, channelId); nodeInfoList.Add(nodeInfo); } TranslateChannelAndContent(nodeInfoList, targetSiteId, targetChannelId, translateType, isChecked, checkedLevel, null, null); if (RblIsDeleteAfterTranslate.Visible && EBooleanUtils.Equals(RblIsDeleteAfterTranslate.SelectedValue, EBoolean.True)) { foreach (int channelId in channelIdListToTranslate) { try { DataProvider.ChannelDao.Delete(SiteId, channelId); } catch { // ignored } } } } BtnSubmit.Enabled = false; var builder = new StringBuilder(); foreach (ListItem listItem in LbChannelIdFrom.Items) { if (listItem.Selected) { builder.Append(listItem.Text).Append(","); } } if (builder.Length > 0) { builder.Length = builder.Length - 1; } Body.AddSiteLog(SiteId, "批量转移", $"栏目:{builder},转移后删除:{RblIsDeleteAfterTranslate.SelectedValue}"); SuccessMessage("批量转移成功!"); PageUtils.Redirect(Body.IsQueryExists("ChannelIDCollection") ? ReturnUrl : GetRedirectUrl(SiteId)); } catch (Exception ex) { FailMessage(ex, "批量转移失败!"); LogUtils.AddSystemErrorLog(ex); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } try { foreach (var channelId in _idsDictionary.Keys) { var tableName = ChannelManager.GetTableName(SiteInfo, channelId); var contentIdList = _idsDictionary[channelId]; if (!_isDeleteFromTrash) { if (bool.Parse(RblRetainFiles.SelectedValue) == false) { DirectoryUtility.DeleteContents(SiteInfo, channelId, contentIdList); SuccessMessage("成功删除内容以及生成页面!"); } else { SuccessMessage("成功删除内容,生成页面未被删除!"); } if (contentIdList.Count == 1) { var contentId = contentIdList[0]; var contentTitle = DataProvider.ContentDao.GetValue(tableName, contentId, ContentAttribute.Title); Body.AddSiteLog(SiteId, channelId, contentId, "删除内容", $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, channelId)},内容标题:{contentTitle}"); } else { Body.AddSiteLog(SiteId, "批量删除内容", $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, channelId)},内容条数:{contentIdList.Count}"); } DataProvider.ContentDao.TrashContents(SiteId, tableName, contentIdList); //引用内容,需要删除 var tableList = DataProvider.TableDao.GetTableCollectionInfoListCreatedInDb(); foreach (var table in tableList) { var targetContentIdList = DataProvider.ContentDao.GetReferenceIdList(table.TableName, contentIdList); if (targetContentIdList.Count > 0) { var targetContentInfo = DataProvider.ContentDao.GetContentInfo(table.TableName, TranslateUtils.ToInt(targetContentIdList[0].ToString())); DataProvider.ContentDao.DeleteContents(targetContentInfo.SiteId, table.TableName, targetContentIdList, targetContentInfo.ChannelId); } } CreateManager.CreateContentTrigger(SiteId, channelId); } else { SuccessMessage("成功从回收站清空内容!"); DataProvider.ContentDao.DeleteContents(SiteId, tableName, contentIdList, channelId); Body.AddSiteLog(SiteId, "从回收站清空内容", $"内容条数:{contentIdList.Count}"); } } AddWaitAndRedirectScript(_returnUrl); } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex); FailMessage(ex, "删除内容失败!"); } }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } ChannelInfo nodeInfo; try { nodeInfo = ChannelManager.GetChannelInfo(SiteId, _channelId); if (!nodeInfo.IndexName.Equals(TbNodeIndexName.Text) && TbNodeIndexName.Text.Length != 0) { var nodeIndexNameList = DataProvider.ChannelDao.GetIndexNameList(SiteId); if (nodeIndexNameList.IndexOf(TbNodeIndexName.Text) != -1) { FailMessage("栏目属性修改失败,栏目索引已存在!"); return; } } if (nodeInfo.ContentModelPluginId != DdlContentModelPluginId.SelectedValue) { nodeInfo.ContentModelPluginId = DdlContentModelPluginId.SelectedValue; nodeInfo.ContentNum = DataProvider.ContentDao.GetCount(ChannelManager.GetTableName(SiteInfo, nodeInfo.ContentModelPluginId), nodeInfo.Id); } nodeInfo.ContentRelatedPluginIds = ControlUtils.GetSelectedListControlValueCollection(CblContentRelatedPluginIds); TbFilePath.Text = TbFilePath.Text.Trim(); if (!nodeInfo.FilePath.Equals(TbFilePath.Text) && TbFilePath.Text.Length != 0) { if (!DirectoryUtils.IsDirectoryNameCompliant(TbFilePath.Text)) { FailMessage("栏目页面路径不符合系统要求!"); return; } if (PathUtils.IsDirectoryPath(TbFilePath.Text)) { TbFilePath.Text = PageUtils.Combine(TbFilePath.Text, "index.html"); } var filePathArrayList = DataProvider.ChannelDao.GetAllFilePathBySiteId(SiteId); if (filePathArrayList.IndexOf(TbFilePath.Text) != -1) { FailMessage("栏目修改失败,栏目页面路径已存在!"); return; } } if (!string.IsNullOrEmpty(TbChannelFilePathRule.Text)) { var filePathRule = TbChannelFilePathRule.Text.Replace("|", string.Empty); if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule)) { FailMessage("栏目页面命名规则不符合系统要求!"); return; } if (PathUtils.IsDirectoryPath(filePathRule)) { FailMessage("栏目页面命名规则必须包含生成文件的后缀!"); return; } } if (!string.IsNullOrEmpty(TbContentFilePathRule.Text)) { var filePathRule = TbContentFilePathRule.Text.Replace("|", string.Empty); if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule)) { FailMessage("内容页面命名规则不符合系统要求!"); return; } if (PathUtils.IsDirectoryPath(filePathRule)) { FailMessage("内容页面命名规则必须包含生成文件的后缀!"); return; } } var extendedAttributes = new ExtendedAttributes(); var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(SiteId, _channelId); var styleInfoList = TableStyleManager.GetTableStyleInfoList(DataProvider.ChannelDao.TableName, relatedIdentities); BackgroundInputTypeParser.SaveAttributes(extendedAttributes, SiteInfo, styleInfoList, Request.Form, null); var attributes = extendedAttributes.ToNameValueCollection(); foreach (string key in attributes) { nodeInfo.Additional.Set(key, attributes[key]); } nodeInfo.ChannelName = TbNodeName.Text; nodeInfo.IndexName = TbNodeIndexName.Text; nodeInfo.FilePath = TbFilePath.Text; nodeInfo.ChannelFilePathRule = TbChannelFilePathRule.Text; nodeInfo.ContentFilePathRule = TbContentFilePathRule.Text; var list = new ArrayList(); foreach (ListItem item in CblNodeGroupNameCollection.Items) { if (item.Selected) { list.Add(item.Value); } } nodeInfo.GroupNameCollection = TranslateUtils.ObjectCollectionToString(list); nodeInfo.ImageUrl = TbImageUrl.Text; nodeInfo.Content = ContentUtility.TextEditorContentEncode(SiteInfo, Request.Form[ChannelAttribute.Content]); nodeInfo.Keywords = TbKeywords.Text; nodeInfo.Description = TbDescription.Text; nodeInfo.Additional.IsChannelAddable = TranslateUtils.ToBool(RblIsChannelAddable.SelectedValue); nodeInfo.Additional.IsContentAddable = TranslateUtils.ToBool(RblIsContentAddable.SelectedValue); nodeInfo.LinkUrl = TbLinkUrl.Text; nodeInfo.LinkType = DdlLinkType.SelectedValue; nodeInfo.Additional.DefaultTaxisType = ETaxisTypeUtils.GetValue(ETaxisTypeUtils.GetEnumType(DdlTaxisType.SelectedValue)); nodeInfo.ChannelTemplateId = DdlChannelTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlChannelTemplateId.SelectedValue) : 0; nodeInfo.ContentTemplateId = DdlContentTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlContentTemplateId.SelectedValue) : 0; DataProvider.ChannelDao.Update(nodeInfo); } catch (Exception ex) { FailMessage(ex, $"栏目修改失败:{ex.Message}"); LogUtils.AddSystemErrorLog(ex); return; } CreateManager.CreateChannel(SiteId, nodeInfo.Id); Body.AddSiteLog(SiteId, "修改栏目", $"栏目:{TbNodeName.Text}"); SuccessMessage("栏目修改成功!"); PageUtils.Redirect(ReturnUrl); }
private int SaveContentInfo(bool isPreview, out string errorMessage) { int savedContentId; errorMessage = string.Empty; var contentId = 0; string redirectUrl; if (!isPreview) { contentId = Body.GetQueryInt("id"); } if (contentId == 0) { var contentInfo = new ContentInfo(); try { contentInfo.ChannelId = _nodeInfo.Id; contentInfo.SiteId = SiteId; contentInfo.AddUserName = Body.AdminName; contentInfo.LastEditUserName = contentInfo.AddUserName; contentInfo.LastEditDate = DateTime.Now; BackgroundInputTypeParser.SaveAttributes(contentInfo, SiteInfo, _styleInfoList, Request.Form, ContentAttribute.AllAttributesLowercase); contentInfo.GroupNameCollection = ControlUtils.SelectedItemsValueToStringCollection(CblContentGroups.Items); var tagCollection = TagUtils.ParseTagsString(TbTags.Text); contentInfo.Title = TbTitle.Text; var formatString = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatStrong"]); var formatEm = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatEM"]); var formatU = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatU"]); var formatColor = Request.Form[ContentAttribute.Title + "_formatColor"]; var theFormatString = ContentUtility.GetTitleFormatString(formatString, formatEm, formatU, formatColor); contentInfo.Set(ContentAttribute.GetFormatStringAttributeName(ContentAttribute.Title), theFormatString); foreach (ListItem listItem in CblContentAttributes.Items) { var value = listItem.Selected.ToString(); var attributeName = listItem.Value; contentInfo.Set(attributeName, value); } contentInfo.LinkUrl = TbLinkUrl.Text; contentInfo.AddDate = TbAddDate.DateTime; if (contentInfo.AddDate.Year <= DateUtils.SqlMinValue.Year) { contentInfo.AddDate = DateTime.Now; } contentInfo.CheckedLevel = TranslateUtils.ToIntWithNagetive(DdlContentLevel.SelectedValue); contentInfo.IsChecked = contentInfo.CheckedLevel >= SiteInfo.Additional.CheckContentLevel; contentInfo.Tags = TranslateUtils.ObjectCollectionToString(tagCollection, " "); foreach (var service in PluginManager.Services) { try { service.OnContentFormSubmit(new ContentFormSubmitEventArgs(SiteId, _nodeInfo.Id, contentInfo, new ExtendedAttributes(Request.Form))); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(IService.ContentFormSubmit)); } } if (isPreview) { savedContentId = DataProvider.ContentDao.InsertPreview(_tableName, SiteInfo, _nodeInfo, contentInfo); } else { savedContentId = DataProvider.ContentDao.Insert(_tableName, SiteInfo, contentInfo); //判断是不是有审核权限 int checkedLevelOfUser; var isCheckedOfUser = CheckManager.GetUserCheckLevel(Body.AdminName, SiteInfo, contentInfo.ChannelId, out checkedLevelOfUser); if (CheckManager.IsCheckable(SiteInfo, contentInfo.ChannelId, contentInfo.IsChecked, contentInfo.CheckedLevel, isCheckedOfUser, checkedLevelOfUser)) { //添加审核记录 DataProvider.ContentDao.UpdateIsChecked(_tableName, SiteId, contentInfo.ChannelId, new List <int> { savedContentId }, 0, true, Body.AdminName, contentInfo.IsChecked, contentInfo.CheckedLevel, ""); } TagUtils.AddTags(tagCollection, SiteId, savedContentId); } contentInfo.Id = savedContentId; } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex); errorMessage = $"内容添加失败:{ex.Message}"; return(0); } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(SiteId, _nodeInfo.Id, contentInfo.Id); } Body.AddSiteLog(SiteId, _nodeInfo.Id, contentInfo.Id, "添加内容", $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, contentInfo.ChannelId)},内容标题:{contentInfo.Title}"); ContentUtility.Translate(SiteInfo, _nodeInfo.Id, contentInfo.Id, Request.Form["translateCollection"], ETranslateContentTypeUtils.GetEnumType(DdlTranslateType.SelectedValue), Body.AdminName); redirectUrl = PageContentAddAfter.GetRedirectUrl(SiteId, _nodeInfo.Id, contentInfo.Id, ReturnUrl); } else { var contentInfo = DataProvider.ContentDao.GetContentInfo(_tableName, contentId); try { var tagsLast = contentInfo.Tags; contentInfo.LastEditUserName = Body.AdminName; contentInfo.LastEditDate = DateTime.Now; BackgroundInputTypeParser.SaveAttributes(contentInfo, SiteInfo, _styleInfoList, Request.Form, ContentAttribute.AllAttributesLowercase); contentInfo.GroupNameCollection = ControlUtils.SelectedItemsValueToStringCollection(CblContentGroups.Items); var tagCollection = TagUtils.ParseTagsString(TbTags.Text); contentInfo.Title = TbTitle.Text; var formatString = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatStrong"]); var formatEm = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatEM"]); var formatU = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatU"]); var formatColor = Request.Form[ContentAttribute.Title + "_formatColor"]; var theFormatString = ContentUtility.GetTitleFormatString(formatString, formatEm, formatU, formatColor); contentInfo.Set(ContentAttribute.GetFormatStringAttributeName(ContentAttribute.Title), theFormatString); foreach (ListItem listItem in CblContentAttributes.Items) { var value = listItem.Selected.ToString(); var attributeName = listItem.Value; contentInfo.Set(attributeName, value); } contentInfo.LinkUrl = TbLinkUrl.Text; contentInfo.AddDate = TbAddDate.DateTime; var checkedLevel = TranslateUtils.ToIntWithNagetive(DdlContentLevel.SelectedValue); if (checkedLevel != CheckManager.LevelInt.NotChange) { contentInfo.IsChecked = checkedLevel >= SiteInfo.Additional.CheckContentLevel; contentInfo.CheckedLevel = checkedLevel; } contentInfo.Tags = TranslateUtils.ObjectCollectionToString(tagCollection, " "); foreach (var service in PluginManager.Services) { try { service.OnContentFormSubmit(new ContentFormSubmitEventArgs(SiteId, _nodeInfo.Id, contentInfo, new ExtendedAttributes(Request.Form))); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(IService.ContentFormSubmit)); } } DataProvider.ContentDao.Update(_tableName, SiteInfo, contentInfo); TagUtils.UpdateTags(tagsLast, contentInfo.Tags, tagCollection, SiteId, contentId); ContentUtility.Translate(SiteInfo, _nodeInfo.Id, contentInfo.Id, Request.Form["translateCollection"], ETranslateContentTypeUtils.GetEnumType(DdlTranslateType.SelectedValue), Body.AdminName); //更新引用该内容的信息 //如果不是异步自动保存,那么需要将引用此内容的content修改 //var sourceContentIdList = new List<int> //{ // contentInfo.Id //}; //var tableList = DataProvider.TableDao.GetTableCollectionInfoListCreatedInDb(); //foreach (var table in tableList) //{ // var targetContentIdList = DataProvider.ContentDao.GetReferenceIdList(table.TableName, sourceContentIdList); // foreach (var targetContentId in targetContentIdList) // { // var targetContentInfo = DataProvider.ContentDao.GetContentInfo(table.TableName, targetContentId); // if (targetContentInfo == null || targetContentInfo.GetString(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString()) continue; // contentInfo.Id = targetContentId; // contentInfo.SiteId = targetContentInfo.SiteId; // contentInfo.ChannelId = targetContentInfo.ChannelId; // contentInfo.SourceId = targetContentInfo.SourceId; // contentInfo.ReferenceId = targetContentInfo.ReferenceId; // contentInfo.Taxis = targetContentInfo.Taxis; // contentInfo.Set(ContentAttribute.TranslateContentType, targetContentInfo.GetString(ContentAttribute.TranslateContentType)); // DataProvider.ContentDao.Update(table.TableName, contentInfo); // //资源:图片,文件,视频 // var targetSiteInfo = SiteManager.GetSiteInfo(targetContentInfo.SiteId); // var bgContentInfo = contentInfo as BackgroundContentInfo; // var bgTargetContentInfo = targetContentInfo as BackgroundContentInfo; // if (bgTargetContentInfo != null && bgContentInfo != null) // { // if (bgContentInfo.ImageUrl != bgTargetContentInfo.ImageUrl) // { // //修改图片 // var sourceImageUrl = PathUtility.MapPath(SiteInfo, bgContentInfo.ImageUrl); // CopyReferenceFiles(targetSiteInfo, sourceImageUrl); // } // else if (bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl)) != bgTargetContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl))) // { // var sourceImageUrls = TranslateUtils.StringCollectionToStringList(bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl))); // foreach (string imageUrl in sourceImageUrls) // { // var sourceImageUrl = PathUtility.MapPath(SiteInfo, imageUrl); // CopyReferenceFiles(targetSiteInfo, sourceImageUrl); // } // } // if (bgContentInfo.FileUrl != bgTargetContentInfo.FileUrl) // { // //修改附件 // var sourceFileUrl = PathUtility.MapPath(SiteInfo, bgContentInfo.FileUrl); // CopyReferenceFiles(targetSiteInfo, sourceFileUrl); // } // else if (bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl)) != bgTargetContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl))) // { // var sourceFileUrls = TranslateUtils.StringCollectionToStringList(bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl))); // foreach (var fileUrl in sourceFileUrls) // { // var sourceFileUrl = PathUtility.MapPath(SiteInfo, fileUrl); // CopyReferenceFiles(targetSiteInfo, sourceFileUrl); // } // } // } // } //} } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex); errorMessage = $"内容修改失败:{ex.Message}"; return(0); } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(SiteId, _nodeInfo.Id, contentId); } Body.AddSiteLog(SiteId, _nodeInfo.Id, contentId, "修改内容", $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, contentInfo.ChannelId)},内容标题:{contentInfo.Title}"); redirectUrl = ReturnUrl; savedContentId = contentId; } if (!isPreview) { PageUtils.Redirect(redirectUrl); } return(savedContentId); }
public override void Submit_OnClick(object sender, EventArgs e) { if (!Page.IsPostBack || !Page.IsValid) { return; } var isChanged = false; try { var nodeInfo = ChannelManager.GetChannelInfo(SiteId, _channelId); if (!nodeInfo.IndexName.Equals(TbNodeIndexName.Text) && TbNodeIndexName.Text.Length != 0) { var nodeIndexNameList = DataProvider.ChannelDao.GetIndexNameList(SiteId); if (nodeIndexNameList.IndexOf(TbNodeIndexName.Text) != -1) { FailMessage("栏目修改失败,栏目索引已存在!"); return; } } if (PhFilePath.Visible) { TbFilePath.Text = TbFilePath.Text.Trim(); if (!nodeInfo.FilePath.Equals(TbFilePath.Text) && TbFilePath.Text.Length != 0) { if (!DirectoryUtils.IsDirectoryNameCompliant(TbFilePath.Text)) { FailMessage("栏目页面路径不符合系统要求!"); return; } if (PathUtils.IsDirectoryPath(TbFilePath.Text)) { TbFilePath.Text = PageUtils.Combine(TbFilePath.Text, "index.html"); } var filePathArrayList = DataProvider.ChannelDao.GetAllFilePathBySiteId(SiteId); if (filePathArrayList.IndexOf(TbFilePath.Text) != -1) { FailMessage("栏目修改失败,栏目页面路径已存在!"); return; } } } var extendedAttributes = new ExtendedAttributes(); var relatedIdentities = RelatedIdentities.GetChannelRelatedIdentities(SiteId, _channelId); var styleInfoList = TableStyleManager.GetTableStyleInfoList(DataProvider.ChannelDao.TableName, relatedIdentities); BackgroundInputTypeParser.SaveAttributes(extendedAttributes, SiteInfo, styleInfoList, Request.Form, null); if (extendedAttributes.ToNameValueCollection().Count > 0) { nodeInfo.Additional.Load(extendedAttributes.ToNameValueCollection()); } nodeInfo.ChannelName = TbNodeName.Text; nodeInfo.IndexName = TbNodeIndexName.Text; if (PhFilePath.Visible) { nodeInfo.FilePath = TbFilePath.Text; } var list = new ArrayList(); foreach (ListItem item in CblNodeGroupNameCollection.Items) { if (item.Selected) { list.Add(item.Value); } } nodeInfo.GroupNameCollection = TranslateUtils.ObjectCollectionToString(list); nodeInfo.ImageUrl = TbImageUrl.Text; nodeInfo.Content = ContentUtility.TextEditorContentEncode(SiteInfo, Request.Form[ChannelAttribute.Content]); if (TbKeywords.Visible) { nodeInfo.Keywords = TbKeywords.Text; } if (TbDescription.Visible) { nodeInfo.Description = TbDescription.Text; } if (PhLinkUrl.Visible) { nodeInfo.LinkUrl = TbLinkUrl.Text; } if (PhLinkType.Visible) { nodeInfo.LinkType = DdlLinkType.SelectedValue; } nodeInfo.Additional.DefaultTaxisType = ETaxisTypeUtils.GetValue(ETaxisTypeUtils.GetEnumType(DdlTaxisType.SelectedValue)); if (PhChannelTemplateId.Visible) { nodeInfo.ChannelTemplateId = DdlChannelTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlChannelTemplateId.SelectedValue) : 0; } nodeInfo.ContentTemplateId = DdlContentTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlContentTemplateId.SelectedValue) : 0; DataProvider.ChannelDao.Update(nodeInfo); Body.AddSiteLog(SiteId, _channelId, 0, "修改栏目", $"栏目:{nodeInfo.ChannelName}"); isChanged = true; } catch (Exception ex) { FailMessage(ex, $"栏目修改失败:{ex.Message}"); LogUtils.AddSystemErrorLog(ex); } if (isChanged) { CreateManager.CreateChannel(SiteId, _channelId); if (string.IsNullOrEmpty(_returnUrl)) { LayerUtils.Close(Page); } else { LayerUtils.CloseAndRedirect(Page, _returnUrl); } } }
public static string Parse(int siteId, string filePath, bool isClearFormat, bool isFirstLineIndent, bool isClearFontSize, bool isClearFontFamily, bool isClearImages) { if (string.IsNullOrEmpty(filePath)) { return(string.Empty); } var filename = PathUtils.GetFileNameWithoutExtension(filePath); //被转换的html文档保存的位置 try { var saveFilePath = PathUtils.GetTemporaryFilesPath(filename + ".html"); FileUtils.DeleteFileIfExists(saveFilePath); WordDntb.buildWord(filePath, saveFilePath); var parsedContent = FileUtils.ReadText(saveFilePath, System.Text.Encoding.Default); parsedContent = RegexUtils.GetInnerContent("body", parsedContent); //try //{ // parsedContent = HtmlClearUtils.ClearElementAttributes(parsedContent, "p"); //} //catch { } if (isClearFormat) { parsedContent = HtmlClearUtils.ClearFormat(parsedContent); } if (isFirstLineIndent) { parsedContent = HtmlClearUtils.FirstLineIndent(parsedContent); } if (isClearFontSize) { parsedContent = HtmlClearUtils.ClearFontSize(parsedContent); } if (isClearFontFamily) { parsedContent = HtmlClearUtils.ClearFontFamily(parsedContent); } if (isClearImages) { parsedContent = StringUtils.StripTags(parsedContent, "img"); } else { var siteInfo = SiteManager.GetSiteInfo(siteId); var imageFileNameArrayList = RegexUtils.GetOriginalImageSrcs(parsedContent); if (imageFileNameArrayList != null && imageFileNameArrayList.Count > 0) { var now = DateTime.Now; foreach (string imageFileName in imageFileNameArrayList) { now = now.AddMilliseconds(10); var imageFilePath = PathUtils.GetTemporaryFilesPath(imageFileName); var fileExtension = PathUtils.GetExtension(imageFilePath); var uploadDirectoryPath = PathUtility.GetUploadDirectoryPath(siteInfo, fileExtension); var uploadDirectoryUrl = PageUtility.GetSiteUrlByPhysicalPath(siteInfo, uploadDirectoryPath, true); if (!FileUtils.IsFileExists(imageFilePath)) { continue; } var uploadFileName = PathUtility.GetUploadFileName(siteInfo, imageFilePath, now); var destFilePath = PathUtils.Combine(uploadDirectoryPath, uploadFileName); FileUtils.MoveFile(imageFilePath, destFilePath, false); parsedContent = parsedContent.Replace(imageFileName, PageUtils.Combine(uploadDirectoryUrl, uploadFileName)); FileUtils.DeleteFileIfExists(imageFilePath); } } } FileUtils.DeleteFileIfExists(filePath); FileUtils.DeleteFileIfExists(saveFilePath); return(parsedContent.Trim()); } catch (Exception ex) { LogUtils.AddSystemErrorLog(ex); return(string.Empty); } }