using Tiger.Business.WMS.Transaction;
|
using Rhea.Common;
|
using Tiger.Model.SeaStone.Shelf;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading;
|
using Microsoft.AspNetCore.Http;
|
using Tiger.IBusiness;
|
|
namespace Tiger.Business.WMS
|
{
|
/// <summary>
|
/// WMS上下文
|
/// </summary>
|
public class WMSContext : IWMSContext
|
{
|
/// <summary>
|
/// 亮灯颜色列表
|
/// </summary>
|
public static List<LightColor> LightColors = InitLightColors();
|
/// <summary>
|
/// 料车上报request接收列表("{RackId}-{LedId}-{CellStatus}")
|
/// </summary>
|
public static List<string> SlotChangedList = new List<string>();
|
|
#region 亮灯颜色管理
|
private static List<LightColor> InitLightColors()
|
{
|
var colors = new List<LightColor>();
|
colors.Add(new LightColor("Blue"));
|
colors.Add(new LightColor("Yellow"));
|
colors.Add(new LightColor("Orange"));
|
colors.Add(new LightColor("Purple"));
|
return colors;
|
}
|
|
private static readonly object UseLightColorLock = new object();
|
public static string GetDefaultLightColor()
|
{
|
lock (UseLightColorLock)
|
{
|
var cur = LightColors.Where(q => q.isUse == false).FirstOrDefault();
|
cur.isUse = true;
|
return cur.Color;
|
}
|
}
|
|
public static void UseLightColor(string color)
|
{
|
lock (UseLightColorLock)
|
{
|
var cur = LightColors.Where(q => q.Color == color).SingleOrDefault();
|
if (cur != null)
|
{
|
cur.isUse = true;
|
}
|
}
|
}
|
|
public static void UnuseLightColor(string color)
|
{
|
lock (UseLightColorLock)
|
{
|
var cur = LightColors.Where(q => q.Color == color).SingleOrDefault();
|
if (cur != null)
|
{
|
cur.isUse = false;
|
}
|
}
|
}
|
#endregion
|
|
#region 事务管理
|
/// <summary>
|
/// WMS事务字典
|
/// </summary>
|
public static Dictionary<string, WMSTransactionBase> TransactionDic => BizContext.TransactionDic.Where(q => q.Value is WMSTransactionBase).ToDictionary(k => k.Key, v => v.Value as WMSTransactionBase);
|
public Dictionary<string, IWMSTransaction> GetTransDic() => BizContext.TransactionDic.Where(q => q.Value is IWMSTransaction).ToDictionary(k => k.Key, v => v.Value as IWMSTransaction);
|
/// <summary>
|
/// 创建一个新事务,并加到事务列表
|
/// </summary>
|
/// <param name="context">请求的HttpContext</param>
|
/// <param name="trans">新的事务</param>
|
/// <param name="IsUniqueInSameClient">相同客户端是否只允许开启一个同类型事务</param>
|
public static void NewTransaction(HttpContext context, WMSTransactionBase trans, bool IsUniqueInSameClient = true)
|
{
|
BizContext.NewTransaction(context, trans, IsUniqueInSameClient);
|
}
|
public void NewTransaction(HttpContext context, IWMSTransaction trans, bool IsUniqueInSameClient = true)
|
{
|
BizContext.NewTransaction(context, trans, IsUniqueInSameClient);
|
}
|
#endregion
|
|
public static string GetApiIP()
|
{
|
using (var webClient = new WebClient())
|
{
|
try
|
{
|
var temp = webClient.DownloadString("http://localhost:9527/WeatherWebForm.aspx");//一般指定网址
|
var ip = Regex.Match(temp, @"\[(?<ip>\d+\.\d+\.\d+\.\d+)]").Groups["ip"].Value;
|
return !string.IsNullOrEmpty(ip) ? ip : null;
|
}
|
catch (Exception ex)
|
{
|
return ex.Message;
|
}
|
}
|
}
|
}
|
}
|