public void DoImport(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, IImportContext context) { var exec = Operations.Facade.InstanceWithPermissions; if (string.IsNullOrEmpty(this.AUSchemaID)) { throw new InvalidOperationException("操作前必须对SchemaID进行赋值"); } var item = (AUSchema)Adapters.AUSnapshotAdapter.Instance.LoadAUSchema(this.AUSchemaID, true, DateTime.MinValue).FirstOrDefault(); if (item == null) { throw new AUObjectValidationException("不存在指定的管理架构,或已删除。"); } var roles = (from p in objectSet.Membership where p.ContainerID == item.ID && p.MemberSchemaType == AUCommon.SchemaAUSchemaRole join q in objectSet.Objects on p.ID equals q.ID where q.SchemaType == AUCommon.SchemaAUSchemaRole select q); int total = roles.Count(); int roleCount = 0; foreach (AUSchemaRole role in roles) { roleCount++; try { context.SetStatusAndLog(roleCount, total, "正在添加角色:" + role.GetQualifiedName()); exec.AddAdminSchemaRole(role, item); } catch (Exception ex) { context.AppendLog("对角色的操作失败,原因是:" + ex.Message); } } }
public void DoImport(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, IImportContext context) { var exec = this.IgnorePermission ? Operations.Facade.DefaultInstance : Operations.Facade.InstanceWithPermissions; IEnumerable<SchemaObjectBase> schemas; if (string.IsNullOrEmpty(TargetCategory)) schemas = objectSet.Objects.Where(m => m.SchemaType == AUCommon.SchemaAUSchema && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal); else schemas = objectSet.Objects.Where(m => m.SchemaType == AUCommon.SchemaAUSchema && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal && ((AUSchema)m).CategoryID == TargetCategory); int allCount = schemas.Count(); int count = 0; foreach (AUSchema item in schemas) { count++; try { context.SetStatusAndLog(count, allCount, "正在导入对象:" + item.GetQualifiedName()); exec.AddAdminSchema(item); ImportSchemaRoles(objectSet, context, exec, item); } catch (Exception ex) { context.ErrorCount++; context.AppendLog("对项的操作失败,原因是:" + ex.Message); } } }
private void DoImportConditions(SCObjectSet objectSet, IImportContext context, PC.SCGroup group) { if (this.ImportConditions && objectSet.HasConditions) { context.SetStatusAndLog(Owner.currentSteps, Owner.allSteps, string.Format("正在替换群组 {0} 的条件", group.Name)); try { var owner = PC.Adapters.SCConditionAdapter.Instance.Load(group.ID, "Default") ?? new PC.Conditions.SCConditionOwner() { OwnerID = group.ID, Type = "Default" }; PC.Conditions.SCConditionCollection src = new PC.Conditions.SCConditionCollection(); src.CopyFrom(ImportService.Instance.FilterConditions(objectSet.Conditions, c => c.OwnerID == group.ID)); owner.Conditions.ReplaceItemsWith(src, group.ID, "Default"); PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner); } catch (Exception ex) { context.AppendLog(string.Format("替换群组 {0} 条件成员时出错:{1}", group.ToDescription(), ex.ToString())); } } }
public void DoImport(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, IImportContext context) { var exec = Operations.Facade.InstanceWithPermissions; if (string.IsNullOrEmpty(this.AUSchemaID)) throw new InvalidOperationException("操作前必须对SchemaID进行赋值"); var item = (AUSchema)Adapters.AUSnapshotAdapter.Instance.LoadAUSchema(this.AUSchemaID, true, DateTime.MinValue).FirstOrDefault(); if (item == null) throw new AUObjectValidationException("不存在指定的管理架构,或已删除。"); var roles = (from p in objectSet.Membership where p.ContainerID == item.ID && p.MemberSchemaType == AUCommon.SchemaAUSchemaRole join q in objectSet.Objects on p.ID equals q.ID where q.SchemaType == AUCommon.SchemaAUSchemaRole select q); int total = roles.Count(); int roleCount = 0; foreach (AUSchemaRole role in roles) { roleCount++; try { context.SetStatusAndLog(roleCount, total, "正在添加角色:" + role.GetQualifiedName()); exec.AddAdminSchemaRole(role, item); } catch (Exception ex) { context.AppendLog("对角色的操作失败,原因是:" + ex.Message); } } }
public void SetStatusAndLog(int currentStep, int maxStep, string message) { if (level > 0) { context.SetSubStatusAndLog(currentStep, maxStep, message); } else { context.SetStatusAndLog(currentStep, maxStep, message); } }
public override void ExecuteEachOrganization(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, PC.SCOrganization org, Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations, Dictionary <string, IList <PC.SCUser> > orgToUserRelations, Dictionary <string, IList <PC.SCGroup> > orgToGroupRelations) { if (objectSet.HasAcls) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在寻找 {0} 的ACL。", org.ToDescription())); var allAcls = ImportService.Instance.FilterAcls(objectSet.Acls, acl => acl.ContainerID == org.ID && acl.Status == SchemaObjectStatus.Normal).ToList(); var summaryName = org.ToDescription(); try { var newContainer = new PC.Permissions.SCAclContainer(org); foreach (var acl in allAcls) { ImportService.Instance.WithEffectObject <PC.SchemaObjectBase>(acl.MemberID, knownObjects, role => { newContainer.Members.Add(acl.ContainerPermission, role); }, null); } var oldMembers = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(org.ID, DateTime.MinValue); if (oldMembers != null) { newContainer.Members.MergeChangedItems(oldMembers); } context.SetStatusAndLog(Owner.currentSteps, Owner.allSteps, string.Format("正在替换 {0} 的ACL:", summaryName)); PC.Adapters.SCAclAdapter.Instance.Update(newContainer); } catch (Exception ex) { context.AppendLogFormat("对象 {0} 的ACL操作失败,原因是:{1}\r\n", summaryName, ex.Message); } } }
public void DoImport(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, IImportContext context) { var exec = this.IgnorePermission ? Operations.Facade.DefaultInstance : Operations.Facade.InstanceWithPermissions; IEnumerable <SchemaObjectBase> schemas; if (string.IsNullOrEmpty(TargetCategory)) { schemas = objectSet.Objects.Where(m => m.SchemaType == AUCommon.SchemaAUSchema && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal); } else { schemas = objectSet.Objects.Where(m => m.SchemaType == AUCommon.SchemaAUSchema && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal && ((AUSchema)m).CategoryID == TargetCategory); } int allCount = schemas.Count(); int count = 0; foreach (AUSchema item in schemas) { count++; try { context.SetStatusAndLog(count, allCount, "正在导入对象:" + item.GetQualifiedName()); exec.AddAdminSchema(item); ImportSchemaRoles(objectSet, context, exec, item); } catch (Exception ex) { context.ErrorCount++; context.AppendLog("对项的操作失败,原因是:" + ex.Message); } } }
public override void ExecuteEachOrganization(SCObjectSet objectSet, IImportContext context, IDictionary<string, PC.SchemaObjectBase> knownObjects, PC.SCOrganization org, Dictionary<string, IList<PC.SCOrganization>> orgToOrgRelations, Dictionary<string, IList<PC.SCUser>> orgToUserRelations, Dictionary<string, IList<PC.SCGroup>> orgToGroupRelations) { if (objectSet.HasAcls) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在寻找 {0} 的ACL。", org.ToDescription())); var allAcls = ImportService.Instance.FilterAcls(objectSet.Acls, acl => acl.ContainerID == org.ID && acl.Status == SchemaObjectStatus.Normal).ToList(); var summaryName = org.ToDescription(); try { var newContainer = new PC.Permissions.SCAclContainer(org); foreach (var acl in allAcls) { ImportService.Instance.WithEffectObject<PC.SchemaObjectBase>(acl.MemberID, knownObjects, role => { newContainer.Members.Add(acl.ContainerPermission, role); }, null); } var oldMembers = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(org.ID, DateTime.MinValue); if (oldMembers != null) { newContainer.Members.MergeChangedItems(oldMembers); } context.SetStatusAndLog(Owner.currentSteps, Owner.allSteps, string.Format("正在替换 {0} 的ACL:", summaryName)); PC.Adapters.SCAclAdapter.Instance.Update(newContainer); } catch (Exception ex) { context.AppendLogFormat("对象 {0} 的ACL操作失败,原因是:{1}\r\n", summaryName, ex.Message); } } }