From 093df84b78ebbf020fcb4f752b900925aac07565 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 07 九月 2023 11:07:48 +0800
Subject: [PATCH] 添加月球出图的操作逻辑代码

---
 MoonExp/cs/PostgreHelper.cs   |  188 +++++++++
 MoonExp/Models/ResponseMsg.cs |   49 ++
 MoonExp/Web.config            |   89 ++++
 MoonExp/Models/SysTask.cs     |   46 ++
 MoonExp/MoonExp.csproj        |   18 
 MoonExp/cs/ExportUtil.cs      |  248 +++++++++++++
 MoonExp/Models/ExportArgs.cs  |  136 +++++++
 MoonExp/cs/LogOut.cs          |  128 ++++++
 MoonExp/Models/XYZArgs.cs     |   86 ++++
 MoonExp/Tools.cs              |  131 ++++++
 10 files changed, 1,114 insertions(+), 5 deletions(-)

diff --git a/MoonExp/Models/ExportArgs.cs b/MoonExp/Models/ExportArgs.cs
new file mode 100644
index 0000000..3b64ffd
--- /dev/null
+++ b/MoonExp/Models/ExportArgs.cs
@@ -0,0 +1,136 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace MoonExp.Models
+{
+    /// <summary>
+    /// 鍑哄浘鍙傛暟
+    /// </summary>
+    public class ExportArgs
+    {
+        public ExportArgs() { }
+
+        public String token { set; get; }
+
+        /// <summary>
+        /// 鏍囬
+        /// </summary>
+        public String title { set; get; }
+
+        /// <summary>
+        /// 绾稿紶澶у皬
+        /// </summary>
+        public String pageSize { set; get; }
+
+        /// <summary>
+        /// 鐪佷唤
+        /// </summary>
+        public String province { set; get; }
+
+        /// <summary>
+        /// 姣斾緥灏�
+        /// </summary>
+        public String scale { set; get; }
+
+        /// <summary>
+        /// 鍒嗚鲸鐜囷紙鍙充笅瑙掓枃鏈級
+        /// </summary>
+        public String resolution { set; get; }
+
+        /// <summary>
+        /// 鍒跺浘鏃堕棿
+        /// </summary>
+        public String date { set; get; }
+
+        /// <summary>
+        /// 鍥惧眰
+        /// </summary>
+        public String layers { set; get; }
+
+        /// <summary>
+        /// 瀵煎嚭璺緞
+        /// </summary>
+        public String imgPath { set; get; }
+
+        /// <summary>
+        /// 鏃嬭浆瑙掑害
+        /// </summary>
+        public double rotation { set; get; }
+
+        /// <summary>
+        /// X鏈�灏�
+        /// </summary>
+        public double xmin { set; get; }
+
+        /// <summary>
+        /// Y鏈�灏�
+        /// </summary>
+        public double ymin { set; get; }
+
+        /// <summary>
+        /// Y鏈�澶�
+        /// </summary>
+        public double ymax { set; get; }
+
+        /// <summary>
+        /// X鏈�澶�
+        /// </summary>
+        public double xmax { set; get; }
+
+        /// <summary>
+        /// 鍑哄浘鍒嗚鲸鐜�
+        /// </summary>
+        public int dpi { set; get; }
+
+        /// <summary>
+        /// 妯℃澘鏂囦欢
+        /// </summary>
+        public String qpt { set; get; }
+
+        /// <summary>
+        /// 璁剧疆榛樿鍊�
+        /// </summary>
+        public void SetDefault()
+        {
+            if (string.IsNullOrWhiteSpace(title)) title = "绠¢亾鍩虹澶ф暟鎹钩鍙�";
+            if (string.IsNullOrWhiteSpace(province)) province = string.Empty;
+            if (string.IsNullOrWhiteSpace(scale)) scale = string.Empty;
+            if (string.IsNullOrWhiteSpace(resolution)) resolution = string.Empty;
+            if (string.IsNullOrWhiteSpace(date)) date = DateTime.Now.ToString("yyyy.MM.dd");
+
+            this.dpi = GetDpi(this.pageSize);
+        }
+
+        /// <summary>
+        /// 鑾峰彇DPI
+        /// </summary>
+        /// <param name="page">椤甸潰澶у皬</param>
+        /// <returns>DPI</returns>
+        public int GetDpi(string page)
+        {
+            if (string.IsNullOrWhiteSpace(page)) return 300;
+
+            switch (page.ToUpper())
+            {
+                case "A0":
+                    return 1200;
+                case "A1":
+                    return 850;
+                case "A2":
+                    return 600;
+                case "A3":
+                    return 424;
+                case "A4":
+                    return 300;
+                case "A5":
+                    return 212;
+                case "A6":
+                    return 150;
+                default:
+                    return 300;
+            }
+        }
+    }
+}
diff --git a/MoonExp/Models/ResponseMsg.cs b/MoonExp/Models/ResponseMsg.cs
new file mode 100644
index 0000000..9bcf486
--- /dev/null
+++ b/MoonExp/Models/ResponseMsg.cs
@@ -0,0 +1,49 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace MoonExp.Models
+{
+    public class ResponseMsg<T>
+    {
+        public ResponseMsg()
+        {
+            time = DateTime.Now.Ticks;
+        }
+
+        public ResponseMsg(int code)
+            : this()
+        {
+            this.code = code;
+        }
+
+        public int code { set; get; }
+
+        public String msg { set; get; }
+
+        public long count { set; get; }
+
+        public T result { set; get; }
+
+        public long time { set; get; }
+
+        public static ResponseMsg<T> success(String msg, T result, long count = 0)
+        {
+            ResponseMsg<T> rm = new ResponseMsg<T>(200);
+            rm.msg = msg;
+            rm.result = result;
+            rm.count = count;
+
+            return rm;
+        }
+
+        public static ResponseMsg<T> fail(String msg)
+        {
+            ResponseMsg<T> rm = new ResponseMsg<T>(500);
+            rm.msg = msg;
+
+            return rm;
+        }
+    }
+}
diff --git a/MoonExp/Models/SysTask.cs b/MoonExp/Models/SysTask.cs
new file mode 100644
index 0000000..bfc2abb
--- /dev/null
+++ b/MoonExp/Models/SysTask.cs
@@ -0,0 +1,46 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace MoonExp.Models
+{
+    public class SysTask
+    {
+        public int id { set; get; }
+
+        public string name { set; get; }
+
+        /// <summary>
+        /// 鐘舵�侊細0-鏈紑濮嬶紝1-杩涜涓紝2-姝e父缁撴潫锛�3-鐢ㄦ埛缁撴潫锛�4-杩愯鍑洪敊
+        /// </summary>
+        public int status { set; get; }
+
+        /// <summary>
+        /// 绫诲埆锛欴OM锛孌EM锛孧PT锛�3DML锛孋PT锛孊IM锛孡AS锛孫SGB锛孭NG
+        /// </summary>
+        public string type { set; get; }
+
+        public string descr { set; get; }
+
+        public string err { set; get; }
+
+        public string ip { set; get; }
+
+        public int pid { set; get; }
+
+        public string gids { set; get; }
+
+        public string depcode { set; get; }
+
+        public string dircode { set; get; }
+
+        public int create_user { set; get; }
+
+        public DateTime create_time { set; get; }
+
+        public int update_user { set; get; }
+
+        public DateTime update_time { set; get; }
+    }
+}
\ No newline at end of file
diff --git a/MoonExp/Models/XYZArgs.cs b/MoonExp/Models/XYZArgs.cs
new file mode 100644
index 0000000..49c23d9
--- /dev/null
+++ b/MoonExp/Models/XYZArgs.cs
@@ -0,0 +1,86 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace MoonExp.Models
+{
+    /// <summary>
+    /// XYZ鍙傛暟
+    /// </summary>
+    public class XYZArgs
+    {
+        public XYZArgs()
+        {
+            srids = new List<int>();
+            zs = new List<double>();
+            ids = new List<int>();
+            isNew = true;
+        }
+
+        /// <summary>
+        /// 浠ょ墝
+        /// </summary>
+        public string token { set; get; }
+
+        /// <summary>
+        /// 鍚嶇О
+        /// </summary>
+        public string name { set; get; }
+
+        /// <summary>
+        /// 鐢ㄦ埛ID
+        /// </summary>
+        public int userId { set; get; }
+
+        /// <summary>
+        /// 鍦板浘鏈�灏忕骇鍒�
+        /// </summary>
+        public int min { set; get; }
+
+        /// <summary>
+        /// 鍦板浘鏈�澶х骇鍒�
+        /// </summary>
+        public int max { set; get; }
+
+        /// <summary>
+        /// 鏃犳暟鎹�
+        /// </summary>
+        public int noData { set; get; }
+
+        /// <summary>
+        /// 鏁版嵁鐩綍缂栫爜
+        /// </summary>
+        public string dircode { set; get; }
+
+        /// <summary>
+        /// 鍗曚綅鐩綍缂栫爜
+        /// </summary>
+        public string depcode { set; get; }
+
+        /// <summary>
+        /// 鍏冩暟鎹甀D闆嗗悎
+        /// </summary>
+        public List<int> ids { set; get; }
+
+        /// <summary>
+        /// 鍗曚綋妯″瀷闆嗗悎
+        /// </summary>
+        public List<int> models { set; get; }
+
+        /// <summary>
+        /// 鏄�/鍚﹀叏鏂板彂甯�
+        /// </summary>
+        public bool isNew { set; get; }
+
+        /// <summary>
+        /// 鍧愭爣绯籌D闆嗗悎
+        /// </summary>
+        public List<int> srids { set; get; }
+
+        /// <summary>
+        /// 楂樺害鍋忕Щ閲�
+        /// </summary>
+        public List<double> zs { set; get; }
+    }
+}
diff --git a/MoonExp/MoonExp.csproj b/MoonExp/MoonExp.csproj
index 1b941c2..2de8452 100644
--- a/MoonExp/MoonExp.csproj
+++ b/MoonExp/MoonExp.csproj
@@ -38,7 +38,16 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="log4net4">
+      <HintPath>..\ExportMap\DLL\log4net4.dll</HintPath>
+    </Reference>
     <Reference Include="Microsoft.CSharp" />
