private void ImportOneUnit(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, Operations.IFacade exec, ImportContextWrapper wrapper, SchemaObjectBase parent, int totalSteps, AdminUnit unit) { int currentStep = 0; var scopes = (from m in objectSet.Membership where m.ContainerID == unit.ID && m.MemberSchemaType == AUCommon.SchemaAUAdminScope && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on m.ID equals o.ID where o.SchemaType == AUCommon.SchemaAUAdminScope && o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select (AUAdminScope)o).ToArray(); var roles = (from m in objectSet.Membership where m.ContainerID == unit.ID && m.MemberSchemaType == AUCommon.SchemaAdminUnitRole && m.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on m.ID equals o.ID where o.SchemaType == AUCommon.SchemaAdminUnitRole && o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal select (AURole)o).ToArray(); try { currentStep++; wrapper.SetStatusAndLog(currentStep, totalSteps, "正在导入管理单元" + unit.GetQualifiedName()); exec.AddAdminUnitWithMembers(unit, (AdminUnit)parent, roles, scopes); ImportRoleMembers(objectSet, exec, wrapper, totalSteps, unit, currentStep, roles); ImportConditions(objectSet, exec, wrapper, totalSteps, unit, currentStep, scopes); if (this.ImportSubUnits) { wrapper.IncreaseLevel(); var subs = (from r in objectSet.Relations where r.ParentID == unit.ID && r.ChildSchemaType == AUCommon.SchemaAdminUnit && r.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal join o in objectSet.Objects on r.ID equals o.ID where o.Status == Schemas.SchemaProperties.SchemaObjectStatus.Normal && o.SchemaType == AUCommon.SchemaAdminUnit select (AdminUnit)o).ToArray(); int count = subs.Length; foreach (AdminUnit s in subs) { ImportOneUnit(objectSet, exec, wrapper, unit, count, s); } wrapper.DecreaseLevel(); } } catch (Exception ex) { wrapper.IncreaseError(); wrapper.SetStatusAndLog(currentStep, totalSteps, string.Format("导入单元 {0} 失败,原因是:{1}", unit.GetQualifiedName(), ex.ToString())); } }