internal void AddUsersToGroups(List <SchemaObjectBase> pendingUsers, SCObjectSet objectSet, IImportContext context) { int count = 0; int allCount = pendingUsers.Count; context.AppendLog("正在查找群组"); foreach (SCUser user in pendingUsers) { count++; context.SetStatus(count, allCount, "正在查找用户" + user.DisplayName + "的群组"); foreach (var s in ImportService.Instance.FilterMembership(objectSet.Membership, m => m.ID == user.ID && m.ContainerSchemaType == "Groups")) { try { ImportService.Instance.WithEffectObject <SCGroup>(s.ContainerID, grp => { ImportService.Instance.CheckRelation(grp.ID, user.ID, () => { context.AppendLogFormat("正在将用户{0}添加到群组{1}\r\n", user.ToDescription(), grp.ToDescription()); Actor.AddUserToGroup(user, grp); }, () => { context.AppendLogFormat("群组{0}已经存在用户{1},已跳过。\r\n", grp.ToDescription(), user.ToDescription()); }); }, null); } catch (Exception ex) { context.AppendLog("添加到群组时出现错误:" + ex.Message); } } } }
private void ImportMembers(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, SchemaObjectCollection memberObjects, SchemaObjectBase grp) { if (this.IncludeMembers && objectSet.HasMembership) { var memberRelations = objectSet.Membership.FindAll(m => m.ContainerID == grp.ID && m.Status == SchemaObjectStatus.Normal); if (memberRelations.Count > 0 && memberObjects != null) { context.AppendLogFormat("正在试图添加{0}个群组成员\r\n", memberRelations.Count); foreach (var r in memberRelations) { var user = (SCUser)(from m in memberObjects where m.ID == r.ID select m).FirstOrDefault(); if (user != null) { try { exec.AddUserToGroup(user, (SCGroup)grp); context.AppendLogFormat("已经向群组{0}添加群组成员:{1}\r\n", ((SCGroup)grp).DisplayName, user.DisplayName); } catch (Exception ex) { context.AppendLogFormat("无法导入群组 {0} 的成员 {1}: {2}\r\n", ((SCGroup)grp).DisplayName, user.DisplayName, ex.Message); } } else { context.AppendLogFormat("已跳过不存在的成员\r\n"); } } } } }
internal void ImportUsers(List <SchemaObjectBase> pendingUsers, SCObjectSet objectSet, IImportContext context, bool includeOrganizations) { int count = 0; int allCount = pendingUsers.Count; foreach (SCUser item in pendingUsers) { count++; try { var summaryName = item.ToDescription(); context.SetStatus(count, allCount, "正在导入项目:" + summaryName); if (includeOrganizations && objectSet.HasRelations) { var user = (SCUser)item; bool anyOrg = false; foreach (var relation in ImportService.Instance.FilterRelations(objectSet.Relations, r => { return(r.ChildSchemaType == user.SchemaType && r.ParentSchemaType == "Organizations" && r.ID == user.ID); })) { try { ImportService.Instance.WithEffectObject <SCOrganization>(relation.ParentID, (org) => { anyOrg = true; context.AppendLogFormat("正在添加{0}并设置为组织{1}的成员\r\n", summaryName, org.ToDescription()); Actor.AddUser(user, org); }, () => { // 未找到组织 }); } catch (Exception ex) { context.AppendLogFormat("发生了错误" + ex.ToString() + "\r\n"); } } if (anyOrg == false) { context.AppendLogFormat("未找到人员{0}的任何组织,将仅添加用户。\r\n", summaryName); this.Actor.AddUser(user, null); } } else { this.Actor.AddUser((SCUser)item, null); } context.AppendLog("已执行导入项目" + summaryName); } catch (Exception ex) { context.AppendLog("对项的操作失败,原因是:" + ex.Message); } } }
internal void ImportBosses(List <SchemaObjectBase> pendingUsers, SCObjectSet objectSet, IImportContext context) { int count = 0; int allCount = pendingUsers.Count; context.AppendLog("正在查找上司"); foreach (SCUser user in pendingUsers) { count++; context.SetStatus(count, allCount, "正在查找用户" + user.DisplayName + "的上司"); foreach (var s in ImportService.Instance.FilterMembership(objectSet.Membership, m => m.ID == user.ID && m.ContainerSchemaType == user.SchemaType)) { try { ImportService.Instance.WithEffectObject <SCUser>(s.ContainerID, secretary => { context.AppendLogFormat("正在替用户{0}添加上司{1}\r\n", user.DisplayName, secretary.DisplayName); Actor.AddSecretaryToUser(user, secretary); }, null); } catch (Exception ex) { context.AppendLog("添加上司时出现错误:" + ex.Message); } } } }
private void ImportRoleConditions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary <object, object> mappings, PC.SCRole[] roles) { if (roles.Length > 0 && objectSet.HasConditions) { foreach (var r in roles) { PC.SCRole role2 = r; if (mappings.ContainsKey(r)) { role2 = (PC.SCRole)mappings[r]; } var roleConditions = (from c in objectSet.Conditions where c.OwnerID == r.ID select c).ToArray(); if (roleConditions.Length > 0) { context.AppendLogFormat("正在替角色{0}添加条件\r\n", role2.ToDescription()); PC.Conditions.SCConditionOwner owner = new PC.Conditions.SCConditionOwner() { OwnerID = role2.ID, Type = "Default" }; foreach (var c in roleConditions) { owner.Conditions.Add(c); } PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner); } } } }
private void ImportAcl(IImportContext context, PC.Executors.ISCObjectOperations executor, PC.SCApplication targetApp, PC.Permissions.SCAclItem[] acls) { if (acls.Length > 0) { var container = new PC.Permissions.SCAclContainer(targetApp); context.AppendLogFormat("正在替 {0} 合并ACL定义\r\n", targetApp.ToDescription()); var oldPermissions = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(targetApp.ID, DateTime.MinValue); PC.Permissions.SCAclMemberCollection members = new PC.Permissions.SCAclMemberCollection(); foreach (var item in acls) { ImportService.Instance.WithEffectObject <PC.SchemaObjectBase>(item.MemberID, role => { members.Add(item.ContainerPermission, role); }, null); } if (oldPermissions != null && oldPermissions.Count > 0) { members.MergeChangedItems(oldPermissions); } container.Members.CopyFrom(members); PC.Adapters.SCAclAdapter.Instance.Update(container); } }
private void ImportRolePermissions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary <object, object> mappings, PC.SCPermission[] permissions, PC.SCRole[] roles, bool copyMode) { if (roles.Length > 0 && permissions.Length > 0 && objectSet.HasRelations) { foreach (var r in roles) { PC.SCRole role2 = r; if (mappings.ContainsKey(r)) { role2 = (PC.SCRole)mappings[r]; } context.AppendLogFormat("正在替 {0} 查找功能定义\r\n", role2.ToDescription()); foreach (var p in permissions) { PC.SCPermission permission2 = p; if (mappings.ContainsKey(p)) { permission2 = (PC.SCPermission)mappings[p]; } var actual = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(role2.ID, permission2.ID); var actualHasPermission = actual != null && actual.Status == SchemaObjectStatus.Normal; var refHasPermission = (from rr in objectSet.Relations where rr.Status == SchemaObjectStatus.Normal && rr.ParentID == r.ID && rr.ID == p.ID && rr.ChildSchemaType == "Permissions" && rr.ParentSchemaType == "Roles" select rr).FirstOrDefault() != null; if (refHasPermission == false && actualHasPermission) { context.AppendLogFormat("正在替角色 {0} 解除功能 {1}\r\n", role2.ToDescription(), permission2.ToDescription()); executor.DisjoinRoleAndPermission(role2, permission2); } else if (refHasPermission && actualHasPermission == false) { context.AppendLogFormat("正在替角色 {0} 指定功能 {1}\r\n", role2.ToDescription(), permission2.ToDescription()); executor.JoinRoleAndPermission(role2, permission2); } } } } }
private static void ImportRoleMembers(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, PC.SCRole roleRef, PC.SCRole roleActual) { foreach (var m in objectSet.Membership) { if (m.ContainerID == roleRef.ID) { var objSc = PC.Adapters.SchemaObjectAdapter.Instance.Load(m.ID) as PC.SCBase; if (objSc != null) { context.AppendLogFormat("正在替角色 {0} 导入角色成员 {1}\r\n", roleActual.DisplayName, objSc.DisplayName); exec.AddMemberToRole(objSc, roleActual); } } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (string.IsNullOrEmpty(this.ApplicationId)) { throw new HttpException("没有指定ApplicationId的情况下无法导入。"); } var app = (PC.SCApplication)PC.Adapters.SchemaObjectAdapter.Instance.Load(this.ApplicationId); if (app == null) { throw new HttpException("指定的应用并不存在"); } if (objectSet.HasObjects) { int count = 0; int allCount = 0; var exec = PC.Executors.SCObjectOperations.InstanceWithPermissions; IEnumerable <PC.SCSimpleRelationBase> permissionRelations = null; if (this.CopyMode) { permissionRelations = from r in objectSet.Membership where r.MemberSchemaType == "Permissions" orderby r.InnerSort ascending select r; } else { permissionRelations = from r in objectSet.Membership where r.MemberSchemaType == "Permissions" && r.ContainerID == app.ID orderby r.InnerSort ascending select r; } var permissions = (from o in objectSet.Objects join p in permissionRelations on o.ID equals p.ID select(PC.SCPermission) o).ToArray(); allCount = permissions.Length; foreach (var p in permissions) { count++; PC.SCPermission fun = this.CopyMode ? AppImportAction.MakeCopy(p) : p; // 只导入明确的 context.SetStatus(count, allCount, "正在导入权限:" + fun.DisplayName); context.AppendLogFormat("正在导入权限 {0} \r\n", fun.DisplayName ?? fun.Name); exec.AddPermission(fun, app); } } }
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); } } }
private void ImportRoleDefinitions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, int count, int allCount, PC.SCRole role, PC.SCRole role2) { context.SetStatus(count, allCount, "正在查找并添加角色功能定义"); context.AppendLogFormat("正在替 {0} 查找角色功能定义\r\n", role2.ToDescription()); var permissionIds = (from p in objectSet.Relations where p.ParentID == role.ID && p.ChildSchemaType == "Permissions" select p.ID).ToArray(); var permissions = permissionIds.Length > 0 ? DbUtil.LoadObjects(permissionIds) : null; if (permissions != null) { foreach (PC.SCPermission p in permissions) { var relation = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(role.ID, p.ID); if (relation == null || relation.Status != SchemaObjectStatus.Normal) { string text = string.Format("正在替角色 {0} 指定功能 {1}\r\n", role.DisplayName ?? role.Name, p.DisplayName ?? p.Name); context.SetStatus(count, allCount, text); context.AppendLog(text); exec.JoinRoleAndPermission(role, (PC.SCPermission)p); } } } }
private void ImportRoleConditions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, PC.SCRole roleRef, PC.SCRole roleActual) { var conditons = (from c in objectSet.Conditions where c.OwnerID == roleRef.ID select c).ToArray(); var owner = new PC.Conditions.SCConditionOwner() { OwnerID = roleActual.ID, Type = "Default" }; foreach (var c in conditons) { owner.Conditions.Add(new PC.Conditions.SCCondition() { Description = c.Description, Condition = c.Condition, OwnerID = roleActual.ID, Type = "Default" }); } context.AppendLogFormat("正在替角色 {0} 导入角色条件\r\n", roleActual.DisplayName); PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner); }
private void ImportAcl(IImportContext context, PC.Executors.ISCObjectOperations executor, PC.SCApplication targetApp, PC.Permissions.SCAclItem[] acls) { if (acls.Length > 0) { var container = new PC.Permissions.SCAclContainer(targetApp); context.AppendLogFormat("正在替 {0} 合并ACL定义\r\n", targetApp.ToDescription()); var oldPermissions = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(targetApp.ID, DateTime.MinValue); PC.Permissions.SCAclMemberCollection members = new PC.Permissions.SCAclMemberCollection(); foreach (var item in acls) { ImportService.Instance.WithEffectObject<PC.SchemaObjectBase>(item.MemberID, role => { members.Add(item.ContainerPermission, role); }, null); } if (oldPermissions != null && oldPermissions.Count > 0) { members.MergeChangedItems(oldPermissions); } container.Members.CopyFrom(members); PC.Adapters.SCAclAdapter.Instance.Update(container); } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasRelations) { int allCount = objectSet.Objects.Count; int count = 0; var pendingGroups = new System.Collections.Generic.Queue <PC.SCGroup>(allCount); var pendingRelations = new System.Collections.Generic.Queue <PC.SCRelationObject>(allCount); foreach (var r in objectSet.Relations) { if (r.ParentID == this.Parent.ID) { pendingRelations.Enqueue(r); } } context.SetStatus(0, pendingRelations.Count, "正在寻找当前组织内的关系。"); if (objectSet.HasObjects) { foreach (var obj in objectSet.Objects) { if (obj.SchemaType == "Groups") { pendingGroups.Enqueue((PC.SCGroup)obj); } } } while (pendingGroups.Count > 0) { var grp = pendingGroups.Dequeue(); try { var summaryName = grp.DisplayName; context.SetStatus(count, allCount, "正在导入群组:" + summaryName); if ((from r in pendingRelations where r.ParentID == this.Parent.ID && r.ID == grp.ID select r).Any()) { PC.Executors.SCObjectOperations.InstanceWithPermissions.AddGroup(grp, this.Parent); context.AppendLog("已执行导入群组" + summaryName); if (this.IncludeMembers && objectSet.HasMembership) { context.AppendLog("正在查找群组成员"); var members = from m in objectSet.Membership where m.ContainerID == grp.ID && m.Status == SchemaObjectStatus.Normal select m; foreach (var m in members) { try { var obj = (PC.SCUser)PC.Adapters.SchemaObjectAdapter.Instance.Load(m.ID); if (obj != null) { context.AppendLogFormat("正在添加群组成员{0}\r\n", obj.DisplayName); PC.Executors.SCObjectOperations.InstanceWithPermissions.AddUserToGroup(obj, grp); } } catch (Exception ex) { context.AppendLog("添加群组成员时遇到错误:" + ex.Message); } } } if (this.IncludeConditions && objectSet.HasConditions) { context.AppendLog("正在查找群组条件表达式"); var conditions = new PC.Conditions.SCConditionCollection(); conditions.CopyFrom(ImportService.Instance.FilterConditions(objectSet.Conditions, c => c.OwnerID == grp.ID && c.Type == "Default")); var owner = PC.Adapters.SCConditionAdapter.Instance.Load(grp.ID, "Default") ?? new PC.Conditions.SCConditionOwner() { OwnerID = grp.ID, Type = "Default" }; owner.Conditions.ReplaceItemsWith(conditions, grp.ID, "Default"); try { context.AppendLog("正在添加群组条件表达式"); PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner); context.AppendLog("群组条件表达式添加完毕"); } catch (Exception ex) { context.AppendLog("未能添加群组条件表达式,原因是:" + ex.Message); } } } } catch (Exception ex) { context.AppendLog("对群组的操作失败,原因是:" + ex.Message); } } } }
private void ImportMembers(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, SchemaObjectCollection memberObjects, SchemaObjectBase grp) { if (this.IncludeMembers && objectSet.HasMembership) { var memberRelations = objectSet.Membership.FindAll(m => m.ContainerID == grp.ID && m.Status == SchemaObjectStatus.Normal); if (memberRelations.Count > 0 && memberObjects != null) { context.AppendLogFormat("正在试图添加{0}个群组成员\r\n", memberRelations.Count); foreach (var r in memberRelations) { var user = (SCUser)(from m in memberObjects where m.ID == r.ID select m).FirstOrDefault(); if (user != null) { try { exec.AddUserToGroup(user, (SCGroup)grp); context.AppendLogFormat("已经向群组{0}添加群组成员:{1}\r\n", ((SCGroup)grp).DisplayName, user.DisplayName); } catch (Exception ex) { context.AppendLogFormat("无法导入群组 {0} 的成员 {1}: {2}\r\n", ((SCGroup)grp).DisplayName, user.DisplayName, ex.Message); } } else { context.AppendLogFormat("已跳过不存在的成员\r\n"); } } } } }
private void ImportRoleDefinitions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, int count, int allCount, PC.SCRole role, PC.SCRole role2) { context.SetStatus(count, allCount, "正在查找并添加角色功能定义"); context.AppendLogFormat("正在替 {0} 查找角色功能定义\r\n", role2.ToDescription()); var permissionIds = (from p in objectSet.Relations where p.ParentID == role.ID && p.ChildSchemaType == "Permissions" select p.ID).ToArray(); var permissions = permissionIds.Length > 0 ? DbUtil.LoadObjects(permissionIds) : null; if (permissions != null) { foreach (PC.SCPermission p in permissions) { var relation = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(role.ID, p.ID); if (relation == null || relation.Status != SchemaObjectStatus.Normal) { string text = string.Format("正在替角色 {0} 指定功能 {1}\r\n", role.DisplayName ?? role.Name, p.DisplayName ?? p.Name); context.SetStatus(count, allCount, text); context.AppendLog(text); exec.JoinRoleAndPermission(role, (PC.SCPermission)p); } } } }
private void ImportRoleConditions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, PC.SCRole roleRef, PC.SCRole roleActual) { var conditons = (from c in objectSet.Conditions where c.OwnerID == roleRef.ID select c).ToArray(); var owner = new PC.Conditions.SCConditionOwner() { OwnerID = roleActual.ID, Type = "Default" }; foreach (var c in conditons) { owner.Conditions.Add(new PC.Conditions.SCCondition() { Description = c.Description, Condition = c.Condition, OwnerID = roleActual.ID, Type = "Default" }); } context.AppendLogFormat("正在替角色 {0} 导入角色条件\r\n", roleActual.DisplayName); PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner); }
private static void ImportRoleMembers(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, PC.SCRole roleRef, PC.SCRole roleActual) { foreach (var m in objectSet.Membership) { if (m.ContainerID == roleRef.ID) { var objSc = PC.Adapters.SchemaObjectAdapter.Instance.Load(m.ID) as PC.SCBase; if (objSc != null) { context.AppendLogFormat("正在替角色 {0} 导入角色成员 {1}\r\n", roleActual.DisplayName, objSc.DisplayName); exec.AddMemberToRole(objSc, roleActual); } } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasAcls) { context.SetStatus(0, 1, "正在寻找当前组织内组织的ACL。"); var pendingOrgs = new List<SCOrganization>(objectSet.Objects.Count); foreach (SCOrganization item in ImportService.Instance.FilterNormalObjects<SCOrganization>(objectSet.Objects)) { // 进行过滤,保留当前组织中的组织 if (objectSet.Relations.Exists(r => r.ParentID == this.Parent.ID && r.Status == SchemaObjectStatus.Normal && r.ID == item.ID)) { pendingOrgs.Add(item); } } int allCount = pendingOrgs.Count; int count = 0; foreach (SCOrganization item in pendingOrgs) { var summaryName = item.ToDescription(); count++; var pendingAcls = ImportService.Instance.FilterAcls(objectSet.Acls, acl => acl.ContainerID == item.ID && acl.Status == SchemaObjectStatus.Normal); try { var newContainer = new PC.Permissions.SCAclContainer(item); PC.Permissions.SCAclMemberCollection members = new PC.Permissions.SCAclMemberCollection(); foreach (var acl in pendingAcls) { ImportService.Instance.WithEffectObject<SchemaObjectBase>(acl.MemberID, role => { members.Add(acl.ContainerPermission, role); }, null); } var oldMembers = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(item.ID, DateTime.MinValue); if (oldMembers != null) { members.MergeChangedItems(oldMembers); } newContainer.Members.CopyFrom(members); context.SetStatus(count, allCount, "正在替换对象ACL:" + summaryName); PC.Adapters.SCAclAdapter.Instance.Update(newContainer); } catch (Exception ex) { context.AppendLogFormat("对项 {0} 的ACL操作失败,原因是:{1}\r\n", summaryName, 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); } } }
private void ImportRoleConditions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary<object, object> mappings, PC.SCRole[] roles) { if (roles.Length > 0 && objectSet.HasConditions) { foreach (var r in roles) { PC.SCRole role2 = r; if (mappings.ContainsKey(r)) { role2 = (PC.SCRole)mappings[r]; } var roleConditions = (from c in objectSet.Conditions where c.OwnerID == r.ID select c).ToArray(); if (roleConditions.Length > 0) { context.AppendLogFormat("正在替角色{0}添加条件\r\n", role2.ToDescription()); PC.Conditions.SCConditionOwner owner = new PC.Conditions.SCConditionOwner() { OwnerID = role2.ID, Type = "Default" }; foreach (var c in roleConditions) { owner.Conditions.Add(c); } PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner); } } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasRelations) { int allCount = objectSet.Objects.Count; int count = 0; var pendingGroups = new System.Collections.Generic.Queue<PC.SCGroup>(allCount); var pendingRelations = new System.Collections.Generic.Queue<PC.SCRelationObject>(allCount); foreach (var r in objectSet.Relations) { if (r.ParentID == this.Parent.ID) { pendingRelations.Enqueue(r); } } context.SetStatus(0, pendingRelations.Count, "正在寻找当前组织内的关系。"); if (objectSet.HasObjects) { foreach (var obj in objectSet.Objects) { if (obj.SchemaType == "Groups") { pendingGroups.Enqueue((PC.SCGroup)obj); } } } while (pendingGroups.Count > 0) { var grp = pendingGroups.Dequeue(); try { var summaryName = grp.DisplayName; context.SetStatus(count, allCount, "正在导入群组:" + summaryName); if ((from r in pendingRelations where r.ParentID == this.Parent.ID && r.ID == grp.ID select r).Any()) { PC.Executors.SCObjectOperations.InstanceWithPermissions.AddGroup(grp, this.Parent); context.AppendLog("已执行导入群组" + summaryName); if (this.IncludeMembers && objectSet.HasMembership) { context.AppendLog("正在查找群组成员"); var members = from m in objectSet.Membership where m.ContainerID == grp.ID && m.Status == SchemaObjectStatus.Normal select m; foreach (var m in members) { try { var obj = (PC.SCUser)PC.Adapters.SchemaObjectAdapter.Instance.Load(m.ID); if (obj != null) { context.AppendLogFormat("正在添加群组成员{0}\r\n", obj.DisplayName); PC.Executors.SCObjectOperations.InstanceWithPermissions.AddUserToGroup(obj, grp); } } catch (Exception ex) { context.AppendLog("添加群组成员时遇到错误:" + ex.Message); } } } if (this.IncludeConditions && objectSet.HasConditions) { context.AppendLog("正在查找群组条件表达式"); var conditions = new PC.Conditions.SCConditionCollection(); conditions.CopyFrom(ImportService.Instance.FilterConditions(objectSet.Conditions, c => c.OwnerID == grp.ID && c.Type == "Default")); var owner = PC.Adapters.SCConditionAdapter.Instance.Load(grp.ID, "Default") ?? new PC.Conditions.SCConditionOwner() { OwnerID = grp.ID, Type = "Default" }; owner.Conditions.ReplaceItemsWith(conditions, grp.ID, "Default"); try { context.AppendLog("正在添加群组条件表达式"); PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner); context.AppendLog("群组条件表达式添加完毕"); } catch (Exception ex) { context.AppendLog("未能添加群组条件表达式,原因是:" + ex.Message); } } } } catch (Exception ex) { context.AppendLog("对群组的操作失败,原因是:" + ex.Message); } } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasAcls) { context.SetStatus(0, 1, "正在寻找当前组织内组织的ACL。"); var pendingOrgs = new List <SCOrganization>(objectSet.Objects.Count); foreach (SCOrganization item in ImportService.Instance.FilterNormalObjects <SCOrganization>(objectSet.Objects)) { // 进行过滤,保留当前组织中的组织 if (objectSet.Relations.Exists(r => r.ParentID == this.Parent.ID && r.Status == SchemaObjectStatus.Normal && r.ID == item.ID)) { pendingOrgs.Add(item); } } int allCount = pendingOrgs.Count; int count = 0; foreach (SCOrganization item in pendingOrgs) { var summaryName = item.ToDescription(); count++; var pendingAcls = ImportService.Instance.FilterAcls(objectSet.Acls, acl => acl.ContainerID == item.ID && acl.Status == SchemaObjectStatus.Normal); try { var newContainer = new PC.Permissions.SCAclContainer(item); PC.Permissions.SCAclMemberCollection members = new PC.Permissions.SCAclMemberCollection(); foreach (var acl in pendingAcls) { ImportService.Instance.WithEffectObject <SchemaObjectBase>(acl.MemberID, role => { members.Add(acl.ContainerPermission, role); }, null); } var oldMembers = PC.Adapters.SCAclAdapter.Instance.LoadByContainerID(item.ID, DateTime.MinValue); if (oldMembers != null) { members.MergeChangedItems(oldMembers); } newContainer.Members.CopyFrom(members); context.SetStatus(count, allCount, "正在替换对象ACL:" + summaryName); PC.Adapters.SCAclAdapter.Instance.Update(newContainer); } catch (Exception ex) { context.AppendLogFormat("对项 {0} 的ACL操作失败,原因是:{1}\r\n", summaryName, ex.Message); } } } }
private void ImportRolePermissions(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary<object, object> mappings, PC.SCPermission[] permissions, PC.SCRole[] roles, bool copyMode) { if (roles.Length > 0 && permissions.Length > 0 && objectSet.HasRelations) { foreach (var r in roles) { PC.SCRole role2 = r; if (mappings.ContainsKey(r)) { role2 = (PC.SCRole)mappings[r]; } context.AppendLogFormat("正在替 {0} 查找功能定义\r\n", role2.ToDescription()); foreach (var p in permissions) { PC.SCPermission permission2 = p; if (mappings.ContainsKey(p)) permission2 = (PC.SCPermission)mappings[p]; var actual = PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(role2.ID, permission2.ID); var actualHasPermission = actual != null && actual.Status == SchemaObjectStatus.Normal; var refHasPermission = (from rr in objectSet.Relations where rr.Status == SchemaObjectStatus.Normal && rr.ParentID == r.ID && rr.ID == p.ID && rr.ChildSchemaType == "Permissions" && rr.ParentSchemaType == "Roles" select rr).FirstOrDefault() != null; if (refHasPermission == false && actualHasPermission) { context.AppendLogFormat("正在替角色 {0} 解除功能 {1}\r\n", role2.ToDescription(), permission2.ToDescription()); executor.DisjoinRoleAndPermission(role2, permission2); } else if (refHasPermission && actualHasPermission == false) { context.AppendLogFormat("正在替角色 {0} 指定功能 {1}\r\n", role2.ToDescription(), permission2.ToDescription()); executor.JoinRoleAndPermission(role2, permission2); } } } } }