コード例 #1
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (HifFile.PostedFile != null && "" != HifFile.PostedFile.FileName)
            {
                var filePath = HifFile.PostedFile.FileName;
                if (!EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                {
                    FailMessage("必须上传Zip压缩文件");
                    return;
                }

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

                    HifFile.PostedFile.SaveAs(localFilePath);

                    var importObject = new ImportObject(SiteId, AuthRequest.AdminName);
                    importObject.ImportChannelsAndContentsByZipFile(TranslateUtils.ToInt(DdlParentChannelId.SelectedValue), localFilePath, TranslateUtils.ToBool(DdlIsOverride.SelectedValue));

                    AuthRequest.AddSiteLog(SiteId, "导入栏目");

                    LayerUtils.Close(Page);
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "导入栏目失败!");
                }
            }
        }
コード例 #2
0
ファイル: ModalChannelImport.cs プロジェクト: skotbenben/cms
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (myFile.PostedFile != null && "" != myFile.PostedFile.FileName)
            {
                var filePath = myFile.PostedFile.FileName;
                if (!EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                {
                    FailMessage("必须上传Zip压缩文件");
                    return;
                }

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

                    myFile.PostedFile.SaveAs(localFilePath);

                    var importObject = new ImportObject(PublishmentSystemId);
                    importObject.ImportChannelsAndContentsByZipFile(TranslateUtils.ToInt(ParentNodeID.SelectedValue), localFilePath, TranslateUtils.ToBool(IsOverride.SelectedValue));

                    Body.AddSiteLog(PublishmentSystemId, "导入栏目");

                    PageUtils.CloseModalPage(Page);
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "导入栏目失败!");
                }
            }
        }
コード例 #3
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (myFile.PostedFile != null && "" != myFile.PostedFile.FileName)
            {
                var filePath = myFile.PostedFile.FileName;
                if (!EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                {
                    FailMessage("必须上传Zip压缩文件");
                    return;
                }

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

                    myFile.PostedFile.SaveAs(localFilePath);

                    ImportObject.ImportTableStyleByZipFile(_tableStyle, _tableName, _relatedIdentity, localFilePath);

                    Body.AddSiteLog(PublishmentSystemId, "导入表单显示样式", $"类型:{ETableStyleUtils.GetText(_tableStyle)}");

                    PageUtils.CloseModalPage(Page);
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "导入表样式失败!");
                }
            }
        }
コード例 #4
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (HifMyFile.PostedFile != null && "" != HifMyFile.PostedFile.FileName)
            {
                var filePath = HifMyFile.PostedFile.FileName;
                if (!EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                {
                    FailMessage("必须上传Zip压缩文件");
                    return;
                }

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

                    HifMyFile.PostedFile.SaveAs(localFilePath);

                    ImportObject.ImportTableStyleByZipFile(_tableName, _relatedIdentity, localFilePath);

                    AuthRequest.AddSiteLog(SiteId, "导入表单显示样式");

                    LayerUtils.Close(Page);
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "导入表样式失败!");
                }
            }
        }
コード例 #5
0
ファイル: SiteTemplateManager.cs プロジェクト: zerojuls/cms-3
        public List <string> GetZipSiteTemplateList()
        {
            var list = new List <string>();

            foreach (var fileName in DirectoryUtils.GetFileNames(_rootPath))
            {
                if (EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(fileName)))
                {
                    list.Add(fileName);
                }
            }
            return(list);
        }
