public void CastEvent <T>(object sender, RemoteEventArgs <T> args) where T : class, new() { IEventOC eventOC = ServiceTaker.GetRemoteService <IEventOC>(); IJsonSerializer serializer = ServiceTaker.GetService <IJsonSerializer>(); EventDC evDc = new EventDC(); evDc.EventKey = Guid.NewGuid().ToString(); evDc.EventName = args.EventName; evDc.Message.TypeQualifiedName = args.Message.GetType().AssemblyQualifiedName; evDc.Message.JsonValue = serializer.Serialize(args.Message); Type senderType = sender.GetType(); Type senderInterface = null; Type[] theInterfaces = senderType.GetInterfaces(); if (theInterfaces.Length == 1) { senderInterface = theInterfaces[0]; } else { senderInterface = theInterfaces.Where(ww => ww.GetEvents().Select(ss => ss.Name).Contains(args.EventName)).FirstOrDefault(); } evDc.SenderInterfaceName = senderInterface == null ? string.Empty : senderInterface.FullName; evDc.SenderTypeName = senderType.FullName; eventOC.CastRemoteEvent(evDc); }
public void RegisterTypeMapFromConfigDB(List <TypeMap> mapList) { var config = ServiceTaker.GetService <IConfiger>(); List <TypeMap> listTM = config.GetMulti <TypeMap>(typeof(TypeMap).FullName); foreach (var aMap in listTM) { lock (mapLoker) { mapList.Remove(aMap); mapList.Add(aMap); } } }
public static DbProviderInfo GetProviderInfo(string DbContextName) { if (LocalConfig.providerInfoList == null || LocalConfig.providerInfoList.Count < 1) { LocalConfig.GetProviderFromFile(); } DbProviderInfo dbProviderInfo = ( from ww in LocalConfig.providerInfoList where ww.DbContextName == DbContextName select ww).FirstOrDefault <DbProviderInfo>(); if (dbProviderInfo == null) { IConfiger service = ServiceTaker.GetService <IConfiger>(new object[0]); dbProviderInfo = service.GetFirst <DbProviderInfo>(DbContextName); LocalConfig.providerInfoList.Remove(dbProviderInfo); LocalConfig.providerInfoList.Add(dbProviderInfo); } return(dbProviderInfo); }
/// <summary> /// 远程事件的播送方法。 /// </summary> /// <param name="sender">发送者。这个参数用于计算响应者路由但不会发往远程响应端。</param> /// <param name="args">参数,参数将传弟到响应端。要发给远程响应端的数据必须放在这个参数中。</param> public void CastEvent <T>(object sender, RemoteEventArgs <T> args) where T : class, new() { Type senderType = sender.GetType(); EventDC evData = new EventDC(); evData.EventKey = Guid.NewGuid().ToString("N"); if (senderType.GetEvent(args.EventName) != null || senderType.GetEvent(args.EventName).EventHandlerType.FullName == typeof(RemoteEventHandler <>).FullName) { evData.EventName = args.EventName; } else { throw new Exception("不存在RemoteEventHandler型事件" + evData.EventName); } Type[] interfaces = senderType.GetInterfaces(); List <Type> inheritInterfaceList = interfaces.Where(ww => (ww.GetMembers().Select(ss => ss.Name)).Contains(args.EventName)).ToList(); if (inheritInterfaceList.Count != 1) { throw new Exception("不存在或多于一个事件发送者所继承的接口中声名事件" + evData.EventName); } else { evData.SenderInterfaceName = inheritInterfaceList.First().FullName; } ParameterDC Message = new ParameterDC(); Message.TypeQualifiedName = args.Message.GetType().AssemblyQualifiedName; Message.JsonValue = ServiceTaker.GetService <IJsonSerializer>().Serialize(args.Message); evData.Message = Message; evData.SenderTypeName = senderType.FullName; IEventOC evOperation = ServiceTaker.GetRemoteService <IEventOC>(); evOperation.CastRemoteEvent(evData); }
public ApiCore(MethodDC Contract) { Serializer = ServiceTaker.GetService <IJsonSerializer>(); theContract = Contract; }
public WebRequseter() { Serializer = ServiceTaker.GetService <IJsonSerializer>(); }
private static T HttpRequest <T>(string url, string jsonData, string method) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = method; request.ContentType = "application/json"; request.Timeout = 180000; request.ReadWriteTimeout = 180000; request.KeepAlive = false; if (method.Equals("POST", StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrEmpty(jsonData)) { byte[] datas = Encoding.UTF8.GetBytes(jsonData); if (datas.Length > 0) { request.ContentLength = datas.Length; try { Stream requestStream = request.GetRequestStream(); requestStream.Write(datas, 0, datas.Length); requestStream.Close(); } catch (ProtocolViolationException) { request.Abort(); throw; } catch (WebException) { request.Abort(); throw; } catch (ObjectDisposedException) { request.Abort(); throw; } catch (InvalidOperationException) { request.Abort(); throw; } catch (NotSupportedException) { request.Abort(); throw; } } } } HttpWebResponse response = null; string responseDatas = string.Empty; try { response = (HttpWebResponse)request.GetResponse(); Stream streamResponse = response.GetResponseStream(); using (StreamReader sr = new StreamReader(streamResponse)) { responseDatas = sr.ReadToEnd(); } } catch (Exception) { throw; } finally { if (response != null) { response.Close(); response = null; } request.Abort(); request = null; } try { return(ServiceTaker.GetService <IJsonSerializer>().Deserialize <T>(responseDatas)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 构造函数。 /// </summary> public ApiHandler() { Serializer = ServiceTaker.GetService <IJsonSerializer>(); }