Пример #1
0
        protected override void CheckStatus()
        {
            AUCommon.DoDbAction(() =>
            {
                List <SchemaObjectBase> dataToBeChecked = new List <SchemaObjectBase>();

                if (this.NeedStatusCheck)
                {
                    dataToBeChecked.Add(this.Data);
                }

                if (this.NeedParentStatusCheck && this.inputParent != null)
                {
                    dataToBeChecked.Add(this.inputParent);
                }

                dataToBeChecked.Add(this.schema);

                CheckObjectStatus(dataToBeChecked.ToArray());

                if (this.NeedDuplicateRelationCheck)
                {
                    var allParentRelations = this.Data.CurrentParentRelations;
                    var relationToSchema   = (from r in allParentRelations where r.ParentSchemaType == AUCommon.SchemaAUSchema select r).FirstOrDefault();
                    var relationToUnit     = (from u in allParentRelations where u.ParentSchemaType == AUCommon.SchemaAdminUnit select u).FirstOrDefault();

                    if (this.inputParent != null)
                    {
                        //添加下级管理单元
                        if (relationToSchema != null)
                        {
                            throw new SCStatusCheckException(string.Format("对象\"{0}\"已经是顶级管理单元了,不能再添加到别的管理单元中",
                                                                           AUCommon.DisplayNameFor(this.Data)));
                        }
                        else if (relationToUnit != null && (relationToUnit.ID != this.Data.ID || relationToUnit.ParentID != inputParent.ID))
                        {
                            throw new SCStatusCheckException(string.Format("对象\"{0}\"已经属于另一管理单元{1}了,不能再添加到其他管理单元",
                                                                           AUCommon.DisplayNameFor(this.Data)));
                        }
                    }
                    else
                    {
                        //顶级管理单元
                        if (relationToSchema != null)
                        {
                            if (relationToSchema.ParentID != schema.ID)
                            {
                                throw new SCStatusCheckException(string.Format("对象\"{0}\"已经是顶级管理单元了,不能再添加到别的管理单元中",
                                                                               AUCommon.DisplayNameFor(this.Data)));
                            }
                        }
                        else if (relationToUnit != null)
                        {
                            throw new SCStatusCheckException(string.Format("对象\"{0}\"已经属于另一管理单元{1}了,不能作为顶级管理单元",
                                                                           AUCommon.DisplayNameFor(this.Data)));
                        }
                    }
                }
            });
        }
Пример #2
0
        protected override void PrepareData(AUObjectOperationContext context)
        {
            AUCommon.DoDbAction(() =>
            {
                this.schema = (AUSchema)SchemaObjectAdapter.Instance.Load(((AdminUnit)Data).AUSchemaID);

                if (this.schema == null || this.schema.Status != SchemaObjectStatus.Normal)
                {
                    throw new AUObjectValidationException(AUCommon.DisplayNameFor((AdminUnit)this.Data) + "管理单元的SchemaID无效,无法找到对应的Schema。");
                }
            });

            this.PrepareRelationObject();

            base.PrepareData(context);

            var oldObject = (AdminUnit)SCActionContext.Current.OriginalObject;

            if (oldObject != null && oldObject.AUSchemaID != this.schema.ID)
            {
                throw new AUObjectValidationException("一旦创建,不能以任何方式修改AdminUnit的AUSchema属性");
            }

            this.existingSchemaRoles = Adapters.AUSnapshotAdapter.Instance.LoadAUSchemaRoles(schema.ID, false, DateTime.MinValue);
            this.existingUnitRoles   = Adapters.AUSnapshotAdapter.Instance.LoadAURoles(new string[] { this.Data.ID }, new string[0], false, DateTime.MinValue);
            this.existingUnitScopes  = Adapters.AUSnapshotAdapter.Instance.LoadAUScope(this.Data.ID, false, DateTime.MinValue);

            this.pendingActions.Clear();
            PrepareRolesAndScopes();
        }
