Пример #1
0
        public void Equals_ValidAndValidNames_Equal()
        {
            var one = new TypeAndName(typeof(IFakeDatabaseService), "Test");
            var two = new TypeAndName(typeof(IFakeDatabaseService), "Test");

            Assert.Equal(one, two);
        }
Пример #2
0
        /// <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();
            }
        }
Пример #3
0
        /// <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));
        }
Пример #4
0
        /// <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();
            }
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        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));
            }
Пример #8
0
        /// <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);
        }
Пример #9
0
        /// <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);
        }
Пример #10
0
        //通过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));
        }
Пример #12
0
        /// <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);
        }
Пример #13
0
        /// <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);
        }
Пример #14
0
        //得到专员信息 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();
            }
        }
Пример #15
0
        public void IsValid_Works_For_Null_Name()
        {
            var sut = new TypeAndName(_type, new Name(null));

            Assert.False(sut.IsValid());
        }
Пример #16
0
        public void IsValid_Works_For_Null_Type()
        {
            var sut = new TypeAndName(null, _name);

            Assert.False(sut.IsValid());
        }
Пример #17
0
        public void Initializing_Sets_HashCode()
        {
            var sut = new TypeAndName(_type, _name);

            Assert.Equal(_hashCode, sut.HashCode);
        }
Пример #18
0
        public void Initializing_Sets_Name()
        {
            var sut = new TypeAndName(_type, _name);

            Assert.Equal(_name, sut.Name);
        }
Пример #19
0
        public void Initializing_Sets_Type()
        {
            var sut = new TypeAndName(_type, _name);

            Assert.Same(_type, sut.Type);
        }
Пример #20
0
 private ThriftClientMetadata Load(TypeAndName typeAndName)
 {
     return(new ThriftClientMetadata(typeAndName.Type, typeAndName.Name, codecManager));
 }
Пример #21
0
 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();
Пример #22
0
 public Property Equals_other_type_works(TypeAndName x, string y) =>
 (!x.Equals(y)).ToProperty();
Пример #23
0
 public Property Equals_null_works(TypeAndName x) =>
 (!x.Equals(null)).ToProperty();
Пример #24
0
        public void NameParameterIsNull_Null()
        {
            var sut = new TypeAndName(typeof(IFakeDatabaseService), null);

            Assert.Null(sut.Name);
        }
Пример #25
0
        public void IsValid_Works_For_Empty_Name()
        {
            var sut = new TypeAndName(_type, new Name(Empty));

            Assert.False(sut.IsValid());
        }
Пример #26
0
 public Property ToString_works(TypeAndName x) =>
 (($"{x.Type?.Name}-{x.Name.Value}" == x.ToString())).ToProperty();
Пример #27
0
        public void IsValid_Works_For_White_Space_Name()
        {
            var sut = new TypeAndName(_type, new Name("  \t  "));

            Assert.False(sut.IsValid());
        }
Пример #28
0
        public void GetHashCode_Works()
        {
            var sut = new TypeAndName(_type, _name);

            Assert.Equal(_hashCode, sut.GetHashCode());
        }
Пример #29
0
 public Property IsValid_works(TypeAndName x) =>
 ((!(x.Type is null) && x.Name.IsValid()) == x.IsValid()).ToProperty();
Пример #30
0
        public void NameParameterIsValid_NotNull()
        {
            var sut = new TypeAndName(typeof(IFakeDatabaseService), "Test");

            Assert.NotNull(sut.Name);
        }