public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasRelations && objectSet.HasObjects) { context.SetStatus(0, 1, "正在分析数据。"); // 查找组织关系 var pendingOperations = new List<Action<object>>(); var objects = objectSet.Objects; Dictionary<string, IList<PC.SCOrganization>> orgToOrgRelations = new Dictionary<string, IList<PC.SCOrganization>>(); Dictionary<string, IList<PC.SCUser>> orgToUserRelations = new Dictionary<string, IList<PC.SCUser>>(); Dictionary<string, IList<PC.SCGroup>> orgToGroupRelations = new Dictionary<string, IList<PC.SCGroup>>(); Dictionary<string, PC.SchemaObjectBase> knownObjects = new Dictionary<string, PC.SchemaObjectBase>(); // 缓存已知对象,避免多次往返 context.SetStatus(0, 1, "正在统计需要导入的对象"); Stat stat = new Stat(); // 统计信息 FindFullOURelations(objectSet, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, new PC.SCOrganization[] { this.Parent }, stat); // 爬出所有组织关系 Dictionary<PC.SCOrganization, IList<PC.SCRelationObject>> userToOrgRelations = new Dictionary<PC.SCOrganization, IList<PC.SCRelationObject>>(); this.allSteps = this.CalculateSteps(stat); this.currentSteps = 0; bool orgValid = false; // 必须校验组织 context.SetStatus(0, this.allSteps, "正在导入数据。"); // 递归导入组织,并剔除错误的数据 orgValid = this.PrepareOrganizations(objectSet, context, knownObjects, orgToOrgRelations, this.Parent, this.IncludeOrganizations == false); if (this.IncludeAcl) { // 递归导入Acl var action = new AclAction(this); action.ExecutePreOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); this.DoHierarchicalAction(objectSet, context, knownObjects, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, this.Parent, action); action.ExecutePostOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); } if (this.IncludeUser) { var action = new UserAction(this); action.ImportSecretaries = this.IncludeSecretaries; action.ExecutePreOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); this.DoHierarchicalAction(objectSet, context, knownObjects, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, this.Parent, action); action.ExecutePostOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); } if (this.IncludeGroup) { var action = new GroupAction(this); action.ImportMembers = this.IncludeGroupMembers; action.ImportConditions = this.IncludeGroupConditions; action.ExecutePreOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); this.DoHierarchicalAction(objectSet, context, knownObjects, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, this.Parent, action); action.ExecutePostOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasRelations && objectSet.HasObjects) { context.SetStatus(0, 1, "正在分析数据。"); // 查找组织关系 var pendingOperations = new List <Action <object> >(); var objects = objectSet.Objects; Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations = new Dictionary <string, IList <PC.SCOrganization> >(); Dictionary <string, IList <PC.SCUser> > orgToUserRelations = new Dictionary <string, IList <PC.SCUser> >(); Dictionary <string, IList <PC.SCGroup> > orgToGroupRelations = new Dictionary <string, IList <PC.SCGroup> >(); Dictionary <string, PC.SchemaObjectBase> knownObjects = new Dictionary <string, PC.SchemaObjectBase>(); // 缓存已知对象,避免多次往返 context.SetStatus(0, 1, "正在统计需要导入的对象"); Stat stat = new Stat(); // 统计信息 FindFullOURelations(objectSet, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, new PC.SCOrganization[] { this.Parent }, stat); // 爬出所有组织关系 Dictionary <PC.SCOrganization, IList <PC.SCRelationObject> > userToOrgRelations = new Dictionary <PC.SCOrganization, IList <PC.SCRelationObject> >(); this.allSteps = this.CalculateSteps(stat); this.currentSteps = 0; bool orgValid = false; // 必须校验组织 context.SetStatus(0, this.allSteps, "正在导入数据。"); // 递归导入组织,并剔除错误的数据 orgValid = this.PrepareOrganizations(objectSet, context, knownObjects, orgToOrgRelations, this.Parent, this.IncludeOrganizations == false); if (this.IncludeAcl) { // 递归导入Acl var action = new AclAction(this); action.ExecutePreOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); this.DoHierarchicalAction(objectSet, context, knownObjects, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, this.Parent, action); action.ExecutePostOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); } if (this.IncludeUser) { var action = new UserAction(this); action.ImportSecretaries = this.IncludeSecretaries; action.ExecutePreOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); this.DoHierarchicalAction(objectSet, context, knownObjects, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, this.Parent, action); action.ExecutePostOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); } if (this.IncludeGroup) { var action = new GroupAction(this); action.ImportMembers = this.IncludeGroupMembers; action.ImportConditions = this.IncludeGroupConditions; action.ExecutePreOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); this.DoHierarchicalAction(objectSet, context, knownObjects, orgToOrgRelations, orgToUserRelations, orgToGroupRelations, this.Parent, action); action.ExecutePostOperation(objectSet, context, knownObjects, this.Parent, orgToOrgRelations, orgToUserRelations, orgToGroupRelations); } } }
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) { var exec = PC.Executors.SCObjectOperations.InstanceWithPermissions; PC.SCRole[] pendingRoles; if (this.CopyMode) { pendingRoles = (from r in objectSet.Objects where r is PC.SCRole select (PC.SCRole)r).ToArray(); } else { pendingRoles = (from r in objectSet.Objects join m in objectSet.Membership on r.ID equals m.ID where r.SchemaType == "Roles" && m.ContainerID == app.ID select (PC.SCRole)r).ToArray(); } int count = 0; int allCount = pendingRoles.Length; foreach (var role in pendingRoles) { var role2 = this.CopyMode ? AppImportAction.MakeCopy(role) : role; context.SetStatus(count, allCount, "正在导入角色:" + role2.DisplayName); context.AppendLog("正在导入角色" + role2.ToDescription()); exec.AddRole(role2, app); // 导入角色 if (this.IncludeConstMembers && objectSet.HasMembership) { context.SetStatus(count, allCount, "正在查找并添加角色成员"); context.AppendLog("正在查找角色成员"); ImportRoleMembers(objectSet, context, exec, role, role2); } if (this.IncludeConditions && objectSet.HasConditions) { context.SetStatus(count, allCount, "正在查找并添加角色条件"); context.AppendLog("正在查找角色条件"); this.ImportRoleConditions(objectSet, context, exec, role, role2); } if (this.IncludeRoleDefinitions && this.CopyMode == false && objectSet.HasRelations) { this.ImportRoleDefinitions(objectSet, context, exec, count, allCount, role, role2); } count++; } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasMembership) { try { var actor = PC.Executors.SCObjectOperations.InstanceWithPermissions; ImportService.Instance.WithEffectObject<PC.SCGroup>(this.groupId, group => { var pendingMembership = ImportService.Instance.FilterMembership(objectSet.Membership, m => m.ContainerID == this.groupId).ToList(); int allCount = pendingMembership.Count; context.SetStatus(0, allCount, "正在寻找当前群组的固定成员。"); int count = 0; foreach (var r in pendingMembership) { count++; try { ImportService.Instance.WithEffectObject<PC.SCUser>(r.ID, o => { string msg = "正在导入成员: " + o.ToDescription(); context.SetStatus(count, allCount, msg); context.AppendLog(msg); actor.AddUserToGroup(o, group); }, () => { string msg = string.Format("跳过了不存在的对象 {0} \r\n", r.ID); context.AppendLog(msg); context.SetStatus(count, allCount, msg); }); } catch (Exception ex) { context.AppendLog("导入成员时出错:" + ex.Message); } } }, () => { context.AppendLog("指定的群组无效,导入终止。"); }); } catch (Exception ex) { context.AppendLog("导入遇到错误,已经终止:" + ex.Message.ToString() + Environment.NewLine); } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasMembership) { try { var actor = PC.Executors.SCObjectOperations.InstanceWithPermissions; ImportService.Instance.WithEffectObject <PC.SCGroup>(this.groupId, group => { var pendingMembership = ImportService.Instance.FilterMembership(objectSet.Membership, m => m.ContainerID == this.groupId).ToList(); int allCount = pendingMembership.Count; context.SetStatus(0, allCount, "正在寻找当前群组的固定成员。"); int count = 0; foreach (var r in pendingMembership) { count++; try { ImportService.Instance.WithEffectObject <PC.SCUser>(r.ID, o => { string msg = "正在导入成员: " + o.ToDescription(); context.SetStatus(count, allCount, msg); context.AppendLog(msg); actor.AddUserToGroup(o, group); }, () => { string msg = string.Format("跳过了不存在的对象 {0} \r\n", r.ID); context.AppendLog(msg); context.SetStatus(count, allCount, msg); }); } catch (Exception ex) { context.AppendLog("导入成员时出错:" + ex.Message); } } }, () => { context.AppendLog("指定的群组无效,导入终止。"); }); } catch (Exception ex) { context.AppendLog("导入遇到错误,已经终止:" + ex.Message.ToString() + Environment.NewLine); } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasRelations) { int allCount = objectSet.Objects.Count; int count = 0; var pendingOrgs = new List<SchemaObjectBase>(objectSet.Objects.Count); foreach (SCOrganization item in ImportService.Instance.FilterNormalObjectsBySchemaCategories(objectSet.Objects, "Organizations")) { // 进行过滤,保留当前组织中的组织 if (objectSet.Relations.Exists(r => r.ParentID == this.Parent.ID && r.Status == SchemaObjectStatus.Normal && r.ID == item.ID)) { pendingOrgs.Add(item); } } allCount = pendingOrgs.Count; if (allCount > 0) { context.SetStatus(0, 1, "正在寻找当前组织内的关系。"); foreach (SCOrganization item in pendingOrgs) { count++; try { var summaryName = item.ToDescription(); context.SetStatus(count, allCount, "正在导入对象:" + summaryName); PC.Executors.SCObjectOperations.InstanceWithPermissions.AddOrganization((PC.SCOrganization)item, this.Parent); context.AppendLog("已执行导入项目" + summaryName); } catch (Exception ex) { context.AppendLog("对项的操作失败,原因是:" + ex.Message); } } } else { context.SetStatus(0, 1, "没有找到符合条件的组织关系。"); } } }
public override void DoImport(SCObjectSet objectSet, IImportContext context) { if (objectSet.HasRelations) { int allCount = objectSet.Objects.Count; int count = 0; var pendingOrgs = new List <SchemaObjectBase>(objectSet.Objects.Count); foreach (SCOrganization item in ImportService.Instance.FilterNormalObjectsBySchemaCategories(objectSet.Objects, "Organizations")) { // 进行过滤,保留当前组织中的组织 if (objectSet.Relations.Exists(r => r.ParentID == this.Parent.ID && r.Status == SchemaObjectStatus.Normal && r.ID == item.ID)) { pendingOrgs.Add(item); } } allCount = pendingOrgs.Count; if (allCount > 0) { context.SetStatus(0, 1, "正在寻找当前组织内的关系。"); foreach (SCOrganization item in pendingOrgs) { count++; try { var summaryName = item.ToDescription(); context.SetStatus(count, allCount, "正在导入对象:" + summaryName); PC.Executors.SCObjectOperations.InstanceWithPermissions.AddOrganization((PC.SCOrganization)item, this.Parent); context.AppendLog("已执行导入项目" + summaryName); } catch (Exception ex) { context.AppendLog("对项的操作失败,原因是:" + ex.Message); } } } else { context.SetStatus(0, 1, "没有找到符合条件的组织关系。"); } } }
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); } } } }
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 DoImportMembers(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, PC.SCGroup group) { if (this.ImportMembers && objectSet.HasMembership) { var members = ImportService.Instance.FilterMembership(objectSet.Membership, m => m.ContainerID == group.ID && m.Status == SchemaObjectStatus.Normal).ToArray(); if (members.Length > 0) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找群组 {0} 的固定成员", group.ToDescription())); for (int j = 0; j < members.Length; j++) { try { var gm = members[j]; ImportService.Instance.WithEffectObject <PC.SCUser>(gm.ID, knownObjects, user => { context.SetSubStatusAndLog(j, members.Length, string.Format("正在向群组 {0} 添加成员 {1} ", group.Name, user.Name)); PC.Executors.SCObjectOperations.Instance.AddUserToGroup(user, group); }, null); } catch (Exception ex2) { context.SetSubStatusAndLog(j, members.Length, string.Format("向群组 {0} 添加成员时出错:", group.ToDescription(), ex2.ToString())); } } } } }
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 (orgToGroupRelations.ContainsKey(org.ID)) { var groups = orgToGroupRelations[org.ID]; if (groups.Count > 0) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找 {0} 中的群组", org.ToDescription())); } for (int i = 0; i < groups.Count; i++) { var group = groups[i]; try { context.SetSubStatusAndLog(i + 1, groups.Count, string.Format("正在向组织 {0} 添加群组 {1}", org.Name, group.Name)); PC.Executors.SCObjectOperations.Instance.AddGroup(group, org); knownObjects.Add(group.ID, group); this.DoImportMembers(objectSet, context, knownObjects, group); this.DoImportConditions(objectSet, context, group); } catch (Exception ex) { context.AppendLog(string.Format("向组织 {0} 导入群组 {1} 时出错:", org.ToDescription(), group.Name, ex.ToString())); } } } }
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); } } }
private void ImportApplication(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, int allCount, int currentStep, int extStepCount, Dictionary <object, object> mappings, PC.SCApplication app) { var app2 = this.CopyMode ? AppImportAction.MakeCopy(app) : app; var summaryName = app2.DisplayName ?? app.Name; context.SetStatus(currentStep, allCount, "正在导入项目:" + summaryName); context.AppendLog("正在导入应用" + summaryName); executor.AddApplication((PC.SCApplication)app2); var permissionRelation = from p in objectSet.Membership where p.ContainerID == app.ID && p.MemberSchemaType == "Permissions" orderby p.InnerSort ascending select p; var permissions = (from o in objectSet.Objects join p in permissionRelation on o.ID equals p.ID select(PC.SCPermission) o).ToArray(); var roleRelations = from r in objectSet.Membership where r.ContainerID == app.ID && r.MemberSchemaType == "Roles" orderby r.InnerSort ascending select r; var roles = (from o in objectSet.Objects join r in roleRelations on o.ID equals r.ID select(PC.SCRole) o).ToArray(); var acls = (from acl in objectSet.Acls where acl.Status == SchemaObjectStatus.Normal && acl.ContainerID == app.ID orderby acl.SortID ascending select acl).ToArray(); int allStepCount = allCount * (extStepCount + 1); int step = currentStep * (extStepCount + 1); if (this.IncludePermissions) { context.SetStatus(step++, allStepCount, "正在查找功能..."); this.ImportPermissions(context, executor, mappings, app2, permissions, this.CopyMode); } if (this.IncludeRoles) { context.SetStatus(step++, allStepCount, "正在查找角色..."); this.ImportRoles(context, executor, mappings, app2, roles); } if (this.IncludeAcls) { context.SetStatus(step++, allStepCount, "正在查找Acl..."); this.ImportAcl(context, executor, app2, acls); } if (this.IncludeRoleMembers) { context.SetStatus(step++, allStepCount, "正在查找角色成员..."); this.ImportRoleMembers(objectSet, context, executor, mappings, roles); } if (this.IncludeRoleConditions) { context.SetStatus(step++, allStepCount, "正在查找角色条件..."); this.ImportRoleConditions(objectSet, context, executor, mappings, roles); } if (this.IncludeRoles && this.IncludePermissions && this.IncludeRoleDefinitions) { context.SetStatus(step++, allStepCount, "正在查找角色功能定义..."); this.ImportRolePermissions(objectSet, context, executor, mappings, permissions, roles, this.CopyMode); } }
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); } } } }
public override void ExecutePostOperation(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 (this.ImportSecretaries) { var allUsers = this.importedUsers.Values.ToArray(); var reducedMemberships = ImportService.Instance.FilterMembership(objectSet.Membership, m => Util.IsUser(m.MemberSchemaType) && Util.IsUser(m.ContainerSchemaType)).ToList(); if (reducedMemberships.Count > 0) { int count = reducedMemberships.Count; int step = 0; context.SetStatus(Owner.currentSteps, Owner.allSteps, "正在查找人员秘书"); foreach (var r in reducedMemberships) { step++; try { if (this.importedUsers.ContainsKey(r.ContainerID)) { var boss = this.importedUsers[r.ContainerID]; // 导入的用户是上司的 ImportService.Instance.WithEffectObject <PC.SCUser>(r.ID, knownObjects, secretary => { context.SetSubStatusAndLog(step, count, string.Format("正在替 {0} 添加秘书 {1}", boss.Name, secretary.Name)); PC.Executors.SCObjectOperations.Instance.AddSecretaryToUser(secretary, boss); }, null); } else if (this.importedUsers.ContainsKey(r.ID)) { var secretary = this.importedUsers[r.ID]; // 作为秘书的 ImportService.Instance.WithEffectObject <PC.SCUser>(r.ContainerID, knownObjects, boss => { context.SetSubStatusAndLog(step, count, string.Format("正在替 {0} 添加秘书 {1}", boss.Name, secretary.Name)); PC.Executors.SCObjectOperations.Instance.AddSecretaryToUser(secretary, boss); }, null); } } catch (Exception ex) { context.SetSubStatusAndLog(step, count, string.Format("未能完成添加秘书操作:{0}", ex.ToString())); } } } } }
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 (orgToUserRelations.ContainsKey(org.ID)) { var users = orgToUserRelations[org.ID]; if (users.Count > 0) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找 {0} 中的用户", org.ToDescription())); } for (int i = 0; i < users.Count; i++) { var user = users[i]; try { if (this.importedUsers.ContainsKey(user.ID) == false) { context.SetSubStatusAndLog(i + 1, users.Count, string.Format("正在向组织 {0} 导入用户 {1}", org.Name, user.Name)); PC.Executors.SCObjectOperations.Instance.AddUser(user, org); this.importedUsers.Add(user.ID, user); if (knownObjects.ContainsKey(user.ID) == false) { knownObjects.Add(user.ID, user); } } else { context.SetSubStatusAndLog(i + 1, users.Count, string.Format("正在向组织 {0} 添加用户 {1}", org.Name, user.Name)); PC.Executors.SCObjectOperations.Instance.AddUserToOrganization(user, org); if (knownObjects.ContainsKey(user.ID) == false) { knownObjects.Add(user.ID, user); } } } catch (Exception ex) { context.AppendLog(string.Format("向组织 {0} 导入用户 {1} 时出错:", org.Name, user.Name, ex.ToString())); } } } }
private void ImportOneGroup(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, SchemaObjectCollection parentObjects, SchemaObjectCollection memberObjects, int allCount, int count, SchemaObjectBase grp) { if (grp.SchemaType == "Groups") { try { var summaryName = grp.Properties.GetValue <string>("Name", "未命名"); context.SetStatus(count, allCount, "正在导入对象:" + summaryName); if (this.IncludeSelf) { SCRelationObject parentOrgRelation = (SCRelationObject)objectSet.Relations.Find(m => ((SCRelationObject)m).ParentSchemaType == "Organizations" && ((SCRelationObject)m).ChildSchemaType == "Groups" && ((SCRelationObject)m).ID == grp.ID); if (parentOrgRelation == null) { throw new HttpException("未找到群组的父级组织"); } var parentOrg = (SCOrganization)(parentObjects != null ? (from p in parentObjects where p.ID == parentOrgRelation.ParentID select p).FirstOrDefault() : null); if (parentOrg == null || parentOrg.Status != SchemaObjectStatus.Normal) { throw new HttpException("群组的父级组织不存在或者已删除,未能导入群组。"); } exec.AddGroup((SCGroup)grp, parentOrg); context.AppendLog("已执行导入对象" + summaryName); } ImportMembers(objectSet, context, exec, memberObjects, grp); ImportConditions(objectSet, context, grp); } catch (Exception ex) { context.AppendLog("对项的操作失败,原因是:" + ex.Message); } } else { context.AppendLog("已跳过不是群组的项"); } }
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 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 ImportOneGroup(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations exec, SchemaObjectCollection parentObjects, SchemaObjectCollection memberObjects, int allCount, int count, SchemaObjectBase grp) { if (grp.SchemaType == "Groups") { try { var summaryName = grp.Properties.GetValue<string>("Name", "未命名"); context.SetStatus(count, allCount, "正在导入对象:" + summaryName); if (this.IncludeSelf) { SCRelationObject parentOrgRelation = (SCRelationObject)objectSet.Relations.Find(m => ((SCRelationObject)m).ParentSchemaType == "Organizations" && ((SCRelationObject)m).ChildSchemaType == "Groups" && ((SCRelationObject)m).ID == grp.ID); if (parentOrgRelation == null) throw new HttpException("未找到群组的父级组织"); var parentOrg = (SCOrganization)(parentObjects != null ? (from p in parentObjects where p.ID == parentOrgRelation.ParentID select p).FirstOrDefault() : null); if (parentOrg == null || parentOrg.Status != SchemaObjectStatus.Normal) throw new HttpException("群组的父级组织不存在或者已删除,未能导入群组。"); exec.AddGroup((SCGroup)grp, parentOrg); context.AppendLog("已执行导入对象" + summaryName); } ImportMembers(objectSet, context, exec, memberObjects, grp); ImportConditions(objectSet, context, grp); } catch (Exception ex) { context.AppendLog("对项的操作失败,原因是:" + ex.Message); } } else { context.AppendLog("已跳过不是群组的项"); } }
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) { var exec = PC.Executors.SCObjectOperations.InstanceWithPermissions; PC.SCRole[] pendingRoles; if (this.CopyMode) { pendingRoles = (from r in objectSet.Objects where r is PC.SCRole select(PC.SCRole) r).ToArray(); } else { pendingRoles = (from r in objectSet.Objects join m in objectSet.Membership on r.ID equals m.ID where r.SchemaType == "Roles" && m.ContainerID == app.ID select(PC.SCRole) r).ToArray(); } int count = 0; int allCount = pendingRoles.Length; foreach (var role in pendingRoles) { var role2 = this.CopyMode ? AppImportAction.MakeCopy(role) : role; context.SetStatus(count, allCount, "正在导入角色:" + role2.DisplayName); context.AppendLog("正在导入角色" + role2.ToDescription()); exec.AddRole(role2, app); // 导入角色 if (this.IncludeConstMembers && objectSet.HasMembership) { context.SetStatus(count, allCount, "正在查找并添加角色成员"); context.AppendLog("正在查找角色成员"); ImportRoleMembers(objectSet, context, exec, role, role2); } if (this.IncludeConditions && objectSet.HasConditions) { context.SetStatus(count, allCount, "正在查找并添加角色条件"); context.AppendLog("正在查找角色条件"); this.ImportRoleConditions(objectSet, context, exec, role, role2); } if (this.IncludeRoleDefinitions && this.CopyMode == false && objectSet.HasRelations) { this.ImportRoleDefinitions(objectSet, context, exec, count, allCount, role, role2); } count++; } } }
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.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); } } } }
/// <summary> /// 准备组织 /// </summary> /// <param name="objectSet"></param> /// <param name="context"></param> /// <param name="knownObjects">向其中写入已经确认存在于数据库中的项</param> /// <param name="orgToOrgRelations">组织关系</param> /// <param name="allSteps"></param> /// <param name="currentSteps"></param> /// <param name="currentParent"></param> /// <param name="checkOnly"><see langword="true"/>表示只检查组织关系,不实际导入。</param> /// <returns></returns> private bool PrepareOrganizations(SCObjectSet objectSet, IImportContext context, IDictionary <string, PC.SchemaObjectBase> knownObjects, Dictionary <string, IList <PC.SCOrganization> > orgToOrgRelations, PC.SCOrganization currentParent, bool checkOnly) { bool valid = true; PC.SchemaObjectCollection objects = objectSet.Objects; if (orgToOrgRelations.ContainsKey(currentParent.ID)) { var childList = orgToOrgRelations[currentParent.ID]; for (int i = 0; i < childList.Count; i++) { this.currentSteps++; var org = childList[i]; try { // 导入该组织 if (checkOnly == false) { var msg = string.Format("正在导入组织{0}", org.ToDescription()); context.AppendLog(msg); context.SetStatus(this.currentSteps, this.allSteps, msg); PC.Executors.SCObjectOperations.Instance.AddOrganization(org, currentParent); if (knownObjects.ContainsKey(org.ID) == false) { knownObjects.Add(org.ID, org); } } else { context.SetStatus(this.currentSteps, this.allSteps, string.Format("正在校验组织 {0} ", org.ToDescription())); if (Util.IsNullOrDeleted(PC.Adapters.SchemaObjectAdapter.Instance.Load(org.ID))) { context.AppendLog(string.Format("组织 {0} 不存在,导入时将排除此组织及子对象", org.ToDescription())); valid = false; childList.RemoveAt(i); i--; continue; } else if (Util.IsNullOrDeleted(PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(currentParent.ID, org.ID))) { context.AppendLog(string.Format("组织 {0} 已存在,但已被移至其他位置,导入时将排除此组织及子对象。", org.ToDescription())); valid = false; childList.RemoveAt(i); i--; continue; } else { if (knownObjects.ContainsKey(org.ID) == false) { knownObjects.Add(org.ID, org); } } } valid &= this.PrepareOrganizations(objectSet, context, knownObjects, orgToOrgRelations, org, checkOnly); } catch (Exception ex) { context.AppendLog(string.Format("导入组织 {0} 时出现错误,已跳过了该组织及子对象:{1}", org.ToDescription(), ex.ToString())); valid = false; childList.RemoveAt(i); i--; } } } return(valid); }
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 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); } } } }
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 DoImportMembers(SCObjectSet objectSet, IImportContext context, IDictionary<string, PC.SchemaObjectBase> knownObjects, PC.SCGroup group) { if (this.ImportMembers && objectSet.HasMembership) { var members = ImportService.Instance.FilterMembership(objectSet.Membership, m => m.ContainerID == group.ID && m.Status == SchemaObjectStatus.Normal).ToArray(); if (members.Length > 0) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找群组 {0} 的固定成员", group.ToDescription())); for (int j = 0; j < members.Length; j++) { try { var gm = members[j]; ImportService.Instance.WithEffectObject<PC.SCUser>(gm.ID, knownObjects, user => { context.SetSubStatusAndLog(j, members.Length, string.Format("正在向群组 {0} 添加成员 {1} ", group.Name, user.Name)); PC.Executors.SCObjectOperations.Instance.AddUserToGroup(user, group); }, null); } catch (Exception ex2) { context.SetSubStatusAndLog(j, members.Length, string.Format("向群组 {0} 添加成员时出错:", group.ToDescription(), ex2.ToString())); } } } } }
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 (orgToGroupRelations.ContainsKey(org.ID)) { var groups = orgToGroupRelations[org.ID]; if (groups.Count > 0) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找 {0} 中的群组", org.ToDescription())); } for (int i = 0; i < groups.Count; i++) { var group = groups[i]; try { context.SetSubStatusAndLog(i + 1, groups.Count, string.Format("正在向组织 {0} 添加群组 {1}", org.Name, group.Name)); PC.Executors.SCObjectOperations.Instance.AddGroup(group, org); knownObjects.Add(group.ID, group); this.DoImportMembers(objectSet, context, knownObjects, group); this.DoImportConditions(objectSet, context, group); } catch (Exception ex) { context.AppendLog(string.Format("向组织 {0} 导入群组 {1} 时出错:", org.ToDescription(), group.Name, ex.ToString())); } } } }
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 (orgToUserRelations.ContainsKey(org.ID)) { var users = orgToUserRelations[org.ID]; if (users.Count > 0) { context.SetStatus(Owner.currentSteps, Owner.allSteps, string.Format("正在查找 {0} 中的用户", org.ToDescription())); } for (int i = 0; i < users.Count; i++) { var user = users[i]; try { if (this.importedUsers.ContainsKey(user.ID) == false) { context.SetSubStatusAndLog(i + 1, users.Count, string.Format("正在向组织 {0} 导入用户 {1}", org.Name, user.Name)); PC.Executors.SCObjectOperations.Instance.AddUser(user, org); this.importedUsers.Add(user.ID, user); if (knownObjects.ContainsKey(user.ID) == false) knownObjects.Add(user.ID, user); } else { context.SetSubStatusAndLog(i + 1, users.Count, string.Format("正在向组织 {0} 添加用户 {1}", org.Name, user.Name)); PC.Executors.SCObjectOperations.Instance.AddUserToOrganization(user, org); if (knownObjects.ContainsKey(user.ID) == false) knownObjects.Add(user.ID, user); } } catch (Exception ex) { context.AppendLog(string.Format("向组织 {0} 导入用户 {1} 时出错:", org.Name, user.Name, ex.ToString())); } } } }
public override void ExecutePostOperation(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 (this.ImportSecretaries) { var allUsers = this.importedUsers.Values.ToArray(); var reducedMemberships = ImportService.Instance.FilterMembership(objectSet.Membership, m => Util.IsUser(m.MemberSchemaType) && Util.IsUser(m.ContainerSchemaType)).ToList(); if (reducedMemberships.Count > 0) { int count = reducedMemberships.Count; int step = 0; context.SetStatus(Owner.currentSteps, Owner.allSteps, "正在查找人员秘书"); foreach (var r in reducedMemberships) { step++; try { if (this.importedUsers.ContainsKey(r.ContainerID)) { var boss = this.importedUsers[r.ContainerID]; // 导入的用户是上司的 ImportService.Instance.WithEffectObject<PC.SCUser>(r.ID, knownObjects, secretary => { context.SetSubStatusAndLog(step, count, string.Format("正在替 {0} 添加秘书 {1}", boss.Name, secretary.Name)); PC.Executors.SCObjectOperations.Instance.AddSecretaryToUser(secretary, boss); }, null); } else if (this.importedUsers.ContainsKey(r.ID)) { var secretary = this.importedUsers[r.ID]; // 作为秘书的 ImportService.Instance.WithEffectObject<PC.SCUser>(r.ContainerID, knownObjects, boss => { context.SetSubStatusAndLog(step, count, string.Format("正在替 {0} 添加秘书 {1}", boss.Name, secretary.Name)); PC.Executors.SCObjectOperations.Instance.AddSecretaryToUser(secretary, boss); }, null); } } catch (Exception ex) { context.SetSubStatusAndLog(step, count, string.Format("未能完成添加秘书操作:{0}", ex.ToString())); } } } } }
private void ImportApplication(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, int allCount, int currentStep, int extStepCount, Dictionary<object, object> mappings, PC.SCApplication app) { var app2 = this.CopyMode ? AppImportAction.MakeCopy(app) : app; var summaryName = app2.DisplayName ?? app.Name; context.SetStatus(currentStep, allCount, "正在导入项目:" + summaryName); context.AppendLog("正在导入应用" + summaryName); executor.AddApplication((PC.SCApplication)app2); var permissionRelation = from p in objectSet.Membership where p.ContainerID == app.ID && p.MemberSchemaType == "Permissions" orderby p.InnerSort ascending select p; var permissions = (from o in objectSet.Objects join p in permissionRelation on o.ID equals p.ID select (PC.SCPermission)o).ToArray(); var roleRelations = from r in objectSet.Membership where r.ContainerID == app.ID && r.MemberSchemaType == "Roles" orderby r.InnerSort ascending select r; var roles = (from o in objectSet.Objects join r in roleRelations on o.ID equals r.ID select (PC.SCRole)o).ToArray(); var acls = (from acl in objectSet.Acls where acl.Status == SchemaObjectStatus.Normal && acl.ContainerID == app.ID orderby acl.SortID ascending select acl).ToArray(); int allStepCount = allCount * (extStepCount + 1); int step = currentStep * (extStepCount + 1); if (this.IncludePermissions) { context.SetStatus(step++, allStepCount, "正在查找功能..."); this.ImportPermissions(context, executor, mappings, app2, permissions, this.CopyMode); } if (this.IncludeRoles) { context.SetStatus(step++, allStepCount, "正在查找角色..."); this.ImportRoles(context, executor, mappings, app2, roles); } if (this.IncludeAcls) { context.SetStatus(step++, allStepCount, "正在查找Acl..."); this.ImportAcl(context, executor, app2, acls); } if (this.IncludeRoleMembers) { context.SetStatus(step++, allStepCount, "正在查找角色成员..."); this.ImportRoleMembers(objectSet, context, executor, mappings, roles); } if (this.IncludeRoleConditions) { context.SetStatus(step++, allStepCount, "正在查找角色条件..."); this.ImportRoleConditions(objectSet, context, executor, mappings, roles); } if (this.IncludeRoles && this.IncludePermissions && this.IncludeRoleDefinitions) { context.SetStatus(step++, allStepCount, "正在查找角色功能定义..."); this.ImportRolePermissions(objectSet, context, executor, mappings, permissions, roles, this.CopyMode); } }
/// <summary> /// 准备组织 /// </summary> /// <param name="objectSet"></param> /// <param name="context"></param> /// <param name="knownObjects">向其中写入已经确认存在于数据库中的项</param> /// <param name="orgToOrgRelations">组织关系</param> /// <param name="allSteps"></param> /// <param name="currentSteps"></param> /// <param name="currentParent"></param> /// <param name="checkOnly"><see langword="true"/>表示只检查组织关系,不实际导入。</param> /// <returns></returns> private bool PrepareOrganizations(SCObjectSet objectSet, IImportContext context, IDictionary<string, PC.SchemaObjectBase> knownObjects, Dictionary<string, IList<PC.SCOrganization>> orgToOrgRelations, PC.SCOrganization currentParent, bool checkOnly) { bool valid = true; PC.SchemaObjectCollection objects = objectSet.Objects; if (orgToOrgRelations.ContainsKey(currentParent.ID)) { var childList = orgToOrgRelations[currentParent.ID]; for (int i = 0; i < childList.Count; i++) { this.currentSteps++; var org = childList[i]; try { // 导入该组织 if (checkOnly == false) { var msg = string.Format("正在导入组织{0}", org.ToDescription()); context.AppendLog(msg); context.SetStatus(this.currentSteps, this.allSteps, msg); PC.Executors.SCObjectOperations.Instance.AddOrganization(org, currentParent); if (knownObjects.ContainsKey(org.ID) == false) knownObjects.Add(org.ID, org); } else { context.SetStatus(this.currentSteps, this.allSteps, string.Format("正在校验组织 {0} ", org.ToDescription())); if (Util.IsNullOrDeleted(PC.Adapters.SchemaObjectAdapter.Instance.Load(org.ID))) { context.AppendLog(string.Format("组织 {0} 不存在,导入时将排除此组织及子对象", org.ToDescription())); valid = false; childList.RemoveAt(i); i--; continue; } else if (Util.IsNullOrDeleted(PC.Adapters.SchemaRelationObjectAdapter.Instance.Load(currentParent.ID, org.ID))) { context.AppendLog(string.Format("组织 {0} 已存在,但已被移至其他位置,导入时将排除此组织及子对象。", org.ToDescription())); valid = false; childList.RemoveAt(i); i--; continue; } else { if (knownObjects.ContainsKey(org.ID) == false) knownObjects.Add(org.ID, org); } } valid &= this.PrepareOrganizations(objectSet, context, knownObjects, orgToOrgRelations, org, checkOnly); } catch (Exception ex) { context.AppendLog(string.Format("导入组织 {0} 时出现错误,已跳过了该组织及子对象:{1}", org.ToDescription(), ex.ToString())); valid = false; childList.RemoveAt(i); i--; } } } return valid; }