|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
|
|
|
namespace Mesnac.Compressor.Entity
|
|
|
{
|
|
|
public class DictionaryOperation<T>
|
|
|
{
|
|
|
public Dictionary<int,T> _dic=new Dictionary<int,T>();
|
|
|
public Dictionary<int, T> Dic
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _dic;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public T find(int i)
|
|
|
{
|
|
|
lock (this)
|
|
|
{
|
|
|
if (_dic.ContainsKey(i))
|
|
|
{
|
|
|
return _dic[i];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return default(T);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Delete(int i)
|
|
|
{
|
|
|
lock (this)
|
|
|
{
|
|
|
if (_dic.ContainsKey(i))
|
|
|
{
|
|
|
_dic.Remove(i);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 已经包好返回原来key,否则返回新key
|
|
|
/// </summary>
|
|
|
/// <param name="i"></param>
|
|
|
/// <param name="t"></param>
|
|
|
/// <returns></returns>
|
|
|
public int Add(int i,T t)
|
|
|
{
|
|
|
lock (this)
|
|
|
{
|
|
|
if (_dic.ContainsValue(t))
|
|
|
{
|
|
|
foreach (KeyValuePair<int, T> item in _dic)
|
|
|
{
|
|
|
if (item.Value.Equals(t))
|
|
|
{
|
|
|
return item.Key;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (!_dic.ContainsKey(i))
|
|
|
{
|
|
|
_dic.Add(i, t);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
i++;
|
|
|
Add(i, t);
|
|
|
}
|
|
|
return i;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//站,先进先出
|
|
|
public class Queue<T>
|
|
|
{
|
|
|
private readonly List<T> _TrayQueue=new List<T>();
|
|
|
|
|
|
public List<T> TrayQueue
|
|
|
{
|
|
|
get { return _TrayQueue; }
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 队列操作
|
|
|
//添加
|
|
|
public bool InsertQueue(T Tray)
|
|
|
{
|
|
|
foreach (T t in _TrayQueue)
|
|
|
{
|
|
|
if (t.Equals(Tray))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
lock (this)
|
|
|
{
|
|
|
_TrayQueue.Add(Tray);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 出队
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public T OutQueue()
|
|
|
{
|
|
|
T tyre = default(T);
|
|
|
lock (this)
|
|
|
{
|
|
|
if (_TrayQueue != null && _TrayQueue.Count > 0)
|
|
|
{
|
|
|
tyre = _TrayQueue[0];
|
|
|
}
|
|
|
}
|
|
|
return tyre;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 删除第一个信息
|
|
|
/// </summary>
|
|
|
/// <param name=""></param>
|
|
|
public void DeleteTyre()
|
|
|
{
|
|
|
if (_TrayQueue.Count > 0)
|
|
|
{
|
|
|
T df = _TrayQueue[0];
|
|
|
lock (this)
|
|
|
{
|
|
|
_TrayQueue.RemoveAt(0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 队列是否为空
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public bool IsRFIDAvailable()
|
|
|
{
|
|
|
bool exist;
|
|
|
lock (this)
|
|
|
{
|
|
|
exist = _TrayQueue.Count > 0;
|
|
|
}
|
|
|
return exist;
|
|
|
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 处理超时则清空某些轮胎
|
|
|
/// </summary>
|
|
|
/// <param name="time"></param>
|
|
|
public void ClearQueue(DateTime time)
|
|
|
{
|
|
|
lock (this)
|
|
|
{
|
|
|
for (int i = 0; i < _TrayQueue.Count; i++)
|
|
|
{
|
|
|
var tyre = _TrayQueue[i];
|
|
|
//if (tyre.InputTime < time)
|
|
|
//{
|
|
|
_TrayQueue.RemoveAt(i);
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
}
|