Ejemplo n.º 1
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("PublishmentSystemID");

            if (Body.IsQueryExists("isRedirectToFiles"))
            {
                var redirectUrl = PageUtils.GetCmsUrl("PageFileMain", new NameValueCollection
                {
                    { "RootPath", $"~/SiteFiles/BackupFiles/{PublishmentSystemInfo.PublishmentSystemDir}" }
                });
                PageUtils.Redirect(redirectUrl);
                return;
            }

            if (!IsPostBack)
            {
                BreadCrumb(AppManager.Cms.LeftMenu.IdFunction, AppManager.Cms.LeftMenu.Function.IdBackup, "数据备份", AppManager.Cms.Permission.WebSite.Backup);

                EBackupTypeUtils.AddListItems(BackupType);
            }
        }
Ejemplo n.º 2
0
        public void ImportChannelsAndContentsByZipFile(int parentId, string zipFilePath, bool isOverride)
        {
            var siteContentDirectoryPath = PathUtils.GetTemporaryFilesPath(EBackupTypeUtils.GetValue(EBackupType.ChannelsAndContents));

            DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            DirectoryUtils.CreateDirectoryIfNotExists(siteContentDirectoryPath);

            ZipUtils.UnpackFiles(zipFilePath, siteContentDirectoryPath);

            ImportChannelsAndContentsFromZip(parentId, siteContentDirectoryPath, isOverride);

            DataProvider.NodeDao.UpdateContentNum(Fso.PublishmentSystemInfo);
        }
Ejemplo n.º 3
0
        public void Options_SelectedIndexChanged(object sender, EventArgs e)
        {
            var backupType = EBackupTypeUtils.GetEnumType(BackupType.SelectedValue);

            if (backupType == EBackupType.Site)
            {
                PlaceHolder_Delete.Visible = true;
            }
            else
            {
                PlaceHolder_Delete.Visible = false;
            }

            PlaceHolderByUpload.Visible = TranslateUtils.ToBool(IsRecoveryByUpload.SelectedValue);
        }
Ejemplo n.º 4
0
        public NameValueCollection Backup(int siteId, string backupType, string userKeyPrefix)
        {
            //返回“运行结果”和“错误信息”的字符串数组
            NameValueCollection retval;
            var request = new RequestImpl(Request);

            try
            {
                var eBackupType = EBackupTypeUtils.GetEnumType(backupType);

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                var filePath = PathUtility.GetBackupFilePath(siteInfo, eBackupType);
                DirectoryUtils.CreateDirectoryIfNotExists(filePath);
                FileUtils.DeleteFileIfExists(filePath);

                if (eBackupType == EBackupType.Templates)
                {
                    BackupUtility.BackupTemplates(siteId, filePath, request.AdminName);
                }
                else if (eBackupType == EBackupType.ChannelsAndContents)
                {
                    BackupUtility.BackupChannelsAndContents(siteId, filePath, request.AdminName);
                }
                else if (eBackupType == EBackupType.Files)
                {
                    BackupUtility.BackupFiles(siteId, filePath, request.AdminName);
                }
                else if (eBackupType == EBackupType.Site)
                {
                    BackupUtility.BackupSite(siteId, filePath, request.AdminName);
                }

                string resultString =
                    $"任务完成,备份地址:<br /><strong> {filePath} </strong>&nbsp;<a href='{ApiRouteActionsDownload.GetUrl(ApiManager.InnerApiUrl, filePath)}'><img src='{SiteServerAssets.GetIconUrl("download.gif")}' />下载</a>。";

                retval = AjaxManager.GetWaitingTaskNameValueCollection(resultString, string.Empty, string.Empty);
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty);
                LogUtils.AddErrorLog(ex);
            }

            return(retval);
        }
