|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading.Tasks; |
2 | 4 | using System.Text; |
3 | 5 | using BaiRong.Core; |
4 | 6 | using BaiRong.Core.Model.Attributes; |
@@ -171,22 +173,46 @@ public void CreateChannel(int nodeId) |
171 | 173 |
|
172 | 174 | StlUtility.ParseStl(PublishmentSystemInfo, pageInfo, contextInfo, contentBuilder, filePath, false); |
173 | 175 |
|
174 | | - for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) |
175 | | - { |
176 | | - var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); |
177 | | - var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); |
178 | | - var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); |
| 176 | + //for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) |
| 177 | + //{ |
| 178 | + // PageContentsDetail(filePath, pageInfo, stlLabelList, pageContentsElementParser, contentBuilder, stlElementTranslated, totalNum, pageCount, currentPageIndex); |
179 | 179 |
|
180 | | - StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); |
| 180 | + // var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); |
| 181 | + // var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); |
| 182 | + // var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); |
181 | 183 |
|
182 | | - filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); |
183 | | - thePageInfo.AddLastPageScript(pageInfo); |
| 184 | + // StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); |
184 | 185 |
|
185 | | - GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); |
| 186 | + // filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); |
| 187 | + // thePageInfo.AddLastPageScript(pageInfo); |
186 | 188 |
|
187 | | - thePageInfo.ClearLastPageScript(pageInfo); |
188 | | - pageInfo.ClearLastPageScript(); |
| 189 | + // GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); |
| 190 | + |
| 191 | + // thePageInfo.ClearLastPageScript(pageInfo); |
| 192 | + // pageInfo.ClearLastPageScript(); |
| 193 | + //} |
| 194 | + |
| 195 | + if (PublishmentSystemInfo.Additional.IsCreateMultiThread) // 多线程并发生成页面 |
| 196 | + { |
| 197 | + for (int i = 1; i <= pageCount; i = i + 3) |
| 198 | + { |
| 199 | + var list = new List<int>(); |
| 200 | + list.Add(i); |
| 201 | + if (i <= pageCount - 1) |
| 202 | + list.Add(i + 1); |
| 203 | + if (i <= pageCount - 2) |
| 204 | + list.Add(i + 2); |
| 205 | + Parallel.ForEach(list, currentPageIndex => PageContentsDetail(filePath, pageInfo, stlLabelList, pageContentsElementParser, contentBuilder, stlElementTranslated, totalNum, pageCount, currentPageIndex)); |
| 206 | + } |
189 | 207 | } |
| 208 | + else // 单线程生成页面 |
| 209 | + { |
| 210 | + for (var currentPageIndex = 0; currentPageIndex < pageCount; currentPageIndex++) |
| 211 | + { |
| 212 | + PageContentsDetail(filePath, pageInfo, stlLabelList, pageContentsElementParser, contentBuilder, stlElementTranslated, totalNum, pageCount, currentPageIndex); |
| 213 | + } |
| 214 | + } |
| 215 | + |
190 | 216 | } |
191 | 217 | //如果标签中存在<stl:pageChannels> |
192 | 218 | else if (StlParserUtility.IsStlElementExists(StlPageChannels.ElementName, stlLabelList)) |
@@ -267,16 +293,67 @@ public void CreateChannel(int nodeId) |
267 | 293 | } |
268 | 294 | } |
269 | 295 |
|
| 296 | + /// <summary> |
| 297 | + /// 处理栏目列表页分页标签PageContents |
| 298 | + /// </summary> |
| 299 | + /// <param name="filePath"></param> |
| 300 | + /// <param name="pageInfo"></param> |
| 301 | + /// <param name="stlLabelList"></param> |
| 302 | + /// <param name="pageContentsElementParser"></param> |
| 303 | + /// <param name="contentBuilder"></param> |
| 304 | + /// <param name="stlElementTranslated"></param> |
| 305 | + /// <param name="totalNum"></param> |
| 306 | + /// <param name="pageCount"></param> |
| 307 | + private void PageContentsDetail(string filePath, PageInfo pageInfo,List<string> stlLabelList, StlPageContents pageContentsElementParser, StringBuilder contentBuilder, string stlElementTranslated,int totalNum,int pageCount, int currentPageIndex) |
| 308 | + { |
| 309 | + var thePageInfo = new PageInfo(pageInfo.PageNodeId, pageInfo.PageContentId, pageInfo.PublishmentSystemInfo, pageInfo.TemplateInfo, null); |
| 310 | + var pageHtml = pageContentsElementParser.Parse(totalNum, currentPageIndex, pageCount, true); |
| 311 | + var pagedBuilder = new StringBuilder(contentBuilder.ToString().Replace(stlElementTranslated, pageHtml)); |
| 312 | + |
| 313 | + StlParserManager.ReplacePageElementsInChannelPage(pagedBuilder, thePageInfo, stlLabelList, thePageInfo.PageNodeId, currentPageIndex, pageCount, totalNum); |
| 314 | + |
| 315 | + filePath = PathUtility.GetChannelPageFilePath(PublishmentSystemInfo, thePageInfo.PageNodeId, currentPageIndex); |
| 316 | + thePageInfo.AddLastPageScript(pageInfo); |
| 317 | + |
| 318 | + GenerateFile(filePath, pageInfo.TemplateInfo.Charset, pagedBuilder); |
| 319 | + |
| 320 | + thePageInfo.ClearLastPageScript(pageInfo); |
| 321 | + pageInfo.ClearLastPageScript(); |
| 322 | + } |
| 323 | + |
270 | 324 | public void CreateContents(int nodeId) |
271 | 325 | { |
272 | 326 | var nodeInfo = NodeManager.GetNodeInfo(PublishmentSystemId, nodeId); |
273 | 327 | var tableStyle = NodeManager.GetTableStyle(PublishmentSystemInfo, nodeInfo); |
274 | 328 | var tableName = NodeManager.GetTableName(PublishmentSystemInfo, nodeInfo); |
275 | 329 | var orderByString = ETaxisTypeUtils.GetContentOrderByString(ETaxisType.OrderByTaxisDesc); |
276 | 330 | var contentIdList = DataProvider.ContentDao.GetContentIdListChecked(tableName, nodeId, orderByString); |
277 | | - foreach (var contentId in contentIdList) |
| 331 | + |
| 332 | + //foreach (var contentId in contentIdList) |
| 333 | + //{ |
| 334 | + // CreateContent(tableStyle, tableName, nodeId, contentId); |
| 335 | + //} |
| 336 | + |
| 337 | + if (PublishmentSystemInfo.Additional.IsCreateMultiThread) // 多线程并发生成页面 |
278 | 338 | { |
279 | | - CreateContent(tableStyle, tableName, nodeId, contentId); |
| 339 | + for (int i = 0; i < contentIdList.Count; i = i + 3) |
| 340 | + { |
| 341 | + var list = new List<int>(); |
| 342 | + list.Add(contentIdList[i]); |
| 343 | + if (i < contentIdList.Count - 1) |
| 344 | + list.Add(contentIdList[i + 1]); |
| 345 | + if (i < contentIdList.Count - 2) |
| 346 | + list.Add(contentIdList[i + 2]); |
| 347 | + Parallel.ForEach(list, contentId => CreateContent(tableStyle, tableName, nodeId, contentId)); |
| 348 | + } |
| 349 | + } |
| 350 | + else // 单线程生成页面 |
| 351 | + { |
| 352 | + foreach (var contentId in contentIdList) |
| 353 | + { |
| 354 | + CreateContent(tableStyle, tableName, nodeId, contentId); |
| 355 | + |
| 356 | + } |
280 | 357 | } |
281 | 358 | } |
282 | 359 |
|
|
0 commit comments