static object FindClientCallback <T>(ServerBase serverBase, ClientInfo client, Type serviceType, string attribName) { var find = serverBase.FindClientCallbackByType(client, serviceType); if (find == null) { GetClientCallbackOfClientContext <T>(serverBase, client); find = serverBase.FindClientCallbackByType(client, serviceType); if (find == null) { AutoLogger.LogText($"GetAllClientCallbackListOfClientContext service not found : {serviceType.FullName} : name: {attribName} session: {client.SessionId}", true); } } return(find); }
/// <summary> /// get current context callback /// </summary> /// <typeparam name="T">type of callback</typeparam> /// <param name="context">client context</param> /// <returns>list of callback context</returns> public static ClientContext <T> GetClientCallbackOfClientContext <T>(this ServerBase serverBase, ClientInfo client) { #if (NETSTANDARD1_6 || NETCOREAPP1_1) if (typeof(T).GetTypeInfo().IsInterface) #else if (typeof(T).IsInterface) #endif { if (!serverBase.Callbacks.ContainsKey(client)) { serverBase.RegisterCallbacksForClient(client); if (!serverBase.Callbacks.ContainsKey(client)) { try { throw new Exception($"context client not exist! {client.SessionId} {serverBase.Callbacks.Count} {serverBase.Services.Count} {DateTime.Now}"); } catch (Exception ex) { AutoLogger.LogError(ex, "GetClientCallbackOfClientContext"); } return(null); } } #if (NETSTANDARD1_6 || NETCOREAPP1_1) var attribName = ((ServiceContractAttribute)typeof(T).GetTypeInfo().GetCustomAttributes(typeof(ServiceContractAttribute), true).FirstOrDefault()).Name; #else var attribName = ((ServiceContractAttribute)typeof(T).GetCustomAttributes(typeof(ServiceContractAttribute), true).FirstOrDefault()).Name; #endif var serviceType = serverBase.GetRegisteredCallbacksTypeByName(attribName); var find = serverBase.FindClientCallbackByType(client, serviceType); if (find != null) { return(new ClientContext <T>(find, client)); } var obj = CSCodeInjection.InstanceServerInterface <T>(serviceType, new List <Type>() { typeof(ServiceContractAttribute) }); //dynamic dobj = obj; if (CSCodeInjection.InvokedServerMethodAction == null) { ServerExtension.Init(); } //dobj.InvokedServerMethodAction = CSCodeInjection.InvokedServerMethodAction; //dobj.InvokedServerMethodFunction = CSCodeInjection.InvokedServerMethodFunction; var field = serviceType #if (NETSTANDARD1_6 || NETCOREAPP1_1) .GetTypeInfo() #endif .GetProperty("InvokedServerMethodAction"); field.SetValue(obj, CSCodeInjection.InvokedServerMethodAction, null); var field2 = serviceType #if (NETSTANDARD1_6 || NETCOREAPP1_1) .GetTypeInfo() #endif .GetProperty("InvokedServerMethodFunction"); field2.SetValue(obj, CSCodeInjection.InvokedServerMethodFunction, null); var op = obj as OperationCalls; op.ServerBase = serverBase; op.CurrentClient = client; //serverBase.RegisteredCallbacksTypes.ContainsKey(attribute.Name); serverBase.Callbacks[client].Add(obj); if (!(obj is OperationCalls)) { Shared.Log.AutoLogger.LogText("is not OprationCalls: " + obj.ToString(), true); } return(new ClientContext <T>(obj, client)); } else { Shared.Log.AutoLogger.LogText("is not interface: " + typeof(T).ToString(), true); return(new ClientContext <T>((T)serverBase.FindClientCallbackByType(client, typeof(T)), client)); } }