Ejemplo n.º 5
0
        public void ImportChannelsAndContentsByZipFile(int parentId, string zipFilePath, bool isOverride)
        {
            var siteContentDirectoryPath = PathUtils.GetTemporaryFilesPath(EBackupTypeUtils.GetValue(EBackupType.ChannelsAndContents));

            DirectoryUtils.DeleteDirectoryIfExists(siteContentDirectoryPath);
            DirectoryUtils.CreateDirectoryIfNotExists(siteContentDirectoryPath);

            ZipUtils.UnpackFiles(zipFilePath, siteContentDirectoryPath);

            ImportChannelsAndContentsFromZip(parentId, siteContentDirectoryPath, isOverride);

            DataProvider.NodeDao.UpdateContentNum(Fso.PublishmentSystemInfo);

            string filePath         = PathUtils.Combine(siteContentDirectoryPath, BackupUtility.UploadFolderName, BackupUtility.UploadFileName);
            var    UploadFolderPath = PathUtils.Combine(siteContentDirectoryPath, BackupUtility.UploadFolderName);
            var    UploadFilePath   = PathUtils.Combine(UploadFolderPath, BackupUtility.UploadFileName);

            if (!FileUtils.IsFileExists(UploadFilePath))
            {
                return;
            }
            var feed = AtomFeed.Load(FileUtils.GetFileStreamReadOnly(UploadFilePath));

            if (feed != null)
            {
                AtomEntry entry = feed.Entries[0];
                string    imageUploadDirectoryPath = AtomUtility.GetDcElementContent(entry.AdditionalElements, "ImageUploadDirectoryName");
                if (imageUploadDirectoryPath != null)
                {
                    DirectoryUtils.MoveDirectory(PathUtils.Combine(siteContentDirectoryPath, imageUploadDirectoryPath), PathUtils.Combine(Fso.PublishmentSystemPath, Fso.PublishmentSystemInfo.Additional.ImageUploadDirectoryName), isOverride);
                }
                string videoUploadDirectoryPath = AtomUtility.GetDcElementContent(entry.AdditionalElements, "VideoUploadDirectoryName");
                if (videoUploadDirectoryPath != null)
                {
                    DirectoryUtils.MoveDirectory(PathUtils.Combine(siteContentDirectoryPath, videoUploadDirectoryPath), PathUtils.Combine(Fso.PublishmentSystemPath, Fso.PublishmentSystemInfo.Additional.VideoUploadDirectoryName), isOverride);
                }
                string fileUploadDirectoryPath = AtomUtility.GetDcElementContent(entry.AdditionalElements, "FileUploadDirectoryName");
                if (fileUploadDirectoryPath != null)
                {
                    DirectoryUtils.MoveDirectory(PathUtils.Combine(siteContentDirectoryPath, fileUploadDirectoryPath), PathUtils.Combine(Fso.PublishmentSystemPath, Fso.PublishmentSystemInfo.Additional.FileUploadDirectoryName), isOverride);
                }
            }
        }
Ejemplo n.º 6
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            PageUtils.CheckRequestParameter("PublishmentSystemID");

            if (!IsPostBack)
            {
                BreadCrumb(AppManager.Cms.LeftMenu.IdFunction, AppManager.Cms.LeftMenu.Function.IdBackup, "数据恢复", AppManager.Cms.Permission.WebSite.Backup);

                EBackupTypeUtils.AddListItems(BackupType);
                ControlUtils.SelectListItems(BackupType, EBackupTypeUtils.GetValue(EBackupType.Templates));

                EBooleanUtils.AddListItems(IsRecoveryByUpload, "从上传文件中恢复", "从服务器备份文件中恢复");
                ControlUtils.SelectListItems(IsRecoveryByUpload, true.ToString());

                Options_SelectedIndexChanged(null, EventArgs.Empty);
            }
        }
Ejemplo n.º 7
0
        public static string GetBackupFilePath(SiteInfo siteInfo, EBackupType backupType)
        {
            var extention = ".zip";
            var siteName  = siteInfo.SiteDir;

            if (!string.IsNullOrEmpty(siteName))
            {
                siteName += "_";
            }
            if (backupType == EBackupType.Templates)
            {
                extention = ".xml";
            }
            return(PathUtils.Combine(PathUtils.PhysicalSiteFilesPath, DirectoryUtils.SiteFiles.BackupFiles, siteInfo.SiteDir, DateTime.Now.ToString("yyyy-MM"), EBackupTypeUtils.GetValue(backupType) + "_" + siteName + DateTime.Now.ToString("yyyy-MM-dd-HH-mm") + extention));
        }
