public void Equals_ValidAndValidNames_Equal() { var one = new TypeAndName(typeof(IFakeDatabaseService), "Test"); var two = new TypeAndName(typeof(IFakeDatabaseService), "Test"); Assert.Equal(one, two); }
/// <summary> /// 得到专员信息 LY 2015-10-10 /// </summary> /// <param name="pclsCache"></param> /// <param name="PatientId"></param> /// <returns></returns> public TypeAndName PsBasicInfoDetailGetSDoctor(DataConnection pclsCache, string PatientId) { TypeAndName ret = new TypeAndName(); try { if (!pclsCache.Connect()) { return(ret); } InterSystems.Data.CacheTypes.CacheSysList list = null; list = Ps.BasicInfoDetail.GetSDoctor(pclsCache.CacheConnectionObject, PatientId); if (list != null) { ret.Type = list[0]; ret.Name = list[1]; } return(ret); } catch (Exception ex) { HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "ModuleInfoMethod.PsBasicInfoDetailGetSDoctor", "数据库操作异常! error information : " + ex.Message + Environment.NewLine + ex.StackTrace); return(ret); } finally { pclsCache.DisConnect(); } }
/// <summary> /// Resolves the last registered service with a matching name. /// </summary> /// <typeparam name="TInterface"></typeparam> /// <param name="name"></param> /// <returns></returns> public TInterface Resolve <TInterface>(string name) { var interfaceType = typeof(TInterface); var typeAndName = new TypeAndName(interfaceType, name); Type type; if (RegisteredTypes.TryGetValue(typeAndName, out type)) { object lazyInstance; if (StoredServices.TryGetValue(typeAndName, out lazyInstance) && lazyInstance.GetType() == typeof(Func <TInterface>)) { // Lazy singletons must be invoked when called first time. var invokedLazy = ((Func <TInterface>)lazyInstance).Invoke(); StoredServices.AddOrUpdate(typeAndName, k => invokedLazy, (k, v) => invokedLazy); } object instance; if (StoredServices.TryGetValue(typeAndName, out instance)) { // Return the stored singleton object. return((TInterface)instance); } // Get the first constructor from the registered type. var constructor = type.GetConstructors().First(); // Create a new instance and return it. var activator = Common.Activator.GetActivator(constructor); return((TInterface)activator()); } return(default(TInterface)); }
/// <summary> /// 得到所有试剂类型 /// </summary> /// <param name="pclsCache"></param> /// <returns></returns> public List <TypeAndName> MstReagentTypeGetAll(DataConnection pclsCache) { List <TypeAndName> list = new List <TypeAndName>(); try { if (!pclsCache.Connect()) { return(list); } InterSystems.Data.CacheTypes.CacheSysList Result = Cm.MstReagentType.GetAll(pclsCache.CacheConnectionObject); int count = Result.Count; int i = 1; while (i < count) { string[] ret = Result[i].Split('|'); TypeAndName info = new TypeAndName(); info.Type = ret[0]; info.Name = ret[1]; list.Add(info); i++; } return(list); } catch (Exception ex) { HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "UserInfoMethod.MstReagentTypeGetAll", "数据库操作异常! error information : " + ex.Message + Environment.NewLine + ex.StackTrace); return(list); } finally { pclsCache.DisConnect(); } }
/// <summary> /// Registers an object as a singleton with a name. When Resolve is called, /// the same object is returned. /// </summary> /// <param name="interfaceType"></param> /// <param name="theObject"></param> /// <param name="name"></param> public void RegisterAsSingleton(Type interfaceType, object theObject, string name) { var typeAndName = new TypeAndName(interfaceType, name); RegisterType(interfaceType, theObject.GetType(), name); StoredServices.AddOrUpdate(typeAndName, k => theObject, (k, v) => theObject); }
public void Equals_NullAndNullNames_Equal() { var one = new TypeAndName(typeof(IFakeDatabaseService), null); var two = new TypeAndName(typeof(IFakeDatabaseService), null); Assert.Equal(one, two); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)) { TypeAndName castedValue = (TypeAndName)value; return(castedValue.name == null ? castedValue.type.AssemblyQualifiedName : castedValue.name); } return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// Cleanup stored services with the matching interface type. /// </summary> /// <param name="interfaceType"></param> /// <param name="name"></param> protected virtual void CleanupServices(Type interfaceType, string name) { if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } var typeAndName = new TypeAndName(interfaceType, name); object instance; StoredServices.TryRemove(typeAndName, out instance); }
/// <summary> /// 浙大输出接口 LY 2015-10-29 /// </summary> /// <param name="PatientId"></param> /// <returns></returns> public List <TypeAndName> GetPatientInfo(DataConnection pclsCache, string PatientId) { List <TypeAndName> List = new List <TypeAndName>(); PatBasicInfo BasicInfo = new UsersRepository().GetPatBasicInfo(pclsCache, PatientId); TypeAndName NewLine1 = new TypeAndName { Type = "name", Name = BasicInfo.UserName }; List.Add(NewLine1); TypeAndName NewLine2 = new TypeAndName { Type = "age", Name = BasicInfo.Age }; List.Add(NewLine2); TypeAndName NewLine3 = new TypeAndName { Type = "sex", Name = BasicInfo.Gender }; List.Add(NewLine3); string Height = new VitalInfoRepository().GetLatestPatientVitalSigns(pclsCache, PatientId, "Height", "Height_1"); TypeAndName NewLine4 = new TypeAndName { Type = "height", Name = Height }; List.Add(NewLine4); string Weight = new VitalInfoRepository().GetLatestPatientVitalSigns(pclsCache, PatientId, "Weight", "Weight_1"); TypeAndName NewLine5 = new TypeAndName { Type = "weight", Name = Weight }; List.Add(NewLine5); string PhoneNumber = new UsersMethod().GetPhoneNoByUserId(pclsCache, PatientId); TypeAndName NewLine6 = new TypeAndName { Type = "mobilephone", Name = PhoneNumber }; List.Add(NewLine6); return(List); }
//通过PID得到模块 LY 2015-10-10 public List <TypeAndName> PsBasicInfoDetailGetModulesByPID(DataConnection pclsCache, string PatientId) { List <TypeAndName> list = new List <TypeAndName>(); CacheCommand cmd = null; CacheDataReader cdr = null; try { if (!pclsCache.Connect()) { return(null); } cmd = new CacheCommand(); cmd = Ps.BasicInfoDetail.GetModulesByPID(pclsCache.CacheConnectionObject); cmd.Parameters.Add("PatientId", CacheDbType.NVarChar).Value = PatientId; cdr = cmd.ExecuteReader(); while (cdr.Read()) { TypeAndName NewLine = new TypeAndName(); NewLine.Type = cdr["CategoryCode"].ToString(); NewLine.Name = cdr["Modules"].ToString(); list.Add(NewLine); } return(list); } catch (Exception ex) { HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "ModuleInfoMethod.PsBasicInfoDetailGetModulesByPID", "数据库操作异常! error information : " + ex.Message + Environment.NewLine + ex.StackTrace); return(null); } finally { if ((cdr != null)) { cdr.Close(); cdr.Dispose(true); cdr = null; } if ((cmd != null)) { cmd.Parameters.Clear(); cmd.Dispose(); cmd = null; } pclsCache.DisConnect(); } }
public object MstReagentTypeSetData(TypeAndName TypeAndName) { string token = Request.Headers.Authorization.ToString(); int valid = new ExceptionHandler().TokenCheck(token); if (valid == 0) { return("Token has expired"); } if (valid == -1) { return("Token has invalid signature"); } int ret = repository.SetMstReagentType(pclsCache, TypeAndName.Type, TypeAndName.Name); return(new ExceptionHandler().SetData(Request, ret)); }
/// <summary> /// Unregisters a service with a name. When this method is called, /// everything related is removed. /// </summary> /// <param name="interfaceType"></param> /// <param name="name"></param> public void Unregister(Type interfaceType, string name) { if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } if (IsNameNullOrValid(name) == false) { throw new ArgumentNullException("name"); } var typeAndName = new TypeAndName(interfaceType, name); Type type; RegisteredTypes.TryRemove(typeAndName, out type); CleanupServices(interfaceType, name); }
/// <summary> /// Registers a type with a name. When Resolve is called, a new object will /// be create. /// </summary> /// <param name="interfaceType"></param> /// <param name="type"></param> /// <param name="name"></param> public void RegisterType(Type interfaceType, Type type, string name) { if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } if (type == null) { throw new ArgumentNullException("type"); } if (IsNameNullOrValid(name) == false) { throw new ArgumentNullException("name"); } var typeAndName = new TypeAndName(interfaceType, name); // Cleanup previous stored services, with the same interface type and name. CleanupServices(interfaceType, name); // Add the typeAndName/type or update a previous registered type, with the same // typeAndName. RegisteredTypes.AddOrUpdate(typeAndName, k => type, (k, v) => type); }
//得到专员信息 LY 2015-10-10 public TypeAndName PsBasicInfoDetailGetSDoctor(DataConnection pclsCache, string PatientId) { TypeAndName ret = new TypeAndName(); try { if (!pclsCache.Connect()) { return(ret); } ret.Type = Ps.BasicInfoDetail.GetSDoctor(pclsCache.CacheConnectionObject, PatientId)[0].ToString(); ret.Name = Ps.BasicInfoDetail.GetSDoctor(pclsCache.CacheConnectionObject, PatientId)[1].ToString(); return(ret); } catch (Exception ex) { HygeiaComUtility.WriteClientLog(HygeiaEnum.LogType.ErrorLog, "PsBasicInfoDetail.GetSDoctor", "数据库操作异常! error information : " + ex.Message + Environment.NewLine + ex.StackTrace); return(ret); } finally { pclsCache.DisConnect(); } }
public void IsValid_Works_For_Null_Name() { var sut = new TypeAndName(_type, new Name(null)); Assert.False(sut.IsValid()); }
public void IsValid_Works_For_Null_Type() { var sut = new TypeAndName(null, _name); Assert.False(sut.IsValid()); }
public void Initializing_Sets_HashCode() { var sut = new TypeAndName(_type, _name); Assert.Equal(_hashCode, sut.HashCode); }
public void Initializing_Sets_Name() { var sut = new TypeAndName(_type, _name); Assert.Equal(_name, sut.Name); }
public void Initializing_Sets_Type() { var sut = new TypeAndName(_type, _name); Assert.Same(_type, sut.Type); }
private ThriftClientMetadata Load(TypeAndName typeAndName) { return(new ThriftClientMetadata(typeAndName.Type, typeAndName.Name, codecManager)); }
public Property Equals_works(TypeAndName x, TypeAndName y) => (!x.IsValid() || !y.IsValid() ? !x.Equals(y) : ((x.Type == y.Type && x.Name.Equals(y.Name)) == x.Equals(y))) .ToProperty();
public Property Equals_other_type_works(TypeAndName x, string y) => (!x.Equals(y)).ToProperty();
public Property Equals_null_works(TypeAndName x) => (!x.Equals(null)).ToProperty();
public void NameParameterIsNull_Null() { var sut = new TypeAndName(typeof(IFakeDatabaseService), null); Assert.Null(sut.Name); }
public void IsValid_Works_For_Empty_Name() { var sut = new TypeAndName(_type, new Name(Empty)); Assert.False(sut.IsValid()); }
public Property ToString_works(TypeAndName x) => (($"{x.Type?.Name}-{x.Name.Value}" == x.ToString())).ToProperty();
public void IsValid_Works_For_White_Space_Name() { var sut = new TypeAndName(_type, new Name(" \t ")); Assert.False(sut.IsValid()); }
public void GetHashCode_Works() { var sut = new TypeAndName(_type, _name); Assert.Equal(_hashCode, sut.GetHashCode()); }
public Property IsValid_works(TypeAndName x) => ((!(x.Type is null) && x.Name.IsValid()) == x.IsValid()).ToProperty();
public void NameParameterIsValid_NotNull() { var sut = new TypeAndName(typeof(IFakeDatabaseService), "Test"); Assert.NotNull(sut.Name); }