using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using SlnMesnac.WPF;
using SlnMesnac.WPF.Page;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本:4.0.30319.42000
* 机器名称:LAPTOP-E0N2L34V
* 命名空间:SlnMesnac.Model.dto
* 唯一标识:96940a51-66a8-4593-b68d-e4d7fdb16c9b
*
* 创建者:WenJY
* 电子邮箱:wenjy@mesnac.com
* 创建时间:2024-04-12 11:07:33
* 版本:V1.0.0
* 描述:
*
*--------------------------------------------------------------------
* 修改人:
* 时间:
* 修改说明:
*
* 版本:V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.Model
{
///
/// 配方管理封装对象
///
public class RecipeManageCache
{
#region 单例实现
private static readonly RecipeManageCache lazy = new RecipeManageCache();
public static RecipeManageCache Instance
{
get
{
return lazy;
}
}
#endregion
#region 变量定义
private readonly ILogger _logger;
private DebugConfig config = DebugConfig.Instance;
private readonly IBaseRecipeManageService? baseRecipeManageService;
///
/// 所有配方列表
///
public List recipeManageList = null;
///
/// 当前正在使用配方
///
public RecipeManage useRecipeManage
{
get
{
if (recipeManageList != null)
{
return recipeManageList.FirstOrDefault(x => x.RecipeName == config.RecipeName);
}
else
{
return null;
}
}
}
///
/// 当前缓存区监测重量
///
public double BufferWeight {
get { return double.Parse(config.BufferWeight); }
set { config.BufferWeight = value.ToString(); }
}
///
/// 2楼缓存区最大停机重量
///
public double MaxBufferWeight
{
get { return double.Parse(config.MaxBufferWeight); }
set { config.MaxBufferWeight = value.ToString(); }
}
///
/// 2楼缓存区最小启动重量
///
public double MinBufferWeight
{
get { return double.Parse(config.MinBufferWeight); }
set { config.MinBufferWeight = value.ToString(); }
}
///
/// 当前使用模版名称
///
public string RecipeName
{
get { return config.RecipeName; }
set { config.RecipeName = value; }
}
///
/// 当前使用模式
///
public string RecipeMode
{
get { return config.RecipeMode; }
set { config.RecipeMode = value; }
}
///
/// 拆包机螺旋--烘干机螺旋切换间隔(单位:ms)
///
public string UnpackToHotTime
{
get { return config.UnpackToHotTime; }
set { config.UnpackToHotTime = value; }
}
///
/// 烘干机螺旋--螺旋1切换间隔(单位:ms)
///
public string HotToSpiralTime
{
get { return config.HotToSpiralTime; }
set { config.HotToSpiralTime = value; }
}
///
/// 螺旋1--螺旋2切换间隔(单位:ms)
///
public string SpiralTwoTime
{
get { return config.SpiralTwoTime; }
set { config.SpiralTwoTime = value; }
}
#endregion
public RecipeManageCache()
{
baseRecipeManageService = App.ServiceProvider.GetService();
recipeManageList = baseRecipeManageService.GetRecipeManageList();
}
///
/// 更新配方
///
///
public void UpdateRecipeManage(RecipeManage recipeManage)
{
try
{
baseRecipeManageService.UpdateRecipeManage(recipeManage);
//刷新缓存
recipeManageList = baseRecipeManageService.GetRecipeManageList();
}
catch (Exception ex)
{
_logger.LogError($"UpdateRecipeManage异常:{ex.Message}");
}
}
}
}