218 lines
8.4 KiB
C#
218 lines
8.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Http;
|
||
using System.Web.Http;
|
||
using System.Web.Http.Description;
|
||
using Newtonsoft.Json;
|
||
using HZQR.Common;
|
||
|
||
namespace CodeBuilderApi.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 文件操作相关接口
|
||
/// </summary>
|
||
public class FileController : BaseController
|
||
{
|
||
#region 方法 -> 保存文件
|
||
/// <summary>
|
||
/// 保存文件
|
||
/// </summary>
|
||
/// <param name="FileParams">保存文件入参模型</param>
|
||
/// <returns></returns>
|
||
[Route("File/SaveFile")]
|
||
[AcceptVerbs("POST")]
|
||
[ResponseType(typeof(Models.JsonMsg<object>))]
|
||
public IHttpActionResult SaveFile(Model.FileParamsModel FileParams)
|
||
{
|
||
string Parameter = "入参信息:" + JsonConvert.SerializeObject(FileParams);
|
||
try
|
||
{
|
||
string resMsg = "";
|
||
|
||
bool Flag = CommonHelper.SaveFile(FileParams.fileDir, FileParams.fileName, FileParams.fileText, ref resMsg, FileParams.postUrl);
|
||
if (Flag)
|
||
{
|
||
return Ok(Method.Common.ReturnJson(100, "操作成功"));
|
||
}
|
||
|
||
return Ok(Method.Common.ReturnJson(999, "保存失败!" + resMsg));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//事务回滚
|
||
transaction.Rollback();
|
||
LogUtil.WriteLog(null, "保存失败!失败原因:" + ex.Message + "\r\n" + Parameter,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_GetSaveFile");
|
||
return Ok(Method.Common.ReturnJson(999, "保存失败!" + ex.Message));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 复制文件夹
|
||
/// <summary>
|
||
/// 复制文件夹
|
||
/// </summary>
|
||
/// <param name="srcDir">原文件夹路径</param>
|
||
/// <param name="destDir">目标文件夹路径</param>
|
||
/// <param name="CoverFile">是否覆盖目标文件</param>
|
||
/// <returns></returns>
|
||
[Route("File/CopyFilesAndDirs")]
|
||
[AcceptVerbs("GET")]
|
||
[ResponseType(typeof(Models.JsonMsg<object>))]
|
||
public IHttpActionResult CopyFilesAndDirs(string srcDir, string destDir, bool CoverFile)
|
||
{
|
||
string Parameter = "入参信息:" + srcDir + "," + destDir + "," + CoverFile + "";
|
||
try
|
||
{
|
||
CommonHelper.CopyFilesAndDirs(srcDir, destDir, CoverFile);
|
||
|
||
return Ok(Method.Common.ReturnJson(100, "操作成功"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//事务回滚
|
||
transaction.Rollback();
|
||
LogUtil.WriteLog(null, "复制失败!失败原因:" + ex.Message + "\r\n" + Parameter,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_CopyFilesAndDirs");
|
||
return Ok(Method.Common.ReturnJson(999, "复制失败!" + ex.Message));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 删除指定服务器下文件
|
||
/// <summary>
|
||
/// 删除指定服务器下文件
|
||
/// </summary>
|
||
/// <param name="FileParams">文件入参模型</param>
|
||
/// <returns></returns>
|
||
[Route("File/DeleteFile")]
|
||
[AcceptVerbs("POST")]
|
||
[ResponseType(typeof(Models.JsonMsg<object>))]
|
||
public IHttpActionResult DeleteFile(Model.FileParamsModel FileParams)
|
||
{
|
||
string Parameter = "入参信息:" + JsonConvert.SerializeObject(FileParams);
|
||
try
|
||
{
|
||
string resMsg = "";
|
||
|
||
bool Flag = CommonHelper.DeleteFile(FileParams.fileDir, FileParams.fileName,
|
||
FileParams.fileText, ref resMsg, FileParams.postUrl);
|
||
if (Flag)
|
||
{
|
||
return Ok(Method.Common.ReturnJson(100, "操作成功"));
|
||
}
|
||
|
||
return Ok(Method.Common.ReturnJson(999, "删除失败!" + resMsg));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
transaction.Rollback();
|
||
LogUtil.WriteLog(null, "删除失败!失败原因:" + ex.Message + "\r\n" + Parameter,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_DeleteFile");
|
||
return Ok(Method.Common.ReturnJson(999, "删除失败!" + ex.Message));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 移动指定服务器下文件或文件夹
|
||
/// <summary>
|
||
/// 移动指定服务器下文件
|
||
/// </summary>
|
||
/// <param name="MoveFileParams">移动指定服务器下文件或文件夹方法入参模型。</param>
|
||
/// <returns></returns>
|
||
[Route("File/MoveFile")]
|
||
[AcceptVerbs("POST")]
|
||
[ResponseType(typeof(Models.JsonMsg<object>))]
|
||
public IHttpActionResult MoveFile(Model.MoveFileParamsModel MoveFileParams)
|
||
{
|
||
string Parameter = "入参信息:" + JsonConvert.SerializeObject(MoveFileParams);
|
||
try
|
||
{
|
||
string resMsg = "";
|
||
|
||
bool Flag = CommonHelper.MoveDirectory(MoveFileParams.fileDir, MoveFileParams.fileName, MoveFileParams.destDir,
|
||
MoveFileParams.DestFileName, MoveFileParams.coverDir, ref resMsg, MoveFileParams.postUrl);
|
||
if (Flag)
|
||
{
|
||
return Ok(Method.Common.ReturnJson(100, "操作成功"));
|
||
}
|
||
|
||
return Ok(Method.Common.ReturnJson(999, "移动失败!" + resMsg));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//事务回滚
|
||
transaction.Rollback();
|
||
LogUtil.WriteLog(null, "移动失败!失败原因:" + ex.Message + "\r\n" + Parameter,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_MoveFile");
|
||
return Ok(Method.Common.ReturnJson(999, "移动失败!" + ex.Message));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 获取文件夹下文件的内容
|
||
/// <summary>
|
||
/// 获取文件夹下文件的内容
|
||
/// </summary>
|
||
/// <param name="filePath">文件路径</param>
|
||
/// <returns></returns>
|
||
[Route("File/GetFileContent")]
|
||
[AcceptVerbs("GET")]
|
||
[ResponseType(typeof(Models.JsonMsg<List<Model.FilesReturnModel>>))]
|
||
public IHttpActionResult GetFileContent(string filePath)
|
||
{
|
||
string Parameter = "入参信息:文件路径" + filePath;
|
||
try
|
||
{
|
||
//获取文件
|
||
List<Model.FilesReturnModel> fileList = CommonHelper.GetFileContent(filePath);
|
||
return Ok(Models.JsonMsg<List<Model.FilesReturnModel>>.Success(fileList, 100, "获取成功"));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
transaction.Rollback();
|
||
LogUtil.WriteLog(null, "发布失败!获取原因:" + ex.Message + "\r\n" + Parameter,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_GetFileContent");
|
||
return Ok(Method.Common.ReturnJson(999, "获取失败" + ex.Message));
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 重新发布前端页面文件
|
||
/// <summary>
|
||
/// 重新发布前端页面文件
|
||
/// </summary>
|
||
/// <param name="flies"></param>
|
||
/// <returns></returns>
|
||
[Route("File/RepublishFiles")]
|
||
[AcceptVerbs("POST")]
|
||
[ResponseType(typeof(Models.JsonMsg<string>))]
|
||
public IHttpActionResult RepublishFiles(Model.FilesParamsModel flies)
|
||
{
|
||
string Parameter = "入参信息:" + JsonConvert.SerializeObject(flies);
|
||
try
|
||
{
|
||
//保存文件
|
||
if (CommonHelper.RepublishFiles(flies))
|
||
{
|
||
return Ok(Method.Common.ReturnJson(100, "发布成功"));
|
||
}
|
||
else
|
||
{
|
||
return Ok(Method.Common.ReturnJson(100, "发布失败"));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
transaction.Rollback();
|
||
LogUtil.WriteLog(null, "发布失败!获取原因:" + ex.Message + "\r\n" + Parameter,
|
||
DateTime.Now.ToString("yyyyMMdd") + "_RepublishFiles");
|
||
return Ok(Method.Common.ReturnJson(999, "发布失败" + ex.Message));
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|