public void OnNext(KeyValuePair <string, object> value) { foreach (var method in _TracingDiagnosticMethodCollection) { XPlusEx.XTry(() => method.Invoke(value.Key, value.Value), ex => Console.WriteLine(ex)); } }
/// <summary> /// Invoke method with diagnostic and tracing /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Class"></param> /// <param name="methodName"></param> /// <param name="parameters"></param> /// <returns>方法的结果对象</returns> public static Object?ByTraceInvoke <T>(this T Class, string methodName, Object?[]?parameters) { if (methodName.IsNullOrEmpty()) { return(null); } var obj = Class.GetType(); var method = obj.GetMethod(methodName); if (method == null) { return(null); } Dictionary <string, object> keyValues = new Dictionary <string, object>(); List <string> ParameterNames = method.GetParameters().Select(t => t.Name).ToList(); if (ParameterNames.Count != parameters?.Length) { throw new TargetParameterCountException("The number of parameters does not match"); } keyValues.Add("MethodName", method.Name); for (int index = 0; index < ParameterNames.Count; index++) { keyValues.Add(ParameterNames[index], parameters[index].ToJson()); } MethodHandlerDiagnosticListener.MethodListener.ExecuteCommandMethodStar(keyValues); return(XPlusEx.XTry <Object>(() => { if (!method.ReturnType.Name.Contains("Task")) { var result = method.Invoke(Class, parameters); MethodHandlerDiagnosticListener.MethodListener.ExecuteCommandMethodEnd(result); return result; } else { var result = (dynamic)method.Invoke(Class, parameters); if (((TaskStatus)result.Status) == TaskStatus.Faulted) { throw (AggregateException)result.Exception; } MethodHandlerDiagnosticListener.MethodListener.ExecuteCommandMethodEnd(result.Result); return result; } }, ex => { MethodHandlerDiagnosticListener.MethodListener.ExecuteCommandMethodException(ex.InnerException); return null; })); }
/// <summary> /// 查询需要生成APIJson的接口 /// </summary> public SocketMiddleData FindLibrary() { List <Type> SourceType = DependencyLibrary.Dependency.Where(item => item.GetCustomAttribute(typeof(SocketRouteAttribute)) != null).ToList(); foreach (var Items in SourceType) { List <string> Route = new List <string>(); SocketRouteAttribute SocketRoute = (Items.GetCustomAttribute(typeof(SocketRouteAttribute)) as SocketRouteAttribute); string ControllerName = string.Empty; if (SocketRoute.ControllerName.IsNullOrEmpty()) { ControllerName = Items.Name; } else { ControllerName = SocketRoute.ControllerName; } Items.GetMethods().Where(x => x.GetCustomAttribute(typeof(SocketMethodAttribute)) != null).ToList().ForEach(Item => { SocketMethodAttribute SocketMethod = (Item.GetCustomAttribute(typeof(SocketMethodAttribute)) as SocketMethodAttribute); string SocketUrl = string.Empty; if (SocketMethod.MethodName.IsNullOrEmpty()) { SocketUrl = $"{SocketRoute.InternalServer}/{ControllerName}/{Item.Name}"; } else { SocketUrl = $"{SocketRoute.InternalServer}/{ControllerName}/{SocketMethod.MethodName}"; } if (!SocketMethod.MethodVersion.IsNullOrEmpty()) { SocketUrl = SocketUrl + "/" + SocketMethod.MethodVersion; } Route.Add(SocketUrl.ToLower()); }); XPlusEx.XTry(() => { var Key = SocketRoute.InternalServer.ToLower(); if (SocketJson.ContainsKey(Key)) { SocketJson[Key].AddRange(Route); } else { SocketJson.Add(Key, Route); } }, Ex => throw Ex); } CreateSocketApiJsonScript(); return(SocketMiddleData.Middle(SendTypeEnum.Init, SocketResultDefault.SetValue(null, SocketJson.ToJson()))); }
public static void ByTraceSocket(this Socket Socket, Object?data) { Dictionary <string, object> keyValues = new Dictionary <string, object>(); keyValues.Add("Ways", Socket.ProtocolType.ToString()); keyValues.Add("Remote", Socket.RemoteEndPoint.ToString()); keyValues.Add("Local", Socket.LocalEndPoint.ToString()); keyValues.Add("AddressWays", Socket.AddressFamily.ToString()); keyValues.Add("SocketType", Socket.SocketType.ToString()); SocketHandlerDiagnosticListener.SocketListener.ExcuteSocketBeginReceive(keyValues); XPlusEx.XTry(() => { SocketHandlerDiagnosticListener.SocketListener.ExcuteSocketBeginEnd(keyValues); }, ex => SocketHandlerDiagnosticListener.SocketListener.ExcuteSocketException(ex)); }
/// <summary> /// 注册XExten服务 /// </summary> /// <param name="services"></param> /// <param name="AssemblyName"></param> /// <returns>IServiceCollection</returns> public static IServiceCollection RegistXExtenService(this IServiceCollection services, string AssemblyName = "XExten.Profile") { var Ass = XPlusEx.XAssembly(AssemblyName); List <Type> DependencyAssembly = Ass.SelectMany(opt => opt.ExportedTypes.Where(t => t.GetInterfaces().Contains(typeof(IDependency)))).ToList(); List <Type> SingletonDependencyAssembly = Ass.SelectMany(opt => opt.ExportedTypes.Where(t => t.GetInterfaces().Contains(typeof(ISingletonDependency)))).ToList(); foreach (Type Item in DependencyAssembly) { if (Item.IsClass) { var TragetService = Item.GetInterfaces().Where(opt => opt != typeof(IDependency)).FirstOrDefault(); services.AddSingleton(TragetService, Item); } } foreach (Type Item in SingletonDependencyAssembly) { if (Item.IsClass) { services.AddSingleton(Item); } } return(services); }
public void XConvertCHN_Test() { decimal data = 4.85M; var res = XPlusEx.XConvertCHN(data); }
public void XBarHtml_Test() { var res = XPlusEx.XBarHtml("ABC", 3, 50); }
public void XVerifyCode_Test() { var res = XPlusEx.XVerifyCode(); }
public void XTel_Test() { var res = XPlusEx.XTel(); }