예제 #1
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);
        }
예제 #2
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");
        }
예제 #3
0
        private List <string> GetFilePathList(IEnumerable <DbUpdateLog> dbLog, string table, string filePathField)
        {
            var result  = new List <string>();
            var groups  = dbLog.GroupBy(o => o.TableName);
            var fileLog = groups.SingleOrDefault(g => g.Key == table);

            if (fileLog != null)
            {
                try
                {
                    var idList    = fileLog.Select(o => o.TargetId);
                    var condition = $" Id IN ({string.Join(",", idList)})";
                    var bll       = BllFactory.GetBllInstance(table) as IBll;
                    var data      = bll.QueryList(condition);
                    foreach (var o in data)
                    {
                        var path = (string)ReflectorHelper.GetPropertyValue(o, filePathField);
                        result.Add(path);
                    }
                }
                catch (Exception ex)
                {
                    new ExceptionLogBll().Insert(new ExceptionLog
                    {
                        ClassName  = nameof(ServerSync),
                        FileName   = nameof(ServerSync),
                        HappenTime = DateTime.Now,
                        Instance   = ex.Source,
                        Message    = ex.Message,
                        Source     = 1,
                        MethodName = nameof(ServerSync.GetFilePathList),
                        StackTrace = ex.StackTrace
                    });
                }
            }

            return(result);
        }