Ejemplo n.º 8
0
        public static void RecoverySite(int siteId, bool isDeleteChannels, bool isDeleteTemplates, bool isDeleteFiles, bool isZip, string path, bool isOverride, bool isUseTable, string administratorName)
        {
            var importObject = new ImportObject(siteId, administratorName);

            var siteInfo = SiteManager.GetSiteInfo(siteId);

            var siteTemplatePath = path;

            if (isZip)
            {
                //解压文件
                siteTemplatePath = PathUtils.GetTemporaryFilesPath(EBackupTypeUtils.GetValue(EBackupType.Site));
                DirectoryUtils.DeleteDirectoryIfExists(siteTemplatePath);
                DirectoryUtils.CreateDirectoryIfNotExists(siteTemplatePath);

                ZipUtils.ExtractZip(path, siteTemplatePath);
            }
            var siteTemplateMetadataPath = PathUtils.Combine(siteTemplatePath, DirectoryUtils.SiteTemplates.SiteTemplateMetadata);

            if (isDeleteChannels)
            {
                var channelIdList = ChannelManager.GetChannelIdList(ChannelManager.GetChannelInfo(siteId, siteId), EScopeType.Children, string.Empty, string.Empty, string.Empty);
                foreach (var channelId in channelIdList)
                {
                    DataProvider.ChannelDao.Delete(siteId, channelId);
                }
            }
            if (isDeleteTemplates)
            {
                var templateInfoList =
                    DataProvider.TemplateDao.GetTemplateInfoListBySiteId(siteId);
                foreach (var templateInfo in templateInfoList)
                {
                    if (templateInfo.IsDefault == false)
                    {
                        DataProvider.TemplateDao.Delete(siteId, templateInfo.Id);
                    }
                }
            }
            if (isDeleteFiles)
            {
                DirectoryUtility.DeleteSiteFiles(siteInfo);
            }

            //导入文件
            importObject.ImportFiles(siteTemplatePath, isOverride);

            //导入模板
            var templateFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileTemplate);

            importObject.ImportTemplates(templateFilePath, isOverride, administratorName);

            //导入辅助表
            var tableDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.Table);

            //导入站点设置
            var configurationFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileConfiguration);

            importObject.ImportConfiguration(configurationFilePath);

            //导入栏目及内容
            var siteContentDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.SiteContent);

            importObject.ImportChannelsAndContents(0, siteContentDirectoryPath, isOverride);

            //导入表样式及清除缓存
            if (isUseTable)
            {
                importObject.ImportTableStyles(tableDirectoryPath);
            }
            importObject.RemoveDbCache();

            CacheUtils.ClearAll();
        }
Ejemplo n.º 9
0
        public static void RecoverySite(int publishmentSystemId, bool isDeleteChannels, bool isDeleteTemplates, bool isDeleteFiles, bool isZip, string path, bool isOverride, bool isUseTable, string administratorName)
        {
            var importObject = new ImportObject(publishmentSystemId);

            var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemId);

            var siteTemplatePath = path;

            if (isZip)
            {
                //解压文件
                siteTemplatePath = PathUtils.GetTemporaryFilesPath(EBackupTypeUtils.GetValue(EBackupType.Site));
                DirectoryUtils.DeleteDirectoryIfExists(siteTemplatePath);
                DirectoryUtils.CreateDirectoryIfNotExists(siteTemplatePath);

                ZipUtils.UnpackFiles(path, siteTemplatePath);
            }
            var siteTemplateMetadataPath = PathUtils.Combine(siteTemplatePath, DirectoryUtils.SiteTemplates.SiteTemplateMetadata);

            if (isDeleteChannels)
            {
                var nodeIdList = DataProvider.NodeDao.GetNodeIdListByParentId(publishmentSystemId, publishmentSystemId);
                foreach (int nodeId in nodeIdList)
                {
                    DataProvider.NodeDao.Delete(nodeId);
                }
            }
            if (isDeleteTemplates)
            {
                var templateInfoList =
                    DataProvider.TemplateDao.GetTemplateInfoListByPublishmentSystemId(publishmentSystemId);
                foreach (var templateInfo in templateInfoList)
                {
                    if (templateInfo.IsDefault == false)
                    {
                        DataProvider.TemplateDao.Delete(publishmentSystemId, templateInfo.TemplateId);
                    }
                }
            }
            if (isDeleteFiles)
            {
                DirectoryUtility.DeletePublishmentSystemFiles(publishmentSystemInfo);
            }

            //导入文件
            importObject.ImportFiles(siteTemplatePath, isOverride);

            //导入模板
            var templateFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileTemplate);

            importObject.ImportTemplates(templateFilePath, isOverride, administratorName);

            //导入辅助表
            var tableDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.Table);

            importObject.ImportAuxiliaryTables(tableDirectoryPath, isUseTable);

            //导入菜单
            var menuDisplayFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileMenuDisplay);

            importObject.ImportMenuDisplay(menuDisplayFilePath, isOverride);

            //导入标签样式
            var tagStyleFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileTagStyle);

            importObject.ImportTagStyle(tagStyleFilePath, isOverride);

            //导入固定广告
            var adFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileAd);

            importObject.ImportAd(adFilePath, isOverride);

            //导入采集规则
            var gatherRuleFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileGatherRule);

            importObject.ImportGatherRule(gatherRuleFilePath, isOverride);

            //导入提交表单
            var inputDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.Input);

            importObject.ImportInput(inputDirectoryPath, isOverride);

            //导入站点设置
            var configurationFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileConfiguration);

            importObject.ImportConfiguration(configurationFilePath);

            //导入内容模型
            var contentModelFilePath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.FileContentModel);

            importObject.ImportContentModel(contentModelFilePath, true);

            //导入栏目及内容
            var siteContentDirectoryPath = PathUtils.Combine(siteTemplateMetadataPath, DirectoryUtils.SiteTemplates.SiteContent);

            importObject.ImportChannelsAndContents(0, siteContentDirectoryPath, isOverride);

            DataProvider.NodeDao.UpdateContentNum(publishmentSystemInfo);

            //导入表样式及清除缓存
            if (isUseTable)
            {
                importObject.ImportTableStyles(tableDirectoryPath);
            }
            importObject.RemoveDbCache();

            CacheUtils.Clear();
        }
