管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2022-12-21 b93b3a846468f0031a49d7689b645b894268f787
ExportMap/cs/ExportUtil.cs
@@ -1,10 +1,14 @@
using LFServer.Models;
using ExportMap.cs;
using LFServer.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
namespace LFServer.cs
@@ -69,13 +73,24 @@
        }
        /// <summary>
        /// 获取出图目录
        /// 获取下载目录
        /// </summary>
        public static string ExportFolder
        public static string DownloadFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["exportFolder"];
                return ConfigurationManager.AppSettings["downloadFolder"];
            }
        }
        /// <summary>
        /// 后台服务地址
        /// </summary>
        public static string LFServer
        {
            get
            {
                return ConfigurationManager.AppSettings["lfServer"];
            }
        }
@@ -84,7 +99,7 @@
        /// </summary>
        public static string GetExportSubFolder()
        {
            string root = ExportFolder;
            string root = DownloadFolder;
            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
@@ -146,10 +161,10 @@
                string info = so.ReadToEnd();
                str = se.ReadToEnd();
                if (p.HasExited == false)
                {
                    p.Kill();
                }
                if (!string.IsNullOrEmpty(info)) LogOut.Debug(info);
                if (!string.IsNullOrEmpty(str)) LogOut.Error(str);
                if (p.HasExited == false) p.Kill();
                si.Close();
                so.Close();
@@ -158,6 +173,7 @@
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.StackTrace);
                str = ex.Message;
            }
@@ -168,8 +184,9 @@
        /// 生成
        /// </summary>
        /// <param name="args">出图参数</param>
        /// <param name="err">错误信息</param>
        /// <returns>图片路径</returns>
        public static string Generate(ExportArgs args)
        public static string Generate(ExportArgs args, ref string err)
        {
            string date = DateStr;
            string sub = GetExportSubFolder();
@@ -180,7 +197,7 @@
            args.SetDefault();
            CreateTemplate(args);
            string info = ExecPython(PyFile, qgz, args.qpt);
            err = ExecPython(PyFile, qgz, args.qpt);
            string qptFile = Path.Combine(SourcesPath, args.qpt);
            if (File.Exists(qptFile))
@@ -188,7 +205,10 @@
                File.Delete(qptFile);
            }
            return args.imgPath;
            string imgPath = Path.Combine(DownloadFolder, args.imgPath);
            bool flag = File.Exists(imgPath);
            return flag ? args.imgPath : null;
        }
        /// <summary>
@@ -197,7 +217,7 @@
        /// <param name="args">出图参数</param>
        public static void CreateTemplate(ExportArgs args)
        {
            string imgPath = Path.Combine(ExportFolder, args.imgPath);
            string imgPath = Path.Combine(DownloadFolder, args.imgPath);
            string templateFile = Path.Combine(SourcesPath, "Template.qpt");
            string qptFile = Path.Combine(SourcesPath, args.qpt);
            if (File.Exists(qptFile))
@@ -209,6 +229,7 @@
            xml = xml
                .Replace("{dpi}", args.dpi.ToString())
                .Replace("{title}", args.title)
                .Replace("{sourcesPath}", SourcesPath)
                .Replace("{rotation}", args.rotation.ToString())
                .Replace("{xmin}", args.xmin.ToString())
                .Replace("{ymin}", args.ymin.ToString())
@@ -223,5 +244,52 @@
            File.WriteAllText(qptFile, xml);
        }
        /// <summary>
        /// 验证令牌
        /// </summary>
        /// <param name="token">令牌</param>
        /// <returns>是/否有效</returns>
        public static bool VerifyToken(string token)
        {
            try
            {
                string url = LFServer + "/sign/check?token=" + token.Trim();
                string json = GetData(url);
                if (string.IsNullOrWhiteSpace(json))
                {
                    return false;
                }
                ResponseMsg<bool> rm = JsonConvert.DeserializeObject<ResponseMsg<bool>>(json);
                return rm != null && rm.code == 200 && rm.result;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// Get获取数据
        /// </summary>
        /// <param name="url">URL</param>
        /// <returns>数据</returns>
        public static string GetData(string url)
        {
            Uri uri = new Uri(url);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "GET";
            request.ContentType = "application/x-www-form-urlencoded";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string str = reader.ReadToEnd();
            reader.Close();
            return str;
        }
    }
}