| | |
| | | using System; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Diagnostics; |
| | | using System.Linq; |
| | | using System.Runtime.Serialization; |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | //using NPOI.SS.Formula.Functions; |
| | | //using 文件读写; |
| | | |
| | | namespace Hydro.MapView |
| | | |
| | | namespace Yw.WinFrmUI.Q3d |
| | | { |
| | | |
| | | |
| | | |
| | | [Serializable] |
| | | public class dict : Dictionary<string, dynamic> |
| | | public class dict<TKey, TValue> : Dictionary<TKey, TValue> |
| | | { |
| | | private List<TKey> keys |
| | | { |
| | | get |
| | | { |
| | | return this.Keys.ToList(); |
| | | } |
| | | } |
| | | |
| | | public bool emptyCreate = true; |
| | | //List<dict> _list = null; |
| | | public dict() : base() |
| | | { |
| | | } |
| | |
| | | public dict(int capacity) : base(capacity) |
| | | { |
| | | } |
| | | |
| | | public dict(IEqualityComparer<string> comparer) : base(comparer) |
| | | public dict(IEnumerable<KeyValuePair<TKey, TValue>> collection) : base((IDictionary<TKey, TValue>)collection) |
| | | { |
| | | } |
| | | public dict(IDictionary<string, dynamic> dictionary) : base(dictionary) |
| | | { |
| | | } |
| | | public dict(int capacity, IEqualityComparer<string> comparer) : base(capacity, comparer) |
| | | { |
| | | } |
| | | public dict(IDictionary<string, dynamic> dictionary, IEqualityComparer<string> comparer) : base(dictionary, comparer) |
| | | { |
| | | } |
| | | protected dict(SerializationInfo info, StreamingContext context) |
| | | : base(info, context) |
| | | { |
| | | Value = info.GetBoolean("Test_Value"); |
| | | } |
| | | |
| | | public override void GetObjectData(SerializationInfo info, StreamingContext context) |
| | | { |
| | | base.GetObjectData(info, context); |
| | | info.AddValue("Test_Value", Value); |
| | | } |
| | | //public Dictionary<string, object> Dictionary() |
| | | //{ |
| | | // Dictionary<string, object> dc = new Dictionary<string, object>(this); |
| | | // return dc; |
| | | //} |
| | | public bool Value { get; set; } |
| | | |
| | | public bool SetKey(string key, dynamic Value) |
| | | public bool SetKey(TKey key, dynamic Value) |
| | | { |
| | | if (this.Contains(key)) |
| | | { |
| | |
| | | return true; |
| | | } |
| | | } |
| | | public string[] GetKeys() |
| | | public TKey[] GetKeys() |
| | | { |
| | | return this.Keys.ToArray(); |
| | | } |
| | | public List<TempForEnum> items() |
| | | public List<TempForEnum<TKey, TValue>> items() |
| | | { |
| | | var temp_list = new List<TempForEnum>(); |
| | | var temp_list = new List<TempForEnum<TKey, TValue>>(); |
| | | foreach (var Pair in this) |
| | | { |
| | | temp_list.Add(new TempForEnum(Pair.Key, Pair.Value)); |
| | | temp_list.Add(new TempForEnum<TKey, TValue>(Pair.Key, Pair.Value)); |
| | | } |
| | | return temp_list; |
| | | } |
| | | public bool Contains(string[] keys) |
| | | public bool Contains(TKey[] keys) |
| | | { |
| | | foreach (var key in keys) |
| | | if (!this.Contains(key)) return false; |
| | | return true; |
| | | } |
| | | public bool Contains(string key) |
| | | public bool Contains(TKey key) |
| | | { |
| | | return this.ContainsKey(key); |
| | | } |
| | | public bool Contains(KeyValuePair<string, dynamic> key) |
| | | public bool Contains(KeyValuePair<TKey, dynamic> key) |
| | | { |
| | | return this.ContainsKey(key.Key); |
| | | } |
| | | public dynamic Get(string key, dynamic @default = null) |
| | | public TValue Get(TKey key, TValue @default = default(TValue)) |
| | | { |
| | | if (this.Contains(key)) |
| | | return this[key];//obj.FirstOrDefault((k) => k.Key == key); |
| | | else |
| | | return @default; |
| | | } |
| | | public dynamic Get(KeyValuePair<string, dynamic> key, dynamic @default = null) |
| | | public TValue Get(KeyValuePair<TKey, TValue> key, TValue @default = default(TValue)) |
| | | { |
| | | if (this.Contains(key)) |
| | | return this[key];//obj.FirstOrDefault((k) => k.Key == key); |
| | | return this[key.Key];//obj.FirstOrDefault((k) => k.Key == key); |
| | | else |
| | | return @default; |
| | | } |
| | | public dynamic pop(string key, dynamic @default = null) |
| | | public TValue pop(TKey key, TValue @default = default(TValue)) |
| | | { |
| | | if (this.Contains(key)) |
| | | { |
| | |
| | | else |
| | | return @default; |
| | | } |
| | | public dynamic pop(KeyValuePair<string, dynamic> key, dynamic @default = null) |
| | | public TValue pop(KeyValuePair<TKey, TValue> key, TValue @default = default(TValue)) |
| | | { |
| | | if (this.Contains(key)) |
| | | { |
| | | var temp = this[key]; |
| | | var temp = this[key.Key]; |
| | | this.Remove(key); |
| | | return temp;//obj.FirstOrDefault((k) => k.Key == key); |
| | | } |
| | | else |
| | | return @default; |
| | | } |
| | | public dynamic this[KeyValuePair<string, dynamic> key] |
| | | public TValue this[KeyValuePair<TKey, TValue> key] |
| | | { |
| | | get { return this[key.Key]; } |
| | | set { this[key.Key] = value; } |
| | | } |
| | | public new dynamic this[string key] |
| | | public TValue this[TKey key] |
| | | { |
| | | get { return base[key]; } |
| | | set |
| | | get |
| | | { |
| | | if (this.ContainsKey(key)) base[key] = value; |
| | | else this.Add(key, value); |
| | | if (!this.ContainsKey(key)) |
| | | { |
| | | lock (this) |
| | | { |
| | | if (!this.ContainsKey(key)) |
| | | { |
| | | if (emptyCreate) |
| | | this.Add(key, default(TValue)); |
| | | else |
| | | return default(TValue); |
| | | } |
| | | } |
| | | } |
| | | return base[key]; |
| | | |
| | | } |
| | | } |
| | | public dynamic this[Type key_Type] |
| | | { |
| | | get { return base[key_Type.Name]; } |
| | | set |
| | | { |
| | | if (this.ContainsKey(key_Type.Name)) base[key_Type.Name] = value; |
| | | if (!this.ContainsKey(key)) |
| | | { |
| | | lock (this) |
| | | { |
| | | if (!this.ContainsKey(key)) |
| | | { |
| | | if (emptyCreate) |
| | | this.Add(key, value); |
| | | else |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | base[key] = value; |
| | | } |
| | | |
| | | } |
| | | |
| | | public TValue this[int index] |
| | | { |
| | | get |
| | | { |
| | | //如果是int类型的key,直接返回base[index],帮我补全以下return后的内容 |
| | | TKey key = default(TKey); |
| | | if (typeof(TKey) == typeof(int)) |
| | | key = (TKey)(object)index; |
| | | else |
| | | key = keys[index]; |
| | | if (!base.ContainsKey(key)) |
| | | base.Add(key, default(TValue)); |
| | | |
| | | return base[key]; |
| | | } |
| | | set |
| | | { |
| | | TKey key = default(TKey); |
| | | if (typeof(TKey) == typeof(int)) |
| | | { |
| | | key = (TKey)(object)index; |
| | | base[key] = value; |
| | | } |
| | | |
| | | else |
| | | { |
| | | this.Add(key_Type.Name, value); |
| | | if (this.dic_Type == null) |
| | | dic_Type = new dict(); |
| | | if (!this.dic_Type.ContainsKey(key_Type.Name)) |
| | | this.dic_Type.Add(key_Type.Name, key_Type); |
| | | if (index < keys.Count) |
| | | { |
| | | key = keys[index]; |
| | | base[key] = value; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | public dict dic_Type; |
| | | public bool Remove(KeyValuePair<string, dynamic> key) |
| | | |
| | | public override string ToString() |
| | | { |
| | | return JsonConvert.SerializeObject(this); |
| | | } |
| | | public void LoadFromString(string s) |
| | | { |
| | | dict<TKey, TValue> d = JsonConvert.DeserializeObject<dict<TKey, TValue>>(s); |
| | | this.Clear(); |
| | | foreach (var kp in d) |
| | | { |
| | | this.Add(kp.Key, kp.Value); |
| | | } |
| | | |
| | | } |
| | | //public void ExportToExcel() |
| | | //{ |
| | | // DataTable dt = new DataTable(); |
| | | // dt.Columns.Add("Key"); |
| | | // dt.Columns.Add("Value",typeof(double)); |
| | | // foreach (var kp in this) |
| | | // { |
| | | // dt.Rows.Add(kp.Key, kp.Value); |
| | | // } |
| | | // ExcelExport.DtToExcel(dt); |
| | | //} |
| | | public bool Remove(KeyValuePair<TKey, TValue> key) |
| | | { |
| | | return this.Remove(key.Key); |
| | | } |
| | | |
| | | public List<string> keys() |
| | | { |
| | | return this.Keys.ToList(); |
| | | } |
| | | public List<dynamic> values() |
| | | |
| | | public List<TValue> values() |
| | | { |
| | | return this.Values.ToList(); |
| | | } |
| | | |
| | | #region 将Session的元素简单放进dict中,简单处理方便使用 |
| | | private DateTime 发送计时; |
| | | private string msgList = ""; |
| | | private System.Timers.Timer t = new System.Timers.Timer(); |
| | | |
| | | public Task finish() |
| | | { |
| | | return Task.Run(() => { }); |
| | | } |
| | | public string msg |
| | | { |
| | | get { return this.Get("message"); } |
| | | } |
| | | public string msg_text |
| | | { |
| | | get { return this.Get("message"); } |
| | | } |
| | | public string current_arg_text |
| | | { |
| | | get { return this.Get("current_arg_text"); } |
| | | } |
| | | public dict ctx |
| | | |
| | | public dict<TKey, TValue> ctx |
| | | { |
| | | get { return this; } |
| | | } |
| | |
| | | #region IntentCommand |
| | | public double confidence; |
| | | public string methodName; |
| | | public dict args; |
| | | public dict<TKey, TValue> args; |
| | | public string current_arg; |
| | | //current_arg: str = '' |
| | | public dict(double confidence, string methodName, string current_arg = "", dict args = null) |
| | | public dict(double confidence, string methodName, string current_arg = "", dict<TKey, TValue> args = null) |
| | | { |
| | | this.confidence = confidence; |
| | | this.methodName = methodName; |
| | |
| | | #endregion |
| | | |
| | | } |
| | | public class TempForEnum<TKey, TValue> |
| | | { |
| | | public TKey Item1; |
| | | public TValue Item2; |
| | | public TempForEnum(TKey key, TValue value) |
| | | { |
| | | Item1 = key; |
| | | Item2 = value; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |