using ExportMap.cs; using ExportMap.Models; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using System.IO; using System.Diagnostics; using System.Threading; namespace ExportMap.Controllers { public class TBController : ApiController { [HttpGet] public ResponseMsg CreateMpt(string path, string token) { try { if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(token)) return ResponseMsg.fail("path和token参数不能为空"); if (!ExportUtil.VerifyToken(token)) return ResponseMsg.fail("令牌无效"); if (!Directory.Exists(path)) return ResponseMsg.fail("文件路径不存在"); string err = null; string rs = TBUtils.CreateMpt(path, ref err); if (string.IsNullOrEmpty(rs)) return ResponseMsg.fail(null == err ? "失败" : err); return ResponseMsg.success("成功", rs, 1); } catch (Exception ex) { LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); return ResponseMsg.fail(ex.Message); } } [HttpGet] // http://localhost/ExportMap/TB/Test public ResponseMsg Test() { try { Stopwatch sw = new Stopwatch(); sw.Start(); string err = null; bool rs = TBUtils.Test(ref err); sw.Stop(); return ResponseMsg.success((rs ? "成功" : "失败") + ",耗时:" + sw.ElapsedMilliseconds / 1000.0 + " s", rs.ToString()); } catch (Exception ex) { LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); return ResponseMsg.fail(ex.Message); } } [HttpGet] // http://localhost/ExportMap/TB/Wait?seconds=10 public ResponseMsg Wait(long seconds) { try { Stopwatch sw = new Stopwatch(); sw.Start(); Thread.Sleep(new TimeSpan(seconds * 10 * 1000 * 1000)); sw.Stop(); return ResponseMsg.success("成功", "耗时:" + sw.ElapsedMilliseconds / 1000.0 + " s"); } catch (Exception ex) { LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); return ResponseMsg.fail(ex.Message); } } } }