using ExportMap.db;
|
using ExportMap.Models;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Web;
|
|
namespace ExportMap.cs
|
{
|
public class CommonUtils
|
{
|
/// <summary>
|
/// 删除文件
|
/// </summary>
|
public static List<int> DeleteFiles(XYZArgs args, ref string err)
|
{
|
List<SysPublish> pubs = PubDBHelper.SelectPublishs(args.ids);
|
if (null == pubs || pubs.Count == 0) return null;
|
|
List<int> list = new List<int>();
|
foreach (SysPublish pub in pubs)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(pub.url) || string.IsNullOrEmpty(pub.path)) continue;
|
|
String path = SGUtils.LFData + "\\" + pub.path.Replace("\\tileset.json", "");
|
if (pub.url.Contains("/SG/") || !Directory.Exists(path))
|
{
|
list.Add(pub.id);
|
continue;
|
}
|
|
Tools.DelPath(path);
|
list.Add(pub.id);
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
err = ex.Message;
|
}
|
}
|
|
return list;
|
}
|
|
/// <summary>
|
/// 删除任务
|
/// </summary>
|
public static List<int> DeleteTask(XYZArgs args, ref string err)
|
{
|
List<int> list = new List<int>();
|
try
|
{
|
List<SysTask> tasks = TaskDBHelper.SelectByIds(args.ids);
|
if (null == tasks || 0 == tasks.Count) return list;
|
|
string ip = Tools.GetLocalIP();
|
foreach (SysTask task in tasks)
|
{
|
if (ip != task.ip || task.status > 1 || task.pid < 1) continue;
|
|
task.status = 3;
|
task.update_user = args.userId;
|
TaskDBHelper.Update(task);
|
list.Add(task.id);
|
|
task.err = KillProcess(task.pid);
|
if (!string.IsNullOrEmpty(task.err))
|
{
|
TaskDBHelper.Update(task);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
|
err = ex.Message;
|
}
|
|
return list;
|
}
|
|
/// <summary>
|
/// 杀死进程
|
/// </summary>
|
public static string KillProcess(int processId)
|
{
|
List<string> list = new List<string>();
|
string cmd = string.Format("taskkill /f /t /pid {0}", processId);
|
list.Add(cmd);
|
|
return Tools.ExecCmd(list);
|
}
|
}
|
}
|