private static Dictionary <string, object> GetVariablesValues(List <NotificationVariable> notificationVariables, Guid entityId,
                                                                      string relationEntityName, ref Guid relationId, Dictionary <string, object> oldValue, int languageId)
        {
            DbContext context = DynamicModelBuilder.CreateDataSource();
            Dictionary <string, object> values       = new Dictionary <string, object>();
            NotificationVariable        rootVariable = notificationVariables.Where(c => c.ParentId == Guid.Empty).First();

            ProcessOneVariable(rootVariable, entityId, context, notificationVariables, values, relationEntityName, ref relationId, oldValue, languageId);
            return(values);
        }
        private static void CreateNotificationItem(IEnumerable entityList, string primaryKey, string entityName,
                                                   NotificationProfile config, Guid operatorUserId, string relationEntityName
                                                   , Dictionary <string, object> oldValue, int languageId)
        {
            DbContext context = DynamicModelBuilder.CreateDataSource();

            foreach (var entityDataItem in entityList)
            {
                ProcessOneEntityData(entityDataItem, primaryKey, entityName, context, config, operatorUserId, relationEntityName, oldValue, languageId);
            }
            context.SaveChanges();
        }
        private static List <Guid> GetUserList(NotificationProfile config, Dictionary <string, object> variablesValues, Guid operatorUserId)
        {
            DbContext   commonContext = DynamicModelBuilder.CreateDataSource();
            List <Guid> userList      = new List <Guid>();
            List <NotificationRecipientAttribute> recipientConfigs = config.NotificationRecipientAttributes.ToList() as List <NotificationRecipientAttribute>;
            MetadataService client = new MetadataService();

            foreach (NotificationRecipientAttribute reipientConfig in recipientConfigs)
            {
                FilterCriteriaHelper helper      = new FilterCriteriaHelper(reipientConfig.RecipientEntityId ?? Guid.Empty, variablesValues);
                CriteriaOperator     theOperator = helper.GeneratrCriteria(reipientConfig.Criterion);
                var  filterEntiy      = MetadataProvider.Instance.EntiyMetadata.Where(c => c.EntityId == reipientConfig.RecipientEntityId).First();
                Type filterEntityType = DynamicTypeBuilder.Instance.GetDynamicType(filterEntiy.Name);

                IQueryable query = commonContext.Set(filterEntityType).AsQueryable();
                System.Linq.Expressions.Expression exception = GetExpression(query, theOperator);
                query = query.Provider.CreateQuery(exception);
                IEnumerator     iter = query.GetEnumerator();
                EntityAttribute att  = filterEntiy.Attributes.Where(c => c.AttributeId == reipientConfig.AttributeId).First();
                while (iter.MoveNext())
                {
                    object userIdValue = GetPropertyValue(iter.Current, att.PhysicalName);
                    if (userIdValue is Guid)
                    {
                        Guid userId = (Guid)GetPropertyValue(iter.Current, att.PhysicalName);
                        if (!userList.Contains(userId) && userId != operatorUserId)
                        {
                            userList.Add(userId);
                        }
                    }
                }
            }
            if (config.Subscriptions != null)
            {
                foreach (var subscription in config.Subscriptions)
                {
                    if (subscription.UserId != null && subscription.UserId != operatorUserId)
                    {
                        if (!userList.Contains((Guid)subscription.UserId))
                        {
                            userList.Add((Guid)subscription.UserId);
                        }
                    }
                }
            }
            return(userList);
        }
        public static void CreateCommonNotification()
        {
            DbContext commonContext = DynamicModelBuilder.CreateDataSource();

            if (commonContext == null)
            {
                return;
            }
            var configs = MetadataProvider.Instance.NotificationProfileList.Where(c => c.IsSys == true);

            if (configs.Count() <= 0)
            {
                return;
            }
            foreach (NotificationProfile config in configs)
            {
                ProcessOneEntity(config, commonContext, Guid.Empty, Guid.Empty, string.Empty, null, 2052, true);
            }
        }
        /// <summary>	Creates API configuration. </summary>
        ///
        /// <returns>	The new API configuration. </returns>
        protected override ApiConfiguration CreateApiConfiguration()
        {
            var apiConfiguration = base.CreateApiConfiguration();

            if (_dynamicModelBuilder == null)
            {
                _dynamicModelBuilder = new DynamicModelBuilder();
                _dynamicModelBuilder.InnerHandler = apiConfiguration.GetHookHandler <IModelBuilder>();
                apiConfiguration.AddHookHandler <IModelBuilder>(_dynamicModelBuilder);
            }

            if (_dynamicModelMapper == null)
            {
                _dynamicModelMapper = new DynamicModelMapper();
                _dynamicModelMapper.InnerHandler = apiConfiguration.GetHookHandler <IModelMapper>();
                apiConfiguration.AddHookHandler <IModelMapper>(_dynamicModelMapper);
            }

            if (_dynamicQueryExpressionExpander == null)
            {
                _dynamicQueryExpressionExpander = new DynamicQueryExpressionExpander();
                _dynamicQueryExpressionExpander.InnerHandler = apiConfiguration.GetHookHandler <IQueryExpressionExpander>();
                apiConfiguration.AddHookHandler <IQueryExpressionExpander>(_dynamicQueryExpressionExpander);
            }

            if (_dynamicQueryExpressionSourcer == null)
            {
                _dynamicQueryExpressionSourcer = new DynamicQueryExpressionSourcer();
                _dynamicQueryExpressionSourcer.InnerHandler = apiConfiguration.GetHookHandler <IQueryExpressionSourcer>();
                apiConfiguration.AddHookHandler <IQueryExpressionSourcer>(_dynamicQueryExpressionSourcer);
            }

            if (_dynamicChangeSetPreparer == null)
            {
                _dynamicChangeSetPreparer = new DynamicChangeSetPreparer();
                _dynamicChangeSetPreparer.InnerHandler = apiConfiguration.GetHookHandler <IChangeSetPreparer>();
                apiConfiguration.AddHookHandler <IChangeSetPreparer>(_dynamicChangeSetPreparer);
            }

            return(apiConfiguration);
        }
        private static void ProcessOneEntity(NotificationProfile config, DbContext commonContext,
                                             Guid entityId, Guid operatorUserId, string relationEntityName
                                             , Dictionary <string, object> oldValue, int languageId, bool isSys)
        {
            if (commonContext == null)
            {
                commonContext = DynamicModelBuilder.CreateDataSource();
            }
            var entityInfo                   = MetadataProvider.Instance.EntiyMetadata.Where(c => c.EntityId == config.ProfileVariables.First().NotificationVariable.EntityId).First();
            var entityTypeId                 = entityInfo.EntityId;
            FilterCriteriaHelper helper      = new FilterCriteriaHelper(oldValue, entityTypeId);
            CriteriaOperator     theOperator = helper.GeneratrCriteria(config.Criterion);

            string primaryKey = string.Empty;

            primaryKey = entityInfo.Attributes.Where(c => c.IsPKAttribute == true).First().TableColumnName;

            Type entityInfoType = DynamicTypeBuilder.Instance.GetDynamicType(entityInfo.Name);

            //fetch data
            if (entityId != Guid.Empty)
            {
                theOperator = new GroupOperator(GroupOperatorType.And, theOperator, GetKeyOperator(entityId, primaryKey));
            }
            IQueryable query = commonContext.Set(entityInfoType).AsQueryable();

            try
            {
                System.Linq.Expressions.Expression expression = GetExpression(query, theOperator);
                query = query.Provider.CreateQuery(expression);
                IEnumerator iter           = query.GetEnumerator();
                var         tempEntityList = new ArrayList();
                while (iter.MoveNext())
                {
                    tempEntityList.Add(iter.Current);
                }
                Type attentionType = DynamicTypeBuilder.Instance.GetDynamicType("Notification");
                var  entityList    = new ArrayList();

                foreach (var item in tempEntityList)
                {
                    bool isExist = false;
                    if (entityId == Guid.Empty && isSys)
                    {
                        IQueryable     notificationQuery = commonContext.Set(attentionType).AsQueryable();
                        BinaryOperator binaryOperator    = new BinaryOperator();
                        binaryOperator.OperatorType = BinaryOperatorType.Equal;
                        binaryOperator.LeftOperand  = ConstantValue.Parse("ObjectId");
                        binaryOperator.RightOperand = (Guid)item.GetType().GetProperty(primaryKey).GetValue(item, null);
                        System.Linq.Expressions.Expression attentionException = GetExpression(notificationQuery, binaryOperator);
                        notificationQuery = notificationQuery.Provider.CreateQuery(attentionException);
                        IEnumerator notificationIter = notificationQuery.GetEnumerator();

                        while (notificationIter.MoveNext())
                        {
                            if (notificationIter.Current != null)
                            {
                                isExist = true;
                                continue;
                            }
                        }
                    }
                    if (!isExist)
                    {
                        entityList.Add(item);
                    }
                }
                if (entityList.Count <= 0)
                {
                    return;
                }
                CreateNotificationItem(entityList, primaryKey, entityInfo.Name, config, operatorUserId, relationEntityName, oldValue, languageId);
            }
            catch
            {
            }
        }
