using ExportMap.db;
|
using ExportMap.Models;
|
using System;
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.Data;
|
using System.Diagnostics;
|
using System.IO;
|
using System.Linq;
|
using System.Threading;
|
using System.Web;
|
|
namespace ExportMap.cs
|
{
|
public class SGUtils
|
{
|
/// <summary>
|
/// Mpt目录
|
/// </summary>
|
public static string MptPath
|
{
|
get
|
{
|
return ConfigurationManager.AppSettings["mptFolder"];
|
}
|
}
|
|
/// <summary>
|
/// 3DML目录
|
/// </summary>
|
public static string D3mlFolder
|
{
|
get
|
{
|
return ConfigurationManager.AppSettings["3dmlFolder"];
|
}
|
}
|
|
/// <summary>
|
/// 廊坊数据目录
|
/// </summary>
|
public static string LFData
|
{
|
get
|
{
|
return ConfigurationManager.AppSettings["lfData"];
|
}
|
}
|
|
/// <summary>
|
/// SG的DB库
|
/// </summary>
|
public static string SGDB
|
{
|
get
|
{
|
return ConfigurationManager.AppSettings["sgDB"];
|
}
|
}
|
|
/// <summary>
|
/// 发布数据
|
/// </summary>
|
/// <param name="args">XYZ参数</param>
|
/// <returns>行数</returns>
|
public int Release(XYZArgs args)
|
{
|
List<SysMeta> list = XYZUtils.selectMetas(args.ids, "and type in ('mpt', '3dml')");
|
if (null == list || list.Count == 0) return 0;
|
|
int maxId = GetMaxId();
|
RomoveNoneFiles(list);
|
if (list.Count == 0) return 0;
|
|
LinkFiles(list);
|
|
for (int i = 0; i < 25; i++)
|
{
|
Thread.Sleep(3000);
|
|
List<SpatialItem> items = SelectItems(maxId);
|
if (null == items || items.Count == 0) continue;
|
|
//
|
}
|
|
return 0;
|
}
|
|
/// <summary>
|
/// 获取最大ID值
|
/// </summary>
|
public static int GetMaxId()
|
{
|
Object obj = SQLiteHelper.ExecuteScalar("select max(id) from SpatialItems");
|
|
return null == obj ? 0 : Convert.ToInt32(obj);
|
}
|
|
/// <summary>
|
/// 查询SG数据项
|
/// </summary>
|
/// <param name="maxId">最大ID值</param>
|
/// <returns>SG数据项</returns>
|
public static List<SpatialItem> SelectItems(int maxId)
|
{
|
string sql = string.Format("select id, Name, RelativePath, LayerName, DataSourceId, Description from SpatialItems where id > {0} order by id desc", maxId);
|
|
DataTable dt = SQLiteHelper.GetDataTable(sql);
|
List<SpatialItem> list = ModelHandler.FillModel<SpatialItem>(dt);
|
|
return list;
|
}
|
|
/// <summary>
|
/// 移除空文件
|
/// </summary>
|
private void RomoveNoneFiles(List<SysMeta> list)
|
{
|
string uploadFolder = Tool.GetSetting("uploadFolder");
|
|
int i = 0;
|
while (i < list.Count)
|
{
|
SysMeta meta = list[i];
|
string filePath = Path.Combine(uploadFolder, meta.path);
|
if (!File.Exists(filePath))
|
{
|
list.RemoveAt(i);
|
continue;
|
}
|
|
if ("mpt".Equals(meta.type))
|
{
|
string midx = Path.Combine(uploadFolder, meta.path.Replace(".mpt", ".midx"));
|
string strmi = Path.Combine(uploadFolder, meta.path.Replace(".mpt", ".strmi"));
|
if (!File.Exists(midx) || !File.Exists(strmi))
|
{
|
list.RemoveAt(i);
|
continue;
|
}
|
}
|
|
i++;
|
}
|
}
|
|
/// <summary>
|
/// 链接文件
|
/// </summary>
|
private string LinkFiles(List<SysMeta> metas)
|
{
|
List<string> list = new List<string>();
|
foreach (SysMeta meta in metas)
|
{
|
switch (meta.type)
|
{
|
case "3dml":
|
AddMptLinkFile(list, meta);
|
break;
|
case "mpt":
|
AddD3mlLinkFile(list, meta);
|
break;
|
}
|
|
}
|
|
string str = Tool.ExecCmd(list);
|
|
return str;
|
}
|
|
/// <summary>
|
/// 添加链接文件
|
/// </summary>
|
private void AddMptLinkFile(List<string> list, SysMeta meta)
|
{
|
string uploadFolder = Tool.GetSetting("uploadFolder");
|
string d3mlFolder = Tool.GetSetting("3dmlFolder");
|
|
string d3ml = Path.Combine(uploadFolder, meta.path);
|
string targetD3ml = Path.Combine(d3mlFolder, meta.id.ToString(), meta.path);
|
|
string link = string.Format("mklink \"{0}\" \"{1}\"", targetD3ml, d3ml); // /H
|
list.Add(link);
|
}
|
|
/// <summary>
|
/// 添加链接文件
|
/// </summary>
|
private void AddD3mlLinkFile(List<string> list, SysMeta meta)
|
{
|
string uploadFolder = Tool.GetSetting("uploadFolder");
|
string mptFolder = Tool.GetSetting("mptFolder");
|
|
string mpt = Path.Combine(uploadFolder, meta.path);
|
string targetMpt = Path.Combine(mptFolder, meta.id.ToString(), meta.path);
|
|
string midx = Path.Combine(uploadFolder, meta.path.Replace(".mpt", ".midx"));
|
string targetMidx = Path.Combine(mptFolder, meta.id.ToString(), meta.path.Replace(".mpt", ".midx"));
|
|
string strmi = Path.Combine(uploadFolder, meta.path.Replace(".mpt", ".strmi"));
|
string targetStrmi = Path.Combine(mptFolder, meta.id.ToString(), meta.path.Replace(".mpt", ".strmi"));
|
|
list.Add(string.Format("mklink \"{0}\" \"{1}\"", targetMpt, mpt));
|
list.Add(string.Format("mklink \"{0}\" \"{1}\"", targetMidx, midx));
|
list.Add(string.Format("mklink \"{0}\" \"{1}\"", targetStrmi, strmi));
|
}
|
}
|
}
|