/// <summary>
        /// 异常处理方法
        /// </summary>
        public void Handler()
        {
            //记录日志
            ILogProvider logProvider = ObjectContainer.CreateInstance <ILogProvider>();
            var          tempMessage = string.Format("统一验证的过程中出现异常,具体如下:Operator:{0};Target:{1};Method:{2};Parameter:{3};Detail:{4}", this.Context.Operator, this.Context.Target, this.Context.Parameters, this.Context.Method, Context.Exception.Message);

            logProvider.Info(Context.Exception.Message, Context.Exception);
            this.ErrorMessage = tempMessage;
        }
Exemple #2
0
        public void Test_CreateInstance()
        {
            object studentObj = ObjectContainer.CreateInstance <Student>();

            Assert.NotNull(studentObj);

            Student student = studentObj as Student;

            Assert.NotNull(student);

            //Assert.Pass();
        }
        /// <summary>
        /// 通过实现此方法来拦截调用并执行所需的拦截行为。
        /// </summary>
        /// <param name="input">调用拦截目标时的输入信息。</param>
        /// <param name="getNext">通过行为链来获取下一个拦截行为的委托。</param>
        /// <returns>从拦截目标获得的返回信息。</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            var methodReturn = getNext().Invoke(input, getNext);

            if (methodReturn.Exception != null)
            {
                ILogProvider logProvider = ObjectContainer.CreateInstance <ILogProvider>();

                logProvider.Info(methodReturn.Exception.Message, methodReturn.Exception);
            }
            return(methodReturn);
        }
Exemple #4
0
        public override void Commit()
        {
            if (!Committed)
            {
                try
                {
                    // var validationErrors = localCtx.Value.GetValidationErrors();
                    var count = localCtx.Value.SaveChanges();
                    Committed = true;
                    aggregateRoots.Clear();

                    //if (true)
                    //{
                    //    //this.GetEntityOperateLogs(this.Context);
                    //    //写操作日志
                    //}
                }
                catch (DbUpdateException e)
                {
                    if (e.InnerException != null && e.InnerException.InnerException is SqlException)
                    {
                        SqlException sqlEx = e.InnerException.InnerException as SqlException;
                        string       msg   = DbExceptionHelper.GetSqlExceptionMessage(sqlEx.Number);
                        throw new Framework.Exceptions.ValidationException("提交数据更新时发生异常:" + msg, sqlEx);
                    }
                    throw;
                }
                catch (Exception ex)
                {
                    //var tempErrors = ex.EntityValidationErrors;
                    //var tempValidateResult = string.Empty;
                    //if (tempErrors != null && tempErrors.Count() > 0)
                    //{
                    //    foreach (var tempError in tempErrors)
                    //    {
                    //        if (tempError == null || tempError.ValidationErrors.Count == 0)
                    //            continue;

                    //        foreach (var validationError in tempError.ValidationErrors)
                    //        {
                    //            tempValidateResult += string.Format("[{0}:{1}];", validationError.PropertyName, validationError.ErrorMessage);
                    //        }
                    //    }
                    //}

                    var logger = ObjectContainer.CreateInstance <NS.Framework.Log.ILogProvider>();
                    logger.Error("持久化数据过程中出现错误:" + ex.Message);

                    throw new Framework.Exceptions.ValidationException(ex.Message);
                }
            }
        }
        private void SaveUnlineData(DataSyncContract tempDataSyncContract)
        {
            //离线数据同步事件委托
            Action tempSyncAction = new Action(() =>
            {
                //同步离线数据到数据中心
                ILocalDataSyncService syncService = ObjectContainer.CreateInstance <ILocalDataSyncService>();
                syncService.Sync(tempDataSyncContract);
            });

            //异步调用
            tempSyncAction.BeginInvoke(null, null);
        }
        /// <summary>
        /// 通过实现此方法来拦截调用并执行所需的拦截行为。
        /// </summary>
        /// <param name="input">调用拦截目标时的输入信息。</param>
        /// <param name="getNext">通过行为链来获取下一个拦截行为的委托。</param>
        /// <returns>从拦截目标获得的返回信息。</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (getNext == null)
            {
                throw new ArgumentNullException("getNext");
            }

            //执行验证操作;
            var tempMethod = input.MethodBase as System.Reflection.MethodInfo;

            var inputParameterCollection = input.Inputs;

            var tempLogAttributes = tempMethod.GetCustomAttributes(typeof(LogAttribute));

            if (tempLogAttributes.Count() == 0)
            {
                return(getNext().Invoke(input, getNext));
            }

            //根据反射获取对象的成员信息
            var realArguments = (object[])ReflectHelper.GetInstanceProperty(inputParameterCollection, "arguments");

            if (inputParameterCollection.Count == 0)
            {
                return(getNext().Invoke(input, getNext));
            }

            //计时器开始 监视方法执行时间---Debug模式下启用

            //开始监视
            //计时器