+    <Reference Include="Mono.Security">
+      <HintPath>..\ExportMap\DLL\Mono.Security.dll</HintPath>
+    </Reference>
+    <Reference Include="Npgsql">
+      <HintPath>..\ExportMap\DLL\Npgsql.dll</HintPath>
+    </Reference>
     <Reference Include="System.Net.Http" />
     <Reference Include="System.Web.DynamicData" />
     <Reference Include="System.Web.Entity" />
@@ -77,10 +86,18 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="App_Start\WebApiConfig.cs" />
+    <Compile Include="cs\ExportUtil.cs" />
+    <Compile Include="cs\LogOut.cs" />
+    <Compile Include="cs\PostgreHelper.cs" />
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
+    <Compile Include="Models\ExportArgs.cs" />
+    <Compile Include="Models\ResponseMsg.cs" />
+    <Compile Include="Models\SysTask.cs" />
+    <Compile Include="Models\XYZArgs.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Tools.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="packages.config" />
@@ -88,7 +105,6 @@
   <ItemGroup>
     <Folder Include="App_Data\" />
     <Folder Include="Controllers\" />
-    <Folder Include="Models\" />
   </ItemGroup>
   <PropertyGroup>
     <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
diff --git a/MoonExp/Tools.cs b/MoonExp/Tools.cs
new file mode 100644
index 0000000..35748c4
--- /dev/null
+++ b/MoonExp/Tools.cs
@@ -0,0 +1,131 @@
+锘縰sing MoonExp.cs;
+using MoonExp.Models;
+using Npgsql;
+using System;
+using System.Collections.Generic;
+using System.Data.Common;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Web;
+
+namespace MoonExp
+{
+    public class Tools
+    {
+        /// <summary>
+        /// 鍩虹鐩綍
+        /// </summary>
+        public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
+
+        private static PostgreHelper _dbHelper;
+
+        /// <summary>
+        /// DB甯姪绫�
+        /// </summary>
+        public static PostgreHelper DBHelper
+        {
+            get
+            {
+                if (null == _dbHelper)
+                {
+                    _dbHelper = new PostgreHelper();
+                }
+
+                return _dbHelper;
+            }
+        }
+
+        /// <summary>
+        /// 鏍规嵁鍋滅墝鑾峰彇鐢ㄦ埛ID
+        /// </summary>
+        public static int SelectUserIdByToken(string token)
+        {
+            string sql = "select create_user from lf.sys_token where token=@token order by create_time desc limit 1;";
+            DbParameter dp1 = new NpgsqlParameter("@token", token);
+
+            object obj = DBHelper.GetScalar(sql, dp1);
+
+            return null == obj ? 0 : int.Parse(obj.ToString());
+        }
+
+        /// <summary>
+        /// 鎵цCMD
+        /// </summary>
+        /// <param name="cmd">鍛戒护琛�</param>
+        /// <param name="isPy">鏄惁涓篞GIS Py鑴氭湰</param>
+        /// <param name="isOut">鏄惁杈撳嚭閿欒</param>
+        /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
+        public static string ExecCmd(string cmd, bool isPy = false, bool isOut = false)
+        {
+            List<string> list = new List<string>();
+            if (isPy)
+            {
+                list.Add("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\"");
+                list.Add("\"C:\\Program Files\\QGIS 3.16\\bin\\qgis_process-qgis-ltr.bat\"");
+                //list.Add("\"C:\\Program Files\\QGIS 3.16\\bin\\python-qgis-ltr.bat\"");
+                //list.Add("exit()");
+            }
+            list.Add(cmd);
+
+            string str = ExecCmd(list, isOut);
+
+            return str;
+        }
+
+        /// <summary>
+        /// 鎵цCMD
+        /// </summary>
+        /// <param name="task">浠诲姟</param>
+        /// <param name="list">鍛戒护闆嗗悎</param>
+        /// <param name="isOut">鏄惁杈撳嚭閿欒</param>
+        /// <returns>鎵ц缁撴灉鎴栧嚭閿欎俊鎭�</returns>
+        public static string ExecCmd(List<string> list, bool isOut = false)
+        {
+            string str;
+            try
+            {
+                Process p = new Process();
+                p.StartInfo.FileName = "cmd.exe";
+                p.StartInfo.UseShellExecute = false;
+                p.StartInfo.CreateNoWindow = true;
+                //p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+                p.StartInfo.RedirectStandardInput = true;
+                p.StartInfo.RedirectStandardOutput = isOut;
+                p.StartInfo.RedirectStandardError = true;
+                p.Start();
+
+                StreamWriter si = p.StandardInput; // 鏍囧噯杈撳叆娴� 
+                StreamReader so = isOut ? p.StandardOutput : null; // 鏍囧噯杈撳嚭娴� 
+                StreamReader se = p.StandardError; // 鏍囧噯閿欒娴�
+
+                LogOut.Info("cmd = " + string.Join("锛�", list));
+                si.AutoFlush = true;
+                foreach (string cmd in list)
+                {
+                    si.WriteLine(cmd);
+                }
+                si.WriteLine("exit");
+
+                string info = null == so ? null : so.ReadToEnd();
+                str = se.ReadToEnd();
+
+                //if (!string.IsNullOrEmpty(info)) LogOut.Debug(info);
+                if (!string.IsNullOrEmpty(str) && !str.Contains("@jit(cache=True, nogil=True)")) LogOut.Error(str);
+                if (p.HasExited == false) p.Kill();
+
+                if (null != so) so.Close();
+                se.Close();
+                si.Close();
+                p.Close();
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                str = ex.Message;
+            }
+
+            return str;
+        }
+    }
+}
diff --git a/MoonExp/Web.config b/MoonExp/Web.config
index 5ce13da..544389a 100644
--- a/MoonExp/Web.config
+++ b/MoonExp/Web.config
@@ -1,21 +1,102 @@
 锘�<?xml version="1.0" encoding="utf-8"?>