Пример #3
0
        protected override void PrepareOperationLog(AUObjectOperationContext context)
        {
            if (this.RelationExisted == false)
            {
                AUOperationLog log = AUOperationLog.CreateLogFromEnvironment();

                log.ResourceID    = this._Object.ID;
                log.SchemaType    = this._Object.SchemaType;
                log.OperationType = this.OperationType;
                log.Category      = this._Object.Schema.Category;
                log.Subject       = string.Format("{0}: {1} 从 {2} 至 {3}",
                                                  EnumItemDescriptionAttribute.GetDescription(this.OperationType), this._Object.Name,
                                                  AUCommon.DisplayNameFor(this._SourceObject), AUCommon.DisplayNameFor(this._ActualTarget));

                log.SearchContent = this._Object.ToFullTextString() +
                                    " " + AUCommon.FullTextFor(this._SourceObject) +
                                    " " + this._ActualTarget.ToFullTextString();

                context.Logs.Add(log);
            }
            else
            {
                AUOperationLog log = AUOperationLog.CreateLogFromEnvironment();

                log.ResourceID    = this._Object.ID;
                log.SchemaType    = this._Object.SchemaType;
                log.OperationType = this.OperationType;
                log.Category      = this._Object.Schema.Category;
                log.Subject       = string.Format("{0}: {1} 从 {2} 至 {3}(跳过已经存在的关系)",
                                                  EnumItemDescriptionAttribute.GetDescription(this.OperationType), this._Object.Name,
                                                  AUCommon.DisplayNameFor(this._SourceObject), AUCommon.DisplayNameFor(this._Target));

                log.SearchContent = this._Object.ToFullTextString() +
                                    " " + AUCommon.DisplayNameFor(this._SourceObject) +
                                    " " + this._ActualTarget.ToFullTextString();

                context.Logs.Add(log);
            }
        }
Пример #4
0
        protected override void PrepareOperationLog(AUObjectOperationContext context)
        {
            AUOperationLog log = AUOperationLog.CreateLogFromEnvironment();

            log.ResourceID    = this.Data.ID;
            log.SchemaType    = this.Data.SchemaType;
            log.OperationType = this.OperationType;
            log.Category      = this.Data.Schema.Category;
            log.Subject       = string.Format("{0}: {1} 于 {2}",
                                              EnumItemDescriptionAttribute.GetDescription(this.OperationType), AUCommon.DisplayNameFor(this.Data), AUCommon.DisplayNameFor(this.actualParent));

            //log.SearchContent = this.Data.ToFullTextString() + " " + this.Container.ToFullTextString();

            context.Logs.Add(log);
        }
Пример #5
0
        protected override void DoValidate(object objectToValidate, object currentObject, string key, ValidationResults validateResults)
        {
            AUSchema schema = (AUSchema)currentObject;
            string   name   = (string)objectToValidate;
            var      target = Adapters.AUSnapshotAdapter.Instance.LoadAUSchemaByName(name, schema.CategoryID, true).GetUniqueNormalObject <AUSchema>();

            if (target != null && schema.ID != target.ID)
            {
                this.RecordValidationResult(validateResults, string.Format("管理架构 {0} 的不唯一名称", AUCommon.DisplayNameFor(schema)), currentObject, key);
            }
        }
        protected override void DoValidate(object objectToValidate, object currentObject, string key, ValidationResults validateResults)
        {
            string typeString      = (string)objectToValidate;
            string messageTemplate = string.IsNullOrEmpty(this.MessageTemplate) ? "{0}包含无效或重复的的管理范围类别字符串:{1}" : this.MessageTemplate;

            string[] parts = typeString.Split(AUCommon.Spliter, StringSplitOptions.RemoveEmptyEntries);

            // 准备有效项的集合
            HashSet <string> effected = new HashSet <string>();
            HashSet <string> repeated = new HashSet <string>();

            foreach (var item in SchemaInfo.FilterByCategory("AUScopeItems"))
            {
                effected.Add(item.Name);
            }

            // 检查有效项
            foreach (var item in parts)
            {
                if (effected.Contains(item) == false)
                {
                    this.RecordValidationResult(validateResults, string.Format(messageTemplate, AUCommon.DisplayNameFor((SchemaObjectBase)currentObject), item), currentObject, key);
                    break;
                }

                if (repeated.Contains(item))
                {
                    this.RecordValidationResult(validateResults, string.Format(messageTemplate, AUCommon.DisplayNameFor((SchemaObjectBase)currentObject), item), currentObject, key);
                    break;
                }
                else
                {
                    repeated.Add(item);
                }
            }
        }