Beispiel #1
0
        private CommonTaskHolder CreateHolder(Type taskType, DescriptorAttribute descriptor)
        {
            var key  = taskType.Name;
            var name = taskType.FullName;

            if (descriptor == null)
            {
                descriptor = UtilReflection.GetAttribute <DescriptorAttribute>(taskType);
                if (descriptor != null)
                {
                    key  = descriptor.Key;
                    name = descriptor.Name;
                }
            }

            var task = (CommonTask)_serviceLocator.GetService(taskType);

            return(new CommonTaskHolder
            {
                Key = key,
                Name = name,
                TaskType = taskType,
                Task = task
            });
        }
Beispiel #2
0
        public CommonTaskHolder FindTask(string key)
        {
            var assemblies = AssemblyLoadContext.Default.Assemblies;

            foreach (var assembly in assemblies)
            {
                foreach (var type in UtilReflection.GetImplementers <CommonTask>(assembly))
                {
                    var attr = UtilReflection.GetAttribute <DescriptorAttribute>(type);
                    if (attr == null)
                    {
                        continue;
                    }
                    if (attr.Key != key)
                    {
                        continue;
                    }

                    var holder = CreateHolder(type, attr);
                    return(holder);
                }
            }

            return(null);
        }
Beispiel #3
0
        private static Container ConfigureServices()
        {
            UtilReflection.LoadAllAssemblies();

            var container = new Container();

            container.Register <IDefinitionExecutor, DefinitionExecutor>();
            container.Register <ITemplateLoaderFactory, TemplateLoaderFactory>();
            container.Register <IEngineFactory, EngineFactory>();
            container.Register <IResultProcessorFactory, ResultProcessorFactory>();

            var serviceLocator = new SimpleInjectorServiceLocator(container);

            container.Register <IServiceLocator>(() => serviceLocator);

            var provider = new SimpleInjectorProvider(container);

            container.Register <ConsoleModeManager>();
            container.Register <IMacroManager, MacroManager>();

            // IMPORTANT! Register our application entry point
            container.Register <Application>(Lifestyle.Transient);

            return(container);
        }
Beispiel #4
0
        public void GetOne()
        {
            Admin admin = db.Admin.Select(e => e).FirstOrDefault();

            UtilReflection.print_r(admin);
            Assert.IsNotNull(admin);
        }
        public void GetOne()
        {
            Logsystem log = db.Logsystem.Select(e => e).FirstOrDefault();

            UtilReflection.print_r(log);
            Assert.IsNotNull(log);
        }
Beispiel #6
0
        public void GetOne()
        {
            Admin admin = adminService.GetOne();

            UtilReflection.print_r(admin);
            Assert.IsNotNull(admin);
        }
Beispiel #7
0
        public void Get()
        {
            List <Admin> admins = db.Admin.Take(10).ToList <Admin>();

            foreach (Admin admin in admins)
            {
                UtilReflection.print_r(admin);
            }
            Assert.AreEqual(10, admins.Count);
        }
Beispiel #8
0
        private void AddTaskTypesFrom(Assembly assembly)
        {
            _logger.LogInformation("Locating types in assembly {0}", assembly.FullName);
            var types = UtilReflection.GetImplementers <CommonTask>(assembly).ToList();

            if (types.Count > 0)
            {
                _taskTypeList.AddRange(types);
            }
        }
        public void Get()
        {
            List <Logsystem> logs = db.Logsystem.Take(10).ToList <Logsystem>();

            foreach (Logsystem log in logs)
            {
                UtilReflection.print_r(log);
            }
            Assert.AreEqual(10, logs.Count);
        }
Beispiel #10
0
        public void QueryPageByPageNo()
        {
            List <Admin> admins = adminService.QueryPage(1, 10);

            foreach (Admin admin in admins)
            {
                UtilReflection.print_r(admin);
            }
            Assert.AreEqual(10, admins.Count);
        }
Beispiel #11
0
        public void Get()
        {
            List <Admin> admins = adminService.Get();

            foreach (Admin admin in admins)
            {
                UtilReflection.print_r(admin);
            }
            Assert.AreEqual(10, admins.Count);
        }
