Exemplo n.º 1
0
		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.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, "没有找到符合条件的组织关系。");
				}
			}
		}
Exemplo n.º 4
0
		public override void DoImport(SCObjectSet objectSet, IImportContext context)
		{
			var executor = PC.Executors.SCObjectOperations.InstanceWithPermissions;

			var apps = ImportService.Instance.FilterNormalObjectsBySchemaCategories(objectSet.Objects, "Applications").ToList();

			int allCount = apps.Count;
			int step = 0;
			context.AppendLog("发现" + allCount + "个应用");
			Dictionary<object, object> mappings = new Dictionary<object, object>(); // 保存新旧对象的对应关系

			// 统计需要哪些附加动作
			int extStepCount = 0;
			if (this.IncludePermissions)
				extStepCount++;
			if (this.IncludeRoles)
				extStepCount++;
			if (this.IncludeRoleMembers)
				extStepCount++;
			if (this.IncludeRoleDefinitions)
				extStepCount++;
			if (this.IncludeRoleConditions)
				extStepCount++;
			if (this.IncludeAcls)
				extStepCount++;

			foreach (PC.SCApplication app in apps)
			{
				this.ImportApplication(objectSet, context, executor, allCount, step++, extStepCount, mappings, app);
			}
		}
		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 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);
				}
			}
		}
Exemplo n.º 7
0
        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("已跳过不是群组的项");
            }
        }
Exemplo n.º 8
0
        private void ImportConditions(SCObjectSet objectSet, IImportContext context, SchemaObjectBase grp)
        {
            if (this.IncludeConditions && objectSet.HasConditions)
            {
                PC.Conditions.SCConditionOwner owner = new PC.Conditions.SCConditionOwner()
                {
                    OwnerID = grp.ID,
                    Type    = "Default"
                };
                var conditions = from c in objectSet.Conditions where c.OwnerID == grp.ID && c.Type == "Default" select c;
                foreach (var c in conditions)
                {
                    owner.Conditions.Add(c);
                }

                context.AppendLog("正在添加条件表达式");
                PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner);
                context.AppendLog("添加条件表达式结束。");
            }
        }
Exemplo n.º 9
0
            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()));
                        }
                    }
                }
            }
Exemplo n.º 10
0
        public override void DoImport(SCObjectSet objectSet, IImportContext context)
        {
            var executor = PC.Executors.SCObjectOperations.InstanceWithPermissions;

            var apps = ImportService.Instance.FilterNormalObjectsBySchemaCategories(objectSet.Objects, "Applications").ToList();

            int allCount = apps.Count;
            int step     = 0;

            context.AppendLog("发现" + allCount + "个应用");
            Dictionary <object, object> mappings = new Dictionary <object, object>();           // 保存新旧对象的对应关系

            // 统计需要哪些附加动作
            int extStepCount = 0;

            if (this.IncludePermissions)
            {
                extStepCount++;
            }
            if (this.IncludeRoles)
            {
                extStepCount++;
            }
            if (this.IncludeRoleMembers)
            {
                extStepCount++;
            }
            if (this.IncludeRoleDefinitions)
            {
                extStepCount++;
            }
            if (this.IncludeRoleConditions)
            {
                extStepCount++;
            }
            if (this.IncludeAcls)
            {
                extStepCount++;
            }

            foreach (PC.SCApplication app in apps)
            {
                this.ImportApplication(objectSet, context, executor, allCount, step++, extStepCount, mappings, app);
            }
        }
Exemplo n.º 11
0
		private void ImportSchemaRoles(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, IImportContext context, Operations.IFacade exec, AUSchema item)
		{
			if (this.IncludeSchemaRoles)
			{
				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 select q);
				int total = roles.Count();
				int roleCount = 0;
				foreach (AUSchemaRole role in roles)
				{
					roleCount++;
					try
					{
						context.SetSubStatusAndLog(roleCount, total, "正在添加角色:" + role.GetQualifiedName());
						exec.AddAdminSchemaRole(role, item);
					}
					catch (Exception ex)
					{
						context.ErrorCount++;
						context.AppendLog("对角色的操作失败,原因是:" + ex.Message);
					}
				}
			}
		}
Exemplo n.º 12
0
		public override void DoImport(SCObjectSet objectSet, IImportContext context)
		{
			context.AppendLog("正在查找人员");

			var actor = PC.Executors.SCObjectOperations.InstanceWithPermissions;

			var pendingUsers = ImportService.Instance.FilterNormalObjectsBySchemaCategories(objectSet.Objects, "Users").ToList();

			int allCount = pendingUsers.Count;

			ImportService.Instance.ImportUsers(pendingUsers, objectSet, context, objectSet.HasRelations && this.IncludeOrganizationRelation);

			if (this.IncludeSecretaries && objectSet.HasMembership)
			{
				ImportService.Instance.ImportSecretaries(pendingUsers, objectSet, context);
				ImportService.Instance.ImportBosses(pendingUsers, objectSet, context);
			}

			if (this.IncludeGroupConstMembers && objectSet.HasMembership)
			{
				ImportService.Instance.AddUsersToGroups(pendingUsers, objectSet, context);
			}
		}
