예제 #1
0
        public void TestIsUpward()
        {
            var trainNo  = "Z180";
            var isUpward = (bool)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "IsUpward", trainNo);

            isUpward.Should().Be(true, "Z180车次尾号是偶数,根据规定,此类车次为上行方向");
        }
예제 #2
0
        public void TestGetInstance()
        {
            var instance = ReflectorHelper.GetInstance("Guoli.UtilitiesTest", "Guoli.UtilitiesTest.Helpers.TestClass");

            instance.Should()
            .BeOfType <TestClass>("because the fullname of the class is Guoli.UtilitiesTest.Helpers.TestClass");
        }
예제 #3
0
        private Dictionary <string, object> GetTableData(List <DbUpdateLog> dbLog)
        {
            var results = new Dictionary <string, object>();

            var tables = Utils.GetServer2ClientTables();
            var groups = dbLog.GroupBy(o => o.TableName);

            foreach (var g in groups)
            {
                var name = g.Key;
                if (!tables.Contains(name))
                {
                    continue;
                }

                var log       = g.ToList();
                var idList    = log.Select(o => o.TargetId);
                var condition = $" Id IN ({string.Join(",", idList)})";
                var bll       = ReflectorHelper.GetInstance("Guoli.Bll", $"Guoli.Bll.{name}Bll") as IBll;
                var data      = bll.QueryList(condition);
                if (data.Any())
                {
                    results.Add(name, data);
                }
            }

            return(results);
        }
예제 #4
0
        /// <summary>
        /// 根据表名创建对应的bll层实体对象
        /// </summary>
        /// <param name="tableName">目标表名称</param>
        /// <returns>继承自BaseBll类型的子类对象</returns>
        public static object GetBllInstance(string tableName)
        {
            var assemblyName = "Guoli.Bll";
            var fullName     = $"{assemblyName}.{tableName}Bll";

            return(ReflectorHelper.GetInstance(assemblyName, fullName));
        }
예제 #5
0
        private CriteriaOperatorCollection GetOperatorCollection(string fields, DataTable dataTable)
        {
            var operatorCollection = new CriteriaOperatorCollection();

            foreach (string property in fields.Split(';'))
            {
                if (property != "" && property.IndexOf("!") == -1 && property != "This")
                {
                    XPMemberInfo xpMemberInfo = ReflectorHelper.GetXpMemberInfo(Session, ObjectType, property);
                    if (xpMemberInfo.IsPersistent)
                    {
                        operatorCollection.Add(CriteriaOperator.Parse(property, new object[0]));
                        var dataColumn = new DataColumn(property)
                        {
                            DataType = xpMemberInfo.MemberType
                        };
                        if (typeof(XPBaseObject).IsAssignableFrom(dataColumn.DataType))
                        {
                            dataColumn.DataType = Session.GetClassInfo(dataColumn.DataType).KeyProperty.MemberType;
                        }
                        dataTable.Columns.Add(dataColumn);
                        if (property == ObjectClassInfo.KeyProperty.Name)
                        {
                            dataTable.PrimaryKey = new[] { dataColumn }
                        }
                        ;
                    }
                }
            }
            return(operatorCollection);
        }
예제 #6
0
        /// <summary>
        /// 更新数据源对应的表之间的关系(将同时更新数据库及缓存)
        /// </summary>
        /// <param name="oracleModel">oracle数据实体对象</param>
        /// <param name="sqlserverModel">sqlserver数据实体对象</param>
        protected bool UpdatePrimaryRelation(TOracle oracleModel, TSqlserver sqlserverModel)
        {
            if (!NeedToCachePrimaryRelation)
            {
                return(true);
            }

            // 更新oracle与sqlserver对应表的主键关系,用作缓存
            var relationBll = new PrimaryIdRelationBll();
            var relation    = new PrimaryIdRelation
            {
                OracleTableName = OracleTableName,
                OraclePrimaryId = ReflectorHelper.GetPropertyValue(oracleModel, OracleTablePrimaryKeyName)?.ToString(),
                SqlTableName    = SqlserverTableName,
                SqlPrimaryId    = ReflectorHelper.GetPropertyValue(sqlserverModel, SqlserverTablePrimaryKeyName)?.ToString()
            };

            var success = relationBll.Insert(relation).Id > 0;

            if (success)
            {
                // 将新的主键关系加入缓存中
                CacheManager.PrimaryIdCache.Add(relation);
            }

            return(success);
        }
