コード例 #1
0
ファイル: TaskCreate.cs プロジェクト: skotbenben/cms
        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
                                {
                                    // ignored
                                }
                            }
                        }
                    }
                    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
                                {
                                    // ignored
                                }
                            }
                        }
                    }
                }
                if (createFile)
                {
                    var templateIdList = DataProvider.TemplateDao.GetTemplateIdListByType(publishmentSystemId, ETemplateType.FileTemplate);
                    foreach (var templateId in templateIdList)
                    {
                        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
                            {
                                // ignored
                            }
                        }
                    }
                }
                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);
                }
            }
        }