#if DEBUG
            var stopwatch        = Stopwatch.StartNew();
            var tempReturnResult = getNext().Invoke(input, getNext);
            stopwatch.Stop();
            var totalMillisencodes = stopwatch.Elapsed.TotalMilliseconds;
#else
            var tempReturnResult = getNext().Invoke(input, getNext);
#endif
            //生成日志对象
            var logInfo = string.Format("TODO....");
            //输出到log---采用异步方式
            ILogProvider logProvider = ObjectContainer.CreateInstance <ILogProvider>();
            logProvider.Debug(logInfo);
            return(tempReturnResult);
        }
Exemple #7
0
        /// <summary>
        /// Create a new type adapter from currect factory
        /// </summary>
        /// <returns>Created type adapter</returns>
        public static ITypeAdapter CreateAdapter()
        {
            if (_currentTypeAdapterFactory == null)
            {
                lock (lock_flag)
                {
                    if (_currentTypeAdapterFactory == null)
                    {
                        _currentTypeAdapterFactory = ObjectContainer.CreateInstance <ITypeAdapterFactory>();
                    }
                }
            }

            return(_currentTypeAdapterFactory.Create());
        }
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";
            Dot.Utility.DotEnvironment.MapDllPath("config/license.lic");
            var dlist = new Dot.Demo.DBContext().Context.Database.SqlQuery <Project>("select * from project").ToList();


            IProjectService service = ObjectContainer.CreateInstance <IProjectService>();
            var             list    = service.GetList();
            var             one     = service.Get(m => m.Id == 1);
            HomeIndexModel  model   = new HomeIndexModel();

            model.div = JsonConvert.SerializeObject(Dot.Config.Model.PlatformConfig.ServerConfig.KeyValueSettings["test"]);
            return(View(model));
        }
        /// <summary>
        /// 通过实现此方法来拦截调用并执行所需的拦截行为。
        /// </summary>
        /// <param name="input">调用拦截目标时的输入信息。</param>
        /// <param name="getNext">通过行为链来获取下一个拦截行为的委托。</param>
        /// <returns>从拦截目标获得的返回信息。</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (getNext == null)
            {
                throw new ArgumentNullException("getNext");
            }

            //获取当前操作的方法
            var tempMethod = input.MethodBase as System.Reflection.MethodInfo;

            //方法参数
            var inputParameterCollection = input.Inputs;

            //根据反射获取对象的成员信息
            var realArguments = (object[])ReflectHelper.GetInstanceProperty(inputParameterCollection, "arguments");

            //获取当前方法所属的对象
            var tempTarget = input.Target;

            var methodReturn = getNext().Invoke(input, getNext);

            if (methodReturn.Exception != null && (methodReturn.Exception is TimeoutException))
            {
                //将当前操作的参数序列化到对象中
                var tempResult = this.PreDealOfflineDto(input, tempTarget, tempMethod, realArguments);

                return(new VirtualMethodReturn(input, tempResult, realArguments));
            }
            else
            {
                //离线数据同步事件委托
                Action tempSyncAction = new Action(() =>
                {
                    //同步离线数据到数据中心
                    IOfflineSyncService syncService = ObjectContainer.CreateInstance <IOfflineSyncService>();
                    syncService.Sync();
                });

                //异步调用
                tempSyncAction.BeginInvoke(null, null);
            }

            return(methodReturn);
        }
        private void RemoteCall(DataSyncContract tempDataSyncContract)
        {
            //离线数据同步事件委托
            Action tempSyncAction = new Action(() =>
            {
                //同步离线数据到数据中心
                IRemoteDataSyncService remoteSyncService = ObjectContainer.CreateInstance <IRemoteDataSyncService>();
                if (!remoteSyncService.Sync(tempDataSyncContract))
                {
                    this.SaveUnlineData(tempDataSyncContract);
                }
            });

            //异步调用
            tempSyncAction.BeginInvoke(null, null);
        }
