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();
        }
        protected override void PrepareData(AUObjectOperationContext context)
        {
            this._OriginalRelation = this._Object.GetCurrentVeryParentRelation();

            if (this._OriginalRelation == null || this._OriginalRelation.Status != SchemaObjectStatus.Normal)
            {
                throw new AUObjectValidationException("未找到此管理单元对应的上级关系");
            }

            AUCommon.DoDbAction(() =>
            {
                this._SourceObject = this._OriginalRelation.Parent;
                this._ActualTarget = this._Target ?? SchemaObjectAdapter.Instance.Load(this._Object.AUSchemaID);
            });

            if (this._SourceObject == null || this._SourceObject.Status != SchemaObjectStatus.Normal)
            {
                throw new AUObjectValidationException("未找到此管理单元对应的上级对象");
            }

            if (this._OriginalRelation.ParentID == this._ActualTarget.ID)
            {
                throw new AUObjectValidationException("此管理单元已经属于目标管理单元,无需移动。");
            }
            AUCommon.DoDbAction(() =>
            {
                this._TargetRelation        = PrepareTargetRelation(this._ActualTarget, this._Object);
                this._NeedGenerateFullPaths = (this._Object is ISCRelationContainer) && (((ISCRelationContainer)this._Object).CurrentChildren.Count > 0);

                Validate();
            });
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            if (this._RelationExisted == false)
            {
                if (this._OriginalRelation.Status == SchemaObjectStatus.Normal)
                {
                    this._OriginalRelation.Status = SchemaObjectStatus.Deleted;
                    AUCommon.DoDbAction(() =>
                                        SchemaRelationObjectAdapter.Instance.UpdateStatus(this._OriginalRelation, SchemaObjectStatus.Deleted));
                }

                AUCommon.DoDbAction(() =>
                                    SchemaRelationObjectAdapter.Instance.Update(this._TargetRelation));

                //if (this.NeedChangeOwner)
                //    SchemaObjectAdapter.Instance.Update(this._Object);

                if (this._NeedGenerateFullPaths)
                {
                    AUCommon.DoDbAction(() =>
                                        SCToDoJobListAdapter.Instance.Insert(SCToDoJob.CreateGenerateFullPathsJob(this._Object)));
                }
            }

            return(this._TargetRelation);
        }
Beispiel #4
0
        private void PrepareScopeItems(AUObjectOperationContext context, AUSchema originalSchema, AUSchema targetSchema)
        {
            var srcArray = originalSchema != null?originalSchema.Scopes.Split(AUCommon.Spliter, StringSplitOptions.RemoveEmptyEntries) : AUCommon.ZeroLengthStringArray;

            var targetArray = targetSchema.Scopes.Split(AUCommon.Spliter, StringSplitOptions.RemoveEmptyEntries);

            Array.Sort(srcArray);
            Array.Sort(targetArray);

            var toBeAddedScopes   = GetToBeAddedScopes(srcArray, targetArray);
            var toBeDeletedScopes = GetToBeRemovedScopes(srcArray, targetArray);

            //角色不在此修改

            this.allCurrentAUs = Adapters.AUSnapshotAdapter.Instance.LoadAUBySchemaID(targetSchema.ID, true, DateTime.MinValue);
            if (allCurrentAUs.Any() && this.Data.Status == SchemaObjectStatus.Deleted)
            {
                throw new InvalidOperationException("必须先删除所有与此管理架构相关的管理单元才可以进行Schema删除。");
            }

            if (toBeAddedScopes.Length > 0 || toBeDeletedScopes.Length > 0)
            {
                if (this.Data.Status == SchemaObjectStatus.Deleted)
                {
                    throw new InvalidOperationException("进行删除操作时,不应修改管理范围。");
                }

                PrepareToBeAddedScopes(toBeAddedScopes, pendingActions);

                PrepareToBeDeletedScopes(toBeDeletedScopes, pendingActions);
            }
        }
        private object InternalExecute()
        {
            AUObjectOperationContext context = new AUObjectOperationContext(this.OperationType, this);

            ExecutionWrapper("PrepareData", () => PrepareData(context));
            ExecutionWrapper("PrepareOperationLog", () => PrepareOperationLog(context));

            object result = null;

            if (this.AutoStartTransaction)
            {
                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    ExecutionWrapper("DoOperation", () => { result = DoOperation(context); });
                    ExecutionWrapper("PersistOperationLog", () => PersistOperationLog(context));

                    scope.Complete();
                }
            }
            else
            {
                ExecutionWrapper("DoOperation", () => result = DoOperation(context));
                ExecutionWrapper("PersistOperationLog", () => PersistOperationLog(context));
            }


            return(result);
        }
        private void PersistOperationLog(AUObjectOperationContext context)
        {
            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                context.Logs.ForEach(log => AUOperationLogAdapter.Instance.Insert(log));

                scope.Complete();
            }
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            object result = base.DoOperation(context);

            this.pendingActions.DoActions();

            this.DoRelativeDataOperation(context);

            return(result);
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                pendingActions.DoActions();
                scope.Complete();
            }

            return(this.actualUnitRole);
        }
