public static void Translate(string administratorName, PublishmentSystemInfo publishmentSystemInfo, int nodeId, int contentId, int targetPublishmentSystemId, int targetNodeId, ETranslateContentType translateType) { if (publishmentSystemInfo == null || nodeId <= 0 || contentId <= 0 || targetPublishmentSystemId <= 0 || targetNodeId <= 0) { return; } var targetPublishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(targetPublishmentSystemId); var targetTableName = NodeManager.GetTableName(targetPublishmentSystemInfo, targetNodeId); var nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); var tableStyle = NodeManager.GetTableStyle(publishmentSystemInfo, nodeInfo); var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeInfo); var contentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, contentId); if (contentInfo == null) { return; } if (translateType == ETranslateContentType.Copy) { FileUtility.MoveFileByContentInfo(publishmentSystemInfo, targetPublishmentSystemInfo, contentInfo); contentInfo.PublishmentSystemId = targetPublishmentSystemId; contentInfo.SourceId = contentInfo.NodeId; contentInfo.NodeId = targetNodeId; contentInfo.Attributes[ContentAttribute.TranslateContentType] = ETranslateContentType.Copy.ToString(); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Copy.ToString()); var theContentId = DataProvider.ContentDao.Insert(targetTableName, targetPublishmentSystemInfo, contentInfo); if (EContentModelTypeUtils.IsPhoto(nodeInfo.ContentModelId)) { var photoInfoList = DataProvider.PhotoDao.GetPhotoInfoList(publishmentSystemInfo.PublishmentSystemId, contentId); if (photoInfoList.Count > 0) { foreach (var photoInfo in photoInfoList) { photoInfo.PublishmentSystemID = targetPublishmentSystemId; photoInfo.ContentID = theContentId; FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.SmallUrl); FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.MiddleUrl); FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.LargeUrl); DataProvider.PhotoDao.Insert(photoInfo); } } } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(targetPublishmentSystemInfo.PublishmentSystemId, contentInfo.NodeId, theContentId); } } else if (translateType == ETranslateContentType.Cut) { FileUtility.MoveFileByContentInfo(publishmentSystemInfo, targetPublishmentSystemInfo, contentInfo); contentInfo.PublishmentSystemId = targetPublishmentSystemId; contentInfo.SourceId = contentInfo.NodeId; contentInfo.NodeId = targetNodeId; contentInfo.Attributes[ContentAttribute.TranslateContentType] = ETranslateContentType.Cut.ToString(); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Cut.ToString()); if (StringUtils.EqualsIgnoreCase(tableName, targetTableName)) { contentInfo.Taxis = DataProvider.ContentDao.GetTaxisToInsert(targetTableName, targetNodeId, contentInfo.IsTop); DataProvider.ContentDao.Update(targetTableName, targetPublishmentSystemInfo, contentInfo); } else { DataProvider.ContentDao.Insert(targetTableName, targetPublishmentSystemInfo, contentInfo); DataProvider.ContentDao.DeleteContents(publishmentSystemInfo.PublishmentSystemId, tableName, TranslateUtils.ToIntList(contentId), nodeId); } DataProvider.NodeDao.UpdateContentNum(publishmentSystemInfo, nodeId, true); DataProvider.NodeDao.UpdateContentNum(targetPublishmentSystemInfo, targetNodeId, true); if (EContentModelTypeUtils.IsPhoto(nodeInfo.ContentModelId)) { var photoInfoList = DataProvider.PhotoDao.GetPhotoInfoList(publishmentSystemInfo.PublishmentSystemId, contentId); if (photoInfoList.Count > 0) { foreach (var photoInfo in photoInfoList) { photoInfo.PublishmentSystemID = targetPublishmentSystemId; FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.SmallUrl); FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.MiddleUrl); FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.LargeUrl); DataProvider.PhotoDao.Update(photoInfo); } } } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(targetPublishmentSystemInfo.PublishmentSystemId, contentInfo.NodeId, contentInfo.Id); } } else if (translateType == ETranslateContentType.Reference) { if (contentInfo.ReferenceId != 0) { return; } contentInfo.PublishmentSystemId = targetPublishmentSystemId; contentInfo.SourceId = contentInfo.NodeId; contentInfo.NodeId = targetNodeId; contentInfo.ReferenceId = contentId; contentInfo.Attributes[ContentAttribute.TranslateContentType] = ETranslateContentType.Reference.ToString(); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Reference.ToString()); DataProvider.ContentDao.Insert(targetTableName, targetPublishmentSystemInfo, contentInfo); } else if (translateType == ETranslateContentType.ReferenceContent) { if (contentInfo.ReferenceId != 0) { return; } FileUtility.MoveFileByContentInfo(publishmentSystemInfo, targetPublishmentSystemInfo, contentInfo); contentInfo.PublishmentSystemId = targetPublishmentSystemId; contentInfo.SourceId = contentInfo.NodeId; contentInfo.NodeId = targetNodeId; contentInfo.ReferenceId = contentId; contentInfo.Attributes[ContentAttribute.TranslateContentType] = ETranslateContentType.ReferenceContent.ToString(); var theContentId = DataProvider.ContentDao.Insert(targetTableName, targetPublishmentSystemInfo, contentInfo); if (EContentModelTypeUtils.IsPhoto(nodeInfo.ContentModelId)) { var photoInfoList = DataProvider.PhotoDao.GetPhotoInfoList(publishmentSystemInfo.PublishmentSystemId, contentId); if (photoInfoList.Count > 0) { foreach (var photoInfo in photoInfoList) { photoInfo.PublishmentSystemID = targetPublishmentSystemId; photoInfo.ContentID = theContentId; FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.SmallUrl); FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.MiddleUrl); FileUtility.MoveFileByVirtaulUrl(publishmentSystemInfo, targetPublishmentSystemInfo, photoInfo.LargeUrl); DataProvider.PhotoDao.Insert(photoInfo); } } } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(targetPublishmentSystemInfo.PublishmentSystemId, contentInfo.NodeId, theContentId); } } }
private static string ParseContentPath(PublishmentSystemInfo publishmentSystemInfo, int nodeId, ContentInfo contentInfo, string contentFilePathRule) { var filePath = contentFilePathRule.Trim(); var regex = "(?<element>{@[^}]+})"; var elements = RegexUtils.GetContents("element", regex, filePath); var addDate = DateTime.MinValue; var contentId = contentInfo.Id; foreach (var element in elements) { var value = string.Empty; if (StringUtils.EqualsIgnoreCase(element, ChannelId)) { value = nodeId.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, ChannelIndex)) { var nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); if (nodeInfo != null) { value = nodeInfo.NodeIndexName; } } else if (StringUtils.EqualsIgnoreCase(element, ContentId)) { value = contentId.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Sequence)) { var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeId); value = BaiRongDataProvider.ContentDao.GetSequence(tableName, nodeId, contentId).ToString(); } else if (StringUtils.EqualsIgnoreCase(element, ParentRule))//继承父级设置 20151113 sessionliang { var nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); var parentInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeInfo.ParentId); if (parentInfo != null) { var parentRule = GetContentFilePathRule(publishmentSystemInfo, parentInfo.NodeId); value = DirectoryUtils.GetDirectoryPath(ParseContentPath(publishmentSystemInfo, parentInfo.NodeId, contentInfo, parentRule)).Replace("\\", "/"); } } else if (StringUtils.EqualsIgnoreCase(element, ChannelName))//栏目名称 20151113 sessionliang { var nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); value = nodeInfo.NodeName; } else if (StringUtils.EqualsIgnoreCase(element, Year) || StringUtils.EqualsIgnoreCase(element, Month) || StringUtils.EqualsIgnoreCase(element, Day) || StringUtils.EqualsIgnoreCase(element, Hour) || StringUtils.EqualsIgnoreCase(element, Minute) || StringUtils.EqualsIgnoreCase(element, Second)) { if (addDate == DateTime.MinValue) { var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeId); addDate = BaiRongDataProvider.ContentDao.GetAddDate(tableName, contentId); } if (StringUtils.EqualsIgnoreCase(element, Year)) { value = addDate.Year.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Month)) { value = addDate.Month.ToString("D2"); //value = addDate.ToString("MM"); } else if (StringUtils.EqualsIgnoreCase(element, Day)) { value = addDate.Day.ToString("D2"); //value = addDate.ToString("dd"); } else if (StringUtils.EqualsIgnoreCase(element, Hour)) { value = addDate.Hour.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Minute)) { value = addDate.Minute.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Second)) { value = addDate.Second.ToString(); } } else { var attributeName = element.Replace("{@", string.Empty).Replace("}", string.Empty); value = contentInfo.GetExtendedAttribute(attributeName); } value = StringUtils.HtmlDecode(value); filePath = filePath.Replace(element, value); } if (filePath.Contains("//")) { filePath = Regex.Replace(filePath, @"(/)\1{2,}", "/"); filePath = filePath.Replace("//", "/"); } if (filePath.Contains("(")) { regex = @"(?<element>\([^\)]+\))"; elements = RegexUtils.GetContents("element", regex, filePath); foreach (var element in elements) { if (!element.Contains("|")) { continue; } var value = element.Replace("(", string.Empty).Replace(")", string.Empty); var value1 = value.Split('|')[0]; var value2 = value.Split('|')[1]; value = value1 + value2; if (!string.IsNullOrEmpty(value1) && !string.IsNullOrEmpty(value1)) { value = value1; } filePath = filePath.Replace(element, value); } } return(filePath); }
private static string GetContentUrlById(PublishmentSystemInfo publishmentSystemInfo, int nodeId, int contentId, int sourceId, int referenceId, string linkUrl, bool isFromBackground) { var tableStyleCurrent = NodeManager.GetTableStyle(publishmentSystemInfo, nodeId); var tableNameCurrent = NodeManager.GetTableName(publishmentSystemInfo, nodeId); var contentInfoCurrent = DataProvider.ContentDao.GetContentInfo(tableStyleCurrent, tableNameCurrent, contentId); if (referenceId > 0 && contentInfoCurrent.GetExtendedAttribute(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString()) { if (sourceId > 0 && (NodeManager.IsExists(publishmentSystemInfo.PublishmentSystemId, sourceId) || NodeManager.IsExists(sourceId))) { var targetNodeId = sourceId; var targetPublishmentSystemId = DataProvider.NodeDao.GetPublishmentSystemId(targetNodeId); var targetPublishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(targetPublishmentSystemId); var targetNodeInfo = NodeManager.GetNodeInfo(targetPublishmentSystemId, targetNodeId); var tableStyle = NodeManager.GetTableStyle(targetPublishmentSystemInfo, targetNodeInfo); var tableName = NodeManager.GetTableName(targetPublishmentSystemInfo, targetNodeInfo); var contentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, referenceId); if (contentInfo == null || contentInfo.NodeId <= 0) { return(PageUtils.UnclickedUrl); } if (contentInfo.PublishmentSystemId == targetPublishmentSystemInfo.PublishmentSystemId) { return(GetContentUrlById(targetPublishmentSystemInfo, contentInfo.NodeId, contentInfo.Id, contentInfo.SourceId, contentInfo.ReferenceId, contentInfo.GetExtendedAttribute(BackgroundContentAttribute.LinkUrl), isFromBackground)); } var publishmentSystemInfoTmp = PublishmentSystemManager.GetPublishmentSystemInfo(contentInfo.PublishmentSystemId); return(GetContentUrlById(publishmentSystemInfoTmp, contentInfo.NodeId, contentInfo.Id, contentInfo.SourceId, contentInfo.ReferenceId, contentInfo.GetExtendedAttribute(BackgroundContentAttribute.LinkUrl), isFromBackground)); } else { var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeId); nodeId = BaiRongDataProvider.ContentDao.GetNodeId(tableName, referenceId); linkUrl = BaiRongDataProvider.ContentDao.GetValue(tableName, referenceId, BackgroundContentAttribute.LinkUrl); return(GetContentUrlById(publishmentSystemInfo, nodeId, referenceId, 0, 0, linkUrl, isFromBackground)); } } if (!string.IsNullOrEmpty(linkUrl)) { return(ParseNavigationUrl(publishmentSystemInfo, linkUrl, isFromBackground)); } var contentUrl = PathUtility.ContentFilePathRules.Parse(publishmentSystemInfo, nodeId, contentId); return(GetPublishmentSystemUrl(publishmentSystemInfo, contentUrl, isFromBackground)); }
//递归处理 private static string ParseChannelPath(PublishmentSystemInfo publishmentSystemInfo, int nodeId, string channelFilePathRule) { var filePath = channelFilePathRule.Trim(); const string regex = "(?<element>{@[^}]+})"; var elements = RegexUtils.GetContents("element", regex, filePath); NodeInfo nodeInfo = null; foreach (var element in elements) { var value = string.Empty; if (StringUtils.EqualsIgnoreCase(element, ChannelId)) { value = nodeId.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, ChannelIndex)) { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.NodeIndexName; } else if (StringUtils.EqualsIgnoreCase(element, Year)) { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.AddDate.Year.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Month)) { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.AddDate.Month.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Day)) { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.AddDate.Day.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Hour)) { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.AddDate.Hour.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Minute)) { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.AddDate.Minute.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Second)) { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.AddDate.Second.ToString(); } else if (StringUtils.EqualsIgnoreCase(element, Sequence)) { value = DataProvider.NodeDao.GetSequence(publishmentSystemInfo.PublishmentSystemId, nodeId).ToString(); } else if (StringUtils.EqualsIgnoreCase(element, ParentRule))//继承父级设置 20151113 sessionliang { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } var parentInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeInfo.ParentId); if (parentInfo != null) { var parentRule = GetChannelFilePathRule(publishmentSystemInfo, parentInfo.NodeId); value = DirectoryUtils.GetDirectoryPath(ParseChannelPath(publishmentSystemInfo, parentInfo.NodeId, parentRule)).Replace("\\", "/"); } } else if (StringUtils.EqualsIgnoreCase(element, ChannelName))//栏目名称 20151113 sessionliang { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } value = nodeInfo.NodeName; } else { if (nodeInfo == null) { nodeInfo = NodeManager.GetNodeInfo(publishmentSystemInfo.PublishmentSystemId, nodeId); } var attributeName = element.Replace("{@", string.Empty).Replace("}", string.Empty); value = nodeInfo.Additional.GetExtendedAttribute(attributeName); } filePath = filePath.Replace(element, value); } if (!filePath.Contains("//")) { return(filePath); } filePath = Regex.Replace(filePath, @"(/)\1{2,}", "/"); filePath = Regex.Replace(filePath, @"//", "/"); return(filePath); }