using FLY.OBJComponents.Server;
using FLY.OBJComponents.Server.OBJProxy;
using FLY.Weight2.Server.Model;
using FLY.Weight2.Server.OBJProxy;
using FObjBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace FLY.Weight2.Server
{
public class TDGage
{
#region 初始化------------------------------------------------------------------
public string mParamDirectory;//参数目录 m_path;//数据文件的 根目录默认是 Gage1
public string mName;//名字 如:gage0
#endregion
#region 本地数据----------------------------------------------------------------
public SysParam mSysParam;
public WeightSystem mData;
public HistoryDb mHistoryDb;
///
/// 报警系统
///
public WarningSystem2 mWarning;
DbModel mDbModel;
#endregion
#region 服务器数据--------------------------------------------------------------
///
/// 吹膜测厚仪, 旋转架模型
///
public FLY.Thick.Blowing.Client.BlowingDetectServiceClient mBDetect;
#endregion
public TDGage(string nam)
{
mName = nam;
mParamDirectory = mName;// @"D:\" + m_name;
if (!System.IO.Directory.Exists(mParamDirectory))
{
System.IO.Directory.CreateDirectory(mParamDirectory);
}
System.Environment.CurrentDirectory = mParamDirectory;
mSysParam = new SysParam();
mData = new WeightSystem();
mDbModel = new DbModel();
mHistoryDb = new HistoryDb();
mWarning = new WarningSystem2();
}
///
/// 第1步, 加载本地数据
///
public async Task Init()
{
//---------------------------------------------------------------------------------------------------------------
//数据库
await Task.Factory.StartNew(() =>
{
//初始数据库(加载 MaxId)
mDbModel.Init();
//删除不需要的备份数据
mDbModel.KeepBackupSize(12);
//备份上一个月之前的数据到 yyyy-MM 文件夹
mDbModel.BackupBbInSize(12);
//当前的数据库只保存上个月与这个月的数据
mDbModel.KeepDBSize(1);
});
mHistoryDb.Init(mDbModel);
mWarning.Init(mHistoryDb.ErrorBuffer);
mData.Init(mHistoryDb, mWarning);
#region 与服务器同步的数据
mBDetect = new Thick.Blowing.Client.BlowingDetectServiceClient(FLY.Thick.Blowing.OBJ_INTERFACE.OBJ_INTERFACE_ID.BDETECT_ID);
#endregion
Init2();
mBDetect.PropertyChanged += MBDetect_PropertyChanged;
}
private void MBDetect_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(mBDetect.FilmVelocity))
{
mData.Accessory.CurrentVelocitySet = (((int)(mBDetect.FilmVelocity * 10)) / 10.0f);
}
}
///
/// 第2步, 连接到服务器,初始化参数 。由界面的 【登陆】 按钮触发
///
private void Init2()
{
#region 网络初始化
//FObjSys.Current.Start_Conn_Server(new IPEndPoint(IPAddress.Any, mSysParam.OBJ_Port), mServerOBJProxy.ID);
var addr = Misc.StringConverter.ToIPEndPoint(mSysParam.BlowingAddr);
FObjSys.Current.Connect_to_Another_OBJSys(
addr,
mBDetect.ID
);
#endregion
}
}
}