Beispiel #9
0
        protected override void PrepareData(AUObjectOperationContext context)
        {
            base.PrepareData(context);
            var originalSchema = SCActionContext.Current.OriginalObject as AUSchema;
            var targetSchema   = (AUSchema)this.Data;

            pendingActions.Clear();

            PrepareScopeItems(context, originalSchema, targetSchema);
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            using (System.Transactions.TransactionScope ts = TransactionScopeFactory.Create())
            {
                bool changeRelationToSchemaDemanded = true;
                bool changeRelationToUnitDemanded   = true;

                //当不是删除操作,且需要修改关系时
                if (this.Data.Status == SchemaObjectStatus.Normal && (OverrideExistedRelation || this.relationExists == false))
                {
                    SchemaRelationObjectAdapter.Instance.Update(this.targetRelation);
                }
                else if (this.Data.Status == SchemaObjectStatus.Deleted && (OverrideExistedRelation || this.relationExists))
                {
                    if (oldRelationToChildren.Any(m => m.Status == SchemaObjectStatus.Normal))
                    {
                        throw new AUObjectValidationException("管理单元存在子对象,不能进行删除操作");
                    }

                    SchemaRelationObjectAdapter.Instance.UpdateStatus(this.targetRelation, SchemaObjectStatus.Deleted);
                }

                if (oldRelationToSchema != null && this.targetRelation.ParentID == this.oldRelationToSchema.ParentID)
                {
                    changeRelationToSchemaDemanded = false;
                }

                if (oldRelationToUnit != null && this.targetRelation.ParentID == this.oldRelationToUnit.ParentID)
                {
                    changeRelationToUnitDemanded = false;
                }

                if (changeRelationToSchemaDemanded && this.oldRelationToSchema != null && this.oldRelationToSchema.Status == SchemaObjectStatus.Normal)
                {
                    SchemaRelationObjectAdapter.Instance.UpdateStatus(this.oldRelationToSchema, SchemaObjectStatus.Deleted);
                }

                if (changeRelationToUnitDemanded && this.oldRelationToUnit != null && this.oldRelationToUnit.Status == SchemaObjectStatus.Normal)
                {
                    SchemaRelationObjectAdapter.Instance.UpdateStatus(this.oldRelationToUnit, SchemaObjectStatus.Deleted);
                }

                SchemaObjectAdapter.Instance.Update(Data);

                this.DoRelativeDataOperation(context);

                if (this.aclContainer != null)
                {
                    DBTimePointActionContext.Current.DoActions(() => SCAclAdapter.Instance.Update(this.aclContainer));
                }

                ts.Complete();
            }
            return(this.TargetRelation);
        }
        protected override void PrepareData(AUObjectOperationContext context)
        {
            base.PrepareData(context);

            this.scope = (AUAdminScope)SchemaObjectAdapter.Instance.Load(this.scope.ID);

            if (this.scope == null || this.scope.Status != SchemaObjectStatus.Normal)
            {
                throw new SCStatusCheckException("指定条件容器对象不存在。");
            }
        }
        protected override void PrepareData(AUObjectOperationContext context)
        {
            PrepareCandidatesRecursively(this._Parent);

            if (this._Candidates.Count > 0)
            {
                ProcessProgress.Current.MinStep     = 0;
                ProcessProgress.Current.MaxStep     = this._Candidates.Count;
                ProcessProgress.Current.CurrentStep = 0;
            }
        }
        /// <summary>
        /// 在派生类中重写时,处理相关数据
        /// </summary>
        /// <param name="context"></param>
        protected virtual void DoRelativeDataOperation(AUObjectOperationContext context)
        {
            if (this._ObjectNameChanged)
            {
                if (context.ContainsKey("parentRelations"))
                {
                    UpdateRelations((IEnumerable <SCRelationObject>)context["parentRelations"]);
                }
            }

            if (this._NeedDeleteRelations)
            {
                if (context.ContainsKey("childrenRelations"))
                {
                    UpdateRelationsStatus((IEnumerable <SCRelationObject>)context["childrenRelations"]);
                }

                if (context.ContainsKey("parentRelations"))
                {
                    UpdateRelationsStatus((IEnumerable <SCRelationObject>)context["parentRelations"]);
                }
            }

            if (context.ContainsKey("containersRelations"))
            {
                UpdateMembersRelationsStatus((IEnumerable <SCSimpleRelationBase>)context["containersRelations"]);
            }

            if (context.ContainsKey("membersRelations"))
            {
                UpdateMembersRelationsStatus((IEnumerable <SCSimpleRelationBase>)context["membersRelations"]);
            }

            if (context.ContainsKey("aclMembers"))
            {
                SCAclAdapter.Instance.UpdateStatus(((SCAclContainerOrMemberCollectionBase)context["aclMembers"]), SchemaObjectStatus.Deleted);
            }

            if (context.ContainsKey("aclContainers"))
            {
                SCAclAdapter.Instance.UpdateStatus(((SCAclContainerOrMemberCollectionBase)context["aclContainers"]), SchemaObjectStatus.Deleted);
            }

            if (this._NeedGenerateFullPaths)
            {
                SCToDoJobListAdapter.Instance.Insert(SCToDoJob.CreateGenerateFullPathsJob(this.Data));
            }

            if (this._NeedDeleteConditions && this.Data is ISCUserContainerWithConditionObject && this.Data.Status != SchemaObjectStatus.Normal)
            {
                AUConditionAdapter.Instance.DeleteByOwner(this.Data.ID, "Default");
            }
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                SCConditionCollection collection = new SCConditionCollection();
                collection.Add(condition);
                AUConditionAdapter.Instance.UpdateConditions(this.scope.ID, "ADM", collection);

                scope.Complete();
            }

            return(this.scope);
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                SchemaObjectAdapter.Instance.Update(Data);

                DoRelativeDataOperation(context);

                scope.Complete();
            }

            return(this.Data);
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            if (OverrideExistedRelation || this.RelationExisted == false || this.Relation.Status == SchemaObjectStatus.Deleted)
            {
                SCMemberRelationAdapter.Instance.Update(this.Relation);
            }

            if (SaveTargetData)
            {
                SchemaObjectAdapter.Instance.Update(Data);
            }

            return(this.Relation);
        }
        protected override void PrepareOperationLog(AUObjectOperationContext context)
        {
            AUOperationLog log = AUOperationLog.CreateLogFromEnvironment();

            log.ResourceID    = ((SchemaObjectBase)this._Parent).ID;
            log.SchemaType    = ((SchemaObjectBase)this._Parent).SchemaType;
            log.OperationType = this.OperationType;
            log.Category      = ((SchemaObjectBase)this._Parent).Schema.Category;
            log.Subject       = string.Format("{0}: {1}",
                                              EnumItemDescriptionAttribute.GetDescription(this.OperationType), ((SCBase)this._Parent).Name);

            log.SearchContent = ((SchemaObjectBase)this._Parent).ToFullTextString();

            context.Logs.Add(log);
        }
        protected override void PrepareOperationLog(AUObjectOperationContext context)
        {
            AUOperationLog log = AUOperationLog.CreateLogFromEnvironment();

            log.ResourceID    = this.scope.ID;
            log.SchemaType    = this.scope.SchemaType;
            log.OperationType = this.OperationType;
            log.Category      = this.scope.Schema.Category;
            log.Subject       = string.Format("{0}: {1}",
                                              EnumItemDescriptionAttribute.GetDescription(this.OperationType), this.scope.ID);

            log.SearchContent = "";            // this.ownerObj.ToFullTextString();

            context.Logs.Add(log);
        }
        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);
        }
        protected override void PrepareData(AUObjectOperationContext context)
        {
            base.PrepareData(context);
            this._ContainerObject = (SCBase)SchemaObjectAdapter.Instance.Load(this._Container.ContainerID);

            if (this._ContainerObject == null || this._ContainerObject.Status != SchemaObjectStatus.Normal)
            {
                throw new SCStatusCheckException("ACL容器对象无效");
            }

            if ((this._ContainerObject is ISCAclContainer) == false)
            {
                throw new SCStatusCheckException(string.Format("ACL容器对象无效:{0}不实现ISCAclContainer接口", this._ContainerObject.ToDescription()));
            }
        }
        protected override void PrepareData(AUObjectOperationContext context)
        {
            AUCommon.DoDbAction(() =>
            {
                actualSchemaRole = (AUSchemaRole)SchemaObjectAdapter.Instance.Load(schemaRole.ID);
                if (actualSchemaRole.Status != Schemas.SchemaProperties.SchemaObjectStatus.Normal)
                {
                    throw new AUStatusCheckException(actualSchemaRole, this.OperationType);
                }

                this.actualUnit = (AdminUnit)SchemaObjectAdapter.Instance.Load(this.unit.ID);
                if (this.actualUnit == null || this.actualUnit.Status != Schemas.SchemaProperties.SchemaObjectStatus.Normal)
                {
                    throw new AUStatusCheckException(actualUnit, this.OperationType);
                }

                this.actualUnitRole = Adapters.AUSnapshotAdapter.Instance.LoadAURole(actualSchemaRole.ID, actualUnit.ID, true, DateTime.MinValue);
                if (actualUnitRole == null || actualUnitRole.Status != Schemas.SchemaProperties.SchemaObjectStatus.Normal)
                {
                    throw new AUStatusCheckException(actualUnitRole, this.OperationType);
                }

                var roleMemberRelations = SCMemberRelationAdapter.Instance.LoadByContainerID(this.actualUnitRole.ID);

                Dictionary <string, SCUser> userDic = users.ToDictionary(m => m.ID);

                foreach (var item in roleMemberRelations)
                {
                    if (item.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal)
                    {
                        if (userDic.ContainsKey(item.ID))
                        {
                            userDic.Remove(item.ID);
                        }
                        else
                        {
                            pendingActions.Add(new RemoveRelationAction(item));
                        }
                    }
                }

                foreach (SCUser user in userDic.Values)
                {
                    pendingActions.Add(new AddRelationAction(this.actualUnitRole, user));
                }
            });
        }
        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);
            }
        }
        protected override void PrepareData(AUObjectOperationContext context)
        {
            base.PrepareData(context);
            this.pendingActions.Clear();

            if (this.Data.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal)
            {
                //添加
                this.adminUnits = Adapters.AUSnapshotAdapter.Instance.LoadAUBySchemaID(this.Container.ID, true, DateTime.MinValue);
                foreach (AdminUnit unit in this.adminUnits)
                {
                    var existedRole = Adapters.AUSnapshotAdapter.Instance.LoadAURole(this.Data.ID, unit.ID, false, DateTime.MinValue);
                    if (existedRole == null)
                    {
                        pendingActions.Add(new AddMemberAction(unit, new AURole()
                        {
                            ID = UuidHelper.NewUuidString(), SchemaRoleID = this.Data.ID
                        }));
                    }
                    else if (existedRole.Status != Schemas.SchemaProperties.SchemaObjectStatus.Normal)
                    {
                        pendingActions.Add(new EnableMemberAction(unit, existedRole));
                    }
                }
            }
            else
            {
                //只是删掉角色
                var existedRoles = Adapters.AUSnapshotAdapter.Instance.LoadAURoles(this.Data.ID, true, DateTime.MinValue);

                foreach (var item in existedRoles)
                {
                    RelationHelper.Instance.ClearContainer(item);
                    pendingActions.Add(new DeleteSelfAction(item));
                }
            }
        }
        protected override object DoOperation(AUObjectOperationContext context)
        {
            SCAclAdapter.Instance.Update(this.Container);

            return(this.Container);
        }
        protected override void PrepareData(AUObjectOperationContext context)
        {
            SCActionContext.Current.OriginalObject = SchemaObjectAdapter.Instance.Load(this.Data.ID);
            SCActionContext.Current.CurrentObject  = this.Data;

            string originalName = SCActionContext.Current.OriginalObject != null?SCActionContext.Current.OriginalObject.Properties.GetValue("Name", string.Empty) : string.Empty;

            string currentName = SCActionContext.Current.OriginalObject != null?SCActionContext.Current.CurrentObject.Properties.GetValue("Name", string.Empty) : string.Empty;

            this._ObjectNameChanged = originalName != currentName;

            //是否是关系容器
            ISCRelationContainer rContainer = this.Data as ISCRelationContainer;

            if (this._ObjectNameChanged)
            {
                this._NeedGenerateFullPaths = (rContainer != null && rContainer.CurrentChildren.Count > 0);

                this.Data.CurrentParentRelations.ForEach(relation =>
                {
                    if (relation.FullPath.IsNotEmpty())
                    {
                        int index = relation.FullPath.LastIndexOf(originalName);

                        if (index >= 0)
                        {
                            relation.FullPath = relation.FullPath.Substring(0, index) + currentName;
                        }
                    }
                });

                context["parentRelations"] = this.Data.CurrentParentRelations;
            }

            this.Validate();

            if (this._NeedDeleteRelations)
            {
                //加载关系对象,然后为了统一删除和打标志。
                if (rContainer != null)
                {
                    context["childrenRelations"] = rContainer.CurrentChildrenRelations;
                }
                context["parentRelations"] = this.Data.CurrentParentRelations;
            }

            if (this._NeedDeleteMemberRelations)
            {
                if (this.Data is ISCMemberObject)
                {
                    context["containersRelations"] = ((ISCMemberObject)this.Data).GetCurrentMemberOfRelations();
                }

                if (this.Data is ISCContainerObject)
                {
                    context["membersRelations"] = ((ISCContainerObject)this.Data).GetCurrentMembersRelations();
                }
            }

            if (this.Data.Status != SchemaObjectStatus.Normal)
            {
                if (this.Data is ISCAclContainer)
                {
                    context["aclMembers"] = ((ISCAclContainer)this.Data).GetAclMembers();
                }

                if (this.Data is ISCAclMember)
                {
                    context["aclContainers"] = ((ISCAclMember)this.Data).GetAclContainers();
                }
            }

            base.PrepareData(context);
        }
 protected override void PrepareOperationLog(AUObjectOperationContext context)
 {
     context.Logs.Add(AUCommon.ToOperationLog(this.Data, this.OperationType));
 }
 protected abstract object DoOperation(AUObjectOperationContext context);
Beispiel #28
0
 protected override void PrepareOperationLog(AUObjectOperationContext context)
 {
     base.PrepareOperationLog(context);
 }
Beispiel #29
0
        protected override void DoRelativeDataOperation(AUObjectOperationContext context)
        {
            base.DoRelativeDataOperation(context);

            this.pendingActions.DoActions();
        }
 protected virtual void PrepareOperationLog(AUObjectOperationContext context)
 {
 }