public IList <AttributeChange> GetChanges(string dn, ObjectModificationType modType, SchemaType type, object source) { List <AttributeChange> attributeChanges = new List <AttributeChange>(); GroupSettings settings = source as GroupSettings; if (settings == null) { GoogleGroup group = source as GoogleGroup; if (group == null) { throw new InvalidOperationException(); } else { settings = group.Settings; } } 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, settings)); } } } return(attributeChanges); }
public object CreateInstance(CSEntryChange csentry) { GoogleGroup g = new GoogleGroup(); g.Group.Email = csentry.DN; return(g); }
public IList <AttributeChange> ApplyChanges(CSEntryChange csentry, SchemaType type, ref object target, bool patch = false) { GoogleGroup g = (GoogleGroup)target; AttributeChange change = this.ApplyGroupAliasChanges(csentry, g.Group); List <AttributeChange> changes = new List <AttributeChange>(); if (change != null) { changes.Add(change); } return(changes); }
private bool SetDNValue(CSEntryChange csentry, GoogleGroup e) { if (csentry.ObjectModificationType != ObjectModificationType.Replace && csentry.ObjectModificationType != ObjectModificationType.Update) { return(false); } string newDN = csentry.GetNewDNOrDefault <string>(); if (newDN == null) { return(false); } e.Group.Email = newDN; return(true); }
private CSEntryChange GetCSEntryForGroup(GoogleGroup group, Schema schema) { CSEntryChange csentry; if (group.Errors.Count > 0) { csentry = CSEntryChange.Create(); csentry.ObjectType = "group"; csentry.ObjectModificationType = ObjectModificationType.Add; csentry.DN = group.Group.Email; csentry.ErrorCodeImport = MAImportError.ImportErrorCustomContinueRun; csentry.ErrorDetail = group.Errors.FirstOrDefault()?.StackTrace; csentry.ErrorName = group.Errors.FirstOrDefault()?.Message; } else { csentry = ImportProcessor.GetCSEntryChange(group, schema.Types[SchemaConstants.Group], this.config); } return(csentry); }
public IList <AttributeChange> ApplyChanges(CSEntryChange csentry, SchemaType type, ref object target, bool patch = false) { bool hasChanged = false; List <AttributeChange> changes = new List <AttributeChange>(); if (!(target is GoogleGroup group)) { throw new InvalidOperationException(); } if (this.SetDNValue(csentry, group)) { hasChanged = true; } foreach (IAttributeAdapter typeDef in this.SchemaType.AttributeAdapters.Where(t => t.Api == this.Api)) { if (typeDef.UpdateField(csentry, group.Group)) { hasChanged = true; } } if (hasChanged) { GoogleGroup result = new GoogleGroup(); if (csentry.ObjectModificationType == ObjectModificationType.Add) { result.Group = this.config.GroupsService.Add(group.Group); group.Group = result.Group; // Group membership operations fail on newly created groups if processed too quickly System.Threading.Thread.Sleep(1000); } else if (csentry.ObjectModificationType == ObjectModificationType.Replace || csentry.ObjectModificationType == ObjectModificationType.Update) { string id = csentry.GetAnchorValueOrDefault <string>("id"); if (patch) { result.Group = this.config.GroupsService.Patch(id, group.Group); group.Group = result.Group; } else { result.Group = this.config.GroupsService.Update(id, group.Group); group.Group = result.Group; } } else { throw new InvalidOperationException(); } changes.AddRange(this.GetLocalChanges(csentry.DN, csentry.ObjectModificationType, type, result)); } foreach (IApiInterface i in this.internalInterfaces) { foreach (AttributeChange c in i.ApplyChanges(csentry, type, ref target, patch)) { //changes.RemoveAll(t => t.Name == c.Name); changes.Add(c); } } return(changes); }