管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-07-30 110685ca201361af20d758fce7cf8a89ab5362b6
ExportMap/cs/Tools.cs
@@ -1,4 +1,5 @@
using ExportMap.db;
using ExportMap.Models;
using Npgsql;
using System;
using System.Collections.Generic;
@@ -8,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.AccessControl;
@@ -25,6 +27,9 @@
        private static string tempDir;
        /// <summary>
        /// 临时目录
        /// </summary>
        public static string TempDir
        {
            get
@@ -32,7 +37,10 @@
                if (string.IsNullOrWhiteSpace(tempDir))
                {
                    tempDir = Path.Combine(BaseDir, "temp");
                    if (!Directory.Exists(tempDir)) Directory.CreateDirectory(tempDir);
                    if (!Directory.Exists(tempDir))
                    {
                        Directory.CreateDirectory(tempDir);
                    }
                }
                return tempDir;
@@ -158,7 +166,7 @@
        /// </summary>
        /// <param name="cmd">命令行</param>
        /// <returns>执行结果或出错信息</returns>
        public static String ExecCmd(string cmd, bool isPy = false)
        public static string ExecCmd(string cmd, bool isPy = false, bool isOut = false)
        {
            List<string> list = new List<string>();
            if (isPy)
@@ -170,7 +178,7 @@
            }
            list.Add(cmd);
            string str = ExecCmd(list);
            string str = ExecCmd(list, isOut);
            return str;
        }
@@ -180,7 +188,7 @@
        /// </summary>
        /// <param name="list">命令集合</param>
        /// <returns>执行结果或出错信息</returns>
        public static string ExecCmd(List<string> list)
        public static string ExecCmd(List<string> list, bool isOut = false)
        {
            string str = null;
            try
@@ -196,7 +204,7 @@
                p.Start();
                StreamWriter si = p.StandardInput; // 标准输入流 
                //StreamReader so = p.StandardOutput; // 标准输出流
                StreamReader so = isOut ? p.StandardOutput : null; // 标准输出流
                StreamReader se = p.StandardError; // 标准错误流
                LogOut.Info("cmd = " + string.Join(",", list));
@@ -207,7 +215,7 @@
                }
                si.WriteLine("exit");
                //string info = so.ReadToEnd();
                string info = null == so ? null : so.ReadToEnd();
                str = se.ReadToEnd();
                //if (!string.IsNullOrEmpty(info)) LogOut.Debug(info);
@@ -221,11 +229,66 @@
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.StackTrace);
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                str = ex.Message;
            }
            return str;
        }
        /// <summary>
        /// 创建数据发布类
        /// </summary>
        public static SysPublish NewPublish(SysMeta meta, XYZArgs args, string url, string path)
        {
            SysPublish sys = new SysPublish();
            sys.name = meta.name;
            sys.url = url; // GetReleaseUrl(meta)
            sys.type = meta.type;
            sys.status = 3;
            sys.dirid = meta.dircode;
            sys.depid = args.depcode;
            sys.min = args.min;
            sys.max = args.max;
            sys.json = null;
            sys.create_user = args.userId;
            sys.geom = null;
            sys.bak = null;
            sys.path = path;
            return sys;
        }
        /// <summary>
        /// 删除路径
        /// </summary>
        public static string DelPath(string path)
        {
            List<string> list = new List<string>();
            list.Add(string.Format("rd \"{0}\" /s /q", path));
            return ExecCmd(list);
        }
        /// <summary>
        /// 设置单体模型参数
        /// </summary>
        public static void SetIsModel(XYZArgs args, List<SysMeta> list)
        {
            if (null == args.models || args.models.Count != args.ids.Count)
            {
                foreach (SysMeta meta in list) meta.ismeta = 1;
                return;
            }
            foreach (SysMeta meta in list)
            {
                int idx = args.ids.IndexOf(meta.id);
                meta.ismeta = idx == -1 ? 1 : args.models[idx];
            }
        }
        [DllImport("ReadLas.dll")]
        public extern static int get_las_cs(string file_name);
    }
}