167 lines
5.2 KiB
C#
167 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Common.Utils;
|
|
using Newtonsoft.Json;
|
|
using Server.MyClass.Class;
|
|
using Server.Services.DataMigration.Services;
|
|
using Server.Services.DataMigration.Services.OldMDK;
|
|
using Server.Utils;
|
|
|
|
namespace Server.Services.DataMigration
|
|
{
|
|
/// <summary>
|
|
/// 数据迁移管理服务
|
|
/// </summary>
|
|
public class DataMigrationManageSerivce
|
|
{
|
|
private DataMigrationManageSerivce()
|
|
{
|
|
|
|
}
|
|
|
|
private static DataMigrationManageSerivce _dataMigrationManageSerivce;
|
|
|
|
private static object lockobj = new object();
|
|
/// <summary>
|
|
/// 实例
|
|
/// </summary>
|
|
public static DataMigrationManageSerivce Instance
|
|
{
|
|
get
|
|
{
|
|
if (_dataMigrationManageSerivce == null)
|
|
{
|
|
lock (lockobj)
|
|
{
|
|
if (_dataMigrationManageSerivce == null)
|
|
{
|
|
_dataMigrationManageSerivce = new DataMigrationManageSerivce();
|
|
}
|
|
}
|
|
}
|
|
return _dataMigrationManageSerivce;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 检查导入数据包,并且解压
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
/// <returns></returns>
|
|
public string Check(string path)
|
|
{
|
|
string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataMigration");
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
Directory.CreateDirectory(dir);
|
|
}
|
|
//开始解压
|
|
if (!ZipHelper.UnZipFile(path, dir, out var err))
|
|
{
|
|
return err;
|
|
}
|
|
if (!File.Exists(Path.Combine(dir, "PackInfo.json")))
|
|
{
|
|
return "打包信息不存在。";
|
|
}
|
|
var json = File.ReadAllText(Path.Combine(dir, "PackInfo.json"));
|
|
if (string.IsNullOrWhiteSpace(json))
|
|
{
|
|
return "打包信息不存在2";
|
|
}
|
|
var packInfo = JsonConvert.DeserializeObject<PackInfo>(json);
|
|
if (packInfo == null)
|
|
{
|
|
return "打包信息不存在3";
|
|
}
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// 开始启动
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
public string Start(string path)
|
|
{
|
|
string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataMigration");
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
return "请先调用检查数据包";
|
|
}
|
|
if (!File.Exists(Path.Combine(dir, "PackInfo.json")))
|
|
{
|
|
return "打包信息不存在";
|
|
}
|
|
var json = File.ReadAllText(Path.Combine(dir, "PackInfo.json"));
|
|
if (string.IsNullOrWhiteSpace(json))
|
|
{
|
|
return "打包信息不存在";
|
|
}
|
|
var packInfo = JsonConvert.DeserializeObject<PackInfo>(json);
|
|
if (packInfo == null)
|
|
{
|
|
return "打包信息不存在";
|
|
}
|
|
var th = new Thread(() =>
|
|
{
|
|
//迁移开始
|
|
DataMigrationProgressService.Instance.Start();
|
|
var state = DataMigrationProgressService.Instance.GetState();
|
|
try
|
|
{
|
|
var ser = new GeneralHandleMigrationService();
|
|
ser.RootDir = dir;
|
|
ser.Name = packInfo.TypeName;
|
|
ser.PackInfo = packInfo;
|
|
ser.Initialize();
|
|
ser.Start(state.AddLog);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
state.AddLog("出现错误:" + e.ToString());
|
|
}
|
|
finally
|
|
{
|
|
DataMigrationProgressService.Instance.Stop();
|
|
}
|
|
});
|
|
th.IsBackground = true;
|
|
th.Start();
|
|
return null;
|
|
}
|
|
|
|
|
|
public void Test()
|
|
{
|
|
string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataMigration");
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
Start(@"C:\Code\yz_dataconvert\yz_dataconvert\bin\Debug\transition.zip");
|
|
}
|
|
if (!File.Exists(Path.Combine(dir, "PackInfo.json")))
|
|
{
|
|
return;
|
|
}
|
|
var json = File.ReadAllText(Path.Combine(dir, "PackInfo.json"));
|
|
if (string.IsNullOrWhiteSpace(json))
|
|
{
|
|
return;
|
|
}
|
|
var packInfo = JsonConvert.DeserializeObject<PackInfo>(json);
|
|
if (packInfo == null)
|
|
{
|
|
return;
|
|
}
|
|
var ser = new GeneralHandleMigrationService();
|
|
ser.RootDir = dir;
|
|
ser.Name = packInfo.TypeName;
|
|
ser.PackInfo = packInfo;
|
|
ser.Initialize();
|
|
ser.Start(Console.WriteLine);
|
|
}
|
|
}
|
|
}
|