예제 #7
0
        public void TestGetTimeTableDownward()
        {
            var sheet     = TestSuite.GetDownwardSheet();
            var timeTable =
                (TimeTable)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetTimeTableOfStyleOne", sheet);

            timeTable.Should().NotBe(null);

            timeTable.Line.Should().NotBe(null);
            timeTable.Line.FirstStation.Should().Be("大同");
            timeTable.Line.LastStation.Should().Be("包头");
            timeTable.Line.LineName.Should().Be("大同-包头");

            timeTable.TrainNo.Should().NotBe(null);
            timeTable.TrainNo.Code.Should().Be("K");
            timeTable.TrainNo.Direction.Should().Be("下行");
            timeTable.TrainNo.FirstStation.Should().Be("大同");
            timeTable.TrainNo.FullName.Should().Be("K1277");
            timeTable.TrainNo.LastStation.Should().Be("包头");
            timeTable.TrainNo.Number.Should().Be("1277");
            timeTable.TrainNo.RunType.Should().Be(1);

            timeTable.Stations.Count.Should().Be(27);
            timeTable.Stations.First().StationName.Should().Be("大同");
            timeTable.Stations.Last().StationName.Should().Be("包头");
            timeTable.Stations[6].StationName.Should().Be("新安庄");

            timeTable.Moments.Count.Should().Be(27);
            timeTable.Moments.First().ArriveTime.Should().Be("13:55:00");
            timeTable.Moments.First().DepartTime.Should().Be("14:11:00");
            timeTable.Moments.Last().ArriveTime.Should().Be("20:30:00");
            timeTable.Moments.Last().DepartTime.Should().Be("");
        }
예제 #8
0
        public IList <TestModel> GetList()
        {
            var dt   = _dal.GetList();
            var list = ReflectorHelper.DataTableToList <TestModel>(dt);//反射将datatable转换为list实体集合

            return(list);
        }
예제 #9
0
        public void TestGetTimeTableUpward()
        {
            var sheet     = TestSuite.GetSheet();
            var timeTable =
                (TimeTable)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetTimeTableOfStyleOne", sheet);

            timeTable.Should().NotBe(null);

            timeTable.Line.Should().NotBe(null);
            timeTable.Line.FirstStation.Should().Be("呼和浩特");
            timeTable.Line.LastStation.Should().Be("集宁南");
            timeTable.Line.LineName.Should().Be("呼和浩特-集宁南");

            timeTable.TrainNo.Should().NotBe(null);
            timeTable.TrainNo.Code.Should().Be("K");
            timeTable.TrainNo.Direction.Should().Be("上行");
            timeTable.TrainNo.FirstStation.Should().Be("呼和浩特");
            timeTable.TrainNo.FullName.Should().Be("K2014");
            timeTable.TrainNo.LastStation.Should().Be("集宁南");
            timeTable.TrainNo.Number.Should().Be("2014");
            timeTable.TrainNo.RunType.Should().Be(1);

            timeTable.Stations.Count.Should().Be(8);
            timeTable.Stations.First().StationName.Should().Be("呼和浩特");
            timeTable.Stations.Last().StationName.Should().Be("集宁南");

            timeTable.Moments.Count.Should().Be(8);
            timeTable.Moments.First().ArriveTime.Should().Be("");
            timeTable.Moments.First().DepartTime.Should().Be("16:10:00");
            timeTable.Moments.Last().ArriveTime.Should().Be("17:43:00");
            timeTable.Moments.Last().DepartTime.Should().Be("18:05:00");
        }
예제 #10
0
        protected BaseBll()
        {
            var assembly = "Guoli.Fs.Dal";
            var fullName = $"Guoli.Fs.Dal.{typeof(T).Name}Dal";

            Dal = ReflectorHelper.GetInstance(assembly, fullName) as BaseDal <T>;
        }
예제 #11
0
        public void TestGetDataTable()
        {
            var fields = new List <string> {
                "Name", "Age", "Birth", "Unknown"
            };
            var list = new List <Person>
            {
                new Person {
                    Name = "Test1", Age = 1, Birth = new DateTime(1999, 6, 10)
                },
                new Person {
                    Name = "Test2", Age = 2, Birth = new DateTime(2000, 8, 15)
                }
            };

            var table = ReflectorHelper.InvokeMethod(new MsSqlToSqlite(), "GetDataTable", fields, list) as DataTable;

            table.Should().NotBeNull();
            table?.Columns.Count.Should().Be(3);
            table?.Columns[0].ColumnName.Should().Be("Name");
            table?.Columns[1].ColumnName.Should().Be("Age");
            table?.Columns[2].ColumnName.Should().Be("Birth");
            table?.Rows.Count.Should().Be(2);
            table?.Rows[0][0].Should().Be("Test1");
            table?.Rows[0][1].Should().Be(1);
            table?.Rows[0][2].Should().Be(list[0].Birth);
            table?.Rows[1][0].Should().Be("Test2");
            table?.Rows[1][1].Should().Be(2);
            table?.Rows[1][2].Should().Be(list[1].Birth);
        }