-<!--
-  For more information on how to configure your ASP.NET application, please visit
-  http://go.microsoft.com/fwlink/?LinkId=301879
-  -->
 <configuration>
   <appSettings>
+    <!-- 鏈嶅姟鍦板潃 -->
+    <add key="moonServer" value="http://127.0.0.1:9000/MoonServer"/>
+    <!-- 涓嬭浇鐩綍 -->
+    <add key="downloadFolder" value="D:\Moon\download"/>
+    <!-- PG杩炴帴 -->
+    <add key="pgConn" value="Server=192.168.20.83;Port=5433;Database=moon;User Id=postgres;Password=Postgres!_14_moon;"/>
   </appSettings>
   <system.web>
     <compilation debug="true" targetFramework="4.5.2" />
     <httpRuntime targetFramework="4.5.2" />
   </system.web>
   <system.webServer>
+    <security>
+      <requestFiltering>
+        <!-- 1GB = 1073741824 -->
+        <requestLimits maxAllowedContentLength="2147483647"/>
+      </requestFiltering>
+    </security>
     <handlers>
       <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
       <remove name="OPTIONSVerbHandler" />
       <remove name="TRACEVerbHandler" />
       <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
     </handlers>
+    <staticContent>
+      <remove fileExtension=".wsv"/>
+      <mimeMap fileExtension=".wsv" mimeType="application/octet-stream"/>
+      <remove fileExtension=".czml"/>
+      <mimeMap fileExtension=".czml" mimeType="application/json"/>
+      <remove fileExtension=".glsl"/>
+      <mimeMap fileExtension=".glsl" mimeType="text/plain"/>
+      <remove fileExtension=".b3dm"/>
+      <mimeMap fileExtension=".b3dm" mimeType="application/octet-stream"/>
+      <remove fileExtension=".pnts"/>
+      <mimeMap fileExtension=".pnts" mimeType="application/octet-stream"/>
+      <remove fileExtension=".i3dm"/>
+      <mimeMap fileExtension=".i3dm" mimeType="application/octet-stream"/>
+      <remove fileExtension=".cmpt"/>
+      <mimeMap fileExtension=".cmpt" mimeType="application/octet-stream"/>
+      <remove fileExtension=".gltf"/>
+      <mimeMap fileExtension=".gltf" mimeType="model/gltf+json"/>
+      <remove fileExtension=".bgltf"/>
+      <mimeMap fileExtension=".bgltf" mimeType="model/gltf-binary"/>
+      <remove fileExtension=".glb"/>
+      <mimeMap fileExtension=".glb" mimeType="model/gltf-binary"/>
+      <remove fileExtension=".json"/>
+      <mimeMap fileExtension=".json" mimeType="application/json"/>
+      <remove fileExtension=".geojson"/>
+      <mimeMap fileExtension=".geojson" mimeType="application/json"/>
+      <remove fileExtension=".topojson"/>
+      <mimeMap fileExtension=".topojson" mimeType="application/json"/>
+      <remove fileExtension=".wasm"/>
+      <mimeMap fileExtension=".wasm" mimeType="application/wasm"/>
+      <remove fileExtension=".woff"/>
+      <mimeMap fileExtension=".woff" mimeType="application/font-woff"/>
+      <remove fileExtension=".woff2"/>
+      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2"/>
+      <remove fileExtension=".kml"/>
+      <mimeMap fileExtension=".kml" mimeType="application/vnd.google-earth.kml+xml"/>
+      <remove fileExtension=".kmz"/>
+      <mimeMap fileExtension=".kmz" mimeType="application/vnd.google-earth.kmz"/>
+      <remove fileExtension=".svg"/>
+      <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
+      <remove fileExtension=".terrain"/>
+      <mimeMap fileExtension=".terrain" mimeType="application/vnd.quantized-mesh"/>
+      <remove fileExtension=".ktx"/>
+      <mimeMap fileExtension=".ktx" mimeType="image/ktx"/>
+      <remove fileExtension=".crn"/>
+      <mimeMap fileExtension=".crn" mimeType="image/crn"/>
+      <remove fileExtension=".ktx2"/>
+      <mimeMap fileExtension=".ktx2" mimeType="image/ktx2"/>
+      <remove fileExtension=".eot"/>
+      <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject"/>
+      <remove fileExtension=".ttf"/>
+      <mimeMap fileExtension=".ttf" mimeType="application/octet-stream"/>
+      <remove fileExtension=".csv"/>
+      <mimeMap fileExtension=".csv" mimeType="application/octet-stream"/>
+      <remove fileExtension=".fly"/>
+      <mimeMap fileExtension=".fly" mimeType="application/octet-stream"/>
+      <remove fileExtension=".emp"/>
+      <mimeMap fileExtension=".emp" mimeType="application/octet-stream"/>
+      <remove fileExtension=".edp"/>
+      <mimeMap fileExtension=".edp" mimeType="application/octet-stream"/>
+      <remove fileExtension=".flv"/>
+      <mimeMap fileExtension=".flv" mimeType="flv-application/octet-stream"/>
+      <remove fileExtension=".mp4"/>
+      <mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
+      <remove fileExtension=".wmv"/>
+      <mimeMap fileExtension=".wmv" mimeType="audio/x-ms-wmv"/>
+      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00"/>
+    </staticContent>
+    <httpProtocol>
+      <customHeaders>
+        <add name="Access-Control-Allow-Headers" value="*,X-Requested-With"/>
+        <add name="Access-Control-Allow-Origin" value="*"/>
+      </customHeaders>
+    </httpProtocol>
   </system.webServer>
 </configuration>