Ejemplo n.º 10
0
        public string ExportChannels(List <int> channelIdList)
        {
            var filePath = PathUtils.GetTemporaryFilesPath(EBackupTypeUtils.GetValue(EBackupType.ChannelsAndContents) + ".zip");

            return(ExportChannels(channelIdList, filePath));
        }
Ejemplo n.º 11
0
        public void RecoveryButton_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                if (TranslateUtils.ToBool(IsRecoveryByUpload.SelectedValue))
                {
                    if (myFile.PostedFile != null && "" != myFile.PostedFile.FileName)
                    {
                        var filePath = myFile.PostedFile.FileName;
                        if (EBackupTypeUtils.Equals(EBackupType.Templates, BackupType.SelectedValue))
                        {
                            if (EFileSystemTypeUtils.GetEnumType(PathUtils.GetExtension(filePath)) != EFileSystemType.Xml)
                            {
                                FailMessage("必须上传Xml文件");
                                return;
                            }
                        }
                        else
                        {
                            if (!EFileSystemTypeUtils.IsCompressionFile(PathUtils.GetExtension(filePath)))
                            {
                                FailMessage("必须上传压缩文件");
                                return;
                            }
                        }

                        try
                        {
                            var localFilePath = PathUtils.GetTemporaryFilesPath(PathUtils.GetFileName(filePath));

                            myFile.PostedFile.SaveAs(localFilePath);

                            var importObject = new ImportObject(PublishmentSystemId);

                            if (EBackupTypeUtils.Equals(EBackupType.Templates, BackupType.SelectedValue))
                            {
                                importObject.ImportTemplates(localFilePath, TranslateUtils.ToBool(IsOverride.SelectedValue), Body.AdministratorName);
                                SuccessMessage("恢复模板成功!");
                            }
                            else if (EBackupTypeUtils.Equals(EBackupType.ChannelsAndContents, BackupType.SelectedValue))
                            {
                                importObject.ImportChannelsAndContentsByZipFile(0, localFilePath, TranslateUtils.ToBool(IsOverride.SelectedValue));
                                SuccessMessage("恢复栏目及内容成功!");
                            }
                            else if (EBackupTypeUtils.Equals(EBackupType.Files, BackupType.SelectedValue))
                            {
                                var filesDirectoryPath = PathUtils.GetTemporaryFilesPath(EBackupTypeUtils.GetValue(EBackupType.Files));
                                DirectoryUtils.DeleteDirectoryIfExists(filesDirectoryPath);
                                DirectoryUtils.CreateDirectoryIfNotExists(filesDirectoryPath);

                                ZipUtils.UnpackFiles(localFilePath, filesDirectoryPath);

                                importObject.ImportFiles(filesDirectoryPath, TranslateUtils.ToBool(IsOverride.SelectedValue));
                                SuccessMessage("恢复文件成功!");
                            }
                            else if (EBackupTypeUtils.Equals(EBackupType.Site, BackupType.SelectedValue))
                            {
                                var userKeyPrefix = StringUtils.Guid();
                                PageUtils.Redirect(PageProgressBar.GetRecoveryUrl(PublishmentSystemId, IsDeleteChannels.SelectedValue, IsDeleteTemplates.SelectedValue, IsDeleteFiles.SelectedValue, true, localFilePath, IsOverride.SelectedValue, IsOverride.SelectedValue, userKeyPrefix));
                            }
                        }
                        catch (Exception ex)
                        {
                            FailMessage(ex, "数据恢复失败!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            _serviceType = EServiceTypeUtils.GetEnumType(Body.GetQueryString("ServiceType"));
            if (!IsPostBack)
            {
                EFrequencyTypeUtils.AddListItems(FrequencyType, false);
                for (var i = 1; i < 32; i++)
                {
                    StartDay.Items.Add(new ListItem(i + "日", i.ToString()));
                }
                for (var i = 1; i < 8; i++)
                {
                    var weekName = string.Empty;
                    if (i == 1)
                    {
                        weekName = "星期一";
                    }
                    else if (i == 2)
                    {
                        weekName = "星期二";
                    }
                    else if (i == 3)
                    {
                        weekName = "星期三";
                    }
                    else if (i == 4)
                    {
                        weekName = "星期四";
                    }
                    else if (i == 5)
                    {
                        weekName = "星期五";
                    }
                    else if (i == 6)
                    {
                        weekName = "星期六";
                    }
                    else if (i == 7)
                    {
                        weekName = "星期日";
                    }
                    StartWeekday.Items.Add(new ListItem(weekName, i.ToString()));
                }
                for (var i = 0; i < 24; i++)
                {
                    StartHour.Items.Add(new ListItem(i + "点", i.ToString()));
                }

                var listItem = new ListItem("周", "5040");
                PeriodIntervalType.Items.Add(listItem);
                listItem = new ListItem("天", "720");
                PeriodIntervalType.Items.Add(listItem);
                listItem = new ListItem("小时", "12");
                PeriodIntervalType.Items.Add(listItem);
                listItem          = new ListItem("分钟", "1");
                listItem.Selected = true;
                PeriodIntervalType.Items.Add(listItem);

                if (_serviceType == EServiceType.Create)
                {
                    PlaceHolder_Create.Visible = true;

                    if (PublishmentSystemId != 0)
                    {
                        NodeManager.AddListItems(CreateChannelIDCollection.Items, PublishmentSystemInfo, false, true, Body.AdministratorName);
                    }
                    else
                    {
                        var arraylist = PublishmentSystemManager.GetPublishmentSystemIdList();
                        foreach (int publishmentSystemID in arraylist)
                        {
                            var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemID);
                            var item = new ListItem(publishmentSystemInfo.PublishmentSystemName, publishmentSystemInfo.PublishmentSystemId.ToString());
                            CreateChannelIDCollection.Items.Add(item);
                        }
                    }

                    ECreateTypeUtils.AddListItems(CreateCreateTypes);
                }
                else if (_serviceType == EServiceType.Gather)
                {
                    PlaceHolder_Gather.Visible = true;

                    if (PublishmentSystemId != 0)
                    {
                        var gatherRuleNameArrayList = DataProvider.GatherRuleDao.GetGatherRuleNameArrayList(PublishmentSystemId);
                        var gatherTypeValue         = EGatherTypeUtils.GetValue(EGatherType.Web);
                        var gatherTypeText          = EGatherTypeUtils.GetText(EGatherType.Web);
                        foreach (string gatherName in gatherRuleNameArrayList)
                        {
                            GatherListBox.Items.Add(new ListItem(gatherName + "(" + gatherTypeText + ")", gatherTypeValue + "_" + gatherName));
                        }
                        gatherRuleNameArrayList = DataProvider.GatherDatabaseRuleDao.GetGatherRuleNameArrayList(PublishmentSystemId);
                        gatherTypeValue         = EGatherTypeUtils.GetValue(EGatherType.Database);
                        gatherTypeText          = EGatherTypeUtils.GetText(EGatherType.Database);
                        foreach (string gatherName in gatherRuleNameArrayList)
                        {
                            GatherListBox.Items.Add(new ListItem(gatherName + "(" + gatherTypeText + ")", gatherTypeValue + "_" + gatherName));
                        }
                        gatherRuleNameArrayList = DataProvider.GatherFileRuleDao.GetGatherRuleNameArrayList(PublishmentSystemId);
                        gatherTypeValue         = EGatherTypeUtils.GetValue(EGatherType.File);
                        gatherTypeText          = EGatherTypeUtils.GetText(EGatherType.File);
                        foreach (string gatherName in gatherRuleNameArrayList)
                        {
                            GatherListBox.Items.Add(new ListItem(gatherName + "(" + gatherTypeText + ")", gatherTypeValue + "_" + gatherName));
                        }

                        GatherHelp.Text = "选择需要定时执行的采集名称";
                    }
                    else
                    {
                        var arraylist = PublishmentSystemManager.GetPublishmentSystemIdList();
                        foreach (int publishmentSystemID in arraylist)
                        {
                            var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemID);
                            var item = new ListItem(publishmentSystemInfo.PublishmentSystemName, publishmentSystemInfo.PublishmentSystemId.ToString());
                            GatherListBox.Items.Add(item);
                        }

                        GatherHelp.Text = "选择需要定时采集的站点";
                    }
                }
                else if (_serviceType == EServiceType.Backup)
                {
                    PlaceHolder_Backup.Visible = true;

                    if (PublishmentSystemId != 0)
                    {
                        PlaceHolder_Backup_PublishmentSystem.Visible = false;
                    }
                    else
                    {
                        PlaceHolder_Backup_PublishmentSystem.Visible = true;
                        var arraylist = PublishmentSystemManager.GetPublishmentSystemIdList();
                        foreach (int publishmentSystemID in arraylist)
                        {
                            var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemID);
                            var item = new ListItem(publishmentSystemInfo.PublishmentSystemName, publishmentSystemInfo.PublishmentSystemId.ToString());
                            BackupPublishmentSystemIDCollection.Items.Add(item);
                        }
                    }

                    EBackupTypeUtils.AddListItems(BackupType);
                }

                if (Body.IsQueryExists("TaskID"))
                {
                    var taskId   = Body.GetQueryInt("TaskID");
                    var taskInfo = DataProvider.TaskDao.GetTaskInfo(taskId);
                    if (taskInfo != null)
                    {
                        TaskName.Text    = taskInfo.TaskName;
                        TaskName.Enabled = false;

                        ControlUtils.SelectListItems(FrequencyType, EFrequencyTypeUtils.GetValue(taskInfo.FrequencyType));
                        ControlUtils.SelectListItems(StartDay, taskInfo.StartDay.ToString());
                        ControlUtils.SelectListItems(StartWeekday, taskInfo.StartWeekday.ToString());
                        ControlUtils.SelectListItems(StartHour, taskInfo.StartHour.ToString());

                        if (taskInfo.PeriodIntervalMinute % 5040 == 0)
                        {
                            PeriodInterval.Text = Convert.ToInt32(taskInfo.PeriodIntervalMinute / 5040).ToString();
                            ControlUtils.SelectListItems(PeriodIntervalType, "5040");
                        }
                        else if (taskInfo.PeriodIntervalMinute % 720 == 0)
                        {
                            PeriodInterval.Text = Convert.ToInt32(taskInfo.PeriodIntervalMinute / 720).ToString();
                            ControlUtils.SelectListItems(PeriodIntervalType, "720");
                        }
                        else if (taskInfo.PeriodIntervalMinute % 12 == 0)
                        {
                            PeriodInterval.Text = Convert.ToInt32(taskInfo.PeriodIntervalMinute / 12).ToString();
                            ControlUtils.SelectListItems(PeriodIntervalType, "12");
                        }
                        else
                        {
                            PeriodInterval.Text = taskInfo.PeriodIntervalMinute.ToString();
                            ControlUtils.SelectListItems(PeriodIntervalType, "1");
                        }

                        Description.Text = taskInfo.Description;

                        if (_serviceType == EServiceType.Create)
                        {
                            var taskCreateInfo = new TaskCreateInfo(taskInfo.ServiceParameters);
                            if (taskCreateInfo.IsCreateAll)
                            {
                                foreach (ListItem item in CreateChannelIDCollection.Items)
                                {
                                    item.Selected = true;
                                }
                                CreateIsCreateAll.Checked = true;
                            }
                            else
                            {
                                var channelIdList = TranslateUtils.StringCollectionToStringList(taskCreateInfo.ChannelIDCollection);
                                ControlUtils.SelectListItems(CreateChannelIDCollection, channelIdList);
                                CreateIsCreateAll.Checked = false;
                            }
                            var createTypeArrayList = TranslateUtils.StringCollectionToStringList(taskCreateInfo.CreateTypes);
                            foreach (ListItem item in CreateCreateTypes.Items)
                            {
                                if (createTypeArrayList.Contains(item.Value))
                                {
                                    item.Selected = true;
                                }
                                else
                                {
                                    item.Selected = false;
                                }
                            }
                        }
                        else if (_serviceType == EServiceType.Gather)
                        {
                            var taskGatherInfo = new TaskGatherInfo(taskInfo.ServiceParameters);
                            if (PublishmentSystemId != 0)
                            {
                                var webGatherNames      = TranslateUtils.StringCollectionToStringList(taskGatherInfo.WebGatherNames);
                                var databaseGatherNames = TranslateUtils.StringCollectionToStringList(taskGatherInfo.DatabaseGatherNames);
                                var fileGatherNames     = TranslateUtils.StringCollectionToStringList(taskGatherInfo.FileGatherNames);
                                foreach (ListItem item in GatherListBox.Items)
                                {
                                    var gatherType = EGatherTypeUtils.GetEnumType(item.Value.Split('_')[0]);
                                    var gatherName = item.Value.Substring(item.Value.Split('_')[0].Length + 1);
                                    if (gatherType == EGatherType.Web && webGatherNames.Contains(gatherName))
                                    {
                                        item.Selected = true;
                                    }
                                    else if (gatherType == EGatherType.Database && databaseGatherNames.Contains(gatherName))
                                    {
                                        item.Selected = true;
                                    }
                                    else if (gatherType == EGatherType.File && fileGatherNames.Contains(gatherName))
                                    {
                                        item.Selected = true;
                                    }
                                }
                            }
                            else
                            {
                                var publishmentSystemIdList = TranslateUtils.StringCollectionToStringList(taskGatherInfo.PublishmentSystemIDCollection);
                                ControlUtils.SelectListItems(GatherListBox, publishmentSystemIdList);
                            }
                        }
                        else if (_serviceType == EServiceType.Backup)
                        {
                            var taskBackupInfo = new TaskBackupInfo(taskInfo.ServiceParameters);

                            if (taskInfo.PublishmentSystemID == 0)
                            {
                                if (taskBackupInfo.IsBackupAll)
                                {
                                    foreach (ListItem item in BackupPublishmentSystemIDCollection.Items)
                                    {
                                        item.Selected = true;
                                    }
                                    BackupIsBackupAll.Checked = true;
                                }
                                else
                                {
                                    var publishmentSystemIdList = TranslateUtils.StringCollectionToStringList(taskBackupInfo.PublishmentSystemIDCollection);
                                    ControlUtils.SelectListItems(BackupPublishmentSystemIDCollection, publishmentSystemIdList);
                                    BackupIsBackupAll.Checked = false;
                                }
                            }
                            else
                            {
                                ControlUtils.SelectListItems(BackupPublishmentSystemIDCollection, taskInfo.PublishmentSystemID.ToString());
                            }

                            ControlUtils.SelectListItems(BackupType, EBackupTypeUtils.GetValue(taskBackupInfo.BackupType));
                        }
                    }
                }

                FrequencyType_SelectedIndexChanged(null, EventArgs.Empty);
            }
        }
