using FreeSql.Internal.Model; using MaterialDesignThemes.Wpf; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Configuration; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using Txgy.EWS.Client.Entity; using Txgy.EWS.Client.Models; using Txgy.Microseismic.BaseLib.Models; namespace Txgy.EWS.Client.Common { public class GlobalData : BindableBase { //public static bool IsDesign = true; public static event EventHandler StaticPropertyChanged; public static UserInfoEntity CurrentUserInfo { get; set; } public static List TaskList = new List(); private static ObservableCollection reportEventLevelList=new ObservableCollection(); /// /// 报表事件等级列表 /// public static ObservableCollection ReportEventLevelList { get { return reportEventLevelList; } set { reportEventLevelList = value; StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs("EportEventLevelList")); } } private static ObservableCollection gridEvents=new ObservableCollection(); public static ObservableCollection GridEvents { get { return gridEvents; } set { gridEvents = value; StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs("GridEvents")); } } public static List SearchEvents { get; set; } = new List(); public static List StatEvents { get; set; } = new List(); public static MmEvent LastEvent { get; set; }= new MmEvent(); public static List ListAlarmEventId = new List(); public static List ReceivedEvents { get; set; }=new List(); public static List AlarmEvents { get; set; } = new List(); private static bool isRunning = false; public static bool IsRunning { get { return isRunning; } set { isRunning = value; StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs("SystemLoadingEvent")); } } private static bool appendEvent = false; public static bool AppendEvent { get { return appendEvent; } set { appendEvent = value; StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs("AppendEvent")); } } /// /// 深拷贝 /// /// /// /// public static T DeepCopyByReflection(T obj) { if (obj is string || obj.GetType().IsValueType) return obj; object retval = Activator.CreateInstance(obj.GetType()); FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); foreach (var field in fields) { try { field.SetValue(retval, DeepCopyByReflection(field.GetValue(obj))); } catch { } } return (T)retval; } public static List FillEvents(List sourceEvents) { List result = new List(); foreach (var item in sourceEvents) { result.Add(new MmEvent { X = item.X, Y = item.Y, Z = item.Z, EventID = item.EventID, ML = item.ML, LocSta = item.LocSta, MLSta = item.MLSta, EventTime = item.EventTime, RMS = item.RMS, WorkAreaID = item.WorkAreaID, }); } return result; } /// /// 获取主频 /// /// /// public static int GetDominFreq(string eventTime) { string downLoadStr = eventTime; string datePath = downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2) + downLoadStr.Substring(8, 2); string jsonStr = "HA." + downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2) + downLoadStr.Substring(8, 2) + downLoadStr.Substring(10, 3) + downLoadStr.Substring(14, 2) + downLoadStr.Substring(17, 2) + ".01" + GlobalConfig.DataTypeString + ".json"; string jsonFilePath = GlobalConfig.ProjectConfig.MseedFilePath + "\\" + datePath + "\\" + jsonStr; int dominantFreq = 0; if (File.Exists(jsonFilePath)) { if (new FileInfo(jsonFilePath).Length < 100) { return dominantFreq; } try { using (StreamReader sr = System.IO.File.OpenText(jsonFilePath)) { JsonTextReader reader = new JsonTextReader(sr); JArray jArray = (JArray)JToken.ReadFrom(reader); //解析普通属性和数组混合的Json文件 //数组0是普通属性集合 JObject jobj = (JObject)jArray[0]; List DominantFreqlist = new List(); JArray phaseArr = JArray.FromObject(jobj["phases"]); //List DominantFreqList = new List(); for (int i = 0; i < phaseArr.Count; i++) { if (phaseArr[i]["fmd_semi_period"] != null) { DominantFreqlist.Add(double.Parse(phaseArr[i]["fmd_semi_period"].ToString())); } } if (DominantFreqlist.Count > 0) { if (DominantFreqlist.Count > 3) { double min = DominantFreqlist.Min(); double max = DominantFreqlist.Max(); DominantFreqlist.Remove(min); DominantFreqlist.Remove(max); dominantFreq = (int)((DominantFreqlist.Sum() / (double)DominantFreqlist.Count) * 1000); } } } } catch (Exception ex) { //return 0; throw ex; } } return dominantFreq; } public static string FocalMechanismType2String(FocalMechanismType fmt) { string focalStr = "张性"; switch (fmt) { case FocalMechanismType.strikeSlip: focalStr = "走滑"; break; case FocalMechanismType.dipSlip: focalStr = "倾滑"; break; case FocalMechanismType.unknown: focalStr = "未识别"; break; } return focalStr; } public static string FocalMechanismIndex2String(int fmt) { string focalStr = "张性"; switch (fmt) { case 0: focalStr = "走滑"; break; case 1: focalStr = "倾滑"; break; case 2: focalStr = "张性"; break; case 3: focalStr = "未识别"; break; } return focalStr; } } }