using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace ShowTrend3.Libs { public static class CustomConverters { private static DateTime _jan1st1970 = new DateTime(1970, 1, 1); public static long JStDateConv(DateTime from) { return System.Convert.ToInt64((from - _jan1st1970).TotalMilliseconds); } public static DateTime JStDateConv(long from) { return _jan1st1970.AddMilliseconds(from); } public static int ArchNameToNumVDP(string s) { var t = s.Split('.'); if (t.Last() != "gz") return int.Parse(t.Last()); t = t[0].Split('-'); if (t.Length == 2) return int.Parse(t.Last()); if (t.Length == 4) return int.Parse(t[2]); return -1; } public static bool CompareStringBuilder(ref StringBuilder a, StringBuilder b) { if (a.Length <= 0 || b.Length <= 0) return false; if (a[0] != '[' && a[a.Length - 1] != ']') return false; if (b[0] != '[' && b[b.Length - 1] != ']') return false; if (b.Length > 2) { a.Remove(a.Length - 1, 1); if (a.Length > 1) a.Append(','); a.Append(b, 1, b.Length - 1); } return true; } public static string ExceptionToString(Exception e) { string res = ""; char sl = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? '/' : '\\'; var st = new StackTrace(e, true).GetFrame(0); res = st.GetFileName().Split(sl).Last() + " > " + st.GetMethod().DeclaringType + " > " + st.GetMethod() + " > " + st.GetFileLineNumber() + ":" + st.GetFileColumnNumber() + " > " + e.Message; return res; } } }