public string DetermineOrigAndNewAttributeValue(UpdateOpContext context, ConnectorObject origObject, ICollection <ConnectorAttribute> attributesForReplace, string attributeName, out string origAttributeValue) { ConnectorAttribute originalAttribute = origObject.GetAttributeByName(attributeName); if (originalAttribute != null) { origAttributeValue = ConnectorAttributeUtil.GetAsStringValue(originalAttribute); } else { origAttributeValue = null; } ConnectorAttribute newAttribute = ConnectorAttributeUtil.Find(attributeName, attributesForReplace); if (newAttribute != null) { return(ConnectorAttributeUtil.GetAsStringValue(newAttribute)); } else { return(origAttributeValue); } /* * string deltaValue = ConnectorAttributeUtil.GetAsStringValue(attribute); * if (attribute == null) { * return origAttributeValue; * } * switch (context.UpdateType) { * case UpdateType.ADD: * if (deltaValue == null) { * return origAttributeValue; * } * if (origAttributeValue != null && !origAttributeValue.Equals(deltaValue)) { * throw new ArgumentException("Multiple values for " + attribute.Name + " are not allowed: existing = " + origAttributeValue + ", one being added = " + deltaValue); * } else { * return deltaValue; * } * case UpdateType.REPLACE: * return deltaValue; * case UpdateType.DELETE: * if (deltaValue == null) { * return origAttributeValue; * } * if (origAttributeValue == null || !origAttributeValue.Equals(deltaValue)) { * LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Trying to remove value from " + attribute.Name + " that is not there: " + deltaValue); * return origAttributeValue; * } else { * return null; * } * default: * throw new ArgumentException("Invalid update type: " + context.UpdateType); * } */ }
/// <summary> /// This will do a basic replace. /// </summary> /// /// <seealso cref="UpdateOp.Update"/> /// public Uid Update(ObjectClass objclass, Uid uid, ICollection <ConnectorAttribute> attrs, OperationOptions options) { string val = ConnectorAttributeUtil.GetAsStringValue(uid); int idx = Convert.ToInt32(val); //.Get out the object.. ConnectorObject baseObject = objects[idx]; ConnectorObjectBuilder bld = new ConnectorObjectBuilder(); bld.Add(baseObject); bld.AddAttributes(attrs); ConnectorObject obj = bld.Build(); objects[idx] = obj; return(obj.Uid); }
public Uid Create(ObjectClass objClass, ICollection <ConnectorAttribute> attrs, OperationOptions options) { StringBuilder sb = new StringBuilder(); ConnectorAttribute NameAttribute = ConnectorAttributeUtil.Find(Name.NAME, attrs); if (NameAttribute == null) { throw new ConnectorException("The name operational attribute cannot be null"); } string parameter = ConnectorAttributeUtil.GetAsStringValue(NameAttribute); string[] login = parameter.Split('@'); PowerShell PowerShellInstance = PowerShell.Create(); PowerShellInstance.AddCommand(this.config.createScript + "create.ps1"); PowerShellInstance.AddArgument(login[0]); Collection <PSObject> results; Collection <ErrorRecord> errors; results = PowerShellInstance.Invoke(); errors = PowerShellInstance.Streams.Error.ReadAll(); if (errors.Count > 0) { foreach (ErrorRecord error in errors) { sb.AppendLine(error.ToString()); } throw new ConnectorException(sb.ToString()); } else { return(new Uid(ConnectorAttributeUtil.GetAsStringValue(NameAttribute))); } }
public Uid Update(ObjectClass objclass, Uid uid, ICollection <ConnectorAttribute> replaceAttributes, OperationOptions options) { StringBuilder sb = new StringBuilder(); PowerShell PowerShellInstance = PowerShell.Create(); ConnectorAttribute StatusAttribute = ConnectorAttributeUtil.Find(OperationalAttributes.ENABLE_NAME, replaceAttributes); String enable = ConnectorAttributeUtil.GetAsStringValue(StatusAttribute).ToLower(); string parameter = ConnectorAttributeUtil.GetAsStringValue(uid); string[] login = parameter.Split('@'); if (enable.Equals("false")) { PowerShellInstance.AddCommand(this.config.createScript + "disable.ps1"); PowerShellInstance.AddArgument(login[0]); Collection <PSObject> results; Collection <ErrorRecord> errors; results = PowerShellInstance.Invoke(); errors = PowerShellInstance.Streams.Error.ReadAll(); if (errors.Count > 0) { foreach (ErrorRecord error in errors) { sb.AppendLine(error.ToString()); } throw new ConnectorException(sb.ToString()); } else { return(uid); } } else if (enable.Equals("true")) { PowerShellInstance.AddCommand(this.config.createScript + "enable.ps1"); PowerShellInstance.AddArgument(login[0]); Collection <PSObject> results; Collection <ErrorRecord> errors; results = PowerShellInstance.Invoke(); errors = PowerShellInstance.Streams.Error.ReadAll(); if (errors.Count > 0) { foreach (ErrorRecord error in errors) { sb.AppendLine(error.ToString()); } throw new ConnectorException(sb.ToString()); } else { return(uid); } } else { return(uid); } }