Example #1
0
        public void UpdateRoleConditions(string ownerID, string conditionType, ClientConditionItem[] items)
        {
            PC.Conditions.SCConditionOwner owner = PC.Adapters.SCConditionAdapter.Instance.Load(ownerID, conditionType) ?? new PC.Conditions.SCConditionOwner()
            {
                OwnerID = ownerID, Type = conditionType
            };

            PC.Conditions.SCConditionCollection conditions = new PC.Conditions.SCConditionCollection();

            foreach (ClientConditionItem item in items)
            {
                if (item.OwnerID != ownerID)
                {
                    throw new InvalidOperationException("不一致的OwnerID:" + item.OwnerID);
                }
                else if (item.Status == ClientSchemaObjectStatus.Normal)
                {
                    conditions.Add(new PC.Conditions.SCCondition()
                    {
                        OwnerID          = ownerID,
                        Status           = SchemaObjectStatus.Normal,
                        Description      = item.Description ?? string.Empty,
                        Condition        = item.Condition,
                        SortID           = item.SortID,
                        Type             = item.Type,
                        VersionEndTime   = item.VersionEndTime,
                        VersionStartTime = item.VersionStartTime
                    });
                }
            }

            owner.Conditions.ReplaceItemsWith(conditions, ownerID, conditionType);

            Facade.UpdateRoleConditions(owner);
        }
Example #2
0
            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()));
                    }
                }
            }
Example #3
0
        public void Load(System.IO.TextReader input)
        {
            int count;

            var xmlDoc = new System.Xml.XmlDocument();

            xmlDoc.Load(input);
            SchemaObjectXmlImporter importer = new SchemaObjectXmlImporter();

            var nodeContext = xmlDoc.SelectSingleNode("/sc/context");

            if (nodeContext != null)
            {
                var attrTime = nodeContext.Attributes["timeContext"];
                if (attrTime != null && attrTime.Specified)
                {
                    this.timeContext = System.Xml.XmlConvert.ToDateTime(attrTime.Value, System.Xml.XmlDateTimeSerializationMode.Local);
                }

                var scope = nodeContext.Attributes["scope"];
                if (scope != null && scope.Specified)
                {
                    this.Scope = scope.Value;
                }
            }

            var nodeObjects = xmlDoc.SelectNodes("/sc/objects/Object");

            this.objects = null;
            count        = nodeObjects.Count;

            if (count > 0)
            {
                this.objects = new SchemaObjectCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml        = nodeObjects[i].OuterXml;
                    var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
                    this.objects.Add(importer.XmlToObject(xml, schemaType));
                }
            }

            nodeObjects    = xmlDoc.SelectNodes("/sc/relations/Object");
            this.relations = null;
            count          = nodeObjects.Count;

            if (count > 0)
            {
                this.relations = new SCRelationObjectCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml        = nodeObjects[i].OuterXml;
                    var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
                    this.relations.Add((SCRelationObject)importer.XmlToObject(xml, schemaType));
                }
            }

            nodeObjects     = xmlDoc.SelectNodes("/sc/membership/Object");
            this.membership = null;
            count           = nodeObjects.Count;

            if (count > 0)
            {
                this.membership = new SCMemberRelationCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml        = nodeObjects[i].OuterXml;
                    var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
                    this.membership.Add((SCSimpleRelationBase)importer.XmlToObject(xml, schemaType));
                }
            }

            nodeObjects     = xmlDoc.SelectNodes("/sc/conditions/condition");
            this.conditions = null;
            count           = nodeObjects.Count;

            if (count > 0)
            {
                this.conditions = new MCS.Library.SOA.DataObjects.Security.Conditions.SCConditionCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml = nodeObjects[i];

                    var condition = LoadCondition(xml);

                    this.conditions.Add(condition);
                }
            }

            nodeObjects = xmlDoc.SelectNodes("/sc/acls/acl");
            this.acls   = null;
            count       = nodeObjects.Count;

            if (count > 0)
            {
                this.acls = new SCAclContainerCollection();

                for (int i = 0; i < count; i++)
                {
                    var xml = nodeObjects[i];

                    var acl = LoadAcl(xml);

                    this.acls.Add(acl);
                }
            }
        }
			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()));
					}
				}
			}
