static private SetAttValue ( string attName, object attValue, ICollection |
||
attName | string | attribute name |
attValue | object | attribute value (if null, we will remove the attribute from the collection) |
attributes | ICollection |
collection of attribute |
Результат | void |
public void Update(UpdateOpContext context) { ExchangeConnector exconn = (ExchangeConnector)context.Connector; ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector; // update in AD first var filtered = ExchangeUtility.FilterOut( context.Attributes, PSExchangeConnector.CommandInfo.EnableMailbox, PSExchangeConnector.CommandInfo.EnableMailUser, PSExchangeConnector.CommandInfo.SetMailbox, PSExchangeConnector.CommandInfo.SetMailUser); adconn.Update(context.UpdateType, context.ObjectClass, context.Uid, filtered, context.Options); // retrieve Exchange-related information about the user string query = "(objectGUID=" + ActiveDirectoryUtils.ConvertUIDToSearchString(context.Uid) + ")"; ConnectorObject currentObject = _helper.GetCurrentObject(context, query); ICollection <ConnectorAttribute> attributesForReplace = _helper.DetermineNewAttributeValues(context, currentObject); attributesForReplace = DeduplicateEmailAddresses(context, attributesForReplace); string origRcptType; var newRcptType = _helper.DetermineOrigAndNewAttributeValue(context, currentObject, attributesForReplace, ExchangeConnectorAttributes.AttRecipientType, out origRcptType); if (newRcptType == null) { newRcptType = ExchangeConnectorAttributes.RcptTypeUser; } string origDatabase; var newDatabase = _helper.DetermineOrigAndNewAttributeValue(context, currentObject, attributesForReplace, ExchangeConnectorAttributes.AttDatabase, out origDatabase); // PART 1 - DEALING WITH MailUser CASE if (ExchangeConnectorAttributes.RcptTypeMailUser.Equals(newRcptType)) { // disabling Mailbox if needed if (ExchangeConnectorAttributes.RcptTypeMailBox.Equals(origRcptType)) { Command cmdDisable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.DisableMailbox, attributesForReplace, context.Uid, exconn.Configuration); cmdDisable.Parameters.Add("Confirm", false); _helper.InvokePipeline(exconn, cmdDisable); } // enabling MailUser if needed if (!ExchangeConnectorAttributes.RcptTypeMailUser.Equals(origRcptType)) { // Enable-MailUser needs the value of ExternalEmailAddress, so we have to get it string origExternalEmailAddress; var newExternalEmailAddress = _helper.DetermineOrigAndNewAttributeValue(context, currentObject, attributesForReplace, ExchangeConnectorAttributes.AttExternalEmailAddress, out origExternalEmailAddress); if (String.IsNullOrEmpty(newExternalEmailAddress)) { throw new InvalidOperationException("Missing ExternalEmailAddress value, which is required for a MailUser"); } ExchangeUtility.SetAttValue(ExchangeConnectorAttributes.AttExternalEmailAddress, newExternalEmailAddress, attributesForReplace); // now execute the Enable-MailUser command Command cmdEnable = ExchangeUtility.GetCommand( PSExchangeConnector.CommandInfo.EnableMailUser, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdEnable); } // setting MailUser attributes Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailUser, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdSet); } // PART 2 - DEALING WITH UserMailbox CASE else if (ExchangeConnectorAttributes.RcptTypeMailBox.Equals(newRcptType)) { // enable mailbox if necessary // we should execute something like this here: // get-user -identity id|?{$_.RecipientType -eq "User"}|enable-mailbox -database "db" // unfortunately I was not able to get it working with the pipeline... that's why there are two commands // executed :-( // alternatively there can be something like: // get-user -identity id -RecipientTypeDetails User|enable-mailbox -database "db", but we have then trouble // with detecting attempt to change the database attribute if (!ExchangeConnectorAttributes.RcptTypeMailBox.Equals(origRcptType)) { Command cmdEnable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.EnableMailbox, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdEnable); } else { // are we trying to update the database? if (newDatabase != null && origDatabase != null && !newDatabase.Equals(origDatabase)) { throw new ArgumentException( context.ConnectorConfiguration.ConnectorMessages.Format( "ex_not_updatable", "Update of [{0}] attribute is not supported", ExchangeConnectorAttributes.AttDatabase)); } } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailbox, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdSet); } // PART 3 - DEALING WITH User CASE else if (ExchangeConnectorAttributes.RcptTypeUser.Equals(newRcptType)) { if (ExchangeConnectorAttributes.RcptTypeMailBox.Equals(origRcptType)) { Command cmdDisable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.DisableMailbox, attributesForReplace, context.Uid, exconn.Configuration); cmdDisable.Parameters.Add("Confirm", false); _helper.InvokePipeline(exconn, cmdDisable); } else if (ExchangeConnectorAttributes.RcptTypeMailUser.Equals(origRcptType)) { Command cmdDisable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.DisableMailUser, attributesForReplace, context.Uid, exconn.Configuration); cmdDisable.Parameters.Add("Confirm", false); _helper.InvokePipeline(exconn, cmdDisable); } else if (ExchangeConnectorAttributes.RcptTypeUser.Equals(origRcptType)) { // if orig is User, there is no need to disable anything } else { throw new InvalidOperationException("Invalid original recipient type: " + origRcptType); } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetUser, attributesForReplace, context.Uid, exconn.Configuration); _helper.InvokePipeline(exconn, cmdSet); } else { // unsupported rcpt type throw new ArgumentException( context.ConnectorConfiguration.ConnectorMessages.Format( "ex_bad_rcpt", "Recipient type [{0}] is not supported", newRcptType)); } }