Exemplo n.º 13
0
        public override void DoImport(SCObjectSet objectSet, IImportContext context)
        {
            context.AppendLog("正在查找人员");

            var actor = PC.Executors.SCObjectOperations.InstanceWithPermissions;

            var pendingUsers = ImportService.Instance.FilterNormalObjectsBySchemaCategories(objectSet.Objects, "Users").ToList();

            int allCount = pendingUsers.Count;

            ImportService.Instance.ImportUsers(pendingUsers, objectSet, context, objectSet.HasRelations && this.IncludeOrganizationRelation);

            if (this.IncludeSecretaries && objectSet.HasMembership)
            {
                ImportService.Instance.ImportSecretaries(pendingUsers, objectSet, context);
                ImportService.Instance.ImportBosses(pendingUsers, objectSet, context);
            }

            if (this.IncludeGroupConstMembers && objectSet.HasMembership)
            {
                ImportService.Instance.AddUsersToGroups(pendingUsers, objectSet, context);
            }
        }
Exemplo n.º 14
0
 private void ImportSchemaRoles(MCS.Library.SOA.DataObjects.Security.SCObjectSet objectSet, IImportContext context, Operations.IFacade exec, AUSchema item)
 {
     if (this.IncludeSchemaRoles)
     {
         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 select q);
         int total     = roles.Count();
         int roleCount = 0;
         foreach (AUSchemaRole role in roles)
         {
             roleCount++;
             try
             {
                 context.SetSubStatusAndLog(roleCount, total, "正在添加角色:" + role.GetQualifiedName());
                 exec.AddAdminSchemaRole(role, item);
             }
             catch (Exception ex)
             {
                 context.ErrorCount++;
                 context.AppendLog("对角色的操作失败,原因是:" + ex.Message);
             }
         }
     }
 }
Exemplo n.º 15
0
        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);
                    }
                }
            }
        }
Exemplo n.º 16
0
        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);
                }
            }
        }
Exemplo n.º 17
0
		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("已跳过不是群组的项");
			}
		}
Exemplo n.º 18
0
		private void ImportConditions(SCObjectSet objectSet, IImportContext context, SchemaObjectBase grp)
		{
			if (this.IncludeConditions && objectSet.HasConditions)
			{
				PC.Conditions.SCConditionOwner owner = new PC.Conditions.SCConditionOwner()
				{
					OwnerID = grp.ID,
					Type = "Default"
				};
				var conditions = from c in objectSet.Conditions where c.OwnerID == grp.ID && c.Type == "Default" select c;
				foreach (var c in conditions)
				{
					owner.Conditions.Add(c);
				}

				context.AppendLog("正在添加条件表达式");
				PC.Adapters.SCConditionAdapter.Instance.UpdateConditions(owner);
				context.AppendLog("添加条件表达式结束。");
			}
		}
Exemplo n.º 19
0
		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 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 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()));
						}
					}
				}
			}
Exemplo n.º 22
0
		private void ImportPermissions(IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary<object, object> mappings, PC.SCApplication app2, PC.SCPermission[] permissions, bool copyMode)
		{
			if (permissions.Length > 0)
			{
				context.AppendLog("正准备导入功能");
				foreach (var p in permissions)
				{
					var permission2 = copyMode ? MakeCopy(p) : p;
					mappings.Add(p, permission2);
					context.AppendLog("正在导入功能" + permission2.DisplayName ?? permission2.Name);
					executor.AddPermission(permission2, app2);
				}
			}
		}
Exemplo n.º 23
0
        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++;
                }
            }
        }
Exemplo n.º 24
0
		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);
					}
				}
			}
		}
Exemplo n.º 25
0
		/// <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;
		}
Exemplo n.º 26
0
		private void ImportRoles(IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary<object, object> mappings, PC.SCApplication app2, PC.SCRole[] roles)
		{
			if (this.IncludeRoles && roles.Length > 0)
			{
				context.AppendLog("正准备导入角色");
				foreach (var p in roles)
				{
					var role2 = this.CopyMode ? AppImportAction.MakeCopy(p) : p;
					mappings.Add(p, role2);
					context.AppendLog("正在导入角色" + role2.ToDescription());
					executor.AddRole(role2, app2);
				}
			}
		}
Exemplo n.º 27
0
        /// <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);
        }
Exemplo n.º 28
0
        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 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()));
						}
					}
				}
			}
Exemplo n.º 30
0
		private void ImportRoleMembers(SCObjectSet objectSet, IImportContext context, PC.Executors.ISCObjectOperations executor, Dictionary<object, object> mappings, PC.SCRole[] roles)
		{
			if (roles.Length > 0)
			{
				foreach (var r in roles)
				{
					PC.SCRole role2 = r;
					if (mappings.ContainsKey(r))
					{
						role2 = (PC.SCRole)mappings[r];
					}

					// 查找角色成员
					var roleMemberIds = (from m in objectSet.Membership where m.ContainerSchemaType == "Roles" && m.ContainerID == r.ID select m.ID).ToArray();
					if (roleMemberIds.Length > 0)
					{
						var roleMembers = DbUtil.LoadObjects(roleMemberIds);
						foreach (PC.SCBase obj in roleMembers)
						{
							context.AppendLog("正在导入角色成员" + obj.DisplayName ?? obj.Name);
							executor.AddMemberToRole(obj, role2);
						}
					}
				}
			}
		}
Exemplo n.º 31
0
		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);
			}
		}