Exemple #11
0
        public void Test_RegisterInstance()
        {
            object studentObj = ObjectContainer.CreateInstance <Student>();

            Assert.NotNull(studentObj);

            Student student = studentObj as Student;

            Assert.NotNull(student);

            int oldCount = ObjectContainer.GetRegisterCount();

            ObjectContainer.RegisterInstance <Student>(student);
            int count = ObjectContainer.GetRegisterCount();

            Assert.AreEqual(1, count - oldCount);
        }
Exemple #12
0
 public static ICacheProvider GetCache(string key)
 {
     if (string.IsNullOrWhiteSpace(key))
     {
         return(instance);
     }
     if (!instances.ContainsKey(key))
     {
         lock (_cacheLock)
         {
             if (!instances.ContainsKey(key))
             {
                 instances.Add(key, ObjectContainer.CreateInstance <ICacheProvider>(key));
             }
         }
     }
     return(instances[key]);
 }
Exemple #13
0
        /// <summary>
        /// 动态调用方法
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="methodName"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static object InvokeMothed(string apptypeName, string methodName, params object[] parameters)
        {
            //根据服务名称,获取服务接口类型
            Type getServiceType = GetAppServiceType(apptypeName);

            if (getServiceType == null)
            {
                getServiceType = GetAppServiceType(apptypeName.Replace("Service.Implement", ""));
            }

            if (getServiceType == null)
            {
                throw new Exception(string.Format("服务器端没有找到名称:'{0}'的服务接口", apptypeName));
            }

            //根据IOC 创建本地服务实例
            var tempServiceInstance = ObjectContainer.CreateInstance(getServiceType);

            var getTypes = GetParameterTypes(parameters);

            //获取客户端调用的方法名称,查找服务器端服务实例中的方法
            var tempInvokeMethod = tempServiceInstance.GetType().GetMethod(methodName, getTypes);


            if (tempInvokeMethod == null)
            {
                throw new Exception(string.Format("服务{0}没有找到名称:'{1}'的方法", apptypeName, methodName));
            }

            try
            {
                //执行方法调用-可能在方法调用的过程中出现异常信息
                return(tempInvokeMethod.Invoke(tempServiceInstance, parameters));
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("调用服务{0}中的:'{1}'方法时出现错误:{2}", apptypeName, methodName, ex.Message));
            }
        }