Ejemplo n.º 13
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            var isChanged = false;

            var serviceParamters = new ExtendedAttributes();

            if (_serviceType == EServiceType.Create)
            {
                var taskCreateInfo = new TaskCreateInfo(string.Empty);
                taskCreateInfo.IsCreateAll         = CreateIsCreateAll.Checked;
                taskCreateInfo.ChannelIDCollection = TranslateUtils.ObjectCollectionToString(ControlUtils.GetSelectedListControlValueArrayList(CreateChannelIDCollection));
                taskCreateInfo.CreateTypes         = TranslateUtils.ObjectCollectionToString(ControlUtils.GetSelectedListControlValueArrayList(CreateCreateTypes));
                serviceParamters = taskCreateInfo;
            }
            else if (_serviceType == EServiceType.Gather)
            {
                var taskGatherInfo = new TaskGatherInfo(string.Empty);
                if (PublishmentSystemId != 0)
                {
                    var webGatherNames      = new ArrayList();
                    var databaseGatherNames = new ArrayList();
                    var fileGatherNames     = new ArrayList();
                    foreach (ListItem item in GatherListBox.Items)
                    {
                        if (item.Selected)
                        {
                            var gatherType = EGatherTypeUtils.GetEnumType(item.Value.Split('_')[0]);
                            var gatherName = item.Value.Substring(item.Value.Split('_')[0].Length + 1);
                            if (gatherType == EGatherType.Web && !webGatherNames.Contains(gatherName))
                            {
                                webGatherNames.Add(gatherName);
                            }
                            else if (gatherType == EGatherType.Database && !databaseGatherNames.Contains(gatherName))
                            {
                                databaseGatherNames.Add(gatherName);
                            }
                            else if (gatherType == EGatherType.File && !fileGatherNames.Contains(gatherName))
                            {
                                fileGatherNames.Add(gatherName);
                            }
                        }
                    }
                    taskGatherInfo.WebGatherNames      = TranslateUtils.ObjectCollectionToString(webGatherNames);
                    taskGatherInfo.DatabaseGatherNames = TranslateUtils.ObjectCollectionToString(databaseGatherNames);
                    taskGatherInfo.FileGatherNames     = TranslateUtils.ObjectCollectionToString(fileGatherNames);
                }
                else
                {
                    taskGatherInfo.PublishmentSystemIDCollection = TranslateUtils.ObjectCollectionToString(ControlUtils.GetSelectedListControlValueArrayList(GatherListBox));
                }
                serviceParamters = taskGatherInfo;
            }
            else if (_serviceType == EServiceType.Backup)
            {
                var taskBackupInfo = new TaskBackupInfo(string.Empty);
                taskBackupInfo.BackupType  = EBackupTypeUtils.GetEnumType(BackupType.SelectedValue);
                taskBackupInfo.IsBackupAll = BackupIsBackupAll.Checked;
                taskBackupInfo.PublishmentSystemIDCollection = TranslateUtils.ObjectCollectionToString(ControlUtils.GetSelectedListControlValueArrayList(BackupPublishmentSystemIDCollection));
                serviceParamters = taskBackupInfo;
            }

            if (Body.IsQueryExists("TaskID"))
            {
                try
                {
                    var taskId   = Body.GetQueryInt("TaskID");
                    var taskInfo = DataProvider.TaskDao.GetTaskInfo(taskId);
                    taskInfo.FrequencyType = EFrequencyTypeUtils.GetEnumType(FrequencyType.SelectedValue);
                    if (taskInfo.FrequencyType == EFrequencyType.Period)
                    {
                        taskInfo.PeriodIntervalMinute = TranslateUtils.ToInt(PeriodInterval.Text) * TranslateUtils.ToInt(PeriodIntervalType.SelectedValue);
                    }
                    else if (taskInfo.FrequencyType != EFrequencyType.JustInTime)
                    {
                        taskInfo.StartDay     = TranslateUtils.ToInt(StartDay.SelectedValue);
                        taskInfo.StartWeekday = TranslateUtils.ToInt(StartWeekday.SelectedValue);
                        taskInfo.StartHour    = TranslateUtils.ToInt(StartHour.SelectedValue);
                    }
                    taskInfo.Description       = Description.Text;
                    taskInfo.ServiceParameters = serviceParamters.ToString();

                    DataProvider.TaskDao.Update(taskInfo);

                    Body.AddSiteLog(PublishmentSystemId, $"修改{EServiceTypeUtils.GetText(taskInfo.ServiceType)}任务", $"任务名称:{taskInfo.TaskName}");

                    SuccessMessage("任务修改成功!");
                    isChanged = true;
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "任务修改失败!");
                }
            }
            else
            {
                if (DataProvider.TaskDao.IsExists(TaskName.Text))
                {
                    FailMessage("任务添加失败,任务名称已存在!");
                }
                else
                {
                    try
                    {
                        var taskInfo = new TaskInfo();
                        taskInfo.TaskName            = TaskName.Text;
                        taskInfo.PublishmentSystemID = PublishmentSystemId;
                        taskInfo.ServiceType         = _serviceType;
                        taskInfo.FrequencyType       = EFrequencyTypeUtils.GetEnumType(FrequencyType.SelectedValue);
                        if (taskInfo.FrequencyType == EFrequencyType.Period)
                        {
                            taskInfo.PeriodIntervalMinute = TranslateUtils.ToInt(PeriodInterval.Text) * TranslateUtils.ToInt(PeriodIntervalType.SelectedValue);
                        }
                        else if (taskInfo.FrequencyType != EFrequencyType.JustInTime)
                        {
                            taskInfo.StartDay     = TranslateUtils.ToInt(StartDay.SelectedValue);
                            taskInfo.StartWeekday = TranslateUtils.ToInt(StartWeekday.SelectedValue);
                            taskInfo.StartHour    = TranslateUtils.ToInt(StartHour.SelectedValue);
                        }
                        taskInfo.Description = Description.Text;

                        taskInfo.ServiceParameters = serviceParamters.ToString();

                        taskInfo.IsEnabled       = true;
                        taskInfo.AddDate         = DateTime.Now;
                        taskInfo.OnlyOnceDate    = DateUtils.SqlMinValue;
                        taskInfo.LastExecuteDate = DateUtils.SqlMinValue;

                        DataProvider.TaskDao.Insert(taskInfo);

                        Body.AddSiteLog(PublishmentSystemId, $"添加{EServiceTypeUtils.GetText(taskInfo.ServiceType)}任务", $"任务名称:{taskInfo.TaskName}");

                        SuccessMessage("任务添加成功!");
                        isChanged = true;
                    }
                    catch (Exception ex)
                    {
                        FailMessage(ex, "任务添加失败!");
                    }
                }
            }

            if (isChanged)
            {
                PageUtils.CloseModalPageAndRedirect(Page, PageTask.GetRedirectUrl(PublishmentSystemId, _serviceType));
            }
        }