From fb8ffbac9d0a1399a5a43e63119da90c49c7abf9 Mon Sep 17 00:00:00 2001 From: starlying Date: Sun, 31 Mar 2019 10:06:46 +0800 Subject: [PATCH] dao --- .../Cms/PageTemplateReference.cs | 8 +- SiteServer.CMS/Core/DirectoryUtility.cs | 2 + SiteServer.CMS/Core/InputParserUtility.cs | 10 +- SiteServer.CMS/Plugin/PluginManager.cs | 5 +- SiteServer.CMS/Provider/AdministratorDao.cs | 3 +- SiteServer.CMS/Provider/DatabaseDao.cs | 58 ++++++-- .../StlParser/FileSystemObjectAsync.cs | 74 +++++++--- SiteServer.CMS/StlParser/Model/StlListBase.cs | 39 +++--- .../StlParser/StlElement/StlChannel.cs | 16 ++- .../StlParser/StlElement/StlChannels.cs | 4 +- .../StlParser/StlElement/StlContent.cs | 5 +- .../StlParser/StlElement/StlFile.cs | 24 ++-- .../StlParser/Utility/StlParserUtility.cs | 46 ++++-- SiteServer.Cli/Core/CliUtils.cs | 8 ++ SiteServer.Cli/Jobs/BackupJob.cs | 20 ++- SiteServer.Cli/Jobs/InstallJob.cs | 131 +++++++++--------- SiteServer.Cli/Jobs/RestoreJob.cs | 21 ++- SiteServer.Cli/Jobs/UpdateJob.cs | 11 +- SiteServer.Cli/Jobs/VersionJob.cs | 11 +- SiteServer.Cli/SiteServer.Cli.csproj | 3 - SiteServer.Utils/PathUtils.cs | 12 ++ SiteServer.Utils/SqlUtils.cs | 105 +++++++++----- SiteServer.Utils/WebConfigUtils.cs | 10 +- SiteServer.Web/Web.config | 2 +- 24 files changed, 391 insertions(+), 237 deletions(-) diff --git a/SiteServer.BackgroundPages/Cms/PageTemplateReference.cs b/SiteServer.BackgroundPages/Cms/PageTemplateReference.cs index abe9e266d..fd46f37d2 100644 --- a/SiteServer.BackgroundPages/Cms/PageTemplateReference.cs +++ b/SiteServer.BackgroundPages/Cms/PageTemplateReference.cs @@ -54,7 +54,7 @@ public void Page_Load(object sender, EventArgs e) {stlAttribute.Title} - https://docs.siteserver.cn/stl#/{tagName}/ + https://www.siteserver.cn/docs/stl/{tagName}/ "); } @@ -96,16 +96,18 @@ public void Page_Load(object sender, EventArgs e) if (attr != null) { + var attrUrl = + $"https://www.siteserver.cn/docs/stl/{tagName}/#{fieldName.ToLower()}-{attr.Title.ToLower()}"; attrBuilder.Append($@" {fieldName} {attr.Title} - https://docs.siteserver.cn/stl#/{tagName}/attributes?id={fieldName} + {attrUrl} "); } } - var helpUrl = $"https://docs.siteserver.cn/stl#/{tagName}/"; + var helpUrl = $"https://www.siteserver.cn/docs/stl/{tagName}/"; var stlAttribute = (StlElementAttribute)Attribute.GetCustomAttribute(elementType, typeof(StlElementAttribute)); diff --git a/SiteServer.CMS/Core/DirectoryUtility.cs b/SiteServer.CMS/Core/DirectoryUtility.cs index d7cbc411c..cdf0af3c7 100644 --- a/SiteServer.CMS/Core/DirectoryUtility.cs +++ b/SiteServer.CMS/Core/DirectoryUtility.cs @@ -28,6 +28,8 @@ public static void ChangeSiteDir(string parentPsPath, string oldPsDir, string ne public static void DeleteSiteFiles(SiteInfo siteInfo) { + if (siteInfo == null) return; + var sitePath = PathUtility.GetSitePath(siteInfo); if (siteInfo.IsRoot) diff --git a/SiteServer.CMS/Core/InputParserUtility.cs b/SiteServer.CMS/Core/InputParserUtility.cs index b1ac9f86b..1d5e69cb4 100644 --- a/SiteServer.CMS/Core/InputParserUtility.cs +++ b/SiteServer.CMS/Core/InputParserUtility.cs @@ -321,10 +321,9 @@ public static string GetVideoHtml(SiteInfo siteInfo, string videoUrl, NameValueC public static string GetFileHtmlWithCount(SiteInfo siteInfo, int channelId, int contentId, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity, bool isLower, bool isUpper) { - var retVal = string.Empty; - if (siteInfo == null) return retVal; - if (string.IsNullOrEmpty(fileUrl)) return retVal; + if (siteInfo == null || string.IsNullOrEmpty(fileUrl)) return string.Empty; + string retVal; if (isStlEntity) { retVal = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, channelId, contentId, @@ -356,10 +355,9 @@ public static string GetFileHtmlWithCount(SiteInfo siteInfo, int channelId, int public static string GetFileHtmlWithoutCount(SiteInfo siteInfo, string fileUrl, NameValueCollection attributes, string innerHtml, bool isStlEntity, bool isLower, bool isUpper) { - var retVal = string.Empty; - if (siteInfo == null) return retVal; - if (string.IsNullOrEmpty(fileUrl)) return retVal; + if (siteInfo == null || string.IsNullOrEmpty(fileUrl)) return string.Empty; + string retVal; if (isStlEntity) { retVal = ApiRouteActionsDownload.GetUrl(ApiManager.ApiUrl, siteInfo.Id, fileUrl); diff --git a/SiteServer.CMS/Plugin/PluginManager.cs b/SiteServer.CMS/Plugin/PluginManager.cs index 48d6b6dd4..18938dc86 100644 --- a/SiteServer.CMS/Plugin/PluginManager.cs +++ b/SiteServer.CMS/Plugin/PluginManager.cs @@ -184,8 +184,7 @@ public static SortedList GetPluginSortedList() public static void LoadPlugins(string applicationPhysicalPath) { - WebConfigUtils.Load(applicationPhysicalPath); - _pluginInfoListRunnable = PluginInfoListRunnable; + WebConfigUtils.Load(applicationPhysicalPath, PathUtils.Combine(applicationPhysicalPath, WebConfigUtils.WebConfigFileName)); Context.Initialize(new EnvironmentImpl(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.AdminDirectory, WebConfigUtils.PhysicalApplicationPath), new ApiCollectionImpl { @@ -200,6 +199,8 @@ public static void LoadPlugins(string applicationPhysicalPath) UserApi = UserApi.Instance, UtilsApi = UtilsApi.Instance }); + + _pluginInfoListRunnable = PluginInfoListRunnable; } public static void ClearCache() diff --git a/SiteServer.CMS/Provider/AdministratorDao.cs b/SiteServer.CMS/Provider/AdministratorDao.cs index 2e5cd8ac2..a3e71c0be 100644 --- a/SiteServer.CMS/Provider/AdministratorDao.cs +++ b/SiteServer.CMS/Provider/AdministratorDao.cs @@ -91,8 +91,7 @@ public class AdministratorDao : DataProviderBase new TableColumn { AttributeName = nameof(AdministratorInfoDatabase.SiteIdCollection), - DataType = DataType.VarChar, - DataLength = 50 + DataType = DataType.Text }, new TableColumn { diff --git a/SiteServer.CMS/Provider/DatabaseDao.cs b/SiteServer.CMS/Provider/DatabaseDao.cs index 40e45ca66..8c01b5431 100644 --- a/SiteServer.CMS/Provider/DatabaseDao.cs +++ b/SiteServer.CMS/Provider/DatabaseDao.cs @@ -655,19 +655,43 @@ public void AlterPluginTable(string pluginId, string tableName, List tableColumns, L var columnNameList = TableColumnManager.GetTableColumnNameList(tableName); foreach (var tableColumn in tableColumns) { - if (!StringUtils.ContainsIgnoreCase(columnNameList, tableColumn.AttributeName)) + if (StringUtils.ContainsIgnoreCase(columnNameList, tableColumn.AttributeName)) + { + var databaseColumn = TableColumnManager.GetTableColumnInfo(tableName, tableColumn.AttributeName); + if (databaseColumn != null && !tableColumn.IsIdentity) + { + if (tableColumn.DataType != databaseColumn.DataType || + tableColumn.DataType == databaseColumn.DataType && tableColumn.DataLength > databaseColumn.DataLength) + { + list.Add(SqlUtils.GetModifyColumnsSqlString(tableName, tableColumn.AttributeName, SqlUtils.GetColumnTypeString(tableColumn))); + } + } + } + else { list.Add(SqlUtils.GetAddColumnsSqlString(tableName, SqlUtils.GetColumnSqlString(tableColumn))); } diff --git a/SiteServer.CMS/StlParser/FileSystemObjectAsync.cs b/SiteServer.CMS/StlParser/FileSystemObjectAsync.cs index 9fc5ed196..cd7dcff08 100644 --- a/SiteServer.CMS/StlParser/FileSystemObjectAsync.cs +++ b/SiteServer.CMS/StlParser/FileSystemObjectAsync.cs @@ -82,46 +82,41 @@ private static async Task CreateChannelAsync(int siteId, int channelId) var contentBuilder = new StringBuilder(TemplateManager.GetTemplateContent(siteInfo, templateInfo)); var stlLabelList = StlParserUtility.GetStlLabelList(contentBuilder.ToString()); - var stlPageContentElement = string.Empty; - foreach (var label in stlLabelList) - { - if (!StlParserUtility.IsStlChannelElement(label, ChannelAttribute.PageContent)) continue; - stlPageContentElement = label; - break; - } //如果标签中存在 - if (!string.IsNullOrEmpty(stlPageContentElement)) //内容存在 + if (StlParserUtility.IsStlChannelElementWithTypePageContent(stlLabelList)) //内容存在 { - var innerBuilder = new StringBuilder(stlPageContentElement); + var stlElement = StlParserUtility.GetStlChannelElementWithTypePageContent(stlLabelList); + var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); + contentBuilder.Replace(stlElement, stlElementTranslated); + + var innerBuilder = new StringBuilder(stlElement); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); - var contentAttributeHtml = innerBuilder.ToString(); - var pageCount = - StringUtils.GetCount(ContentUtility.PagePlaceHolder, contentAttributeHtml) + 1; //一共需要的页数 + var pageContentHtml = innerBuilder.ToString(); + var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, pageContentHtml) + 1; //一共需要的页数 - pageInfo.AddPageBodyCodeIfNotExists(PageInfo.Const.Jquery); Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) { var thePageInfo = pageInfo.Clone(); - var index = contentAttributeHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); - var length = index == -1 ? contentAttributeHtml.Length : index; - var pagedContentAttributeHtml = contentAttributeHtml.Substring(0, length); - var pagedBuilder = new StringBuilder(contentBuilder.ToString() - .Replace(stlPageContentElement, pagedContentAttributeHtml)); + + var index = pageContentHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); + var length = index == -1 ? pageContentHtml.Length : index; + + var pageHtml = pageContentHtml.Substring(0, length); + var pagedBuilder = + new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageChannelId, currentPageIndex, pageCount, 0); filePath = PathUtility.GetChannelPageFilePath(siteInfo, thePageInfo.PageChannelId, currentPageIndex); - await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); if (index != -1) { - contentAttributeHtml = - contentAttributeHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); + pageContentHtml = pageContentHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); } } } @@ -293,6 +288,43 @@ private static async Task CreateContentAsync(SiteInfo siteInfo, ChannelInfo chan } } } + //如果标签中存在 + else if (StlParserUtility.IsStlChannelElementWithTypePageContent(stlLabelList)) //内容存在 + { + var stlElement = StlParserUtility.GetStlChannelElementWithTypePageContent(stlLabelList); + var stlElementTranslated = StlParserManager.StlEncrypt(stlElement); + contentBuilder.Replace(stlElement, stlElementTranslated); + + var innerBuilder = new StringBuilder(stlElement); + StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); + var pageContentHtml = innerBuilder.ToString(); + var pageCount = StringUtils.GetCount(ContentUtility.PagePlaceHolder, pageContentHtml) + 1; //一共需要的页数 + + Parser.Parse(pageInfo, contextInfo, contentBuilder, filePath, false); + + for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) + { + var thePageInfo = pageInfo.Clone(); + + var index = pageContentHtml.IndexOf(ContentUtility.PagePlaceHolder, StringComparison.Ordinal); + var length = index == -1 ? pageContentHtml.Length : index; + + var pageHtml = pageContentHtml.Substring(0, length); + var pagedBuilder = + new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); + StlParserManager.ReplacePageElementsInContentPage(pagedBuilder, thePageInfo, stlLabelList, + channelInfo.Id, contentId, currentPageIndex, pageCount); + + filePath = PathUtility.GetContentPageFilePath(siteInfo, thePageInfo.PageChannelId, contentInfo, + currentPageIndex); + await GenerateFileAsync(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); + + if (index != -1) + { + pageContentHtml = pageContentHtml.Substring(length + ContentUtility.PagePlaceHolder.Length); + } + } + } //如果标签中存在 else if (StlParserUtility.IsStlElementExists(StlPageContents.ElementName, stlLabelList)) { diff --git a/SiteServer.CMS/StlParser/Model/StlListBase.cs b/SiteServer.CMS/StlParser/Model/StlListBase.cs index 9ccec3a30..89a31bd7b 100644 --- a/SiteServer.CMS/StlParser/Model/StlListBase.cs +++ b/SiteServer.CMS/StlParser/Model/StlListBase.cs @@ -17,19 +17,19 @@ public class StlListBase [StlAttribute(Title = "从首页向下的栏目级别")] public const string TopLevel = nameof(TopLevel); - [StlAttribute(Title = "内容范围")] + [StlAttribute(Title = "范围")] public const string Scope = nameof(Scope); - [StlAttribute(Title = "指定显示的栏目组")] + [StlAttribute(Title = "指定栏目组")] public const string GroupChannel = nameof(GroupChannel); - [StlAttribute(Title = "指定不显示的栏目组")] + [StlAttribute(Title = "排除栏目组")] public const string GroupChannelNot = nameof(GroupChannelNot); - [StlAttribute(Title = "指定显示的内容组")] + [StlAttribute(Title = "指定内容组")] public const string GroupContent = nameof(GroupContent); - [StlAttribute(Title = "指定不显示的内容组")] + [StlAttribute(Title = "排除内容组")] public const string GroupContentNot = nameof(GroupContentNot); [StlAttribute(Title = "指定标签")] @@ -47,13 +47,14 @@ public class StlListBase [StlAttribute(Title = "仅显示醒目内容")] public const string IsColor = nameof(IsColor); - [StlAttribute(Title = "显示内容数目")] + [StlAttribute(Title = "显示信息总数")] public const string TotalNum = nameof(TotalNum); [StlAttribute(Title = "从第几条信息开始显示")] public const string StartNum = nameof(StartNum); - [StlAttribute(Title = "排序")] public const string Order = nameof(Order); + [StlAttribute(Title = "排序")] + public const string Order = nameof(Order); [StlAttribute(Title = "仅显示图片内容")] public const string IsImage = nameof(IsImage); @@ -67,40 +68,40 @@ public class StlListBase [StlAttribute(Title = "显示相关内容列表")] public const string IsRelatedContents = nameof(IsRelatedContents); - [StlAttribute(Title = "获取内容列表的条件判断")] + [StlAttribute(Title = "条件判断")] public const string Where = nameof(Where); + [StlAttribute(Title = "布局")] + public const string Layout = nameof(Layout); + [StlAttribute(Title = "列数")] public const string Columns = nameof(Columns); [StlAttribute(Title = "方向")] public const string Direction = nameof(Direction); - [StlAttribute(Title = "指定列表布局方式")] - public const string Height = nameof(Height); - [StlAttribute(Title = "整体高度")] - public const string Width = nameof(Width); + public const string Height = nameof(Height); [StlAttribute(Title = "整体宽度")] - public const string Align = nameof(Align); + public const string Width = nameof(Width); [StlAttribute(Title = "整体对齐")] - public const string ItemHeight = nameof(ItemHeight); + public const string Align = nameof(Align); [StlAttribute(Title = "项高度")] - public const string ItemWidth = nameof(ItemWidth); + public const string ItemHeight = nameof(ItemHeight); [StlAttribute(Title = "项宽度")] - public const string ItemAlign = nameof(ItemAlign); + public const string ItemWidth = nameof(ItemWidth); [StlAttribute(Title = "项水平对齐")] - public const string ItemVerticalAlign = nameof(ItemVerticalAlign); + public const string ItemAlign = nameof(ItemAlign); [StlAttribute(Title = "项垂直对齐")] - public const string ItemClass = nameof(ItemClass); + public const string ItemVerticalAlign = nameof(ItemVerticalAlign); [StlAttribute(Title = "项Css类")] - public const string Layout = nameof(Layout); + public const string ItemClass = nameof(ItemClass); } } diff --git a/SiteServer.CMS/StlParser/StlElement/StlChannel.cs b/SiteServer.CMS/StlParser/StlElement/StlChannel.cs index 61946eed7..ffdaf3de1 100644 --- a/SiteServer.CMS/StlParser/StlElement/StlChannel.cs +++ b/SiteServer.CMS/StlParser/StlElement/StlChannel.cs @@ -1,4 +1,5 @@ -using SiteServer.Utils; +using System.Text; +using SiteServer.Utils; using SiteServer.CMS.Core; using SiteServer.CMS.DataCache; using SiteServer.CMS.DataCache.Content; @@ -199,7 +200,18 @@ public static object Parse(PageInfo pageInfo, ContextInfo contextInfo) return channel.ToDictionary(); } - return ParseImpl(pageInfo, contextInfo, leftText, rightText, type, formatString, separator, startIndex, length, wordNum, ellipsis, replace, to, isClearTags, isReturnToBr, isLower, isUpper, channel, channelId); + var parsedContent = ParseImpl(pageInfo, contextInfo, leftText, rightText, type, formatString, separator, startIndex, length, wordNum, ellipsis, replace, to, isClearTags, isReturnToBr, isLower, isUpper, channel, channelId); + + var innerBuilder = new StringBuilder(parsedContent); + StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); + parsedContent = innerBuilder.ToString(); + + if (!StringUtils.EqualsIgnoreCase(type, ChannelAttribute.PageContent)) + { + parsedContent = parsedContent.Replace(ContentUtility.PagePlaceHolder, string.Empty); + } + + return parsedContent; } private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string leftText, string rightText, string type, string formatString, string separator, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, ChannelInfo channel, int channelId) diff --git a/SiteServer.CMS/StlParser/StlElement/StlChannels.cs b/SiteServer.CMS/StlParser/StlElement/StlChannels.cs index 0fe00147d..bb029d9fc 100644 --- a/SiteServer.CMS/StlParser/StlElement/StlChannels.cs +++ b/SiteServer.CMS/StlParser/StlElement/StlChannels.cs @@ -17,10 +17,10 @@ public class StlChannels : StlListBase { public const string ElementName = "stl:channels"; - [StlAttribute(Title = "是否从所有栏目中选择")] + [StlAttribute(Title = "从所有栏目中选择")] public const string IsTotal = nameof(IsTotal); - [StlAttribute(Title = "是否显示所有级别的子栏目")] + [StlAttribute(Title = "显示所有级别的子栏目")] public const string IsAllChildren = nameof(IsAllChildren); public static object Parse(PageInfo pageInfo, ContextInfo contextInfo) diff --git a/SiteServer.CMS/StlParser/StlElement/StlContent.cs b/SiteServer.CMS/StlParser/StlElement/StlContent.cs index 42a401e9c..7e7e80892 100644 --- a/SiteServer.CMS/StlParser/StlElement/StlContent.cs +++ b/SiteServer.CMS/StlParser/StlElement/StlContent.cs @@ -178,7 +178,10 @@ public static object Parse(PageInfo pageInfo, ContextInfo contextInfo) StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); parsedContent = innerBuilder.ToString(); - parsedContent = parsedContent.Replace(ContentUtility.PagePlaceHolder, string.Empty); + if (!StringUtils.EqualsIgnoreCase(type, ContentAttribute.PageContent)) + { + parsedContent = parsedContent.Replace(ContentUtility.PagePlaceHolder, string.Empty); + } return parsedContent; } diff --git a/SiteServer.CMS/StlParser/StlElement/StlFile.cs b/SiteServer.CMS/StlParser/StlElement/StlFile.cs index 9f261906d..1674e530d 100644 --- a/SiteServer.CMS/StlParser/StlElement/StlFile.cs +++ b/SiteServer.CMS/StlParser/StlElement/StlFile.cs @@ -1,3 +1,4 @@ +using System.Collections.Specialized; using System.Text; using SiteServer.Utils; using SiteServer.CMS.Core; @@ -60,6 +61,7 @@ public static string Parse(PageInfo pageInfo, ContextInfo contextInfo) var isUpper = false; var leftText = string.Empty; var rightText = string.Empty; + var attributes = new NameValueCollection(); foreach (var name in contextInfo.Attributes.AllKeys) { @@ -109,12 +111,16 @@ public static string Parse(PageInfo pageInfo, ContextInfo contextInfo) { rightText = value; } + else + { + attributes[name] = value; + } } - return ParseImpl(pageInfo, contextInfo, type, no, src, isFileName, isFileType, isFileSize, isCount, isLower, isUpper, leftText, rightText); + return ParseImpl(pageInfo, contextInfo, type, no, src, isFileName, isFileType, isFileSize, isCount, isLower, isUpper, leftText, rightText, attributes); } - private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string type, int no, string src, bool isFileName, bool isFileType, bool isFileSize, bool isCount, bool isLower, bool isUpper, string leftText, string rightText) + private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, string type, int no, string src, bool isFileName, bool isFileType, bool isFileSize, bool isCount, bool isLower, bool isUpper, string leftText, string rightText, NameValueCollection attributes) { if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) { @@ -212,20 +218,12 @@ private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, stri } else { - var innerHtml = string.Empty; - if (!string.IsNullOrEmpty(contextInfo.InnerHtml)) - { - var innerBuilder = new StringBuilder(contextInfo.InnerHtml); - StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); - innerHtml = innerBuilder.ToString(); - } - parsedContent = contextInfo.ContentInfo != null ? InputParserUtility.GetFileHtmlWithCount(pageInfo.SiteInfo, contextInfo.ContentInfo.ChannelId, - contextInfo.ContentInfo.Id, fileUrl, contextInfo.Attributes, innerHtml, + contextInfo.ContentInfo.Id, fileUrl, attributes, contextInfo.InnerHtml, contextInfo.IsStlEntity, isLower, isUpper) - : InputParserUtility.GetFileHtmlWithoutCount(pageInfo.SiteInfo, fileUrl, contextInfo.Attributes, - innerHtml, contextInfo.IsStlEntity, isLower, isUpper); + : InputParserUtility.GetFileHtmlWithoutCount(pageInfo.SiteInfo, fileUrl, attributes, + contextInfo.InnerHtml, contextInfo.IsStlEntity, isLower, isUpper); } if (!string.IsNullOrEmpty(parsedContent)) diff --git a/SiteServer.CMS/StlParser/Utility/StlParserUtility.cs b/SiteServer.CMS/StlParser/Utility/StlParserUtility.cs index 52516698f..0c3b9ac7c 100644 --- a/SiteServer.CMS/StlParser/Utility/StlParserUtility.cs +++ b/SiteServer.CMS/StlParser/Utility/StlParserUtility.cs @@ -78,29 +78,36 @@ public static bool IsStlElementExists(string stlElementName, List list) return exists; } - public static bool IsStlContentElementWithTypePageContent(List list) + public static bool IsStlChannelElementWithTypePageContent(List list) { foreach (var label in list) { - if (!IsStlContentElement(label, ContentAttribute.PageContent)) continue; + if (!IsStlChannelElement(label, ChannelAttribute.PageContent)) continue; return true; } return false; } - public static string GetStlElement(string stlElementName, List labelList) + public static string GetStlChannelElementWithTypePageContent(List labelList) { - var stlElement = string.Empty; - foreach (var labelWithDisplayModeEnNameAndChannelId in labelList) + var stlPageChannelElement = string.Empty; + foreach (var label in labelList) { - if (labelWithDisplayModeEnNameAndChannelId.ToLower().StartsWith($"<{stlElementName.ToLower()} ") || labelWithDisplayModeEnNameAndChannelId.ToLower().StartsWith( - $"<{stlElementName.ToLower()}>")) - { - stlElement = labelWithDisplayModeEnNameAndChannelId; - break; - } + if (!IsStlChannelElement(label, ChannelAttribute.PageContent)) continue; + stlPageChannelElement = label; + break; } - return stlElement; + return stlPageChannelElement; + } + + public static bool IsStlContentElementWithTypePageContent(List list) + { + foreach (var label in list) + { + if (!IsStlContentElement(label, ContentAttribute.PageContent)) continue; + return true; + } + return false; } public static string GetStlContentElementWithTypePageContent(List labelList) @@ -115,6 +122,21 @@ public static string GetStlContentElementWithTypePageContent(List labelL return stlPageContentElement; } + public static string GetStlElement(string stlElementName, List labelList) + { + var stlElement = string.Empty; + foreach (var labelWithDisplayModeEnNameAndChannelId in labelList) + { + if (labelWithDisplayModeEnNameAndChannelId.ToLower().StartsWith($"<{stlElementName.ToLower()} ") || labelWithDisplayModeEnNameAndChannelId.ToLower().StartsWith( + $"<{stlElementName.ToLower()}>")) + { + stlElement = labelWithDisplayModeEnNameAndChannelId; + break; + } + } + return stlElement; + } + public static string GetNameFromEntity(string stlEntity) { var name = stlEntity; diff --git a/SiteServer.Cli/Core/CliUtils.cs b/SiteServer.Cli/Core/CliUtils.cs index f89c2e3ab..9e74c5300 100644 --- a/SiteServer.Cli/Core/CliUtils.cs +++ b/SiteServer.Cli/Core/CliUtils.cs @@ -131,5 +131,13 @@ public static async Task AppendErrorLogAsync(string filePath, TextLogInfo log) await FileUtils.AppendTextAsync(filePath, Encoding.UTF8, builder.ToString()); } + + public static string GetWebConfigPath(string configFile) + { + return PathUtils.IsFilePath(configFile) + ? configFile + : PathUtils.Combine(PhysicalApplicationPath, + !string.IsNullOrEmpty(configFile) ? configFile : WebConfigUtils.WebConfigFileName); + } } } diff --git a/SiteServer.Cli/Jobs/BackupJob.cs b/SiteServer.Cli/Jobs/BackupJob.cs index 627c89e7b..070d17ee9 100644 --- a/SiteServer.Cli/Jobs/BackupJob.cs +++ b/SiteServer.Cli/Jobs/BackupJob.cs @@ -14,22 +14,22 @@ public static class BackupJob { public const string CommandName = "backup"; - private static bool _isHelp; private static string _directory; + private static string _configFile; private static List _includes; private static List _excludes; - private static string _webConfig; private static int _maxRows; + private static bool _isHelp; private static readonly OptionSet Options = new OptionSet() { { "d|directory=", "指定保存备份文件的文件夹名称", v => _directory = v }, - { "includes=", "指定需要还原的表,多个表用英文逗号隔开", + { "c|config-file=", "指定配置文件Web.config路径或文件名", + v => _configFile = v }, + { "includes=", "指定需要备份的表,多个表用英文逗号隔开,默认备份所有表", v => _includes = v == null ? null : TranslateUtils.StringCollectionToStringList(v) }, { "excludes=", "指定需要排除的表,多个表用英文逗号隔开", v => _excludes = v == null ? null : TranslateUtils.StringCollectionToStringList(v) }, - { "web-config=", "指定Web.config文件名", - v => _webConfig = v }, { "max-rows=", "指定需要备份的表的最大行数", v => _maxRows = v == null ? 0 : TranslateUtils.ToInt(v) }, { "h|help", "命令说明", @@ -61,20 +61,18 @@ public static async Task Execute(IJobContext context) var treeInfo = new TreeInfo(_directory); DirectoryUtils.CreateDirectoryIfNotExists(treeInfo.DirectoryPath); - var webConfigName = string.IsNullOrEmpty(_webConfig) ? "web.config" : _webConfig; - - var webConfigPath = PathUtils.Combine(CliUtils.PhysicalApplicationPath, webConfigName); + var webConfigPath = CliUtils.GetWebConfigPath(_configFile); if (!FileUtils.IsFileExists(webConfigPath)) { await CliUtils.PrintErrorAsync($"系统配置文件不存在:{webConfigPath}!"); return; } - WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, webConfigName); + WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, webConfigPath); if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString)) { - await CliUtils.PrintErrorAsync($"{webConfigName} 中数据库连接字符串 connectionString 未设置"); + await CliUtils.PrintErrorAsync($"{webConfigPath} 中数据库连接字符串 connectionString 未设置"); return; } @@ -84,7 +82,7 @@ public static async Task Execute(IJobContext context) if (!DataProvider.DatabaseDao.IsConnectionStringWork(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString)) { - await CliUtils.PrintErrorAsync($"系统无法连接到 {webConfigName} 中设置的数据库"); + await CliUtils.PrintErrorAsync($"系统无法连接到 {webConfigPath} 中设置的数据库"); return; } diff --git a/SiteServer.Cli/Jobs/InstallJob.cs b/SiteServer.Cli/Jobs/InstallJob.cs index cab6f8c22..882d8babe 100644 --- a/SiteServer.Cli/Jobs/InstallJob.cs +++ b/SiteServer.Cli/Jobs/InstallJob.cs @@ -12,15 +12,18 @@ namespace SiteServer.Cli.Jobs public static class InstallJob { public const string CommandName = "install"; - - private static bool _isHelp; + + private static string _configFile; private static string _userName; private static string _password; + private static bool _isHelp; private static readonly OptionSet Options = new OptionSet { - { "u|userName=", "管理员用户名", + { "c|config-file=", "指定配置文件Web.config路径或文件名", + v => _configFile = v }, + { "u|userName=", "超级管理员用户名", v => _userName = v }, - { "p|password=", "管理员密码", + { "p|password=", "超级管理员密码", v => _password = v }, { "h|help", "命令说明", v => _isHelp = v != null } @@ -28,7 +31,7 @@ public static class InstallJob public static void PrintUsage() { - Console.WriteLine("安装系统: siteserver install"); + Console.WriteLine("系统安装: siteserver install"); Options.WriteOptionDescriptions(Console.Out); Console.WriteLine(); } @@ -43,75 +46,67 @@ public static async Task Execute(IJobContext context) return; } - try + var webConfigPath = CliUtils.GetWebConfigPath(_configFile); + if (!FileUtils.IsFileExists(webConfigPath)) + { + await CliUtils.PrintErrorAsync($"系统配置文件不存在:{webConfigPath}!"); + return; + } + + if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString)) + { + await CliUtils.PrintErrorAsync($"{webConfigPath} 中数据库连接字符串 connectionString 未设置"); + return; + } + + if (string.IsNullOrEmpty(_userName)) + { + await CliUtils.PrintErrorAsync("未设置参数管理员用户名:{userName} !"); + return; + } + + if (string.IsNullOrEmpty(_password)) + { + await CliUtils.PrintErrorAsync("未设置参数管理员密码:{password} !"); + return; + } + + if (_password.Length < 6) { - if (string.IsNullOrEmpty(_userName)) - { - await CliUtils.PrintErrorAsync("未设置参数管理员用户名:{userName} !"); - return; - } - - if (string.IsNullOrEmpty(_password)) - { - await CliUtils.PrintErrorAsync("未设置参数管理员密码:{password} !"); - return; - } - - if (_password.Length < 6) - { - await CliUtils.PrintErrorAsync("管理员密码必须大于6位 !"); - return; - } - - if (!EUserPasswordRestrictionUtils.IsValid(_password, EUserPasswordRestrictionUtils.GetValue(EUserPasswordRestriction.LetterAndDigit))) - { - await CliUtils.PrintErrorAsync($"管理员密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestriction.LetterAndDigit)}"); - return; - } - - var webConfigPath = PathUtils.Combine(CliUtils.PhysicalApplicationPath, "web.config"); - if (!FileUtils.IsFileExists(webConfigPath)) - { - await CliUtils.PrintErrorAsync($"系统配置文件不存在:{webConfigPath}!"); - return; - } - - if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString)) - { - await CliUtils.PrintErrorAsync("web.config 中数据库连接字符串 connectionString 未设置"); - return; - } - - WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, "web.config"); - - await Console.Out.WriteLineAsync($"数据库类型: {WebConfigUtils.DatabaseType.Value}"); - await Console.Out.WriteLineAsync($"连接字符串: {WebConfigUtils.ConnectionString}"); - await Console.Out.WriteLineAsync($"系统文件夹: {CliUtils.PhysicalApplicationPath}"); - - if (!DataProvider.DatabaseDao.IsConnectionStringWork(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString)) - { - await CliUtils.PrintErrorAsync("系统无法连接到 web.config 中设置的数据库"); - return; - } - - if (!SystemManager.IsNeedInstall()) - { - await CliUtils.PrintErrorAsync("系统已安装在 web.config 指定的数据库中,命令执行失败"); - return; - } - - WebConfigUtils.UpdateWebConfig(WebConfigUtils.IsProtectData, WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.ApiPrefix, WebConfigUtils.AdminDirectory, WebConfigUtils.HomeDirectory, StringUtils.GetShortGuid(), false); - - DataProvider.Reset(); - - SystemManager.InstallDatabase(_userName, _password); + await CliUtils.PrintErrorAsync("管理员密码必须大于6位 !"); + return; } - catch (Exception e) + + if (!EUserPasswordRestrictionUtils.IsValid(_password, EUserPasswordRestrictionUtils.GetValue(EUserPasswordRestriction.LetterAndDigit))) { - await CliUtils.PrintErrorAsync(e.Message); + await CliUtils.PrintErrorAsync($"管理员密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestriction.LetterAndDigit)}"); return; } + WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, webConfigPath); + + await Console.Out.WriteLineAsync($"数据库类型: {WebConfigUtils.DatabaseType.Value}"); + await Console.Out.WriteLineAsync($"连接字符串: {WebConfigUtils.ConnectionString}"); + await Console.Out.WriteLineAsync($"系统文件夹: {CliUtils.PhysicalApplicationPath}"); + + if (!DataProvider.DatabaseDao.IsConnectionStringWork(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString)) + { + await CliUtils.PrintErrorAsync("系统无法连接到 web.config 中设置的数据库"); + return; + } + + if (!SystemManager.IsNeedInstall()) + { + await CliUtils.PrintErrorAsync("系统已安装在 web.config 指定的数据库中,命令执行失败"); + return; + } + + WebConfigUtils.UpdateWebConfig(WebConfigUtils.IsProtectData, WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.ApiPrefix, WebConfigUtils.AdminDirectory, WebConfigUtils.HomeDirectory, StringUtils.GetShortGuid(), false); + + DataProvider.Reset(); + + SystemManager.InstallDatabase(_userName, _password); + await Console.Out.WriteLineAsync("恭喜,系统安装成功!"); } } diff --git a/SiteServer.Cli/Jobs/RestoreJob.cs b/SiteServer.Cli/Jobs/RestoreJob.cs index 5063bce15..d12b9fa99 100644 --- a/SiteServer.Cli/Jobs/RestoreJob.cs +++ b/SiteServer.Cli/Jobs/RestoreJob.cs @@ -6,7 +6,6 @@ using Newtonsoft.Json.Linq; using SiteServer.Cli.Core; using SiteServer.CMS.Core; -using SiteServer.CMS.DataCache; using SiteServer.Plugin; using SiteServer.Utils; @@ -16,22 +15,22 @@ public static class RestoreJob { public const string CommandName = "restore"; - private static bool _isHelp; private static string _directory; + private static string _configFile; private static List _includes; private static List _excludes; - private static string _webConfig; private static bool _dataOnly; + private static bool _isHelp; private static readonly OptionSet Options = new OptionSet { { "d|directory=", "从指定的文件夹中恢复数据", v => _directory = v }, - { "includes=", "指定需要还原的表,多个表用英文逗号隔开", + { "c|config-file=", "指定配置文件Web.config路径或文件名", + v => _configFile = v }, + { "includes=", "指定需要还原的表,多个表用英文逗号隔开,默认还原所有表", v => _includes = v == null ? null : TranslateUtils.StringCollectionToStringList(v) }, { "excludes=", "指定需要排除的表,多个表用英文逗号隔开", v => _excludes = v == null ? null : TranslateUtils.StringCollectionToStringList(v) }, - { "web-config=", "指定Web.config文件名", - v => _webConfig = v }, { "data-only", "仅恢复数据", v => _dataOnly = v != null }, { "h|help", "命令说明", @@ -76,20 +75,18 @@ public static async Task Execute(IJobContext context) return; } - var webConfigName = string.IsNullOrEmpty(_webConfig) ? "web.config" : _webConfig; - - var webConfigPath = PathUtils.Combine(CliUtils.PhysicalApplicationPath, webConfigName); + var webConfigPath = CliUtils.GetWebConfigPath(_configFile); if (!FileUtils.IsFileExists(webConfigPath)) { await CliUtils.PrintErrorAsync($"系统配置文件不存在:{webConfigPath}!"); return; } - WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, webConfigName); + WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, webConfigPath); if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString)) { - await CliUtils.PrintErrorAsync($"{webConfigName} 中数据库连接字符串 connectionString 未设置"); + await CliUtils.PrintErrorAsync($"{webConfigPath} 中数据库连接字符串 connectionString 未设置"); return; } @@ -99,7 +96,7 @@ public static async Task Execute(IJobContext context) if (!DataProvider.DatabaseDao.IsConnectionStringWork(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString)) { - await CliUtils.PrintErrorAsync($"系统无法连接到 {webConfigName} 中设置的数据库"); + await CliUtils.PrintErrorAsync($"系统无法连接到 {webConfigPath} 中设置的数据库"); return; } diff --git a/SiteServer.Cli/Jobs/UpdateJob.cs b/SiteServer.Cli/Jobs/UpdateJob.cs index 41a682594..6e7b592cc 100644 --- a/SiteServer.Cli/Jobs/UpdateJob.cs +++ b/SiteServer.Cli/Jobs/UpdateJob.cs @@ -6,7 +6,6 @@ using NDesk.Options; using SiteServer.Cli.Core; using SiteServer.Cli.Updater; -using SiteServer.CMS.Core; using SiteServer.CMS.Provider; using SiteServer.Plugin; using SiteServer.Utils; @@ -17,13 +16,13 @@ public static class UpdateJob { public const string CommandName = "update"; private const string Folder = "update"; - - private static bool _isHelp; + private static string _directory; private static bool _contentSplit; + private static bool _isHelp; - private static readonly OptionSet Options = new OptionSet() { - { "d|directory=", "指定需要转换至最新版本的备份数据文件夹", + private static readonly OptionSet Options = new OptionSet { + { "d|directory=", "指定需要升级至最新版本的备份数据文件夹", v => _directory = v }, { "content-split", "拆分内容表", v => _contentSplit = v != null }, @@ -33,7 +32,7 @@ public static class UpdateJob public static void PrintUsage() { - Console.WriteLine("升级备份数据: siteserver update"); + Console.WriteLine("系统升级: siteserver update"); Options.WriteOptionDescriptions(Console.Out); Console.WriteLine(); } diff --git a/SiteServer.Cli/Jobs/VersionJob.cs b/SiteServer.Cli/Jobs/VersionJob.cs index 1e0ec92e0..88b8cab50 100644 --- a/SiteServer.Cli/Jobs/VersionJob.cs +++ b/SiteServer.Cli/Jobs/VersionJob.cs @@ -13,16 +13,19 @@ public static class VersionJob { public const string CommandName = "version"; + private static string _configFile; private static bool _isHelp; private static readonly OptionSet Options = new OptionSet { + { "c|config-file=", "指定配置文件Web.config路径或文件名", + v => _configFile = v }, { "h|help", "命令说明", v => _isHelp = v != null } }; public static void PrintUsage() { - Console.WriteLine("当前版本: siteserver version"); + Console.WriteLine("显示当前版本: siteserver version"); Options.WriteOptionDescriptions(Console.Out); Console.WriteLine(); } @@ -42,9 +45,11 @@ public static async Task Execute(IJobContext context) await Console.Out.WriteLineAsync($"当前文件夹: {CliUtils.PhysicalApplicationPath}"); await Console.Out.WriteLineAsync(); - if (FileUtils.IsFileExists(PathUtils.Combine(CliUtils.PhysicalApplicationPath, "web.config"))) + var webConfigPath = CliUtils.GetWebConfigPath(_configFile); + + if (FileUtils.IsFileExists(webConfigPath)) { - WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, "web.config"); + WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, webConfigPath); try { diff --git a/SiteServer.Cli/SiteServer.Cli.csproj b/SiteServer.Cli/SiteServer.Cli.csproj index f9b0ae94b..2cd1900a1 100644 --- a/SiteServer.Cli/SiteServer.Cli.csproj +++ b/SiteServer.Cli/SiteServer.Cli.csproj @@ -72,9 +72,6 @@ - - ..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll - diff --git a/SiteServer.Utils/PathUtils.cs b/SiteServer.Utils/PathUtils.cs index a86333ae7..6fa42cd4f 100644 --- a/SiteServer.Utils/PathUtils.cs +++ b/SiteServer.Utils/PathUtils.cs @@ -44,6 +44,18 @@ public static bool IsDirectoryPath(string path) return retval; } + public static bool IsFilePath(string val) + { + try + { + return FileUtils.IsFileExists(val); + } + catch + { + return false; + } + } + public static string GetExtension(string path) { var retval = string.Empty; diff --git a/SiteServer.Utils/SqlUtils.cs b/SiteServer.Utils/SqlUtils.cs index dd20ba086..a064fa620 100644 --- a/SiteServer.Utils/SqlUtils.cs +++ b/SiteServer.Utils/SqlUtils.cs @@ -431,31 +431,46 @@ public static string ToInTopSqlString(string tableName, string columns, string w $"SELECT {builder} FROM ({ToTopSqlString(tableName, columns, whereString, orderString, topN)})"; } + public static string GetQuotedIdentifier(string identifier) + { + if (WebConfigUtils.DatabaseType == DatabaseType.MySql) + { + return $"`{identifier}`"; + } + + return WebConfigUtils.DatabaseType == DatabaseType.SqlServer ? $"[{identifier}]" : identifier; + } + public static string GetColumnSqlString(TableColumn tableColumn) + { + return $@"{GetQuotedIdentifier(tableColumn.AttributeName)} {GetColumnTypeString(tableColumn)}"; + } + + public static string GetColumnTypeString(TableColumn tableColumn) { if (tableColumn.IsIdentity) { - return $@"{tableColumn.AttributeName} {GetAutoIncrementDataType()}"; + return GetAutoIncrementDataType(); } if (WebConfigUtils.DatabaseType == DatabaseType.MySql) { - return ToMySqlColumnString(tableColumn.DataType, tableColumn.AttributeName, tableColumn.DataLength); + return ToMySqlColumnTypeString(tableColumn.DataType, tableColumn.DataLength); } if (WebConfigUtils.DatabaseType == DatabaseType.SqlServer) { - return ToSqlServerColumnString(tableColumn.DataType, tableColumn.AttributeName, tableColumn.DataLength); + return ToSqlServerColumnTypeString(tableColumn.DataType, tableColumn.DataLength); } if (WebConfigUtils.DatabaseType == DatabaseType.PostgreSql) { - return ToPostgreColumnString(tableColumn.DataType, tableColumn.AttributeName, tableColumn.DataLength); + return ToPostgreColumnTypeString(tableColumn.DataType, tableColumn.DataLength); } if (WebConfigUtils.DatabaseType == DatabaseType.Oracle) { - return ToOracleColumnString(tableColumn.DataType, tableColumn.AttributeName, tableColumn.DataLength); + return ToOracleColumnTypeString(tableColumn.DataType, tableColumn.DataLength); } return string.Empty; @@ -516,6 +531,30 @@ public static string GetAddColumnsSqlString(string tableName, string columnsSqlS return retval; } + public static string GetModifyColumnsSqlString(string tableName, string columnName, string columnTypeString) + { + var retval = string.Empty; + + if (WebConfigUtils.DatabaseType == DatabaseType.MySql) + { + retval = $"ALTER TABLE `{tableName}` MODIFY {columnName} {columnTypeString}"; + } + else if (WebConfigUtils.DatabaseType == DatabaseType.SqlServer) + { + retval = $"ALTER TABLE [{tableName}] ALTER COLUMN {columnName} {columnTypeString}"; + } + else if (WebConfigUtils.DatabaseType == DatabaseType.PostgreSql) + { + retval = $"ALTER TABLE {tableName} ALTER COLUMN {columnName} TYPE {columnTypeString}"; + } + else if (WebConfigUtils.DatabaseType == DatabaseType.Oracle) + { + retval = $"ALTER TABLE {tableName} MODIFY {columnName} {columnTypeString}"; + } + + return retval; + } + public static string GetDropColumnsSqlString(string tableName, string columnName) { var retval = string.Empty; @@ -815,104 +854,104 @@ private static OracleDbType ToOracleDbType(DataType type) return OracleDbType.NVarchar2; } - private static string ToMySqlColumnString(DataType type, string attributeName, int length) + private static string ToMySqlColumnTypeString(DataType type, int length) { if (type == DataType.Boolean) { - return $"`{attributeName}` tinyint(1)"; + return "tinyint(1)"; } if (type == DataType.DateTime) { - return $"`{attributeName}` datetime"; + return "datetime"; } if (type == DataType.Decimal) { - return $"`{attributeName}` decimal(18, 2)"; + return "decimal(18, 2)"; } if (type == DataType.Integer) { - return $"`{attributeName}` int"; + return "int"; } if (type == DataType.Text) { - return $"`{attributeName}` longtext"; + return "longtext"; } - return $"`{attributeName}` varchar({length})"; + return $"varchar({length})"; } - private static string ToSqlServerColumnString(DataType type, string attributeName, int length) + private static string ToSqlServerColumnTypeString(DataType type, int length) { if (type == DataType.Boolean) { - return $"[{attributeName}] [bit]"; + return "[bit]"; } if (type == DataType.DateTime) { - return $"[{attributeName}] [datetime]"; + return "[datetime]"; } if (type == DataType.Decimal) { - return $"[{attributeName}] [decimal] (18, 2)"; + return "[decimal] (18, 2)"; } if (type == DataType.Integer) { - return $"[{attributeName}] [int]"; + return "[int]"; } if (type == DataType.Text) { - return $"[{attributeName}] [ntext]"; + return "[ntext]"; } - return $"[{attributeName}] [nvarchar] ({length})"; + return $"[nvarchar] ({length})"; } - private static string ToPostgreColumnString(DataType type, string attributeName, int length) + private static string ToPostgreColumnTypeString(DataType type, int length) { if (type == DataType.Boolean) { - return $"{attributeName} bool"; + return "bool"; } if (type == DataType.DateTime) { - return $"{attributeName} timestamptz"; + return "timestamptz"; } if (type == DataType.Decimal) { - return $"{attributeName} numeric(18, 2)"; + return "numeric(18, 2)"; } if (type == DataType.Integer) { - return $"{attributeName} int4"; + return "int4"; } if (type == DataType.Text) { - return $"{attributeName} text"; + return "text"; } - return $"{attributeName} varchar({length})"; + return $"varchar({length})"; } - private static string ToOracleColumnString(DataType type, string attributeName, int length) + private static string ToOracleColumnTypeString(DataType type, int length) { if (type == DataType.Boolean) { - return $"{attributeName} number(1)"; + return "number(1)"; } if (type == DataType.DateTime) { - return $"{attributeName} timestamp(6) with time zone"; + return "timestamp(6) with time zone"; } if (type == DataType.Decimal) { - return $"{attributeName} number(38, 2)"; + return "number(38, 2)"; } if (type == DataType.Integer) { - return $"{attributeName} number"; + return "number"; } if (type == DataType.Text) { - return $"{attributeName} nclob"; + return "nclob"; } - return $"{attributeName} nvarchar2({length})"; + return $"nvarchar2({length})"; } public static string GetDateDiffLessThanYears(string fieldName, string years) diff --git a/SiteServer.Utils/WebConfigUtils.cs b/SiteServer.Utils/WebConfigUtils.cs index 90334c561..60a0dd807 100644 --- a/SiteServer.Utils/WebConfigUtils.cs +++ b/SiteServer.Utils/WebConfigUtils.cs @@ -37,7 +37,7 @@ private set public static bool IsNightlyUpdate { get; private set; } - public static void Load(string physicalApplicationPath, string webConfigFileName = WebConfigFileName) + public static void Load(string physicalApplicationPath, string webConfigPath) { PhysicalApplicationPath = physicalApplicationPath; @@ -48,9 +48,7 @@ public static void Load(string physicalApplicationPath, string webConfigFileName { var doc = new XmlDocument(); - var configFile = PathUtils.Combine(PhysicalApplicationPath, webConfigFileName); - - doc.Load(configFile); + doc.Load(webConfigPath); var appSettings = doc.SelectSingleNode("configuration/appSettings"); if (appSettings != null) @@ -347,7 +345,7 @@ public static string GetConnectionString(DatabaseType databaseType, string serve { connectionString += $"Database={database};"; } - connectionString += "SslMode=none;CharSet=utf8;"; + connectionString += "SslMode=Preferred;CharSet=utf8;"; } else if (databaseType == DatabaseType.SqlServer) { @@ -394,7 +392,7 @@ private static string GetConnectionString(DatabaseType databaseType, string conn connectionString = connectionString.TrimEnd(';'); if (!StringUtils.ContainsIgnoreCase(connectionString, "SslMode=")) { - connectionString += ";SslMode=none;"; + connectionString += ";SslMode=Preferred;"; } if (!StringUtils.ContainsIgnoreCase(connectionString, "CharSet=")) { diff --git a/SiteServer.Web/Web.config b/SiteServer.Web/Web.config index 9e369797a..412f36977 100644 --- a/SiteServer.Web/Web.config +++ b/SiteServer.Web/Web.config @@ -14,7 +14,7 @@ + -->