Exemple #14
0
        /// <summary>
        /// Create a new Automapper type adapter factory
        /// </summary>
        public AutomapperTypeAdapterFactory()
        {
            var tempAssemblys = NS.Framework.Config.PlatformConfig.ServerConfig.IOCSetting.ConfigurationItems.Select(pre => pre.Value);

            //scan all assemblies finding Automapper Profile
            var tempAllAssemblys = AppDomain.CurrentDomain.GetAssemblies().Where(pre =>
                                                                                 !pre.GetName().Name.ToLower().EndsWith("fakes.test") &&
                                                                                 !pre.GetName().Name.ToLower().EndsWith("fakes") &&
                                                                                 !pre.GetName().Name.ToLower().StartsWith("system.") &&
                                                                                 !pre.GetName().Name.ToLower().StartsWith("microsoft.") &&
                                                                                 !pre.GetName().Name.ToLower().StartsWith("entity") &&
                                                                                 !pre.GetName().Name.ToLower().StartsWith("auto")
                                                                                 ).ToList();

            IList <Assembly> tempAssemblyList  = new List <Assembly>();
            List <string>    tempAssemblyNames = new List <string>();

            foreach (var tempAssembly in tempAssemblys)
            {
                tempAssemblyNames.AddRange(tempAssembly.Split(';'));
            }

            foreach (var tempAllAssembly in tempAllAssemblys)
            {
                var tempAssemblyName = tempAllAssembly.GetName().Name;

                if (tempAssemblyNames.Where(pre => pre.Trim().ToLower().Contains(tempAssemblyName.ToLower())).Count() > 0)
                {
                    tempAssemblyList.Add(tempAllAssembly);
                }
            }

            //var assemblys = AppDomain.CurrentDomain
            //                        .GetAssemblies().Where((Assembly assembly) =>
            //                        {
            //                            return tempAssemblys.Where(pre => pre.Split(';').Contains(assembly.GetName().Name)).Count() > 0;
            //                            //&& !pre.GetName().Name.ToLower().EndsWith("fakes.test")
            //                            //&& !pre.GetName().Name.ToLower().EndsWith("fakes")
            //                            //&& !pre.GetName().Name.ToLower().StartsWith("system.")
            //                            //&& !pre.GetName().Name.ToLower().StartsWith("microsoft.")
            //                            //&& !pre.GetName().Name.ToLower().StartsWith("entity")
            //                            //&& !pre.GetName().Name.ToLower().StartsWith("auto")
            //                        }).ToList();
            var profiles = tempAssemblyList.SelectMany(pre => pre.GetTypes()).Where(t => t.BaseType == typeof(DomainDtoMapProfile)).Distinct().ToList();

            int count = profiles.Count();

            try
            {
                //Mapper.Initialize(cfg =>
                //{
                //    foreach (var item in profiles)
                //    {
                //        if (item.FullName != "AutoMapper.SelfProfiler`2")
                //            cfg.AddProfile(Activator.CreateInstance(item) as Profile);
                //    }
                //});
                foreach (var item in profiles)
                {
                    var tempProfile = Activator.CreateInstance(item) as DomainDtoMapProfile;
                    tempProfile.Configure();
                }
            }
            catch (Exception ex)
            {
                ILogProvider logger = ObjectContainer.CreateInstance <ILogProvider>();
                //logger.Error("初始化Automapper的过程中出现错误:" + ex.Message);
                logger.Error("初始化mapper的过程中出现错误:" + ex.Message);
            }
        }
