/// <summary> /// Gets a list of attribute changes as Put fragments for submission to the Resource Management Service /// </summary> /// <returns>A list of PutFragmentType objects containing all the value changes pending on the object</returns> internal List <PutFragmentType> GetPutFragements() { List <PutFragmentType> fragments = new List <PutFragmentType>(); foreach (KeyValuePair <string, List <AttributeValueChange> > kvp in this.PendingChanges) { AttributeTypeDefinition type = this.ObjectType[kvp.Key]; if (ResourceManagementSchema.ComputedAttributes.Contains(type.SystemName)) { continue; } foreach (AttributeValueChange change in kvp.Value) { string value = null; if (change.Value != null) { switch (type.Type) { case AttributeType.Binary: value = Convert.ToBase64String((byte[])change.Value); break; case AttributeType.DateTime: value = ((DateTime)change.Value).ToResourceManagementServiceDateFormat(); break; case AttributeType.Integer: case AttributeType.Boolean: case AttributeType.String: case AttributeType.Text: value = change.Value.ToString(); break; case AttributeType.Reference: value = ((UniqueIdentifier)change.Value).ToString(); break; case AttributeType.Unknown: default: throw new ArgumentException(string.Format("Unknown value type {0}", change.Value.GetType().Name)); } } PutFragmentType fragment = new PutFragmentType(kvp.Key, change.ChangeType, kvp.Key, null, false, value); fragments.Add(fragment); } } return(fragments); }
internal static Message CreateCreateMessage(ResourceObject[] resources) { Create op = new Create(); op.Dialect = Namespaces.RMIdentityAttributeType; if (resources == null || resources.Length == 0) { throw new ArgumentNullException(nameof(resources)); } else if (resources.Length == 1) { return(MessageComposer.CreateCreateMessage(resources[0])); } List <FragmentType> fragments = new List <FragmentType>(); foreach (ResourceObject resource in resources) { foreach (PutFragmentType fragment in resource.GetPutFragements()) { fragment.TargetIdentifier = resource.ObjectID.ToString(false); fragments.Add(fragment); } // Add Object ID PutFragmentType fragmentObjectID = new PutFragmentType( AttributeNames.ObjectID, ModeType.Insert, AttributeNames.ObjectID, null, false, resource.ObjectID.ToString(false)); fragmentObjectID.TargetIdentifier = resource.ObjectID.ToString(false); fragments.Add(fragmentObjectID); } if (fragments.Count == 0) { return(null); } op.Fragments = fragments.ToArray(); Message message = Message.CreateMessage(MessageVersion.Default, Namespaces.Create, new SerializerBodyWriter(op)); message.AddHeader(Namespaces.IdMDirectoryAccess, HeaderConstants.IdentityManagementOperation, null, true); message.AddHeader(Namespaces.ResourceManagement, HeaderConstants.CompositeTypeOperation, null); message.AddHeader(HeaderConstants.ResourceReferenceProperty, resources.Select(t => t.ObjectID.ToString(false)).ToCommaSeparatedString()); return(message); }