public void SubscribeConfig(ClientConfigModel model) { if (model.ClientID < 1 && string.IsNullOrEmpty(model.ConfigCode) == false) { ConfigModel config = DBFactory.GetModel <IDBConfigDal>("IDBConfigDal").GetConfig(new ConfigModel() { ID = model.ConfigID, Code = model.ConfigCode, ParentID = model.ConfigParentID });; if (config == null || config.ID < 1) { return; } model.ConfigID = config.ID; model.ConfigParentID = config.ParentID; } if (model.ClientID < 1) { return; } if (model.ClientState < 1) { ClientMonitor.CancelClient(model.ClientID); return; } if (model.ConfigID > 0) { ClientMonitor.RegisterClient(model.ClientID, model.ConfigID); } else { ClientMonitor.RegisterClient(model.ClientID); } }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:HiLoSocket.SocketApp.Client`1" /> class. /// </summary> /// <param name="clientConfigModel">The client model.</param> /// <param name="logger">The logger.</param> /// <exception cref="T:System.ArgumentNullException">clientConfigModel</exception> /// <exception cref="T:System.ComponentModel.DataAnnotations.ValidationException"></exception> internal Client(ClientConfigModel clientConfigModel, ILogger logger) : base(clientConfigModel?.FormatterType, clientConfigModel?.CompressType, logger) { CheckIfNullModel(clientConfigModel); ValidateModel(clientConfigModel); LocalIpEndPoint = clientConfigModel?.LocalIpEndPoint; RemoteIpEndPoint = clientConfigModel?.RemoteIpEndPoint; TimeoutTime = clientConfigModel?.TimeOutTime ?? 3000; }
private static void ValidateModel(ClientConfigModel clientConfigModel) { if (clientConfigModel.ValidateObject(out var errorMessages) == false) { throw new ValidationException( $@"時間 : {DateTime.Now.GetDateTimeString( )}, 類別 : {nameof( Client<TCommandModel> )}, 方法 : Constructor, 內容 : {string.Join( "\n", errorMessages )}"); } }
private static void CheckIfNullModel(ClientConfigModel clientConfigModel) { if (clientConfigModel == null) { throw new ArgumentNullException(nameof(clientConfigModel), $@"時間 : {DateTime.Now.GetDateTimeString( )}, 類別 : {nameof( Client<TCommandModel> )}, 方法 : Constructor, 內容 : 你沒初始化 {nameof( clientConfigModel )} 喔。"); } }
public void Init() { var testClientConfigModel = new ClientConfigModel { Url = "ws://127.0.0.1:10001", EncodingType = Encoding.UTF8, ServerMessageMaxLength = 102400 }; _testClientClient.OnConfigChange += TestClientClientOnConfigChange; _testClientClient.OnSendCommand += TestClientClientOnSendCommand; _testClientClient.OnReceiveEvent += TestClientClientOnReceiveEvent; _testClientClient.OnStateChange += TestClientClientOnStateChange; _testClientClient.SetConfig(testClientConfigModel); }
public IHttpActionResult GetClientConfig(bool isRef = false) { var clientConfig = new ClientConfigModel(); foreach (IGTypeFhirElement fit in IGTypeSection.GetSection().FhirIgTypes) { ImplementationGuideType igType = this.tdb.ImplementationGuideTypes.SingleOrDefault(y => y.Name.ToLower() == fit.ImplementationGuideTypeName.ToLower()); if (igType == null) { Log.For(this).Warn("Configured FHIR IG Type could not be found in the database: " + fit.ImplementationGuideTypeName); continue; } var fhirIgType = new ClientConfigModel.FhirIgType() { Id = igType.Id, Name = igType.Name, Version = fit.Version, BaseUrl = "" }; switch (fhirIgType.Version) { case "DSTU1": fhirIgType.BaseUrl = "/api/FHIR1/"; break; case "DSTU2": fhirIgType.BaseUrl = "/api/FHIR2/"; break; case "STU3": fhirIgType.BaseUrl = "/api/FHIR3/"; break; } clientConfig.FhirIgTypes.Add(fhirIgType); } if (isRef) { var clientConfigJson = Newtonsoft.Json.JsonConvert.SerializeObject(clientConfig); return(Content <string>(HttpStatusCode.OK, "var trifoliaConfig = " + clientConfigJson + ";", new Formatters.JavaScriptFormatter(), "text/javascript")); } return(Content <ClientConfigModel>(HttpStatusCode.OK, clientConfig)); }
public IHttpActionResult GetClientConfig(bool isRef = false) { var clientConfig = new ClientConfigModel(); //Collect all methods in script Assembly assembly = Assembly.GetExecutingAssembly(); //Find all FHIR API IGControllers var FHIRClasses = assembly.GetTypes() .Where(t => t.IsClass && t.GetCustomAttributes(typeof(FHIRInfo)).Any()) .ToArray(); foreach (var FHIRClass in FHIRClasses) { //Get the attributes of the FHIR IGController being examined var attributes = FHIRClass.GetCustomAttributes(); //Collect the version attribute of that IGController var versionAttribute = (FHIRInfo)attributes.Single(a => a.GetType() == typeof(FHIRInfo)); //Find the igType in the database ImplementationGuideType igType = this.tdb.ImplementationGuideTypes.SingleOrDefault(y => y.Name.ToLower() == versionAttribute.IGType.ToLower()); //If doesn't exist, throw an error but continue if (igType == null) { Log.For(this).Error("Implementation guide type defined in web.config not found in database: " + versionAttribute.IGType); continue; } //Get the route attribute var routeCheck = attributes.Where(a => a.GetType() == typeof(RoutePrefixAttribute)); //Make sure there's exactly one route attribute (shouldn't be possible but doesn't hurt to check) if (routeCheck.Count() > 1 || routeCheck.Count() == 0) { throw new Exception("There are " + routeCheck.Count().ToString() + " route prefixes when there should be 1 for FHIR " + versionAttribute.Version); } //Get the route attribute of the IGController var routeAttribute = (RoutePrefixAttribute)attributes.Single(a => a.GetType() == typeof(RoutePrefixAttribute)); var fhirIgType = new ClientConfigModel.FhirIgType() { Id = igType.Id, Name = igType.Name, Version = versionAttribute.Version, BaseUrl = "/" + routeAttribute.Prefix + "/" }; clientConfig.FhirIgTypes.Add(fhirIgType); } if (isRef) { var clientConfigJson = Newtonsoft.Json.JsonConvert.SerializeObject(clientConfig); return(Content <string>(HttpStatusCode.OK, "var trifoliaConfig = " + clientConfigJson + ";", new Formatters.JavaScriptFormatter(), "text/javascript")); } return(Content <ClientConfigModel>(HttpStatusCode.OK, clientConfig)); }
/// <summary> /// 构造方法 /// </summary> /// <param name="config"></param> protected ClientImpl(ClientConfigModel config) { _cancellationToken = new CancellationToken(); SetConfig(config); }
/// <inheritdoc /> /// <summary> /// Initializes a new instance of the <see cref="T:HiLoSocket.SocketApp.Client`1" /> class. /// </summary> /// <param name="clientConfigModel">The client model.</param> internal Client(ClientConfigModel clientConfigModel) : this(clientConfigModel, null) { }