Exemple #15
0
 private QuartzManager()
 {
     quartzProvider = ObjectContainer.CreateInstance <IQuartzProvider>();
 }
        /// <summary>
        /// 根据类型获取类型对应的主键生成器类型
        /// </summary>
        /// <param name="type">待持久化的对象类型</param>
        /// <returns></returns>
        public static IAggregateIdGenerator GetGenerator(Type type)
        {
            if (type == null)
            {
                throw new RepositoryException("在获取主键构建器时的聚合根类型不能为空");
            }

            if (NS.Framework.Config.PlatformConfig.ServerConfig.DomainSetting.AggregateIdGeneratorItemStrategys.Where(pre => pre.AggregateTypeName == type.Name ||
                                                                                                                      pre.AggregateTypeName == type.FullName).Count() > 0)
            {
                var tempStrategys = NS.Framework.Config.PlatformConfig.ServerConfig.DomainSetting.AggregateIdGeneratorItemStrategys.Where(pre => pre.AggregateTypeName == type.Name ||
                                                                                                                                          pre.AggregateTypeName == type.FullName).ToList();

                if (!string.IsNullOrEmpty(tempStrategys[0].Generator))
                {
                    var generatorType = Type.GetType(tempStrategys[0].Generator);

                    if (generatorType == null)
                    {
                        throw new RepositoryException(string.Format("没有找到配置的主键生成器类型,请确认配置是否正确,配置节名称:{0}", tempStrategys[0].AggregateTypeName));
                    }

                    return((IAggregateIdGenerator)ObjectContainer.CreateInstance(generatorType));
                }
            }

            var generatorFullType = string.Empty;
            var tempAssemblyName  = string.Empty;

            if (NS.Framework.Config.PlatformConfig.ServerConfig.DomainSetting.AggregateIdGeneratorItems.Count > 0)
            {
                var    tempItems    = NS.Framework.Config.PlatformConfig.ServerConfig.DomainSetting.AggregateIdGeneratorItems;
                string assemblyName = type.Assembly.GetName().Name;

                foreach (var tempItem in tempItems)
                {
                    if (string.IsNullOrEmpty(tempItem.GeneratorKey) || string.IsNullOrEmpty(tempItem.GeneratorValue))
                    {
                        continue;
                    }

                    if (tempItem.AggregateIdGeneratorAssemblys.Count == 0)
                    {
                        continue;
                    }

                    var tempSelectItem = tempItem.AggregateIdGeneratorAssemblys.Where(pre => pre.AssemblyName == assemblyName).FirstOrDefault();

                    if (tempSelectItem == null)
                    {
                        continue;
                    }

                    generatorFullType = tempItem.GeneratorValue.Split(';')[1];
                    tempAssemblyName  = tempItem.GeneratorValue.Split(';')[0];
                }
            }

            if (!string.IsNullOrEmpty(generatorFullType))
            {
                var generatorTypeAssembly = System.AppDomain.CurrentDomain.GetAssemblies().Where(Predicate => Predicate.GetName().Name == tempAssemblyName).FirstOrDefault();

                var generatorType = generatorTypeAssembly.GetTypes().Where(Predicate => Predicate.FullName == generatorFullType).FirstOrDefault();

                if (generatorType == null)
                {
                    throw new RepositoryException(string.Format("没有找到配置的主键生成器类型,请确认配置是否正确,配置节名称:{0}", generatorFullType));
                }

                return((IAggregateIdGenerator)ObjectContainer.CreateInstance(generatorType));
            }

            return(ObjectContainer.CreateInstance <IGuidGenerator>());
        }
Exemple #17
0
 private CacheManager()
 {
     cacheProvider = ObjectContainer.CreateInstance <ICacheProvider>();
 }
