You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.8 KiB
102 lines
2.8 KiB
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<A, B>(Dictionary<A, B> map, A key, B value) {
|
|
map.Remove(key);
|
|
map.Add(key, value);
|
|
}
|
|
|
|
public static T Pop<T>(List<T> 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<A, B>(Dictionary<A, B> 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<string, CADAttr> 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<A, B>(Dictionary<A, B> map, string splitter = ", ") {
|
|
return string.Join(splitter, map.Select(kv => "["+ kv.Key + "]=[" + kv.Value + "]").ToArray());
|
|
}
|
|
|
|
public static bool CompareDictionary<A, B>(Dictionary<A, B> dic1, Dictionary<A, B> 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);
|
|
}
|
|
}
|
|
}
|