예제 #12
0
        public void TestIsStyleTwo()
        {
            var sheet   = TestSuite.GetHuocheSheet();
            var isValid = (bool)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "IsStyleTwo", sheet);

            isValid.Should().Be(true, "测试表格符合第二种格式要求");
        }
예제 #13
0
        public void TestIsStyleOne()
        {
            var sheet   = TestSuite.GetSheet();
            var isValid = (bool)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "IsStyleOne", sheet);

            isValid.Should().Be(true, "测试表格完全符合TimeTableImporter类所要求的格式");
        }
예제 #14
0
        public void CreateNewEntity_ValidNewEntityObjectPassed_ShouldReturnNonzero()
        {
            int       newEntityId             = (int)ReflectorHelper.StaticCallMethod(entity, "CreateNew" + entity.Name, EntityFactory.Factory_CreateFreshEntityWithValidSampleData(entity.Name));
            const int INITIAL_NO_ENTITY_STATE = 0;

            Assert.AreNotEqual(INITIAL_NO_ENTITY_STATE, newEntityId, entity.Name + " was not created.");
            Console.WriteLine("NEW " + entity.Name + " ID: " + newEntityId);
        }
예제 #15
0
        public void TestIsEmptyRow()
        {
            var sheet   = TestSuite.GetSheet();
            var row     = sheet.GetRow(sheet.LastRowNum);
            var isEmpty = (bool)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "IsEmptyRow", row);

            isEmpty.Should().Be(true, "测试表格最后一行为空");
        }
예제 #16
0
        public void TestChangeConfig()
        {
            var frm = new FrmInit();

            ReflectorHelper.InvokeMethod(frm, "ChangeConfig", "test1");

            ConfigurationManager.ConnectionStrings["MainDb"].ConnectionString.Should().Be("test1");
        }
예제 #17
0
        public void TestGetStation()
        {
            var row     = TestSuite.GetRow(6);
            var station = (BaseStation)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetStation", row);

            station.Should().NotBe(null, "给定数据源中有车站名称");
            station.Spell.Should().Be("zjkn", "车站名称为张家口南");
            station.StationName.Should().Be("张家口南");
        }
예제 #18
0
        /// <summary>
        /// 创建导入过程中所需要的实例
        /// </summary>
        private void BuildInstance()
        {
            CacheManager = CacheManager.GetInstance();

            OracleBaseBll =
                ReflectorHelper.GetInstance("Guoli.Bll", $"Guoli.Bll.{OracleTableName}Bll") as BaseBll <TOracle>;

            SqlserverBaseBll =
                ReflectorHelper.GetInstance("Guoli.Bll", $"Guoli.Bll.{SqlserverTableName}Bll") as BaseBll <TSqlserver>;
        }
예제 #19
0
        public void TestGetPropertyValue()
        {
            var testInstance = new TestClass {
                TestProp = "test success"
            };
            var propValue = ReflectorHelper.GetPropertyValue(testInstance, "TestProp");

            propValue.Should().NotBeNull("because I've given a value when create the instance")
            .And.Subject.ToString().Should().BeEquivalentTo("test success");
        }
예제 #20
0
        public Expression <Func <T, bool> > AsExpression <T>() where T : class
        {
            QueryCollection queryCollection = new QueryCollection();
            var             properties      = typeof(T).GetTypeInfo().GetProperties();

            if (Columns == null)
            {
                return(t => true);
            }
            foreach (var item in Columns)
            {
                var p = properties.FirstOrDefault(m => m.Name.Equals(item.Name, StringComparison.OrdinalIgnoreCase));
                if (p == null)
                {
                    continue;
                }
                var    realType = Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType;
                string value    = null;
                if (item.Search != null && item.Search.Value.IsNotNullAndWhiteSpace())
                {
                    value = item.Search.Value;
                }
                else if (Search != null && Search.Value.IsNotNullAndWhiteSpace() && realType == typeof(string))
                {
                    value = Search.Value;
                }
                if ((item.Search.Opeartor == Query.Operators.Range && item.Search.ValueMin.IsNullOrWhiteSpace() && item.Search.ValueMax.IsNullOrWhiteSpace()) ||
                    (item.Search.Opeartor != Query.Operators.Range && value.IsNullOrWhiteSpace()))
                {
                    continue;
                }

                Query query = new Query();
                query.Name = p.Name;
                try
                {
                    query.Value    = ReflectorHelper.ValueConvert(p, value);
                    query.ValueMin = ReflectorHelper.ValueConvert(p, item.Search.ValueMin);
                    query.ValueMax = ReflectorHelper.ValueConvert(p, item.Search.ValueMax);

                    //if (query.ValueMax != null && query.ValueMax is DateTime)
                    //{
                    //    query.ValueMax = ((DateTime)query.ValueMax).AddDays(1).AddMilliseconds(-1);
                    //}
                }
                catch (Exception e)
                {
                    continue;
                }

                query.Operator = item.Search.Opeartor;
                queryCollection.Add(query);
            }
            return(queryCollection.AsExpression <T>(Query.Condition.AndAlso));
        }