Exemple #18
0
        /// <summary>
        /// 传入DTO,然后执行转换操作,转换完成后,自动执行领域上的业务操作,只执行具有业务规则的相关方法。
        /// </summary>
        /// <param name="dto">目标Dto类型</param>
        /// <param name="domainObj">转换后的领域对象</param>
        /// <param name="contextObj">数据库中根据主键查询出来的主键</param>
        /// <returns></returns>
        public static bool Excute(object dto, object domainObj, object contextObj, IRepositoryContext context)
        {
            //0、先调用Dto转换为Domain
            if (dto == null)
            {
                throw new AppServiceException("待操作的对象不能为空");
            }

            //if (domainObj == null)
            //    throw new AppServiceException("待操作的对象不能为空");

            //1、转换完成后,只想相应的操作。
            //object domainObj = dto.GetMapTarget(dto.GetMapTargetType());

            if (domainObj == null)
            {
                throw new AppServiceException("转换完成后的领域对象不能为空");
            }

            var primaryKeyValue = domainObj.GetType().GetProperties().Where(pre => pre.Name == "AggregateID").FirstOrDefault().GetValue(domainObj, null);

            //2、将领域内部的所有打了特殊标记的Rule 执行。

            var allPropertys = domainObj.GetType().GetProperties();

            if (allPropertys == null || allPropertys.Length == 0)
            {
                return(true);
            }

            var allMthods = domainObj.GetType().GetMethods();

            if (allMthods == null || allMthods.Length == 0)
            {
                return(true);
            }

            foreach (var tempProperty in allPropertys)
            {
                var attributes = (DependencyAttribute[])tempProperty.GetCustomAttributes(typeof(DependencyAttribute), false);

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

                //根据参数类型获取参数的实例
                var tempRule = ObjectContainer.CreateInstance(tempProperty.PropertyType);

                if (tempRule == null)
                {
                    continue;
                }

                //设置领域中的属性
                tempProperty.SetValue(domainObj, tempRule, null);

                //要求执行规则的方法与规则名称差别不大-按照去除规则名称的Rule四个字母
                var tempMethodName = tempProperty.Name.Replace("Rule", "");
                if (string.IsNullOrEmpty(tempMethodName))
                {
                    continue;
                }

                var parameterName = string.Empty;
                var tempName      = string.Empty;

                #region 判断执行的操作
                //(primaryKeyValue == null || (contextObj == null)) &&
                if ((tempMethodName.StartsWith("Add")))
                {
                    tempName = tempMethodName.Replace("Add", "");
                    if (tempName == domainObj.GetType().Name)
                    {
                        parameterName = "Childrens";
                    }
                    else
                    {
                        parameterName = tempName;
                    }
                }
                else if ((tempMethodName.StartsWith("Set")))
                {
                    tempName      = tempMethodName.Replace("Set", "");
                    parameterName = tempName;
                }
                else if (contextObj != null && tempMethodName.StartsWith("Remove"))
                {
                    tempName      = tempMethodName.Replace("Remove", "");
                    parameterName = tempName;
                }
                else
                {
                    continue;
                }

                #endregion

                if (string.IsNullOrEmpty(parameterName))
                {
                    continue;
                }

                var tempSelectProperty = dto.GetType().GetProperty(parameterName);

                if (tempSelectProperty == null)
                {
                    if (tempMethodName.StartsWith("Set"))
                    {
                        parameterName = parameterName + "Id";

                        tempSelectProperty = dto.GetType().GetProperty(parameterName);

                        if (tempSelectProperty == null)
                        {
                            continue;
                        }
                    }
                    else if (tempMethodName.StartsWith("Add"))
                    {
                        parameterName = parameterName + "s";

                        tempSelectProperty = dto.GetType().GetProperty(parameterName);

                        if (tempSelectProperty == null)
                        {
                            continue;
                        }
                    }
                }

                if (tempSelectProperty == null)
                {
                    continue;
                }

                //获取参数值
                var propertyValue = tempSelectProperty.GetValue(dto, null);
                if (propertyValue == null)
                {
                    continue;
                }

                //判定指定名称的方法是否存在。
                if (allMthods.Where(pre => pre.Name.ToLower().StartsWith(tempMethodName.ToLower())).Count() == 0)
                {
                    continue;
                }

                //查询当前类型中与制定名称匹配的方法集合
                var tempMethods = allMthods.Where(pre => pre.Name.ToLower().StartsWith(tempMethodName.ToLower())).ToList();

                //循环方法列表
                foreach (var tempMethod in tempMethods)
                {
                    if (tempMethod.GetParameters().Length == 0)
                    {
                        continue;
                    }

                    //判定当前方法是否是泛型方法
                    if (propertyValue.GetType().GetGenericArguments().Count() > 0)
                    {
                        //判定当前泛型方法集合于当前的获取的参数值是否匹配-如果匹配则执行批量操作。
                        if (tempMethod.GetParameters().Where(pre => pre.ParameterType == propertyValue.GetType()).Count() > 0)
                        {
                            tempMethod.Invoke(domainObj, (propertyValue as IEnumerable <object>).ToArray());

                            break;
                        }
                    }

                    //判断当前属性值是否是泛型集合
                    if (propertyValue is IEnumerable <object> )
                    {
                        var tempList = propertyValue as IEnumerable <object>;
                        foreach (var tempItem in tempList)
                        {
                            if (tempItem == null)
                            {
                                continue;
                            }

                            var tempTargetValue = tempItem.GetMapTarget(tempMethod.GetParameters()[0].ParameterType);

                            if (tempTargetValue == null)
                            {
                                continue;
                            }

                            tempMethod.Invoke(domainObj, new object[] { tempTargetValue });
                        }
                        break;
                    }
                    else
                    {
                        var parameterType = tempMethod.GetParameters()[0].ParameterType;

                        if (parameterType == null)
                        {
                            continue;
                        }

                        if (propertyValue.GetType() != parameterType)
                        {
                            var querierName = string.Format("{0}Querier", parameterType.Name);

                            var searchIocItems = ObjectContainer.GetRegisterItems().Where(pre => pre.MappedToType.Name == querierName).ToList();

                            object tempFindValue = null;

                            if (searchIocItems.Count > 0)
                            {
                                //先从仓储集合中查找指定类型的仓储。
                                var searchQuerier         = searchIocItems.FirstOrDefault();
                                var searchQuerierInstance = ObjectContainer.CreateInstance(searchQuerier.RegisteredType);

                                var methodName = string.Format("Get{0}ById", parameterType.Name);

                                var tempQuerierMethod = searchQuerierInstance.GetType().GetMethod(methodName);

                                if (tempQuerierMethod != null)
                                {
                                    tempFindValue = tempQuerierMethod.Invoke(searchQuerierInstance, new object[] { propertyValue });

                                    if (tempFindValue == null)
                                    {
                                        continue;
                                    }

                                    tempMethod.Invoke(domainObj, new object[] { tempFindValue });

                                    break;
                                }
                            }

                            //如果没有找到,再执行后续的代码。
                            var dbContext = (DbContext)context.GetType().GetProperty("Context").GetValue(context, null);

                            if (dbContext == null)
                            {
                                throw new ApplicationException("没有找到持久化上下文");
                            }

                            //暂无好的方案
                            //tempFindValue = dbContext.Set(parameterType).Find(propertyValue);
                            if (tempFindValue == null)
                            {
                                continue;
                            }

                            tempMethod.Invoke(domainObj, new object[] { tempFindValue });
                            break;
                        }

                        tempMethod.Invoke(domainObj, new object[] { propertyValue });

                        break;
                    }
                }
            }

            return(true);
        }
