using connor_zwcadm.model; using KPlan.Logger; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace connor_zwcadm.util { class KUtil { public static void Log(string format, params object[] args) { TDefaultLogger.CreateInstance().LogAgent.DebugFormat(format, args); } public static void Put(Dictionary map, A key, B value) { map.Remove(key); map.Add(key, value); } public static T Pop(List arr) { if (arr == null || arr.Count == 0) { return default(T); } T t = arr[0]; arr.RemoveAt(0); return t; } public static int GetLen(object[] arr) { return arr == null ? 0 : arr.Length; } public static B Get(Dictionary map, A key) { if (map == null || key == null || !map.ContainsKey(key)) { return default(B); } return map[key]; } public static bool IsMechanical() { return "true".Equals(ConfigUtil.GetValue("mechanical")); } public static string GetCADValue(Dictionary map, string key) { if (map == null || key == null || !map.ContainsKey(key)) { return null; } CADAttr attr = map[key]; return attr == null ? null : attr.Value; } public static string PrintDictionary(Dictionary map, string splitter = ", ") { return string.Join(splitter, map.Select(kv => "["+ kv.Key + "]=[" + kv.Value + "]").ToArray()); } public static bool CompareDictionary(Dictionary dic1, Dictionary dic2) { if (dic1 == null && dic2 == null) { return true; } if (dic1 == null || dic2 == null) { return false; } if (dic1.Count != dic2.Count) { return false; } foreach(A key in dic1.Keys) { if (!dic2.ContainsKey(key)) { return false; } B value1 = dic1[key]; B value2 = dic2[key]; if (value1 == null) { if (value2 != null) { return false; } } else { if (!value1.Equals(value2)) { return false; } } } return true; } public static void LogErr(Exception ex) { if (ex.InnerException == null) { Log(ex.Message + "\r\n" + ex.StackTrace); } else { Log(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.InnerException.Message); } } public static bool IsEmpty(string str) { return string.IsNullOrWhiteSpace(str); } } }