Beispiel #12
0
        public static CatalogType GetCatalogTypeFromAttribute <T>()
        {
            var type = typeof(T);
            var attr = UtilReflection.GetAttribute <CatalogTypeAttribute>(type);

            if (attr == null)
            {
                throw new InvalidOperationException("Catalog object without CatalogTypeAttribute: " + type.FullName);
            }
            return(attr.CatalogType);
        }
Beispiel #13
0
        public void SqlExecute()
        {
            List <Admin> admins = db.Admin.SqlQuery("select * from Admin where LoginTimes>900").ToList <Admin>();

            Console.WriteLine("总计数:" + admins.Count);
            foreach (Admin admin in admins)
            {
                UtilReflection.print_r(admin);
            }

            Assert.IsTrue(admins.Count > 10);
        }
Beispiel #14
0
        /// <summary>
        /// 将Datatable每行根据列名和对象的属性名关系对应一一赋值
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="row"></param>
        /// <param name="cols"></param>
        public static void ToObject(Object obj, DataRow row, DataColumnCollection cols)
        {
            List <string> props = UtilReflection.GetPropertNames(obj);

            foreach (string prop in props)
            {
                if (cols.Contains(prop))
                {
                    UtilReflection.SetValue(obj, prop, row[prop].ToString());
                }
            }
        }
        public void SqlExecute()
        {
            List <Logsystem> logs = db.Logsystem.SqlQuery("select * from Logsystem where Logtime<getdate()").ToList <Logsystem>();

            Console.WriteLine("总计数:" + logs.Count);
            foreach (Logsystem log in logs)
            {
                UtilReflection.print_r(log);
            }

            Assert.IsTrue(logs.Count > 10);
        }
Beispiel #16
0
        /// <summary>
        /// 清除数据对象关联的数据对象,一般在获取到所需数据之后最后执行
        /// </summary>
        protected object ClearInclude(object entityObject, bool IsIncludeCommitTime = true, bool IsIncludeUpdateTime = true)
        {
            object destObject;

            if (entityObject.GetType().BaseType.FullName.Equals("System.Object"))
            {
                destObject = Activator.CreateInstance(entityObject.GetType());
            }
            else
            {
                destObject = Activator.CreateInstance(entityObject.GetType().BaseType);
            }
            List <string> keysList = UtilReflection.GetPropertNames(entityObject);
            PropertyInfo  p, p_n;

            foreach (string key in keysList)
            {
                p   = entityObject.GetType().GetProperty(key);
                p_n = destObject.GetType().GetProperty(key);
                if (p_n != null)
                {
                    if (p_n.PropertyType.FullName.Contains("Database."))
                    {
                        p_n.SetValue(destObject, null);
                    }
                    else
                    {
                        if (!IsIncludeCommitTime)
                        {
                            if (key.ToUpper().Equals("COMMITTIME"))
                            {
                                p_n.SetValue(destObject, null);
                                continue;
                            }
                        }
                        if (!IsIncludeUpdateTime)
                        {
                            if (key.ToUpper().Equals("UPDATETIME"))
                            {
                                p_n.SetValue(destObject, null);
                                continue;
                            }
                        }
                        object origin_pro = p.GetValue(entityObject);
                        if (origin_pro != null)
                        {
                            UtilReflection.SetValue(destObject, key, origin_pro.ToString());
                        }
                    }
                }
            }
            return(destObject);
        }
