Example #1
0
        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);
                }
            }
        }
Example #2
0
        public void Main()
        {
            var body = new RequestBody();

            var publishmentSystemId = body.GetQueryInt("publishmentSystemId");
            var channelId           = body.GetQueryInt("channelId");

            if (channelId == 0)
            {
                channelId = publishmentSystemId;
            }
            var contentId      = body.GetQueryInt("contentId");
            var fileTemplateId = body.GetQueryInt("fileTemplateId");
            var isRedirect     = TranslateUtils.ToBool(body.GetQueryString("isRedirect"));

            var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemId);
            var fso        = new FileSystemObject(publishmentSystemId);
            var nodeInfo   = NodeManager.GetNodeInfo(publishmentSystemId, channelId);
            var tableStyle = NodeManager.GetTableStyle(publishmentSystemInfo, nodeInfo);
            var tableName  = NodeManager.GetTableName(publishmentSystemInfo, nodeInfo);

            if (fileTemplateId != 0)
            {
                fso.CreateFile(fileTemplateId);
            }
            else if (contentId != 0)
            {
                fso.CreateContent(tableStyle, tableName, channelId, contentId);
            }
            else if (channelId != 0)
            {
                fso.CreateChannel(channelId);
            }
            else if (publishmentSystemId != 0)
            {
                fso.CreateChannel(publishmentSystemId);
            }

            if (isRedirect)
            {
                var redirectUrl = string.Empty;
                if (fileTemplateId != 0)
                {
                    redirectUrl = PageUtility.GetFileUrl(publishmentSystemInfo, fileTemplateId);
                }
                else if (contentId != 0)
                {
                    var contentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, contentId);
                    redirectUrl = PageUtility.GetContentUrl(publishmentSystemInfo, contentInfo);
                }
                else if (channelId != 0)
                {
                    redirectUrl = PageUtility.GetChannelUrl(publishmentSystemInfo, nodeInfo);
                }
                else if (publishmentSystemId != 0)
                {
                    redirectUrl = PageUtility.GetIndexPageUrl(publishmentSystemInfo);
                }

                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = PageUtils.AddQueryString(redirectUrl, "__r", StringUtils.GetRandomInt(1, 10000).ToString());
                    HttpContext.Current.Response.Redirect(redirectUrl, true);
                    return;
                }
            }

            HttpContext.Current.Response.Write(string.Empty);
            HttpContext.Current.Response.End();
        }