static private AddAttributeToOptions ( |
||
options | Existing Operation Options | |
Результат |
/// <summary> /// Implementation of UpdateOp.Update /// </summary> /// <param name="type">Update type</param> /// <param name="oclass">Object class</param> /// <param name="attributes">Object attributes</param> /// <param name="options">Operation options</param> /// <returns>Uid of the updated object</returns> public override Uid Update( UpdateType type, ObjectClass oclass, ICollection <ConnectorAttribute> attributes, OperationOptions options) { const string METHOD = "Update"; Debug.WriteLine(METHOD + ":entry", ClassName); ExchangeUtility.NullCheck(type, "updatetype", this.configuration); ExchangeUtility.NullCheck(oclass, "oclass", this.configuration); ExchangeUtility.NullCheck(attributes, "attributes", this.configuration); // we handle accounts only if (!oclass.Is(ObjectClass.ACCOUNT_NAME)) { return(base.Update(type, oclass, attributes, options)); } // get recipient type and database string rcptType = ExchangeUtility.GetAttValue(AttRecipientType, attributes) as string; string database = ExchangeUtility.GetAttValue(AttDatabase, attributes) as string; // update in AD first var filtered = FilterOut( attributes, PSExchangeConnector.CommandInfo.EnableMailbox, PSExchangeConnector.CommandInfo.EnableMailUser, PSExchangeConnector.CommandInfo.SetMailbox, PSExchangeConnector.CommandInfo.SetMailUser); Uid uid = base.Update(type, oclass, filtered, options); ConnectorObject aduser = this.ADSearchByUid(uid, oclass, ExchangeUtility.AddAttributeToOptions(options, AttDatabaseADName)); attributes.Add(aduser.Name); PSExchangeConnector.CommandInfo cmdInfo = PSExchangeConnector.CommandInfo.GetUser; if (aduser.GetAttributeByName(AttDatabaseADName) != null) { // we can be sure it is user mailbox type cmdInfo = PSExchangeConnector.CommandInfo.GetMailbox; } PSObject psuser = this.GetUser(cmdInfo, attributes); string origRcptType = psuser.Members[AttRecipientType].Value.ToString(); if (String.IsNullOrEmpty(rcptType)) { rcptType = origRcptType; } if (rcptType == RcptTypeMailUser) { if (type == UpdateType.REPLACE) { if (origRcptType != rcptType) { Command cmdEnable = ExchangeUtility.GetCommand( PSExchangeConnector.CommandInfo.EnableMailUser, attributes, this.configuration); this.InvokePipeline(cmdEnable); } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailUser, attributes, this.configuration); this.InvokePipeline(cmdSet); } else { throw new ConnectorException(this.configuration.ConnectorMessages.Format( "ex_wrong_update_type", "Update type [{0}] not supported", type)); } } else if (rcptType == RcptTypeMailBox) { // 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 string origDatabase = psuser.Members[AttDatabase] != null ? psuser.Members[AttDatabase].Value.ToString() : null; if (origRcptType != rcptType) { Command cmdEnable = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.EnableMailbox, attributes, this.configuration); this.InvokePipeline(cmdEnable); } else { // trying to update the database? if (database != null && database != origDatabase) { throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_not_updatable", "Update of [{0}] attribute is not supported", AttDatabase)); } } Command cmdSet = ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.SetMailbox, attributes, this.configuration); this.InvokePipeline(cmdSet); } else if (rcptType == RcptTypeUser && origRcptType != rcptType) { throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_update_notsupported", "Update of [{0}] to [{1}] is not supported", AttRecipientType, rcptType)); } else if (rcptType != RcptTypeUser) { // unsupported rcpt type throw new ArgumentException( this.configuration.ConnectorMessages.Format( "ex_bad_rcpt", "Recipient type [{0}] is not supported", rcptType)); } Debug.WriteLine(METHOD + ":exit", ClassName); return(uid); }