Example #5
0
		public void Load(System.IO.TextReader input)
		{
			int count;

			var xmlDoc = new System.Xml.XmlDocument();
			xmlDoc.Load(input);
			SchemaObjectXmlImporter importer = new SchemaObjectXmlImporter();

			var nodeContext = xmlDoc.SelectSingleNode("/sc/context");
			if (nodeContext != null)
			{
				var attrTime = nodeContext.Attributes["timeContext"];
				if (attrTime != null && attrTime.Specified)
				{
					this.timeContext = System.Xml.XmlConvert.ToDateTime(attrTime.Value, System.Xml.XmlDateTimeSerializationMode.Local);
				}

				var scope = nodeContext.Attributes["scope"];
				if (scope != null && scope.Specified)
				{
					this.Scope = scope.Value;
				}
			}

			var nodeObjects = xmlDoc.SelectNodes("/sc/objects/Object");
			this.objects = null;
			count = nodeObjects.Count;

			if (count > 0)
			{
				this.objects = new SchemaObjectCollection();

				for (int i = 0; i < count; i++)
				{
					var xml = nodeObjects[i].OuterXml;
					var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
					this.objects.Add(importer.XmlToObject(xml, schemaType));
				}
			}

			nodeObjects = xmlDoc.SelectNodes("/sc/relations/Object");
			this.relations = null;
			count = nodeObjects.Count;

			if (count > 0)
			{
				this.relations = new SCRelationObjectCollection();

				for (int i = 0; i < count; i++)
				{
					var xml = nodeObjects[i].OuterXml;
					var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
					this.relations.Add((SCRelationObject)importer.XmlToObject(xml, schemaType));
				}
			}

			nodeObjects = xmlDoc.SelectNodes("/sc/membership/Object");
			this.membership = null;
			count = nodeObjects.Count;

			if (count > 0)
			{
				this.membership = new SCMemberRelationCollection();

				for (int i = 0; i < count; i++)
				{
					var xml = nodeObjects[i].OuterXml;
					var schemaType = nodeObjects[i].Attributes["SchemaType"].Value;
					this.membership.Add((SCSimpleRelationBase)importer.XmlToObject(xml, schemaType));
				}
			}

			nodeObjects = xmlDoc.SelectNodes("/sc/conditions/condition");
			this.conditions = null;
			count = nodeObjects.Count;

			if (count > 0)
			{
				this.conditions = new MCS.Library.SOA.DataObjects.Security.Conditions.SCConditionCollection();

				for (int i = 0; i < count; i++)
				{
					var xml = nodeObjects[i];

					var condition = LoadCondition(xml);

					this.conditions.Add(condition);
				}
			}

			nodeObjects = xmlDoc.SelectNodes("/sc/acls/acl");
			this.acls = null;
			count = nodeObjects.Count;

			if (count > 0)
			{
				this.acls = new SCAclContainerCollection();

				for (int i = 0; i < count; i++)
				{
					var xml = nodeObjects[i];

					var acl = LoadAcl(xml);

					this.acls.Add(acl);
				}
			}
		}
		public void UpdateRoleConditions(string ownerID, string conditionType, ClientConditionItem[] items)
		{
			PC.Conditions.SCConditionOwner owner = PC.Adapters.SCConditionAdapter.Instance.Load(ownerID, conditionType) ?? new PC.Conditions.SCConditionOwner() { OwnerID = ownerID, Type = conditionType };

			PC.Conditions.SCConditionCollection conditions = new PC.Conditions.SCConditionCollection();

			foreach (ClientConditionItem item in items)
			{
				if (item.OwnerID != ownerID)
					throw new InvalidOperationException("不一致的OwnerID:" + item.OwnerID);
				else if (item.Status == ClientSchemaObjectStatus.Normal)
				{
					conditions.Add(new PC.Conditions.SCCondition()
					{
						OwnerID = ownerID,
						Status = SchemaObjectStatus.Normal,
						Description = item.Description ?? string.Empty,
						Condition = item.Condition,
						SortID = item.SortID,
						Type = item.Type,
						VersionEndTime = item.VersionEndTime,
						VersionStartTime = item.VersionStartTime
					});
				}
			}

			owner.Conditions.ReplaceItemsWith(conditions, ownerID, conditionType);

			Facade.UpdateRoleConditions(owner);
		}
Example #7
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 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);
					}
				}
			}
		}