using System.Collections.Generic;
using System.Linq;

public class StockEmitMgr : StockSequenceMgr
{
	private List<Dictionary<string, object>> _pubSequenceSendAllData = new List<Dictionary<string, object>>();

	public static float WAIT_ACK_TIMEOUT = 3f;

	private long _emitTime;

	public static float ACK_NOT_RECEIVE_LOG_TIME = 15f;

	public int SequenceNumber { get; private set; }

	public long EmitToAckCheckTime { get; private set; }

	public bool IsReceiveAck { get; private set; }

	public StockEmitMgr(string name)
		: base(name)
	{
		SequenceNumber = 1;
	}

	public override void StockData(Dictionary<string, object> data)
	{
		base.StockData(data);
		bool flag = false;
		if (_pubSequenceSendAllData.Count > 0)
		{
			for (int i = 0; i < _pubSequenceSendAllData.Count; i++)
			{
				if (_pubSequenceSendAllData[i].ContainsKey("pubSeq") && data.ContainsKey("pubSeq") && _pubSequenceSendAllData[i]["pubSeq"] == data["pubSeq"])
				{
					flag = true;
					break;
				}
			}
		}
		if (!flag)
		{
			_pubSequenceSendAllData.Add(data);
		}
	}

	public void AddSequenceNumber()
	{
		SequenceNumber++;
	}

	public void ResetSequence()
	{
		SequenceNumber = 1;
		_pubSequenceSendAllData.Clear();
	}

	public Dictionary<string, object> GetSelectData(int num)
	{
		Dictionary<string, object> dictionary = sequenceDataList.FirstOrDefault((Dictionary<string, object> d) => GetSequenceNumber(d) == num);
		if (dictionary == null)
		{
			dictionary = _pubSequenceSendAllData.FirstOrDefault((Dictionary<string, object> d) => GetSequenceNumber(d) == num);
		}
		return dictionary;
	}

	public Dictionary<string, object> GetAllSelectData(int num)
	{
		return _pubSequenceSendAllData.FirstOrDefault((Dictionary<string, object> d) => GetSequenceNumber(d) == num);
	}

	public void FirstAddSequenceDataList(Dictionary<string, object> info)
	{
		lock (sequenceDataList)
		{
			sequenceDataList.Insert(0, info);
		}
	}

	public List<Dictionary<string, object>> GetSequenceAllData()
	{
		return sequenceDataList;
	}

	public void Recovery(int sequenceNumber)
	{
		SequenceNumber = sequenceNumber;
		ClearSequenceDataList();
	}

	public void SetEmitTime(long emitTime)
	{
		_emitTime = emitTime;
		if (IsReceiveAck)
		{
			SetEmitToAckCheckTime(emitTime);
		}
		IsReceiveAck = false;
	}

	public void SetEmitToAckCheckTime(long time)
	{
		EmitToAckCheckTime = time;
	}

	public void SetReceiveAck()
	{
		IsReceiveAck = true;
	}

	public long GetEmitTime()
	{
		return _emitTime;
	}
}
