//============================================ //--4>: // Exported by ExcelConfigExport // // 此代码为工具根据配置自动生成, 请不要修改 // //============================================ using System; using Sog; using System.Collections.Generic; using Newtonsoft.Json.Linq; using System.IO; using System.Linq; public partial class PassCardDescMgr : IConfigManager { //Singleton private static PassCardDescMgr _instance; private static readonly object syslock = new object(); public static PassCardDescMgr Instance { get { if (_instance == null) { lock (syslock) { if (_instance == null) { _instance = new PassCardDescMgr(); }}} return _instance; }} public class ItemData { public PassCardDesc Item; public int Line; public bool ReadAlready; } protected Dictionary> m_ItemTable = new (); protected Dictionary n_ItemTable = new (); //for server only, m_readKeyOnly must be false protected SortedList> m_ItemDescTable = new (); public SortedList> ItemTable { get { if (m_ItemDescTable.Count != m_ItemTable.Count) { foreach (var list in m_ItemTable) { if (m_ItemDescTable.ContainsKey(list.Key) == false) { GetGroup(list.Key);} // GetGroup里会添加 } } return m_ItemDescTable; } } private TabBinFile m_tbf; //private TabTextFile m_tf; private int m_curAsynKey1; private int m_curAsynKey2; public override bool InitBin(string fileName, byte[] fileContent) { m_ErrorCount = 0; m_ItemTable.Clear(); m_ItemDescTable.Clear(); n_ItemTable.Clear(); m_allRead = false; m_curAsynKey1 = 0; m_curAsynKey2 = 0; m_tbf = new TabBinFile(fileName, fileContent); while (m_tbf.Next()) { ItemData itemData = new ItemData() { Item = new PassCardDesc() }; var item = itemData.Item; if (m_readKeyOnly) {m_tbf.SetCurrentCol(0); } if (item.ReadItemBin(m_tbf, m_readKeyOnly) == false) { TraceLog.Error("Failed to init TabManager:{0}, read line error, line: {1}", this.ToString(), m_tbf.CurrentLine); m_ErrorCount++; return false; } if (m_ItemTable.ContainsKey(item.GetKey1()) == false) { m_ItemTable.Add(item.GetKey1(), new Dictionary()); } else if (m_ItemTable[item.GetKey1()].ContainsKey(item.GetKey2())) { TraceLog.Error("Failed to init TabManager:{0}, multi key1:{1}, key2: {2}, line: {3}",this.ToString(), item.GetKey1(), item.GetKey2(), m_tbf.CurrentLine); m_ErrorCount++; return false; } m_ItemTable[item.GetKey1()].Add(item.GetKey2(), itemData); n_ItemTable.Add(item.InternalId,item); if (m_readKeyOnly) { itemData.Line = m_tbf.CurrentLine; } else { itemData.ReadAlready = true; } } if (!m_readKeyOnly) { m_tbf = null; } return true; } public PassCardDesc GetConfig(int key1, int key2) { Dictionary itemDataGroup; m_ItemTable.TryGetValue(key1, out itemDataGroup); if (itemDataGroup == null) { return null; } ItemData itemData; itemDataGroup.TryGetValue(key2, out itemData); if(itemData == null) { return null; } if(itemData.ReadAlready) { return itemData.Item; } m_tbf.SetCurrentLine(itemData.Line); m_tbf.SetCurrentCol(0); itemData.ReadAlready = true; if (m_tbf == null) { TraceLog.Error("Cfg1KeyMgrTemplate.GetConfig Failed fs null TabManager:{ 0}, read line error", this.ToString()); return null; } if (itemData.Item.ReadItemBin(m_tbf, false) == false) { TraceLog.Error("Cfg1KeyMgrTemplate.GetConfig Failed to init TabManager:{0}, read line error, line: {1}", this.ToString(), m_tbf.CurrentLine); return null; } return itemData.Item; } public PassCardDesc GetConfigByInternal(int internalId) { var desc = n_ItemTable.GetValueOrDefault(internalId, null); if (desc == null) { TraceLog.Error("Cfg1KeyMgrTemplate.Get by InternalId Failed fs null TabManager:{0}, internalId={1},read line error,", this.ToString(), internalId); } return desc; } public int GetCountKey1(int key1) { int allCount = 0; var group = GetGroup(key1); if(group != null) { allCount = group.Count; } return allCount; } //GetGroup的时候如果是延迟读取的,一次性读取整个group public SortedList GetGroup(int key1) { Dictionary itemDataGroup; m_ItemTable.TryGetValue(key1, out itemDataGroup); if (itemDataGroup == null) { return null; } if(m_ItemDescTable.ContainsKey(key1)) { return m_ItemDescTable[key1]; } var group = new SortedList(); foreach (var item in itemDataGroup) { if(item.Value.ReadAlready == false) { GetConfig(key1, item.Key); } group.Add(item.Key, item.Value.Item); } m_ItemDescTable.Add(key1, group); return group; } public bool Has(int key1, int key2) { return m_ItemTable.ContainsKey(key1) && m_ItemTable[key1].ContainsKey(key2); } } public partial class PassCardDesc { public partial class Free { /// /// 0免费奖励类型1 /// public int Type { get; set; } /// /// 0免费奖励id1 /// public string Id { get; set; } /// /// 0免费奖励数量1 /// public int Value { get; set; } } public partial class Pay { /// /// 0付费奖励类型1 /// public int Type { get; set; } /// /// 0付费奖励id1 /// public string Id { get; set; } /// /// 0付费奖励数量1 /// public int Value { get; set; } } public static readonly string _KEY_InternalId = "InternalId"; public static readonly string _KEY_cardIndex = "cardIndex"; public static readonly string _KEY_seq = "seq"; public static readonly string _KEY_reasonType = "reasonType"; public static readonly string _KEY_reasonTypeNum = "reasonTypeNum"; public static readonly string _KEY_free_0_Type = "free_0_Type"; public static readonly string _KEY_free_0_Id = "free_0_Id"; public static readonly string _KEY_free_0_Value = "free_0_Value"; public static readonly string _KEY_free_1_Type = "free_1_Type"; public static readonly string _KEY_free_1_Id = "free_1_Id"; public static readonly string _KEY_free_1_Value = "free_1_Value"; public static readonly string _KEY_pay_0_Type = "pay_0_Type"; public static readonly string _KEY_pay_0_Id = "pay_0_Id"; public static readonly string _KEY_pay_0_Value = "pay_0_Value"; public static readonly string _KEY_pay_1_Type = "pay_1_Type"; public static readonly string _KEY_pay_1_Id = "pay_1_Id"; public static readonly string _KEY_pay_1_Value = "pay_1_Value"; /// /// 内部ID /// public int InternalId { get; set; } /// /// 通行证索引号 /// public int cardIndex { get; set; } /// /// 奖励档位 /// public int seq { get; set; } /// /// 领奖条件 /// public ReasonType reasonType { get; set; } /// /// 领奖条件参数 /// public int[] reasonTypeNum { get; set; } public Free[] free { get; set; } public Pay[] pay { get; set; } public Dictionary listDic = new Dictionary(); public PassCardDesc() { free = new Free[2]; free[0] = new Free(); free[1] = new Free(); listDic.Add("free", typeof(Free)); pay = new Pay[2]; pay[0] = new Pay(); pay[1] = new Pay(); listDic.Add("pay", typeof(Pay)); } public int GetKey1() { return cardIndex; } public int GetKey2() { return seq; } public bool ReadItemBin(TabBinFile txf, bool readKeyOnly) { InternalId = txf.GetintByIndex(_KEY_InternalId); cardIndex = txf.GetintByIndex(_KEY_cardIndex); seq = txf.GetintByIndex(_KEY_seq); if(readKeyOnly) { return true; } reasonType = (ReasonType)txf.GetintByIndex(_KEY_reasonType); reasonTypeNum = txf.GetintArrayByIndex(_KEY_reasonTypeNum); free[0].Type = txf.GetintByIndex(_KEY_free_0_Type); free[0].Id = txf.GetstringByIndex(_KEY_free_0_Id); free[0].Value = txf.GetintByIndex(_KEY_free_0_Value); free[1].Type = txf.GetintByIndex(_KEY_free_1_Type); free[1].Id = txf.GetstringByIndex(_KEY_free_1_Id); free[1].Value = txf.GetintByIndex(_KEY_free_1_Value); pay[0].Type = txf.GetintByIndex(_KEY_pay_0_Type); pay[0].Id = txf.GetstringByIndex(_KEY_pay_0_Id); pay[0].Value = txf.GetintByIndex(_KEY_pay_0_Value); pay[1].Type = txf.GetintByIndex(_KEY_pay_1_Type); pay[1].Id = txf.GetstringByIndex(_KEY_pay_1_Id); pay[1].Value = txf.GetintByIndex(_KEY_pay_1_Value); return true; } }