Beispiel #1
0
        private void PrepareToBeAddedScopes(string[] items, PendingActionCollection pendingActions)
        {
            foreach (string scope in items)
            {
                foreach (AdminUnit au in allCurrentAUs)
                {
                    var existed = Adapters.AUSnapshotAdapter.Instance.LoadAUScope(au.ID, scope, false, false, DateTime.MinValue);
                    if (existed.Count == 0)
                    {
                        pendingActions.Add(new AddMemberAction(au, new AUAdminScope()
                        {
                            ID = UuidHelper.NewUuidString(), ScopeSchemaType = scope
                        }));
                    }
                    else
                    {
                        // 尽量恢复已经删除的Scope,而不是重新创建一个
                        if (existed.GetUniqueNormalObject <AUAdminScope>() == null)
                        {
                            AUAdminScope onlyScope = (AUAdminScope)existed.First();
                            onlyScope.Status = SchemaObjectStatus.Normal;
                            pendingActions.Add(new EnableMemberAction(au, onlyScope));
                        }

                        // 否则,这个Scope已经是正常状态了?
                    }
                }
            }
        }
Beispiel #2
0
 private void PrepareToBeDeletedScopes(string[] items, PendingActionCollection pendingActions)
 {
     foreach (string scope in items)
     {
         foreach (AdminUnit au in allCurrentAUs)
         {
             var auScope = Adapters.AUSnapshotAdapter.Instance.LoadAUScope(au.ID, scope, true, DateTime.MinValue).GetUniqueNormalObject <AUAdminScope>();
             if (auScope != null)
             {
                 pendingActions.Add(new ClearConditionAction(auScope));
                 pendingActions.Add(new ClearContainerAction(auScope));
                 pendingActions.Add(new RemoveMemberAction(au, auScope));
             }
         }
     }
 }
        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));
                }
            });
        }
        private void PrepareRolesAndScopes()
        {
            if (Data.Status == SchemaObjectStatus.Normal)
            {
                // 新建或更新,确定要增加哪些辅助对象:AURole,AUScopes
                PrepareRolesForAdd();

                PrepareScopesForAdd();
            }
            else
            {
                // 删除
                foreach (AURole role in this.existingUnitRoles)
                {
                    RelationHelper.Instance.ClearContainer(role); // 消除角色中的人员关系,矩阵就没办法了
                    pendingActions.Add(new RemoveMemberAction((AdminUnit)this.Data, role));
                }

                foreach (AUAdminScope scope in this.existingUnitScopes)
                {
                    RelationHelper.Instance.ClearContainer(scope);
                    AUConditionAdapter.Instance.DeleteByOwner(scope.ID, AUCommon.ConditionType);
                    pendingActions.Add(new RemoveMemberAction((AdminUnit)this.Data, scope));
                }
            }
        }
        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));
                }
            }
        }