コード例 #6
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId       = request.GetPostInt("siteId");
                var guid         = request.GetPostString("guid");
                var specialId    = request.GetPostInt("specialId");
                var isEditOnly   = request.GetPostBool("isEditOnly");
                var isUploadOnly = request.GetPostBool("isUploadOnly");
                var title        = request.GetPostString("title");
                var url          = request.GetPostString("url");
                var fileNames    = TranslateUtils.StringCollectionToStringList(request.GetPostString("fileNames"));
                var siteInfo     = SiteManager.GetSiteInfo(siteId);

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSitePermissions(siteId,
                                                                     ConfigManager.SitePermissions.Specials))
                {
                    return(Unauthorized());
                }

                if (specialId > 0 && isEditOnly)
                {
                    var specialInfo      = SpecialManager.GetSpecialInfo(siteId, specialId);
                    var oldDirectoryPath = string.Empty;
                    var newDirectoryPath = string.Empty;

                    if (specialInfo.Title != title && DataProvider.SpecialDao.IsTitleExists(siteId, title))
                    {
                        return(BadRequest("专题修改失败,专题名称已存在!"));
                    }
                    if (specialInfo.Url != url)
                    {
                        if (DataProvider.SpecialDao.IsUrlExists(siteId, url))
                        {
                            return(BadRequest("专题修改失败,专题访问地址已存在!"));
                        }

                        oldDirectoryPath = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url);
                        newDirectoryPath = SpecialManager.GetSpecialDirectoryPath(siteInfo, url);
                    }

                    specialInfo.Title = title;
                    specialInfo.Url   = url;
                    DataProvider.SpecialDao.Update(specialInfo);

                    if (oldDirectoryPath != newDirectoryPath)
                    {
                        DirectoryUtils.MoveDirectory(oldDirectoryPath, newDirectoryPath, true);
                    }
                }
                else if (specialId > 0 && isUploadOnly)
                {
                    var specialInfo = SpecialManager.GetSpecialInfo(siteId, specialId);

                    var directoryPath    = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url);
                    var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                    DirectoryUtils.CreateDirectoryIfNotExists(srcDirectoryPath);

                    var uploadDirectoryPath = PathUtils.GetTemporaryFilesPath(guid);
                    foreach (var filePath in DirectoryUtils.GetFilePaths(uploadDirectoryPath))
                    {
                        var fileName = PathUtils.GetFileName(filePath);
                        if (!StringUtils.ContainsIgnoreCase(fileNames, fileName))
                        {
                            continue;
                        }

                        if (EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                        {
                            ZipUtils.ExtractZip(filePath, srcDirectoryPath);
                        }
                        else
                        {
                            FileUtils.MoveFile(filePath, PathUtils.Combine(srcDirectoryPath, fileName), true);
                        }
                    }

                    DirectoryUtils.Copy(srcDirectoryPath, directoryPath);
                }
                else if (specialId == 0)
                {
                    if (DataProvider.SpecialDao.IsTitleExists(siteId, title))
                    {
                        return(BadRequest("专题添加失败,专题名称已存在!"));
                    }
                    if (DataProvider.SpecialDao.IsUrlExists(siteId, url))
                    {
                        return(BadRequest("专题添加失败,专题访问地址已存在!"));
                    }

                    var directoryPath    = SpecialManager.GetSpecialDirectoryPath(siteInfo, url);
                    var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                    DirectoryUtils.CreateDirectoryIfNotExists(srcDirectoryPath);

                    var uploadDirectoryPath = PathUtils.GetTemporaryFilesPath(guid);
                    foreach (var filePath in DirectoryUtils.GetFilePaths(uploadDirectoryPath))
                    {
                        var fileName = PathUtils.GetFileName(filePath);
                        if (!StringUtils.ContainsIgnoreCase(fileNames, fileName))
                        {
                            continue;
                        }

                        if (EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                        {
                            ZipUtils.ExtractZip(filePath, srcDirectoryPath);
                        }
                        else
                        {
                            FileUtils.MoveFile(filePath, PathUtils.Combine(srcDirectoryPath, fileName), true);
                        }
                    }

                    DirectoryUtils.Copy(srcDirectoryPath, directoryPath);

                    specialId = DataProvider.SpecialDao.Insert(new SpecialInfo
                    {
                        Id      = 0,
                        SiteId  = siteId,
                        Title   = title,
                        Url     = url,
                        AddDate = DateTime.Now
                    });

                    request.AddSiteLog(siteId, "新建专题", $"专题名称:{title}");
                }

                CreateManager.CreateSpecial(siteId, specialId);

                return(Ok(new
                {
                    Value = specialId
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #7
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.IsZip(PathUtils.GetExtension(filePath)))
                            {
                                FailMessage("必须上传Zip压缩文件");
                                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, "数据恢复失败!");
                        }
                    }
                }
            }
        }