예제 #21
0
        public void TestGetLine()
        {
            var sheet = TestSuite.GetSheet();
            var row   = sheet.GetRow(4);
            var line  = (BaseLine)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetLine", row);

            line.Should().NotBe(null, "测试表格中第五行包含线路信息");
            line.FirstStation.Should().Be("呼和浩特");
            line.LastStation.Should().Be("集宁南");
            line.LineName.Should().Be("呼和浩特-集宁南");
        }
예제 #22
0
        public async override Task <string> ProviderField()
        {
            if (httpContext != null)
            {
                var features = httpContext.Features;
                var serverIp = ReflectorHelper.GetProp <System.Net.IPAddress>(features, "LocalIpAddress");

                return(serverIp.ToString());
            }
            return(string.Empty);
        }
예제 #23
0
        private void InitSystemParams(IDictionary <string, object> config)
        {
            string       pluginsAssembly  = config.GetValue <string>("SystemPramsPluginAssemblyPath");
            string       pluginsClassName = config.GetValue <string>("SystemPramsPluginClassName");;
            ParamsPlugin paramsPlugin     = ReflectorHelper.GetPluginInstance <ParamsPlugin>(pluginsAssembly, pluginsClassName);

            if (paramsPlugin != null)
            {
                paramsPlugin.InitParams();
            }
        }
예제 #24
0
        /// <summary>
        /// 外部调用接口
        /// </summary>
        /// <param name="code">接口编码</param>
        /// <param name="inputParameters">可传入参数</param>
        /// <returns></returns>
        public object DynamicFetch(IDictionary <string, object> config, string code, IDictionary <string, object> inputParameters = null)
        {
            string dataBaseKey        = config.GetValue <string>("DataBaseKey");
            string pluginAssemblyPath = config.GetValue <string>("PluginAssemblyPath");
            string pluginClassName    = config.GetValue <string>("PluginClassName");

            threadLocalDataBaseKey.Value = dataBaseKey;
            ConfigApiPlugin dynamicApiPlugin = ReflectorHelper.GetPluginInstance <ConfigApiPlugin>(pluginAssemblyPath, pluginClassName);
            IDictionary <string, object>             parameters = RequestDataHelper.GetMixParams();
            IDictionary <string, IList <IFormFile> > files      = RequestDataHelper.GetAllFiles();
            IDictionary <string, object>             headers    = RequestDataHelper.GetHeaders();
            IDictionary <string, object>             cookies    = RequestDataHelper.GetCookies();
            object bodyJson = RequestDataHelper.GetBodyJsonParameters();

            if (inputParameters != null && inputParameters.Count > 0)
            {
                parameters = RequestDataHelper.MergeDictionary(parameters, inputParameters);
            }
            return(this.AopDynamicApi <object>((apiConfig, paramsData, formFiles, reqHeaders, reqCookies, json) =>
            {
                if (dynamicApiPlugin != null)
                {
                    IDbHelper dbHelper = this._dbContext.Use(dataBaseKey);
                    //调用接口前扩展处理
                    dynamicApiPlugin.Before(dbHelper, apiConfig, paramsData, formFiles, json);
                }
            }, (apiConfig, paramsData, json) =>
            {
                string scriptCode = apiConfig.GetValue <string>("ScriptCode");

                /*
                 * 1=单一结果(单个值,或者一条sql语句执行结果)
                 * 2=分页
                 * 3=列表结果集(多个值以List<object>返回
                 * 4=字典结果集(多个值以Dictionary<string,object>返回
                 * 5=主从结果集 (会查询嵌套子查询,多个值以Dictionary<string,object>返回
                 * 6=返回脚本执行结果(直接返回脚本执行结果)
                 */
                int codeKind = apiConfig.GetValue <int>("CodeKind");
                int apiKind = apiConfig.GetValue <int>("ApiKind"); //0=公共接口;1=对内接口
                int status = apiConfig.GetValue <int>("Status");   //0=禁用;1=启用
                return this.ExecuteScript(scriptCode, codeKind, paramsData, bodyJson);
            }, (apiConfig, paramsData, json, result) =>
            {
                if (dynamicApiPlugin != null)
                {
                    IDbHelper dbHelper = this._dbContext.Use(dataBaseKey);
                    //调用接口后扩展处理
                    return dynamicApiPlugin.After(dbHelper, apiConfig, paramsData, json, result);
                }
                return result;
            }, config, parameters, files, headers, cookies, bodyJson));
        }
