Exemple #1
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();
        }
Exemple #2
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);
                }
            }
        }
Exemple #3
0
        public void ImportTemplates(bool overwrite, string administratorName)
        {
            if (!FileUtils.IsFileExists(_filePath))
            {
                return;
            }
            var feed = AtomFeed.Load(FileUtils.GetFileStreamReadOnly(_filePath));

            var fso = new FileSystemObject(_publishmentSystemId);

            foreach (AtomEntry entry in feed.Entries)
            {
                var templateName = AtomUtility.GetDcElementContent(entry.AdditionalElements, "TemplateName");
                if (!string.IsNullOrEmpty(templateName))
                {
                    var templateInfo = new TemplateInfo
                    {
                        PublishmentSystemId = _publishmentSystemId,
                        TemplateName        = templateName,
                        TemplateType        =
                            ETemplateTypeUtils.GetEnumType(AtomUtility.GetDcElementContent(entry.AdditionalElements, "TemplateType")),
                        RelatedFileName     = AtomUtility.GetDcElementContent(entry.AdditionalElements, "RelatedFileName"),
                        CreatedFileFullName = AtomUtility.GetDcElementContent(entry.AdditionalElements, "CreatedFileFullName"),
                        CreatedFileExtName  = AtomUtility.GetDcElementContent(entry.AdditionalElements, "CreatedFileExtName"),
                        Charset             = ECharsetUtils.GetEnumType(AtomUtility.GetDcElementContent(entry.AdditionalElements, "Charset")),
                        IsDefault           = false
                    };

                    var templateContent = AtomUtility.Decrypt(AtomUtility.GetDcElementContent(entry.AdditionalElements, "Content"));

                    var srcTemplateInfo = TemplateManager.GetTemplateInfoByTemplateName(_publishmentSystemId, templateInfo.TemplateType, templateInfo.TemplateName);

                    int templateId;

                    if (srcTemplateInfo != null)
                    {
                        if (overwrite)
                        {
                            srcTemplateInfo.RelatedFileName     = templateInfo.RelatedFileName;
                            srcTemplateInfo.TemplateType        = templateInfo.TemplateType;
                            srcTemplateInfo.CreatedFileFullName = templateInfo.CreatedFileFullName;
                            srcTemplateInfo.CreatedFileExtName  = templateInfo.CreatedFileExtName;
                            srcTemplateInfo.Charset             = templateInfo.Charset;
                            DataProvider.TemplateDao.Update(fso.PublishmentSystemInfo, srcTemplateInfo, templateContent, administratorName);
                            templateId = srcTemplateInfo.TemplateId;
                        }
                        else
                        {
                            templateInfo.TemplateName = DataProvider.TemplateDao.GetImportTemplateName(_publishmentSystemId, templateInfo.TemplateName);
                            templateId = DataProvider.TemplateDao.Insert(templateInfo, templateContent, administratorName);
                        }
                    }
                    else
                    {
                        templateId = DataProvider.TemplateDao.Insert(templateInfo, templateContent, administratorName);
                    }

                    if (templateInfo.TemplateType == ETemplateType.FileTemplate)
                    {
                        fso.CreateFile(templateId);
                    }
                }
            }
        }