Repository navigation
Expand file tree
/
Copy pathTaskCreate.cs
More file actions
173 lines (167 loc) · 7.65 KB
/
Copy pathTaskCreate.cs
File metadata and controls
173 lines (167 loc) · 7.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using BaiRong.Core;
using SiteServer.CMS.Core;
using SiteServer.CMS.Model;
using SiteServer.CMS.Model.Enumerations;
using SiteServer.CMS.StlParser;
namespace siteserver
{
public class TaskCreate
{
public static bool Execute(TaskInfo taskInfo)
{
var taskCreateInfo = new TaskCreateInfo(taskInfo.ServiceParameters);
if (!string.IsNullOrEmpty(taskCreateInfo.CreateTypes))
{
var createTypeArrayList = TranslateUtils.StringCollectionToStringList(taskCreateInfo.CreateTypes);
var createChannel = createTypeArrayList.Contains(ECreateTypeUtils.GetValue(ECreateType.Channel));
var createContent = createTypeArrayList.Contains(ECreateTypeUtils.GetValue(ECreateType.Content));
var createFile = createTypeArrayList.Contains(ECreateTypeUtils.GetValue(ECreateType.File));
if (taskInfo.PublishmentSystemID != 0)
{
List<int> nodeIdList = null;
if (taskCreateInfo.IsCreateAll)
{
nodeIdList = DataProvider.NodeDao.GetNodeIdListByPublishmentSystemId(taskInfo.PublishmentSystemID);
}
else
{
nodeIdList = TranslateUtils.StringCollectionToIntList(taskCreateInfo.ChannelIDCollection);
}
Create(createChannel, createContent, createFile, taskInfo, taskInfo.PublishmentSystemID, nodeIdList);
}
else
{
List<int> publishmentSystemIDArrayList = null;
if (taskCreateInfo.IsCreateAll)
{
publishmentSystemIDArrayList = PublishmentSystemManager.GetPublishmentSystemIdList();
}
else
{
publishmentSystemIDArrayList = TranslateUtils.StringCollectionToIntList(taskCreateInfo.ChannelIDCollection);
}
foreach (int publishmentSystemID in publishmentSystemIDArrayList)
{
var nodeIdList = DataProvider.NodeDao.GetNodeIdListByPublishmentSystemId(publishmentSystemID);
Create(createChannel, createContent, createFile, taskInfo, publishmentSystemID, nodeIdList);
}
}
}
return true;
}
private static void Create(bool createChannel, bool createContent, bool createFile, TaskInfo taskInfo, int publishmentSystemID, List<int> nodeIdList)
{
var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemID);
if (publishmentSystemInfo != null)
{
var fso = new FileSystemObject(publishmentSystemID);
var errorChannelNodeIdSortedList = new SortedList();
var errorContentNodeIdSortedList = new SortedList();
var errorFileTemplateIdSortedList = new SortedList();
if (nodeIdList != null && nodeIdList.Count > 0)
{
if (createChannel)
{
foreach (var nodeId in nodeIdList)
{
try
{
fso.CreateChannel(nodeId);
}
catch (Exception ex)
{
errorChannelNodeIdSortedList.Add(nodeId, ex.Message);
}
}
if (errorChannelNodeIdSortedList.Count > 0)
{
foreach (int nodeID in errorChannelNodeIdSortedList.Keys)
{
try
{
fso.CreateChannel(nodeID);
}
catch { }
}
}
}
if (createContent)
{
foreach (var nodeId in nodeIdList)
{
try
{
fso.CreateContents(nodeId);
}
catch (Exception ex)
{
errorContentNodeIdSortedList.Add(nodeId, ex.Message);
}
}
if (errorContentNodeIdSortedList.Count > 0)
{
foreach (int nodeID in errorContentNodeIdSortedList.Keys)
{
try
{
fso.CreateContents(nodeID);
}
catch { }
}
}
}
}
if (createFile)
{
var templateIDArrayList = DataProvider.TemplateDao.GetTemplateIdArrayListByType(publishmentSystemID, ETemplateType.FileTemplate);
foreach (int templateID in templateIDArrayList)
{
try
{
fso.CreateFile(templateID);
}
catch (Exception ex)
{
errorFileTemplateIdSortedList.Add(templateID, ex.Message);
}
}
if (errorFileTemplateIdSortedList.Count > 0)
{
foreach (int templateID in errorFileTemplateIdSortedList.Keys)
{
try
{
fso.CreateFile(templateID);
}
catch { }
}
}
}
if (errorChannelNodeIdSortedList.Count > 0 || errorContentNodeIdSortedList.Count > 0 || errorFileTemplateIdSortedList.Count > 0)
{
var errorMessage = new StringBuilder();
foreach (int nodeID in errorChannelNodeIdSortedList.Keys)
{
errorMessage.AppendFormat("Create channel {0} error:{1}", nodeID, errorChannelNodeIdSortedList[nodeID]).Append(StringUtils.Constants.ReturnAndNewline);
}
foreach (int nodeID in errorContentNodeIdSortedList.Keys)
{
errorMessage.AppendFormat("Create content {0} error:{1}", nodeID, errorContentNodeIdSortedList[nodeID]).Append(StringUtils.Constants.ReturnAndNewline);
}
foreach (int templateID in errorFileTemplateIdSortedList.Keys)
{
errorMessage.AppendFormat("Create file {0} error:{1}", templateID, errorFileTemplateIdSortedList[templateID]).Append(StringUtils.Constants.ReturnAndNewline);
}
}
if (taskInfo.ServiceType == EServiceType.Create && taskInfo.FrequencyType == EFrequencyType.OnlyOnce)
{
DataProvider.TaskDao.Delete(taskInfo.TaskID);
}
}
}
}
}