115 lines
3.0 KiB
C#
115 lines
3.0 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 Server.Utils;
|
|
using SqlSugar;
|
|
|
|
namespace Server.Services.DataMigration
|
|
{
|
|
/// <summary>
|
|
/// 数据迁移进度监控服务
|
|
/// </summary>
|
|
public class DataMigrationProgressService
|
|
{
|
|
private DataMigrationProgressService()
|
|
{
|
|
}
|
|
private static DataMigrationProgressService _migrationService;
|
|
private static object lockobj = new object();
|
|
/// <summary>
|
|
/// 单例的属性
|
|
/// </summary>
|
|
public static DataMigrationProgressService Instance
|
|
{
|
|
get
|
|
{
|
|
if (_migrationService == null)
|
|
{
|
|
lock (lockobj)
|
|
{
|
|
if (_migrationService == null)
|
|
{
|
|
_migrationService = new DataMigrationProgressService();
|
|
}
|
|
}
|
|
}
|
|
return _migrationService;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 迁移进度
|
|
/// </summary>
|
|
private MigrationProgressState State { get; set; }
|
|
/// <summary>
|
|
/// 开始记录
|
|
/// </summary>
|
|
public void Start()
|
|
{
|
|
State = new MigrationProgressState();
|
|
this.State.StartDateTime = DateTime.Now;
|
|
this.State.State = 1;
|
|
}
|
|
/// <summary>
|
|
/// 停止
|
|
/// </summary>
|
|
public void Stop()
|
|
{
|
|
this.State.EndDateTime=DateTime.Now;
|
|
this.State.ElapsedTime = (this.State.EndDateTime - this.State.StartDateTime).TotalMinutes;
|
|
this.State.State = 2;
|
|
}
|
|
/// <summary>
|
|
/// 获取当前迁移进度
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public MigrationProgressState GetState()
|
|
{
|
|
return this.State;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 迁移状态
|
|
/// </summary>
|
|
public class MigrationProgressState
|
|
{
|
|
/// <summary>
|
|
/// 开始时间
|
|
/// </summary>
|
|
public DateTime StartDateTime { get; set; }
|
|
/// <summary>
|
|
/// 结束时间
|
|
/// </summary>
|
|
public DateTime EndDateTime { get; set; }
|
|
/// <summary>
|
|
/// 总耗时(分钟)
|
|
/// </summary>
|
|
public double ElapsedTime { get; set; }
|
|
/// <summary>
|
|
/// 处理状态 0未开始 1处理中 2完成
|
|
/// </summary>
|
|
public int State { get; set; }
|
|
/// <summary>
|
|
/// 日志
|
|
/// </summary>
|
|
public List<string> Logs { get; set; } = new List<string>();
|
|
/// <summary>
|
|
/// 添加日志
|
|
/// </summary>
|
|
/// <param name="text"></param>
|
|
public void AddLog(string text)
|
|
{
|
|
if (Logs.Count > 10)
|
|
{
|
|
Logs.RemoveAt(0);
|
|
}
|
|
Logs.Add(text);
|
|
}
|
|
}
|
|
}
|