using Admin.NET.Application.CommonHelper;
|
using Admin.NET.Application.Entity;
|
using Furion.DatabaseAccessor;
|
|
namespace Admin.NET.Application;
|
/// <summary>
|
/// pda服务
|
/// </summary>
|
[ApiDescriptionSettings(ApplicationConst.PdaUpdateGroup, Order = 100)]
|
public class PdaUpdateService : IDynamicApiController, ITransient
|
{
|
|
public PdaUpdateService(
|
)
|
{
|
}
|
|
/// <summary>
|
/// PDA程序更新文件地址
|
/// </summary>
|
/// <returns></returns>
|
/// string
|
[HttpGet]
|
[ApiDescriptionSettings(Name = "GetUpdate")]
|
[Description("PdaUpdate/GetUpdate")]
|
[AllowAnonymous]
|
public async Task<string> GetUpdate()
|
{
|
/** ly-0729*/
|
var savePath = Path.Combine(App.HostEnvironment.ContentRootPath + "wwwroot\\", "PDAUpdate");
|
if (!Directory.Exists(savePath))
|
{
|
throw Oops.Oh("文件夹不存在");
|
}
|
List<FileInfo> lstfiles = await GetFile(savePath, ".wgt");
|
//Regex rxNonDigits = new Regex(@"[^\d]+");
|
//long i = 0;
|
FileInfo fileInfo = null;
|
|
foreach (var item in lstfiles)
|
{
|
//string str = rxNonDigits.Replace(item.Name, "");
|
//long j = Convert.ToInt64(rxNonDigits.Replace(item.Name, ""));
|
//if (i < j)
|
//{
|
// fileInfo = item;
|
// i = j;
|
//}
|
if (fileInfo == null)
|
{
|
fileInfo = item;
|
}
|
else
|
{
|
//比较两个文件的生成时间,取生成比较晚的
|
if (item.CreationTimeUtc.Subtract(fileInfo.CreationTimeUtc).TotalSeconds > 0)
|
{
|
fileInfo = item;
|
}
|
}
|
}
|
if (fileInfo == null)
|
{
|
throw Oops.Oh("没有要更新的文件");
|
}
|
return GetFilePreviewURL() + "PDAUpdate/" + fileInfo.Name;
|
|
}
|
|
/// <summary>
|
/// 获取文件预览地址
|
/// </summary>
|
/// <returns></returns>
|
private static string GetFilePreviewURL()
|
{
|
try
|
{
|
//App.Configuration.GetSection("IpRateLimiting")
|
return App.Configuration["AppSettings:FilePreviewUrl"].ToString();
|
}
|
catch
|
{
|
return string.Empty;
|
}
|
}
|
|
/// <summary>
|
/// 获取文件夹下的指定后缀的所有文件
|
/// </summary>
|
/// <param name="path">文件路径</param>
|
/// <param name="ExtName">文件后缀</param>
|
/// <returns></returns>
|
[NonAction]
|
public async Task<List<FileInfo>> GetFile(string path, string ExtName)
|
{
|
|
try
|
{
|
List<FileInfo> lst = new List<FileInfo>();
|
string[] dir = Directory.GetDirectories(path);// 文件夹列表
|
DirectoryInfo directoryInfo = new DirectoryInfo(path);
|
FileInfo[] files = directoryInfo.GetFiles();
|
if (files.Length != 0 || dir.Length != 0) // 当前目录文件或文件夹不能为空
|
{
|
foreach (FileInfo f in files)
|
{
|
if (ExtName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
|
{
|
lst.Add(f);
|
}
|
}
|
foreach (string d in dir)
|
{
|
await GetFile(d, ExtName);
|
}
|
}
|
return lst;
|
}
|
catch (Exception ex)
|
{
|
throw Oops.Oh(ex.Message);
|
}
|
}
|
|
|
}
|