Beispiel #17
0
        public void GetByIDAdmin()
        {
            Admin admin = db.Admin.Find(AdminID);//new Guid(PersonID)

            if (admin != null)
            {
                UtilReflection.print_r(admin);
                Assert.AreEqual("admin", admin.Username);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
        public void GetByIDLogSystem()
        {
            Guid      logID = new Guid(originalLogID);
            Logsystem log   = db.Logsystem.Find(logID);

            if (log != null)
            {
                UtilReflection.print_r(log);
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Beispiel #19
0
        /// <summary>
        /// 将配置文件App.config里的AppSetting配置信息注入到全局变量中供应用使用
        /// </summary>
        private static void initAppSettings(char AppType = EnumAppType.Web)
        {
            Configuration config = AppConfig.Instance().getCurrentConfig(AppType);

            // Get the KeyValueConfigurationCollection from the configuration.
            KeyValueConfigurationCollection settings = config.AppSettings.Settings;
            Hashtable data = new Hashtable();

            foreach (KeyValueConfigurationElement keyValueElement in settings)
            {
                data.Add(keyValueElement.Key, keyValueElement.Value);
            }
            UtilReflection.SetPublicStaticProperties(typeof(Gc), data);
            UtilReflection.IsDebug = Gc.IsDebug;
        }
Beispiel #20
0
        private void RegisterDefaultService(Type type, InterfaceImplementationDefaultAttribute attribute)
        {
            var fullName = type.FullName;

            _logger.LogInformation("ServiceFinder. Registering type {0} as default service", fullName);
            var interfaces = UtilReflection.GetCleanInterfaces(type);

            if (interfaces.Count == 0)
            {
                throw new InvalidOperationException(
                          "Tried to register service with default interface, but the service has no interfaces");
            }

            var interfaceType = interfaces[0];

            _injectionProvider.Add(interfaceType, type, attribute.LifetimeMode);
        }
        public void QueryPageByPageNo()
        {
            int PageNo   = 3;
            int PageSize = 10;

            int StartPoint = (PageNo - 1) * PageSize;

            List <Logsystem> logs = db.Logsystem
                                    .OrderByDescending(e => e.Logtime)
                                    .Skip(StartPoint)
                                    .Take(PageSize).ToList <Logsystem>();

            foreach (Logsystem log in logs)
            {
                UtilReflection.print_r(log);
            }
            Assert.AreEqual(10, logs.Count);
        }
Beispiel #22
0
        public void QueryPageByPageNo()
        {
            int PageNo   = 1;
            int PageSize = 10;

            int StartPoint = (PageNo - 1) * PageSize;

            List <Admin> admins = db.Admin
                                  .OrderByDescending(e => e.ID)
                                  .Skip(StartPoint)
                                  .Take(PageSize).ToList <Admin>();

            foreach (Admin admin in admins)
            {
                UtilReflection.print_r(admin);
            }
            Assert.AreEqual(10, admins.Count);
        }
Beispiel #23
0
        public void Find()
        {
            var assemblies = AssemblyLoadContext.Default.Assemblies;

            AssemblyLoadContext.Default.Resolving += Default_Resolving;

            TypeListContainers = new List <Type>();
            foreach (var assembly in assemblies)
            {
                var types = assembly.GetTypes();
                foreach (var type in types)
                {
                    if (typeof(ITypeListContainer).IsAssignableFrom(type))
                    {
                        TypeListContainers.Add(type);
                    }

                    var serviceAttribute = UtilReflection.GetAttribute <ServiceAttribute>(type);
                    if (serviceAttribute != null)
                    {
                        RegisterService(type, serviceAttribute);
                        continue;
                    }

                    var interfaceImplementationDefaultAttribute =
                        UtilReflection.GetAttribute <InterfaceImplementationDefaultAttribute>(type);
                    if (interfaceImplementationDefaultAttribute != null)
                    {
                        RegisterDefaultService(type, interfaceImplementationDefaultAttribute);
                        continue;
                    }

                    var interfaceImplementationByConfigAttribute =
                        UtilReflection.GetAttribute <InterfaceImplementationByConfigAttribute>(type);
                    if (interfaceImplementationByConfigAttribute != null)
                    {
                        RegisterServiceByConfig(type, types.ToList(), interfaceImplementationByConfigAttribute);
                    }
                }
            }
        }
        public void QueryPage()
        {
            //开始记录数
            int StartPoint = 1;
            //结束记录数
            int EndPoint = 10;


            int From              = StartPoint - 1;
            int PageSize          = EndPoint - StartPoint + 1;
            List <Logsystem> logs = db.Logsystem
                                    .OrderByDescending(e => e.Logtime)
                                    .Skip(From)
                                    .Take(PageSize).ToList <Logsystem>();

            foreach (Logsystem log in logs)
            {
                UtilReflection.print_r(log);
            }

            Assert.AreEqual(10, logs.Count);
        }
Beispiel #25
0
        public void QueryPage()
        {
            //开始记录数
            int StartPoint = 1;
            //结束记录数
            int EndPoint = 10;


            int          From     = StartPoint - 1;
            int          PageSize = EndPoint - StartPoint + 1;
            List <Admin> admins   = db.Admin
                                    .OrderByDescending(e => e.ID)
                                    .Skip(From)
                                    .Take(PageSize).ToList <Admin>();

            foreach (Admin admin in admins)
            {
                UtilReflection.print_r(admin);
            }

            Assert.AreEqual(10, admins.Count);
        }
Beispiel #26
0
        /// <summary>
        /// 基本的复制同名的属性从数组到对象
        /// </summary>
        /// <param name="enti"></param>
        protected void CopyProperties(object entityObject, HttpRequest condition)
        {
            NameValueCollection conForm = condition.Form;

            String[]            keys     = conForm.AllKeys;
            LinkedList <string> keysList = new LinkedList <string>(keys);

            this.ClearValuelessData(keysList);
            String       value;
            PropertyInfo propertyInfo;

            foreach (string key in keysList)
            {
                value        = condition[key];
                propertyInfo = entityObject.GetType().GetProperty(key);
                UtilReflection.SetValue(entityObject, key, value);
            }
            propertyInfo = entityObject.GetType().GetProperty("UpdateTime");
            if (propertyInfo != null)
            {
                propertyInfo.SetValue(entityObject, DateTime.Now, null);
            }
        }
        /// <summary>
        /// 清除数据对象关联的数据对象,一般在获取到所需数据之后最后执行
        /// </summary>
        protected object ClearInclude(object entityObject)
        {
            object destObject;

            if (entityObject.GetType().BaseType.FullName.Equals("System.Object"))
            {
                destObject = Activator.CreateInstance(entityObject.GetType());
            }
            else
            {
                destObject = Activator.CreateInstance(entityObject.GetType().BaseType);
            }
            List <string> keysList = UtilReflection.GetPropertNames(entityObject);
            PropertyInfo  p, p_n;

            foreach (string key in keysList)
            {
                p   = entityObject.GetType().GetProperty(key);
                p_n = destObject.GetType().GetProperty(key);
                if (p_n != null)
                {
                    if (p_n.PropertyType.FullName.Contains("Database."))
                    {
                        p_n.SetValue(destObject, null);
                    }
                    else
                    {
                        object origin_pro = p.GetValue(entityObject);
                        if (origin_pro != null)
                        {
                            UtilReflection.SetValue(destObject, key, origin_pro.ToString());
                        }
                    }
                }
            }
            return(destObject);
        }
Beispiel #28
0
        public void FindFactories()
        {
            foreach (var container in TypeListContainers)
            {
                if (container.IsInterface || container.IsAbstract)
                {
                    continue;
                }

                var pi         = container.GetProperty("TypeList");
                var interfaces = UtilReflection.GetCleanInterfaces(container);
                if (interfaces.Count != 1)
                {
                    continue;
                }

                var instance = ServiceLocator.GetService(interfaces[0]);
                var typeList = (IList <Type>)pi.GetValue(instance, null);
                foreach (var type in typeList)
                {
                    _injectionProvider.Add(type, type, LifetimeMode.Singleton);
                }
            }
        }
Beispiel #29
0
        /// <summary>
        /// 根据Log Type显示描述
        /// </summary>
        /// <param name="ivrStatueType"></param>
        /// <returns></returns>
        public static string ShowLogType(string logType)
        {
            string result = UtilReflection.GetPublicStaticFieldValueByValue(typeof(LogType), logType, "TYPE", "DESC");

            return(result);
        }