diff --git a/MoonExp/cs/ExportUtil.cs b/MoonExp/cs/ExportUtil.cs
new file mode 100644
index 0000000..27ff854
--- /dev/null
+++ b/MoonExp/cs/ExportUtil.cs
@@ -0,0 +1,248 @@
+锘縰sing MoonExp.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 MoonExp.cs
+{
+    public class ExportUtil
+    {
+        /// <summary>
+        /// 鏈�澶ф枃浠舵暟
+        /// </summary>
+        public const int MaxFileCount = 2000;
+
+        private static string sourcesPath;
+
+        /// <summary>
+        /// 鑾峰彇璧勬簮鐩綍
+        /// </summary>
+        public static string SourcesPath
+        {
+            get
+            {
+                if (string.IsNullOrEmpty(sourcesPath))
+                {
+                    sourcesPath = Path.Combine(Tools.BaseDir, "Sources");
+                }
+
+                return sourcesPath;
+            }
+        }
+
+        private static string pyFile;
+
+        /// <summary>
+        /// 鑾峰彇Python鏂囦欢
+        /// </summary>
+        public static string PyFile
+        {
+            get
+            {
+                if (string.IsNullOrWhiteSpace(pyFile))
+                {
+                    pyFile = Path.Combine(SourcesPath, "render.py");
+                }
+
+                return pyFile;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇涓婃湡瀛楃涓�
+        /// </summary>
+        public static string DateStr
+        {
+            get
+            {
+                return DateTime.Now.ToString("yyyyMMddHHmmss");
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇涓嬭浇鐩綍
+        /// </summary>
+        public static string DownloadFolder
+        {
+            get
+            {
+                return ConfigurationManager.AppSettings["downloadFolder"];
+            }
+        }
+
+        /// <summary>
+        /// 鍚庡彴鏈嶅姟鍦板潃
+        /// </summary>
+        public static string MoonServer
+        {
+            get
+            {
+                return ConfigurationManager.AppSettings["moonServer"];
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍑哄浘瀛愮洰褰�
+        /// </summary>
+        public static string GetExportSubFolder()
+        {
+            string root = DownloadFolder;
+            if (!Directory.Exists(root))
+            {
+                Directory.CreateDirectory(root);
+            }
+
+            int i = 1;
+            while (true)
+            {
+                string subFolder = Path.Combine(root, i.ToString());
+                if (!Directory.Exists(subFolder))
+                {
+                    Directory.CreateDirectory(subFolder);
+                    break;
+                }
+
+                DirectoryInfo dir = new DirectoryInfo(subFolder);
+                FileInfo[] files = dir.GetFiles();
+                if (files == null || files.Length < MaxFileCount)
+                {
+                    break;
+                }
+
+                i++;
+            }
+
+            return i.ToString();
+        }
+
+        /// <summary>
+        /// 鐢熸垚
+        /// </summary>
+        /// <param name="args">鍑哄浘鍙傛暟</param>
+        /// <param name="err">閿欒淇℃伅</param>
+        /// <returns>鍥剧墖璺緞</returns>
+        public static string Generate(ExportArgs args, ref string err)
+        {
+            string date = DateStr;
+            string sub = GetExportSubFolder();
+            string qgz = "Test.qgz";
+
+            args.imgPath = sub + "\\" + date + ".png";
+            args.qpt = date + ".qpt";
+
+            args.SetDefault();
+            CreateTemplate(args);
+
+            string cmd = string.Format("python \"{0}\" -qgz {1} -qpt {2}", PyFile, qgz, args.qpt);
+            err = Tools.ExecCmd(cmd, true, true);
+
+            string qptFile = Path.Combine(SourcesPath, args.qpt);
+            if (File.Exists(qptFile)) File.Delete(qptFile);
+
+            string imgPath = Path.Combine(DownloadFolder, args.imgPath);
+            bool flag = File.Exists(imgPath);
+
+            return flag ? args.imgPath : null;
+        }
+
+        /// <summary>
+        /// 杞崲涓篨YZ鍙傛暟
+        /// </summary>
+        private static XYZArgs ToXYZArgs(ExportArgs ea)
+        {
+            XYZArgs args = new XYZArgs();
+            args.name = ea.title;
+            args.ids = new List<int>();
+            args.depcode = null;
+            args.dircode = null;
+            args.userId = Tools.SelectUserIdByToken(ea.token);
+
+            return args;
+        }
+
+        /// <summary>
+        /// 鍒涘缓妯℃澘
+        /// </summary>
+        /// <param name="args">鍑哄浘鍙傛暟</param>
+        public static void CreateTemplate(ExportArgs args)
+        {
+            string imgPath = Path.Combine(DownloadFolder, args.imgPath);
+            string templateFile = Path.Combine(SourcesPath, "Template.qpt");
+            string qptFile = Path.Combine(SourcesPath, args.qpt);
+            LogOut.Info("imgPath = " + imgPath + ", tempFile = " + templateFile + ", qptFile = " + qptFile);
+
+            string xml = File.ReadAllText(templateFile);
+            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())
+                .Replace("{ymax}", args.ymax.ToString())
+                .Replace("{xmax}", args.xmax.ToString())
+                .Replace("{province}", args.province)
+                .Replace("{scale}", args.scale)
+                .Replace("{resolution}", args.resolution)
+                //.Replace("{date}", args.date)
+                .Replace("{date}", DateTime.Now.ToString("yyyy.MM.dd"))
+                .Replace("{layers}", args.layers)
+                .Replace("{imgPath}", imgPath);
+
+            File.WriteAllText(qptFile, xml);
+        }
+
+        /// <summary>
+        /// 楠岃瘉浠ょ墝
+        /// </summary>
+        /// <param name="token">浠ょ墝</param>
+        /// <returns>鏄�/鍚︽湁鏁�</returns>
+        public static bool VerifyToken(string token)
+        {
+            try
+            {
+                string url = MoonServer + "/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;
+        }
+    }
+}
diff --git a/MoonExp/cs/LogOut.cs b/MoonExp/cs/LogOut.cs
new file mode 100644
index 0000000..2259b74
--- /dev/null
+++ b/MoonExp/cs/LogOut.cs
@@ -0,0 +1,128 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Web;
+
+namespace MoonExp.cs
+{
+    /// <summary>
+    /// 鏃ュ織杈撳嚭绫�
+    /// </summary>
+    public class LogOut
+    {
+        /// <summary>
+        /// 鏃ュ織
+        /// </summary>
+        protected static readonly log4net.ILog _log;
+
+        /// <summary>
+        /// 闈欐�佹瀯閫犲嚱鏁�
+        /// </summary>
+        static LogOut()
+        {
+            try
+            {
+                _log = log4net.LogManager.GetLogger("log4net");
+
+                //HttpContext.Current.Request.PhysicalApplicationPath
+                string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sources\\Log.config");
+
+                log4net.Config.XmlConfigurator.Configure(new FileInfo(fileName));
+            }
+            catch
+            {
+            }
+        }
+
+        /// <summary>
+        /// 璋冭瘯
+        /// </summary>
+        /// <param name="message">鏃ュ織</param>
+        public static void Debug(string message)
+        {
+            try
+            {
+                if (_log.IsDebugEnabled)
+                {
+                    _log.Debug("璋冭瘯锛�" + message + "\r\n\r\n");
+                }
+            }
+            catch
+            {
+            }
+        }
+
+        /// <summary>
+        /// 淇℃伅
+        /// </summary>
+        /// <param name="message">鏃ュ織</param>
+        public static void Info(string message)
+        {
+            try
+            {
+                if (_log.IsInfoEnabled)
+                {
+                    _log.Info("淇℃伅锛�" + message + "\r\n\r\n");
+                }
+            }
+            catch
+            {
+            }
+        }
+
+        /// <summary>
+        /// 璀﹀憡
+        /// </summary>
+        /// <param name="message">鏃ュ織</param>
+        public static void Warn(string message)
+        {
+            try
+            {
+                if (_log.IsWarnEnabled)
+                {
+                    _log.Warn("璀﹀憡锛�" + message + "\r\n\r\n");
+                }
+            }
+            catch
+            {
+            }
+        }
+
+        /// <summary>
+        /// 閿欒
+        /// </summary>
+        /// <param name="message">鏃ュ織</param>
+        public static void Error(string message)
+        {
+            try
+            {
+                if (_log.IsErrorEnabled)
+                {
+                    _log.Error("閿欒锛�" + message + "\r\n\r\n");
+                }
+            }
+            catch
+            {
+            }
+        }
+
+        /// <summary>
+        /// 鑷村懡
+        /// </summary>
+        /// <param name="message">鏃ュ織</param>
+        public static void Fatal(string message)
+        {
+            try
+            {
+                if (_log.IsFatalEnabled)
+                {
+                    _log.Fatal("鑷村懡锛�" + message + "\r\n\r\n");
+                }
+            }
+            catch
+            {
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/MoonExp/cs/PostgreHelper.cs b/MoonExp/cs/PostgreHelper.cs
new file mode 100644
index 0000000..2136ae6
--- /dev/null
+++ b/MoonExp/cs/PostgreHelper.cs
@@ -0,0 +1,188 @@
+锘縰sing Npgsql;
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Data.Common;
+using System.Linq;
+using System.Text.RegularExpressions;
+using System.Web;
+
+namespace MoonExp.cs
+{
+    /// <summary>
+    /// Postgre甯姪绫�
+    /// </summary>
+    public class PostgreHelper
+    {
+        private const string StrRegex = @"<[^>]+?style=[\w]+?:expression\(|\b(alert|confirm|prompt)\b|^\+/v(8|9)|<[^>]*?=[^>]*?&#[^>]*?>|\b(and|or)\b.{1,6}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|<\s*img\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)";
+
+        private string conStr = null;
+
+        public PostgreHelper()
+        {
+            this.conStr = ConfigurationManager.AppSettings["pgConn"];
+        }
+
+        /// <summary>
+        /// 杩炴帴瀛楃涓�
+        /// </summary>
+        public String ConStr
+        {
+            get
+            {
+                return this.conStr;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇DataTable
+        /// </summary>
+        public DataTable GetDataTable(string sql, params DbParameter[] args)
+        {
+            using (NpgsqlConnection con = new NpgsqlConnection(ConStr))
+            {
+                if (con.State != ConnectionState.Open)
+                {
+                    con.Open();
+                }
+
+                using (NpgsqlCommand cmd = new NpgsqlCommand(sql, con))
+                {
+                    if (args != null)
+                    {
+                        foreach (DbParameter arg in args)
+                        {
+                            //arg.ParameterName = arg.ParameterName.Replace("@", ":");
+                            cmd.Parameters.Add(arg);
+                        }
+                    }
+
+                    using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(cmd))
+                    {
+                        DataTable dt = new DataTable();
+                        adapter.Fill(dt);
+
+                        return dt;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇璁板綍鏁�
+        /// </summary>
+        public int GetCount(string sql, params DbParameter[] args)
+        {
+            using (NpgsqlConnection con = new NpgsqlConnection(ConStr))
+            {
+                if (con.State != ConnectionState.Open)
+                {
+                    con.Open();
+                }
+
+                using (NpgsqlCommand cmd = new NpgsqlCommand(sql, con))
+                {
+                    if (args != null)
+                    {
+                        foreach (DbParameter arg in args)
+                        {
+                            //arg.ParameterName = arg.ParameterName.Replace("@", ":");
+                            cmd.Parameters.Add(arg);
+                        }
+                    }
+
+                    object obj = cmd.ExecuteScalar();
+
+                    return obj == null ? 0 : Convert.ToInt32(obj);
+                }
+            }
+        }
+
+        public Object GetScalar(string sql, params DbParameter[] args)
+        {
+            using (NpgsqlConnection con = new NpgsqlConnection(ConStr))
+            {
+                if (con.State != ConnectionState.Open)
+                {
+                    con.Open();
+                }
+
+                using (NpgsqlCommand cmd = new NpgsqlCommand(sql, con))
+                {
+                    if (args != null)
+                    {
+                        foreach (DbParameter arg in args)
+                        {
+                            cmd.Parameters.Add(arg);
+                        }
+                    }
+
+                    return cmd.ExecuteScalar();
+                }
+            }
+        }
+
+        public int GetIntScalar(string sql, params DbParameter[] args)
+        {
+            using (NpgsqlConnection con = new NpgsqlConnection(ConStr))
+            {
+                if (con.State != ConnectionState.Open)
+                {
+                    con.Open();
+                }
+
+                using (NpgsqlCommand cmd = new NpgsqlCommand(sql, con))
+                {
+                    if (args != null)
+                    {
+                        foreach (DbParameter arg in args)
+                        {
+                            cmd.Parameters.Add(arg);
+                        }
+                    }
+
+                    object obj = cmd.ExecuteScalar();
+
+                    return null == obj ? 0 : Convert.ToInt32(obj);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鎵цSQL锛岃繑鍥炲奖鍝嶈鏁�
+        /// </summary>
+        public int ExecuteNonQuery(string sql, params DbParameter[] args)
+        {
+            using (NpgsqlConnection con = new NpgsqlConnection(ConStr))
+            {
+                if (con.State != ConnectionState.Open)
+                {
+                    con.Open();
+                }
+
+                using (NpgsqlCommand cmd = new NpgsqlCommand(sql, con))
+                {
+                    if (args != null)
+                    {
+                        foreach (DbParameter arg in args)
+                        {
+                            //arg.ParameterName = arg.ParameterName.Replace("@", ":");
+                            cmd.Parameters.Add(arg);
+                        }
+                    }
+
+                    return cmd.ExecuteNonQuery();
+                }
+            }
+        }
+
+        /// <summary>
+        /// 妫�鏌ュ瓧绗︿覆
+        /// </summary>
+        public static bool CheckStr(string input)
+        {
+            return Regex.IsMatch(input, StrRegex, RegexOptions.IgnoreCase);
+        }
+    }
+}

--
Gitblit v1.9.3