Beispiel #7
0
 public LoginViewModel()
 {
     logindata = DynamicModelBuilder.GetInstance <ILoginVM>(typeof(BaseModel));
     logindata.ValidateMetadataType = typeof(LoginVM);
 }
Beispiel #8
0
 public UserDetailViewModel(bool needValidate = true) : base(needValidate)
 {
     userdata = DynamicModelBuilder.GetInstance <IUserVM>(parent: typeof(BaseModel), ctorArgs: needValidate);
     userdata.ValidateMetadataType = typeof(UserVM);
 }
Beispiel #9
0
 public PermDetailViewModel(bool needValidate = true) : base(needValidate)
 {
     permdata = DynamicModelBuilder.GetInstance <IPermVM>(parent: typeof(BaseModel), ctorArgs: needValidate);
     permdata.ValidateMetadataType = typeof(PermVM);
 }
Beispiel #10
0
 public GroupDetailViewModel(bool needValidate = true) : base(needValidate)
 {
     groupdata = DynamicModelBuilder.GetInstance <IGroupVM>(parent: typeof(BaseModel), ctorArgs: needValidate);
     groupdata.ValidateMetadataType = typeof(GroupVM);
 }
Beispiel #11
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            if (!CanBindType(bindingContext.ModelType))
            {
                return(false);
            }
            if (!bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName))
            {
                return(false);
            }
            //创建针对目标类型的空对象
            var ins = DynamicModelBuilder.GetInstance <IContact>(parent: bindingContext.ModelType, propAttrProvider: () =>
            {
                return(new List <PropertyCustomAttributeUnit>
                {
                    new PropertyCustomAttributeUnit
                    {
                        prop_name = "phone",
                        attrs = new List <PropertyCustomAttribute>
                        {
                            new PropertyCustomAttribute
                            {
                                attr_type = "System.ComponentModel.DataAnnotations.RequiredAttribute,System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                                ctor_arg_types = "",
                                ctor_arg_values = new object[0],
                                error_msg = "姓名不能为空",
                                error_msg_res_name = "",
                                error_msg_res_type = ""
                            }
                        }
                    }
                });
            });

            //bindingContext.Model = Activator.CreateInstance(bindingContext.ModelType);
            bindingContext.Model = ins;

            //创建针对目标类型的ComplexModelDto
            //创建ModelBindingContext,并将ComplexModelDto作为Model,驱动新一轮的Model绑定
            ComplexModelDto     dto        = new ComplexModelDto(bindingContext.ModelMetadata, bindingContext.PropertyMetadata.Values);
            ModelBindingContext subContext = new ModelBindingContext(bindingContext)
            {
                ModelMetadata = actionContext.GetMetadataProvider().GetMetadataForType(() => dto, typeof(ComplexModelDto)),
                ModelName     = bindingContext.ModelName
            };

            actionContext.Bind(subContext);

            //从ComplexModelDto获取相应的值并为相应的属性赋值
            foreach (KeyValuePair <ModelMetadata, ComplexModelDtoResult> item in dto.Results)
            {
                ModelMetadata         propertyMetadata = item.Key;
                ComplexModelDtoResult dtoResult        = item.Value;
                if (dtoResult != null)
                {
                    PropertyInfo propertyInfo = bindingContext.ModelType.GetProperty(propertyMetadata.PropertyName);
                    if (propertyInfo.CanWrite)
                    {
                        propertyInfo.SetValue(bindingContext.Model, dtoResult.Model);
                    }
                }
            }
            return(true);
        }
Beispiel #12
0
 public ChgPwdDetailViewModel(bool needValidate = true) : base(needValidate)
 {
     chgpwddata = DynamicModelBuilder.GetInstance <IChgPwdVM>(parent: typeof(BaseModel), ctorArgs: needValidate);
     chgpwddata.ValidateMetadataType = typeof(ChgPwdVM);
 }