/// <summary> /// Creates a new userDelta with the new password for the given user, then uses /// the given model port to transmit userDelta to Midpoint. /// </summary> /// <param name="modelPort">The model port to transmit new userDelta back to Midpoint.</param> /// <param name="oid">The user ID.</param> /// <param name="newPassword">The new password value.</param> public static void changeUserPassword(modelPortType modelPort, string oid, string newPassword) { XmlDocument doc = new XmlDocument(); ObjectModificationType userDelta = new ObjectModificationType(); userDelta.oid = oid; ItemDeltaType passwordDelta = new ItemDeltaType(); passwordDelta.modificationType = ModificationTypeType.replace; // Set path value - webservices name is apparently 'Any'? passwordDelta.Any = createPathElement("credentials/password", doc); ItemDeltaTypeValue passwordValue = new ItemDeltaTypeValue(); // New passwordValue object so add at first index? passwordValue.Any = new XmlElement[1]; passwordValue.Any.SetValue(toPasswordElement(NS_COMMON, createProtectedString(newPassword), doc), 0); passwordDelta.value = passwordValue; // New userDelta object so add at first index? userDelta.modification = new ItemDeltaType[1]; userDelta.modification.SetValue(passwordDelta, 0); modifyObject request = new modifyObject(getTypeUri(new UserType()), userDelta); modifyObjectResponse response = modelPort.modifyObject(request); System.Console.WriteLine("Result: '" + response.result.status.ToString() + "' for user oid: '" + oid + "'"); }
public IEnumerable <AttributeChange> CreateAttributeChanges(string dn, ObjectModificationType modType, object obj) { if (this.propInfo == null) { this.propInfo = obj.GetType().GetProperty(this.PropertyName); } object value = this.propInfo.GetValue(obj); if (value == null) { yield break; } foreach (AdapterPropertyValue attribute in this.AttributeAdapters) { foreach (AttributeChange change in attribute.CreateAttributeChanges(dn, modType, value)) { yield return(change); } } }
private List <AttributeChange> GetLocalChanges(string dn, ObjectModificationType modType, SchemaType type, object source) { List <AttributeChange> attributeChanges = new List <AttributeChange>(); foreach (IAttributeAdapter typeDef in this.SchemaType.AttributeAdapters.Where(t => t.Api == this.Api)) { if (typeDef.IsAnchor) { continue; } foreach (AttributeChange change in typeDef.CreateAttributeChanges(dn, modType, source)) { if (type.HasAttribute(change.Name)) { attributeChanges.Add(change); } } } return(attributeChanges); }
public void TestCSEntryChangeAttributeDeleteOnObjectAdd() { ObjectModificationType objectModificationType = ObjectModificationType.Add; AcmaSchemaAttribute testAttribute = ActiveConfig.DB.GetAttribute("mailAlternateAddresses"); IList <object> startValues = new List <object>() { "*****@*****.**", "*****@*****.**" }; IList <ValueChange> startValueChanges = new List <ValueChange>(startValues.Select(t => ValueChange.CreateValueAdd(t))); IList <object> changedValues = new List <object>() { "*****@*****.**", "*****@*****.**" }; IList <object> expectedValues = new List <object>() { "*****@*****.**", "*****@*****.**" }; CSEntryChange csentry; // No pending AttributeChanges csentry = CreateNewCSEntry(objectModificationType); csentry.AttributeChanges.DeleteAttribute(objectModificationType, testAttribute); TestAttributeChangeResults(csentry, testAttribute, AttributeModificationType.Unconfigured, null); // With existing attribute add csentry = CreateNewCSEntry(objectModificationType); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(testAttribute.Name, startValues)); csentry.AttributeChanges.DeleteAttribute(objectModificationType, testAttribute); TestAttributeChangeResults(csentry, testAttribute, AttributeModificationType.Unconfigured, null); // With existing attribute update // Invalid // With existing attribute replace // Invalid // With existing attribute delete // Invalid }
public IEnumerable <AttributeChange> CreateAttributeChanges(string dn, ObjectModificationType modType, object obj) { if (this.propInfo == null) { this.propInfo = obj.GetType().GetProperty(this.PropertyName); } IList <T> list = this.GetList(obj); if (list == null) { yield break; } HashSet <string> processedTypes = new HashSet <string>(); foreach (T item in list) { string type = this.GetTypeName(item); if (!processedTypes.Add(type)) { Logger.WriteLine($"Ignoring duplicate type {type} for attribute {this.AttributeName} on object {dn}", LogLevel.Debug); continue; } foreach (AdapterPropertyValue attribute in this.Attributes) { if (attribute.AssignedType == type) { foreach (AttributeChange change in attribute.CreateAttributeChanges(dn, modType, item)) { yield return(change); } } } } }
public IList <AttributeChange> GetChanges(string dn, ObjectModificationType modType, SchemaType type, object source) { GoogleGroup group = source as GoogleGroup; if (group == null) { throw new InvalidOperationException(); } List <AttributeChange> attributeChanges = new List <AttributeChange>(); foreach (IAttributeAdapter typeDef in ManagementAgent.Schema[SchemaConstants.Group].AttributeAdapters.Where(t => t.Api == this.Api)) { foreach (string attributeName in typeDef.MmsAttributeNames) { if (type.HasAttribute(attributeName)) { attributeChanges.AddRange(typeDef.CreateAttributeChanges(dn, modType, group.Group)); } } } return(attributeChanges); }
public void TestCSEntryChangeAttributeUpdateValueChangeRemoveAddDelete() { ObjectModificationType objectModificationType = ObjectModificationType.Update; AcmaSchemaAttribute testAttribute = ActiveConfig.DB.GetAttribute("mailAlternateAddresses"); CSEntryChange csentry; List <ValueChange> startValues = new List <ValueChange>() { ValueChange.CreateValueAdd("*****@*****.**"), ValueChange.CreateValueAdd("*****@*****.**") }; List <ValueChange> changes = new List <ValueChange>() { ValueChange.CreateValueDelete("*****@*****.**") }; List <ValueChange> expectedValues = new List <ValueChange>() { ValueChange.CreateValueAdd("*****@*****.**") }; csentry = CreateNewCSEntry(objectModificationType); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate(testAttribute.Name, startValues)); csentry.AttributeChanges.UpdateAttribute(objectModificationType, testAttribute, changes); TestAttributeChangeResults(csentry, testAttribute, expectedValues); }
/// <summary> /// Creates a new AttributeChange of type 'delete' /// </summary> /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param> /// <param name="attribute">The attribute to create the AttributeChange for</param> private static void CreateAttributeChangeDelete(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute) { switch (objectModificationType) { case ObjectModificationType.Add: // This is a new object, so there is nothing to delete break; case ObjectModificationType.Delete: throw new DeletedObjectModificationException(); case ObjectModificationType.Replace: // This object is being replaced, so the absence of an attribute add implies that any existing attribute values shall be deleted break; case ObjectModificationType.Update: attributeChanges.Add(AttributeChange.CreateAttributeDelete(attribute.Name)); break; case ObjectModificationType.None: case ObjectModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(objectModificationType); } }
/// <summary> /// Converts an existing AttributeChange to a new AttributeChange of type 'delete' /// </summary> /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param> /// <param name="attribute">The attribute to create the AttributeChange for</param> /// <param name="existingChange">The existing attribute change that was found on the CSEntryChange</param> private static void ConvertAttributeChangeToDelete(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, AttributeChange existingChange) { switch (objectModificationType) { case ObjectModificationType.Add: attributeChanges.Remove(existingChange); break; case ObjectModificationType.Delete: throw new DeletedObjectModificationException(); case ObjectModificationType.Replace: attributeChanges.Remove(existingChange); break; case ObjectModificationType.Update: switch (existingChange.ModificationType) { case AttributeModificationType.Add: attributeChanges.Remove(existingChange); break; case AttributeModificationType.Delete: break; case AttributeModificationType.Replace: attributeChanges.Remove(existingChange); Logger.WriteLine("Removed " + existingChange.Name); attributeChanges.Add(AttributeChange.CreateAttributeDelete(attribute.Name)); Logger.WriteLine("Added " + attribute.Name); break; case AttributeModificationType.Update: attributeChanges.Remove(existingChange); attributeChanges.Add(AttributeChange.CreateAttributeDelete(attribute.Name)); break; case AttributeModificationType.Unconfigured: default: break; } break; case ObjectModificationType.Unconfigured: case ObjectModificationType.None: default: throw new UnknownOrUnsupportedModificationTypeException(objectModificationType); } }
/// <summary> /// Converts an existing AttributeChange to a new AttributeChange of type 'replace' /// </summary> /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param> /// <param name="attribute">The attribute to create the AttributeChange for</param> /// <param name="values">The values to assign</param> /// <param name="existingChange">The existing attribute change that was found on the CSEntryChange</param> private static void ConvertAttributeChangeToReplace(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <object> values, AttributeChange existingChange) { TypeConverter.ThrowOnAnyInvalidDataType(values); attributeChanges.Remove(existingChange); switch (objectModificationType) { case ObjectModificationType.Add: attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, values)); break; case ObjectModificationType.Delete: throw new DeletedObjectModificationException(); case ObjectModificationType.Replace: attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, values)); break; case ObjectModificationType.Update: attributeChanges.Add(AttributeChange.CreateAttributeReplace(attribute.Name, values)); break; case ObjectModificationType.Unconfigured: case ObjectModificationType.None: default: break; } }
public static void ExportToXml(IEnumerable <MAObjectHologram> maObjects, XmlWriter writer, ObjectModificationType modificationType) { foreach (MAObjectHologram maObject in maObjects) { CSEntryChangeXmlExport.ExportToXml(maObject, writer, modificationType); } }
public override IEnumerable <AttributeChange> CreateAttributeChanges(string dn, ObjectModificationType modType, object obj) { User user = obj as User; if (user == null) { throw new InvalidOperationException(); } if (!this.HasSchemaField(user)) { yield break; } IDictionary <string, object> schema = this.GetOrCreateSchema(user, out bool created); object value = null; if (schema.ContainsKey(this.FieldName)) { value = schema[this.FieldName]; } if (value == null) { if (modType == ObjectModificationType.Update) { yield return(AttributeChange.CreateAttributeDelete(this.MmsAttributeName)); } yield break; } value = this.ConvertToNativeFimFormat(value); if (modType == ObjectModificationType.Add || modType == ObjectModificationType.Replace) { yield return(AttributeChange.CreateAttributeAdd(this.MmsAttributeName, TypeConverter.ConvertData(value, this.AttributeType))); } else if (modType == ObjectModificationType.Update) { yield return(AttributeChange.CreateAttributeReplace(this.MmsAttributeName, TypeConverter.ConvertData(value, this.AttributeType))); } }
public static void ExportToXml(IEnumerable <MAObjectHologram> maObjects, string fileName, ObjectModificationType modificationType) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineChars = Environment.NewLine; XmlWriter writer = XmlWriter.Create(fileName, settings); writer.WriteStartDocument(); writer.WriteStartElement("acma-export"); ImportExportEngine.ExportToXml(maObjects, writer, modificationType); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); }
public IList <AttributeChange> GetChanges(string dn, ObjectModificationType modType, SchemaType type, object source) { List <AttributeChange> attributeChanges = this.GetLocalChanges(dn, modType, type, source); return(attributeChanges); }
/// <summary> /// Creates a new AttributeChange of type 'update' /// </summary> /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param> /// <param name="attribute">The attribute to create the AttributeChange for</param> /// <param name="valueChanges">The value changes to apply</param> private static void CreateAttributeChangeUpdate(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <ValueChange> valueChanges) { switch (objectModificationType) { case ObjectModificationType.Add: attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, valueChanges.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList <object>())); break; case ObjectModificationType.Delete: throw new DeletedObjectModificationException(); case ObjectModificationType.Replace: attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, valueChanges.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList <object>())); break; case ObjectModificationType.Update: attributeChanges.Add(AttributeChange.CreateAttributeUpdate(attribute.Name, valueChanges)); break; case ObjectModificationType.Unconfigured: case ObjectModificationType.None: default: throw new UnknownOrUnsupportedModificationTypeException(objectModificationType); } }
/// <summary> /// Processes an attribute update request on the specified CSEntryChange /// </summary> /// <param name="csentry">The CSEntryChange to process</param> /// <param name="attribute">The attribute associated with this request</param> /// <param name="valueChanges">The value changes to apply to the attribute</param> public static void UpdateAttribute(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <ValueChange> valueChanges) { if (valueChanges == null) { throw new ArgumentNullException("valueChanges"); } if (!attribute.IsMultivalued && valueChanges.Count(t => t.ModificationType == ValueModificationType.Add) > 1) { throw new TooManyValuesException(attribute.Name); } valueChanges = RemoveDuplicateValueChanges(attribute, valueChanges); if (attributeChanges.Contains(attribute.Name)) { AttributeChange existingChange = attributeChanges[attribute.Name]; switch (existingChange.ModificationType) { case AttributeModificationType.Add: ConvertAttributeChangeUpdateFromAdd(attributeChanges, objectModificationType, attribute, valueChanges, existingChange); break; case AttributeModificationType.Delete: ConvertAttributeChangeUpdateFromDelete(attributeChanges, objectModificationType, attribute, valueChanges, existingChange); break; case AttributeModificationType.Replace: ConvertAttributeChangeUpdateFromReplace(attributeChanges, objectModificationType, attribute, valueChanges, existingChange); break; case AttributeModificationType.Update: ConvertAttributeChangeUpdateFromUpdate(attributeChanges, objectModificationType, attribute, valueChanges, existingChange); break; case AttributeModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(existingChange.ModificationType); } } else { CreateAttributeChangeUpdate(attributeChanges, objectModificationType, attribute, valueChanges); } RemoveAttributeChangeIfEmpty(attributeChanges, attribute.Name); }
/// <summary> /// Initializes a new instance of the UnknownOrUnsupportedModificationTypeException class /// </summary> /// <param name="modificationType">The modification type that was unknown or supported</param> public UnknownOrUnsupportedModificationTypeException(ObjectModificationType modificationType) : base(string.Format("An unknown or unsupported object modification type was used: {0}", modificationType.ToSmartString())) { }
/// <summary> /// Creates a CSEntryChange of the specified modification type for the supplied MAObjectHologram /// </summary> /// <param name="maObject">The MAObjectHologram to create the CSEntryChange from</param> /// <param name="objectModificationType">The object modification type to apply</param> /// <returns>A new CSEntryChange object representing the current state of the specified MAObjectHologram </returns> public static AcmaCSEntryChange CreateCSEntryChangeFromMAObjectHologram(this MAObjectHologram maObject, ObjectModificationType objectModificationType) { AcmaCSEntryChange csentry = new AcmaCSEntryChange(); csentry.ObjectModificationType = objectModificationType; csentry.DN = maObject.ObjectID.ToString(); csentry.ObjectType = maObject.ObjectClass.Name; if (objectModificationType != ObjectModificationType.Delete) { AttributeModificationType attributeModificationType = objectModificationType == ObjectModificationType.Update ? AttributeModificationType.Replace : AttributeModificationType.Add; foreach (AcmaSchemaAttribute attribute in maObject.ObjectClass.Attributes.Where(t => t.Name != "objectId" && t.Name != "objectClass")) { AttributeValues values = maObject.GetAttributeValues(attribute); if (values.IsEmptyOrNull) { continue; } if (attributeModificationType == AttributeModificationType.Add) { AttributeChange change = AttributeChange.CreateAttributeAdd(attribute.Name, values.ToObjectList()); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, values.ToObjectList())); } else { csentry.AttributeChanges.Add(AttributeChange.CreateAttributeReplace(attribute.Name, values.ToObjectList())); } } } if (csentry.ErrorCodeImport == MAImportError.Success) { MAStatistics.AddImportOperation(); } else { MAStatistics.AddImportError(); } return(csentry); }
public abstract IEnumerable <AttributeChange> CreateAttributeChanges(string dn, ObjectModificationType modType, object obj);
private async Task <CSEntryChange> UserToCSEntryChange(bool inDelta, SchemaType schemaType, IUser user, ImportContext context) { Resource profile = user.GetProperty <Resource>("profile"); string login = profile.GetProperty <string>("login"); logger.Trace($"Creating CSEntryChange for {user.Id}/{login}"); ObjectModificationType modType = this.GetObjectModificationType(user, inDelta, context); if (modType == ObjectModificationType.None) { return(null); } CSEntryChange c = CSEntryChange.Create(); c.ObjectType = "user"; c.ObjectModificationType = modType; c.AnchorAttributes.Add(AnchorAttribute.Create("id", user.Id)); c.DN = user.Id; if (modType != ObjectModificationType.Delete) { foreach (SchemaAttribute type in schemaType.Attributes) { if (type.Name == "provider.name") { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, TypeConverter.ConvertData(user.Credentials.Provider.Name, type.DataType))); continue; } else if (type.Name == "provider.type") { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, TypeConverter.ConvertData(user.Credentials.Provider.Type.Value, type.DataType))); continue; } else if (type.Name == "suspended") { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, user.Status == UserStatus.Suspended)); continue; } else if (type.Name == "enrolledFactors") { List <object> items = new List <object>(); foreach (IFactor factor in await user.ListFactors().ToList().ConfigureAwait(false)) { items.Add($"{factor.Provider}/{factor.FactorType}"); } if (items.Count > 0) { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, items)); } continue; } else if (type.Name == "availableFactors") { List <object> items = new List <object>(); foreach (IFactor factor in await user.ListSupportedFactors().ToList().ConfigureAwait(false)) { items.Add($"{factor.Provider}/{factor.FactorType}"); } if (items.Count > 0) { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, items)); } continue; } object value = user.GetProperty <object>(type.Name) ?? profile.GetProperty <object>(type.Name); if (value != null) { if (value is IList list) { IList <object> values = new List <object>(); foreach (object item in list) { values.Add(TypeConverter.ConvertData(item, type.DataType)); } c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, values)); } else { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, TypeConverter.ConvertData(value, type.DataType))); } } } } return(c); }
/// <summary> /// Processes an attribute replace request on the specified CSEntryChange /// </summary> /// <param name="csentry">The CSEntryChange to process</param> /// <param name="attribute">The attribute associated with this request</param> /// <param name="value">The new value to assign to the attribute</param> public static void ReplaceAttribute(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, object value) { ReplaceAttribute(attributeChanges, objectModificationType, attribute, new List <object>() { value }); }
/// <summary> /// Processes an attribute replace request on the specified CSEntryChange /// </summary> /// <param name="csentry">The CSEntryChange to process</param> /// <param name="attribute">The attribute associated with this request</param> /// <param name="values">The new values to assign to the attribute</param> public static void ReplaceAttribute(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <object> values) { if (values == null || values.Count == 0) { DeleteAttribute(attributeChanges, objectModificationType, attribute); return; } if (!attribute.IsMultivalued && values.Count > 1) { throw new TooManyValuesException(attribute.Name); } TypeConverter.ThrowOnAnyInvalidDataType(values); if (attributeChanges.Contains(attribute.Name)) { ConvertAttributeChangeToReplace(attributeChanges, objectModificationType, attribute, values, attributeChanges[attribute.Name]); } else { CreateAttributeChangeReplace(attributeChanges, objectModificationType, attribute, values); } }
private async Task <CSEntryChange> GroupToCSEntryChange(ImportContext context, SchemaType schemaType, IGroup group) { Resource profile = group.GetProperty <Resource>("profile"); logger.Trace($"Creating CSEntryChange for group {group.Id}"); ObjectModificationType modType = this.GetObjectModificationType(group, context.InDelta); if (modType == ObjectModificationType.None) { return(null); } CSEntryChange c = CSEntryChange.Create(); c.ObjectType = "group"; c.ObjectModificationType = modType; c.AnchorAttributes.Add(AnchorAttribute.Create("id", group.Id)); c.DN = group.Id; if (modType == ObjectModificationType.Delete) { return(c); } foreach (SchemaAttribute type in schemaType.Attributes) { if (type.Name == "member") { IList <object> members = new List <object>(); var items = ((OktaConnectionContext)context.ConnectionContext).Client.GetCollection <User>($"/api/v1/groups/{group.Id}/skinny_users"); await items.ForEachAsync(u => members.Add(u.Id)).ConfigureAwait(false); if (modType == ObjectModificationType.Update) { if (members.Count == 0) { c.AttributeChanges.Add(AttributeChange.CreateAttributeDelete(type.Name)); } else { c.AttributeChanges.Add(AttributeChange.CreateAttributeReplace(type.Name, members)); } } else { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, members)); } continue; } object value = group.GetProperty <object>(type.Name) ?? profile.GetProperty <object>(type.Name); if (modType == ObjectModificationType.Update) { if (value == null) { c.AttributeChanges.Add(AttributeChange.CreateAttributeDelete(type.Name)); } else { c.AttributeChanges.Add(AttributeChange.CreateAttributeReplace(type.Name, TypeConverter.ConvertData(value, type.DataType))); } } else { if (value != null) { c.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(type.Name, TypeConverter.ConvertData(value, type.DataType))); } } } return(c); }
public static void ExportToXml(MAObjectHologram maObject, XmlWriter writer, ObjectModificationType modificationType) { CSEntryChange csentry = CSEntryChangeExtensions.CreateCSEntryChangeFromMAObjectHologram(maObject, modificationType); ExportToXml(csentry, writer); }
/// <summary> /// Processes an attribute delete request on the specified CSEntryChange /// </summary> /// <param name="csentry">The CSEntryChange to process</param> /// <param name="attribute">The attribute associated with this request</param> public static void DeleteAttribute(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute) { if (attributeChanges.Contains(attribute.Name)) { ConvertAttributeChangeToDelete(attributeChanges, objectModificationType, attribute, attributeChanges[attribute.Name]); } else { CreateAttributeChangeDelete(attributeChanges, objectModificationType, attribute); } }
public static void ExportToXml(IEnumerable <MAObjectHologram> maObjects, XmlWriter writer, ObjectModificationType modificationType) { foreach (MAObjectHologram maObject in maObjects) { ImportExportEngine.ExportToXml(maObject, writer, modificationType); } }
/// <summary> /// Converts an AttributeChange of type 'update' to a new AttributeChange of type 'update' /// </summary> /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param> /// <param name="attribute">The attribute to create the AttributeChange for</param> /// <param name="valueChanges">The value changes to apply</param> /// <param name="existingChange">The existing attribute change that was found on the CSEntryChange</param> private static void ConvertAttributeChangeUpdateFromUpdate(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <ValueChange> valueChanges, AttributeChange existingChange) { IList <ValueChange> mergedList = MergeValueChangeLists(attribute, existingChange.ValueChanges, valueChanges); attributeChanges.Remove(existingChange); switch (objectModificationType) { case ObjectModificationType.Add: throw new InvalidOperationException("The attribute change type is not valid for the object modification type"); case ObjectModificationType.Delete: throw new DeletedObjectModificationException(); case ObjectModificationType.Replace: throw new InvalidOperationException("The attribute change type is not valid for the object modification type"); case ObjectModificationType.Update: attributeChanges.Add(AttributeChange.CreateAttributeUpdate(attribute.Name, mergedList)); break; case ObjectModificationType.None: case ObjectModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(objectModificationType); } }
/// <summary> /// Converts an AttributeChange of type 'add' to a new AttributeChange of type 'update' /// </summary> /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param> /// <param name="attribute">The attribute to create the AttributeChange for</param> /// <param name="valueChanges">The value changes to apply</param> /// <param name="existingChange">The existing attribute change that was found on the CSEntryChange</param> private static void ConvertAttributeChangeUpdateFromAdd(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <ValueChange> valueChanges, AttributeChange existingChange) { IList <ValueChange> mergedList = MergeValueChangeLists(attribute, existingChange.ValueChanges, valueChanges); //if (mergedList.Count == 0) //{ // return; //} //if (mergedList.ContainsSameElements(attributeChanges[attribute.Name].ValueChanges) && attributeChanges[attribute.Name].ModificationType == AttributeModificationType.Update) //{ // return; //} attributeChanges.Remove(existingChange); switch (objectModificationType) { case ObjectModificationType.Add: attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, mergedList.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList())); break; case ObjectModificationType.Delete: throw new DeletedObjectModificationException(); case ObjectModificationType.Replace: attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, mergedList.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList())); break; case ObjectModificationType.Update: attributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, mergedList.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList())); break; case ObjectModificationType.None: case ObjectModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(objectModificationType); } }
public IEnumerable <AttributeChange> CreateAttributeChanges(string dn, ObjectModificationType modType, object obj) { throw new NotImplementedException(); }
public void TestCSEntryChangeSplitCSEntry() { ObjectModificationType objectModificationType = ObjectModificationType.Add; AcmaSchemaAttribute testAttribute1 = ActiveConfig.DB.GetAttribute("supervisor"); AcmaSchemaAttribute testAttribute2 = ActiveConfig.DB.GetAttribute("accountName"); CSEntryChange csentry; Guid reference = Guid.NewGuid(); csentry = CreateNewCSEntry(objectModificationType); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(testAttribute1.Name, reference)); csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(testAttribute2.Name, "testuser")); List <CSEntryChange> changes = CSEntryChangeExtensions.SplitReferenceUpdatesFromCSEntryChangeAdd(csentry).ToList(); if (changes.Count != 2) { Assert.Fail("The operation did not return the correct number of CSEntryChangeObjects"); } CSEntryChange addChange = changes[0]; if (addChange.ObjectModificationType != ObjectModificationType.Add) { Assert.Fail("The operation did not correct set the object modification type"); } if (addChange.AttributeChanges.Count != 1) { Assert.Fail("The operation did not return the correct number of attribute changes"); } if (addChange.AttributeChanges[0].Name != testAttribute2.Name) { Assert.Fail("The operation did not correctly split the reference attributes from the CSEntryChange"); } if (addChange.AttributeChanges[0].ValueChanges[0].Value.ToString() != "testuser") { Assert.Fail("The operation did not correctly update the attribute change with the correct value"); } CSEntryChange updateChange = changes[1]; if (updateChange.ObjectModificationType != ObjectModificationType.Update) { Assert.Fail("The operation did not correct set the object modification type"); } if (updateChange.AttributeChanges.Count != 1) { Assert.Fail("The operation did not return the correct number of attribute changes"); } if (updateChange.AttributeChanges[0].Name != testAttribute1.Name) { Assert.Fail("The operation did not correctly split the reference attributes from the CSEntryChange"); } if (updateChange.AttributeChanges[0].ValueChanges[0].Value.ToString() != reference.ToString()) { Assert.Fail("The operation did not correctly update the attribute change with the correct value"); } }
/// <summary> /// Converts an AttributeChange of type 'delete' to a new AttributeChange of type 'update' /// </summary> /// <param name="csentry">The CSEntryChange to apply the AttributeChange to</param> /// <param name="attribute">The attribute to create the AttributeChange for</param> /// <param name="valueChanges">The value changes to apply</param> /// <param name="existingChange">The existing attribute change that was found on the CSEntryChange</param> private static void ConvertAttributeChangeUpdateFromDelete(this KeyedCollection <string, AttributeChange> attributeChanges, ObjectModificationType objectModificationType, AcmaSchemaAttribute attribute, IList <ValueChange> valueChanges, AttributeChange existingChange) { attributeChanges.Remove(existingChange); IList <object> valueAdds = valueChanges.Where(t => t.ModificationType == ValueModificationType.Add).Select(t => t.Value).ToList(); switch (objectModificationType) { case ObjectModificationType.Add: throw new InvalidOperationException("The attribute change type is not valid for the object modification type"); case ObjectModificationType.Delete: throw new DeletedObjectModificationException(); case ObjectModificationType.Replace: throw new InvalidOperationException("The attribute change type is not valid for the object modification type"); case ObjectModificationType.Update: attributeChanges.Add(AttributeChange.CreateAttributeReplace(attribute.Name, valueAdds)); break; case ObjectModificationType.None: case ObjectModificationType.Unconfigured: default: throw new UnknownOrUnsupportedModificationTypeException(objectModificationType); } }