예제 #25
0
        public void TestCreateSqliteTables()
        {
            var instance = new MsSqlToSqlite();

            ReflectorHelper.InvokeMethod(instance, "CreateSqliteTables");

            var sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='TrainNoLine';";
            var res = _sqliteHelper.ExecuteScalar(_connStr, CommandType.Text, sql);

            res.Should().NotBeNull();
            res?.ToString().Should().Be("TrainNoLine");
        }
예제 #26
0
        public void TestGetTime()
        {
            var sheet = TestSuite.GetDownwardSheet();
            var row   = sheet.GetRow(48);
            var cell  = row.GetCell(5);
            var time  = (string)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetTime", cell);

            time.Should().Be("18:54:00");

            cell = row.GetCell(6);
            time = (string)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetTime", cell);
            time.Should().Be("19:05:00");
        }
예제 #27
0
        public void TestGetTrainMoment()
        {
            var row1   = TestSuite.GetRow(24);
            var row2   = TestSuite.GetRow(25);
            var moment =
                (TrainMoment)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetTrainMoment", row1, row2);

            moment.Should().NotBe(null);
            moment.ArriveTime.Should().Be("17:43:00");
            moment.DepartTime.Should().Be("18:05:00");
            moment.IntervalKms.Should().Be(8);
            moment.StopMinutes.Should().Be(22);
            moment.SuggestSpeed.Should().Be(48);
        }
예제 #28
0
        public void TestGetTrainNo()
        {
            var sheet   = TestSuite.GetSheet();
            var row     = sheet.GetRow(4);
            var trainNo = (TrainNo)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "GetTrainNo", row);

            trainNo.Should().NotBe(null, "测试表格中第五行包含车次信息");
            trainNo.Code.Should().Be("K");
            trainNo.Direction.Should().Be("上行");
            trainNo.FirstStation.Should().Be("呼和浩特");
            trainNo.FullName.Should().Be("K2014");
            trainNo.LastStation.Should().Be("集宁南");
            trainNo.Number.Should().Be("2014");
            trainNo.RunType.Should().Be(1);
        }
예제 #29
0
        public void TestTimeFormatter()
        {
            var res = (string)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "TimeFormatter", "48");

            res.Should().Be("48");

            res = (string)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "TimeFormatter", "4830");
            res.Should().Be("48");

            res = (string)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "TimeFormatter", "23:30");
            res.Should().Be("23:30");

            res = (string)ReflectorHelper.InvokeStaticMethod(typeof(TimeTableImporter), "TimeFormatter", "23:1530");
            res.Should().Be("23:15");
        }
예제 #30
0
        public object Bind(object obj)
        {
            var type = obj.GetType();

            var iProgramTool = ToolFactory.CreateIProgramTool();

            foreach (var propertyPath in this._NameValueCollection.AllKeys)
            {
                if (string.IsNullOrEmpty(propertyPath))
                {
                    continue;
                }

                var nvValues = this._NameValueCollection.GetValues(propertyPath);

                if (nvValues == null || nvValues.Length == 0)
                {
                    continue;
                }

                var bindingFlags = BindingFlags.IgnoreCase | BindingFlags.Instance |
                                   BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty;

                var property = ReflectorHelper.GetPropertyInfoOrDefault(type, propertyPath, bindingFlags);

                if (property == null)
                {
                    continue;
                }

                object realValue    = null;
                var    propertyType = property.PropertyType;

                try
                {
                    realValue = iProgramTool.ChanageType(nvValues, property.PropertyType);
                }
                catch
                {
                }

                if (realValue != null)
                {
                    ReflectorHelper.SetProperty(obj, propertyPath, realValue, null);
                }
            }
            return(obj);
        }