VerController.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using ProjectManagementSystem.Common.Config;
  2. using ProjectManagementSystem.WebApi.Filters;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Net.Http;
  9. using System.Net.Http.Headers;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Web.Http;
  13. using System.Web.Http.Description;
  14. namespace ProjectManagementSystem.WebApi.Controller
  15. {
  16. [GlobalActionFilter]
  17. [ApiExplorerSettings(IgnoreApi = true)]
  18. /// <summary>
  19. /// 版本信息和提供自动更新下载
  20. /// </summary>
  21. public class VerController : ApiController
  22. {
  23. [HttpGet]
  24. public HttpResponseMessage PmsXml()
  25. {
  26. try
  27. {
  28. string currPath = ExcelConfig.Instance.CurrentPath;
  29. string dataFile = Path.Combine(currPath, "pms.xml");
  30. string reuslt = File.ReadAllText(dataFile, System.Text.Encoding.UTF8);
  31. var response = new HttpResponseMessage()
  32. {
  33. Content = new StringContent(reuslt, System.Text.Encoding.UTF8, "text/xml")
  34. };
  35. return response;
  36. }
  37. catch (Exception ex)
  38. {
  39. return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message);
  40. }
  41. }
  42. [HttpGet]
  43. public HttpResponseMessage PmsZip()
  44. {
  45. try
  46. {
  47. string currPath = ExcelConfig.Instance.CurrentPath;
  48. string dataFile = Path.Combine(currPath, "pms.zip");
  49. var stream = new FileStream(dataFile, FileMode.Open);
  50. HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
  51. response.Content = new StreamContent(stream);
  52. response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
  53. response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
  54. {
  55. FileName = "pms.zip"
  56. };
  57. return response;
  58. }
  59. catch (Exception ex)
  60. {
  61. return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message);
  62. }
  63. }
  64. }
  65. }