Exemple #19
0
        public static LoginResult Parse(PassportLoginRequest model)
        {
            var result = new LoginResult();

            try
            {
                model.Trim();
                //获取应用信息
                var appInfo = new AppInfoService().Get(model.AppKey);
                if (appInfo == null)
                {
                    throw new Exception("应用不存在");
                }
                //获取用户信息

                User userInfo = null;
                if (model.Account == "System")
                {
                    userInfo = new User
                    {
                        Id       = Guid.Empty.ToString(), //TODO:可以根据需要调整
                        Account  = "System",
                        Name     = "超级管理员",
                        Password = "******"
                    };
                }
                else
                {
                    var usermanager = ObjectContainer.CreateInstance <IUserManagementApplication>();
                    userInfo = usermanager.GetUser(model.Account);
                }

                if (userInfo == null)
                {
                    throw new Exception("用户不存在");
                }
                if (userInfo.Password != model.Password)
                {
                    throw new Exception("密码错误");
                }

                var currentSession = new UserAuthSession
                {
                    Account    = model.Account,
                    Name       = userInfo.Name,
                    Token      = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    AppKey     = model.AppKey,
                    CreateTime = DateTime.Now,
                    IpAddress  = HttpContext.Current.Request.UserHostAddress
                };

                //创建Session
                //new ObjCacheProvider<UserAuthSession>().Create(currentSession.Token, currentSession, DateTime.Now.AddDays(10));
                //创建Session
                UserSessionCacheProvider.Instance.CreateNewUserSesssion(currentSession.Token, currentSession, 10);

                result.Code      = 200;
                result.ReturnUrl = appInfo.ReturnUrl;
                result.Token     = currentSession.Token;
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
            }

            return(result);
        }
Exemple #20
0
        /// <summary>
        /// 获取负载均衡的数据库字符串
        /// </summary>
        /// <param name="key">关键字</param>
        /// <returns></returns>
        public static string GetConnectionString(string key)
        {
            IDbLoadBalanceRouter tempRouter = ObjectContainer.CreateInstance <IDbLoadBalanceRouter>();

            return(tempRouter.GetDbConnectionString(LoadBalanceDbType.Best, key));
        }
Exemple #21
0
 /// <summary>
 /// 仅触发一次的触发器
 /// </summary>
 public OnceTrigger()
     : base()
 {
     _logProvider = ObjectContainer.CreateInstance <ILogProvider>();
 }