internal virtual Uid Update(ConnectorObject connectorObject) { ConcurrentDictionary <string, Pair <ConnectorObject, DateTime> > storage = GetStore(connectorObject.ObjectClass); Pair <ConnectorObject, DateTime> old; if (storage.TryGetValue(connectorObject.Uid.GetUidValue(), out old)) { if (null != connectorObject.Uid.Revision && !connectorObject.Uid.Revision.Equals(Convert.ToString(old.Second.ToLongTimeString()))) { throw new PreconditionFailedException(); } if (null == connectorObject.Uid.Revision) { throw new PreconditionRequiredException(); } Pair <ConnectorObject, DateTime> item = Pair <ConnectorObject, DateTime> .Of(connectorObject, DateTime.Now); if (!storage.TryUpdate(connectorObject.Uid.GetUidValue(), item, old)) { throw new PreconditionFailedException(); } return(new Uid(connectorObject.Uid.GetUidValue(), Convert.ToString(item.Second.ToLongTimeString()))); } throw new UnknownUidException(connectorObject.Uid, connectorObject.ObjectClass); }
/// <summary> /// helper method for searching object in AD by UID /// </summary> /// <param name="uid">Uid of the searched </param> /// <param name="oclass">Object class</param> /// <param name="options">Operation options</param> /// <returns>Connector object found by the Uid</returns> private ConnectorObject ADSearchByUid(Uid uid, ObjectClass oclass, OperationOptions options) { ExchangeUtility.NullCheck(uid, "uid", this.configuration); ExchangeUtility.NullCheck(oclass, "oclass", this.configuration); if (options == null) { options = new OperationOptionsBuilder().Build(); } ConnectorObject ret = null; Filter filter = FilterBuilder.EqualTo(uid); var translator = base.CreateFilterTranslator(oclass, options); IList <string> queries = translator.Translate(filter); if (queries.Count == 1) { ResultsHandler handler = delegate(ConnectorObject cobject) { ret = cobject; return(false); }; base.ExecuteQuery(oclass, queries[0], handler, options); } return(ret); }
/// <summary> /// Finds the attributes in connector object and rename it according to input array of names, but only /// if the atribute name is in attributes to get /// </summary> /// <param name="cobject">ConnectorObject which attributes should be replaced</param> /// <param name="attsToGet">Attributes to get list</param> /// <param name="map">Replace mapping</param> /// <returns>ConnectorObject with replaced attributes</returns> /// <exception cref="ArgumentNullException">If some of the params is null</exception> internal static ConnectorObject ReplaceAttributes(ConnectorObject cobject, ICollection <string> attsToGet, IDictionary <string, string> map) { Assertions.NullCheck(cobject, "cobject"); Assertions.NullCheck(map, "map"); if (attsToGet == null) { return(cobject); } var attributes = cobject.GetAttributes(); var builder = new ConnectorObjectBuilder(); foreach (ConnectorAttribute attribute in attributes) { string newName; if (map.TryGetValue(attribute.Name, out newName) && attsToGet.Contains(newName)) { var newAttribute = RenameAttribute(attribute, newName); builder.AddAttribute(newAttribute); break; } builder.AddAttribute(attribute); } builder.AddAttributes(attributes); builder.ObjectClass = cobject.ObjectClass; builder.SetName(cobject.Name); builder.SetUid(cobject.Uid); return(builder.Build()); }
public void ExecuteQuery(ObjectClass oclass, String query, ResultsHandler handler, OperationOptions options) { for (int i = 0; i < _config.numResults; i++) { int?delay = (int?)CollectionUtil.GetValue(options.Options, "delay", null); if (delay != null) { Thread.Sleep((int)delay); } ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.SetUid("" + i); builder.SetName(i.ToString()); builder.ObjectClass = oclass; for (int j = 0; j < 50; j++) { builder.AddAttribute("myattribute" + j, "myvaluevaluevalue" + j); } ConnectorObject rv = builder.Build(); if (!handler(rv)) { break; } } }
internal ConnectorObject GetCurrentObject(UpdateOpContext context, string query) { ConnectorObject currentObject = null; LOG.Trace("Fetching object using query {0}", query); ResultsHandler handler = new ResultsHandler() { Handle = cobject => { //LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Object-to-be-modified: {0}", CommonUtils.DumpConnectorAttributes(cobject.GetAttributes())); if (currentObject != null) { throw new InvalidOperationException("More than one object complying with " + query + " was found"); } currentObject = cobject; return(true); } }; ((ExchangeConnector)context.Connector).ExecuteQuery(context.ObjectClass, query, handler, null); if (currentObject == null) { throw new ObjectNotFoundException("Object with UID " + context.Uid.GetUidValue() + " was not found"); } return(currentObject); }
// TODO move to appropriate place /// <summary> /// helper method for searching object in AD by UID /// </summary> /// <param name="uid">Uid of the searched </param> /// <param name="oclass">Object class</param> /// <param name="options">Operation options</param> /// <returns>Connector object found by the Uid</returns> internal ConnectorObject ADSearchByUid(ExchangeConnector connector, Uid uid, ObjectClass oclass, OperationOptions options) { ExchangeConfiguration configuration = connector.Configuration; ExchangeUtility.NullCheck(uid, "uid", configuration); ExchangeUtility.NullCheck(oclass, "oclass", configuration); if (options == null) { options = new OperationOptionsBuilder().Build(); } ConnectorObject ret = null; Filter filter = FilterBuilder.EqualTo(uid); var translator = connector.ActiveDirectoryConnector.CreateFilterTranslator(oclass, options); IList <string> queries = translator.Translate(filter); if (queries.Count == 1) { ResultsHandler handler = new ResultsHandler() { Handle = cobject => { ret = cobject; return(false); } }; connector.ActiveDirectoryConnector.ExecuteQuery(oclass, queries[0], handler, options); } return(ret); }
/// <summary> /// Finds the attributes in connector object and rename it according to input array of names, but only /// if the atribute name is in attributes to get /// </summary> /// <param name="cobject">ConnectorObject which attributes should be replaced</param> /// <param name="map">Replace mapping</param> /// <returns>ConnectorObject with replaced attributes</returns> /// <exception cref="ArgumentNullException">If some of the params is null</exception> internal static ConnectorObject ConvertAdAttributesToExchange(ConnectorObject cobject) { Assertions.NullCheck(cobject, "cobject"); var attributes = cobject.GetAttributes(); var builder = new ConnectorObjectBuilder(); bool emailAddressPolicyEnabled = true; foreach (ConnectorAttribute attribute in attributes) { string newName; if (attribute.Is(ExchangeConnectorAttributes.AttMsExchPoliciesExcludedADName)) { if (attribute.Value != null && attribute.Value.Contains("{26491cfc-9e50-4857-861b-0cb8df22b5d7}")) { emailAddressPolicyEnabled = false; } } else if (attribute.Is(ExchangeConnectorAttributes.AttAddressBookPolicyADName)) { var newAttribute = ExtractCommonName(attribute, ExchangeConnectorAttributes.AttAddressBookPolicy); builder.AddAttribute(newAttribute); builder.AddAttribute(attribute); // keep the original one as well } else if (attribute.Is(ExchangeConnectorAttributes.AttOfflineAddressBookADName)) { var newAttribute = ExtractCommonName(attribute, ExchangeConnectorAttributes.AttOfflineAddressBook); builder.AddAttribute(newAttribute); builder.AddAttribute(attribute); // keep the original one as well } else if (ExchangeConnectorAttributes.AttMapFromAD.TryGetValue(attribute.Name, out newName)) { var newAttribute = RenameAttribute(attribute, newName); builder.AddAttribute(newAttribute); } else { builder.AddAttribute(attribute); } } builder.AddAttribute(ConnectorAttributeBuilder.Build(ExchangeConnectorAttributes.AttEmailAddressPolicyEnabled, emailAddressPolicyEnabled)); copyAttribute(builder, cobject, ExchangeConnectorAttributes.AttPrimarySmtpAddressADName, ExchangeConnectorAttributes.AttPrimarySmtpAddress); // derive recipient type string recipientType = GetRecipientType(cobject); if (recipientType != null) { builder.AddAttribute(ConnectorAttributeBuilder.Build(ExchangeConnectorAttributes.AttRecipientType, new string[] { recipientType })); } builder.ObjectClass = cobject.ObjectClass; builder.SetName(cobject.Name); builder.SetUid(cobject.Uid); return(builder.Build()); }
private static void copyAttribute(ConnectorObjectBuilder builder, ConnectorObject cobject, string src, string dest) { ConnectorAttribute srcAttr = cobject.GetAttributeByName(src); if (srcAttr != null) { builder.AddAttribute(RenameAttribute(srcAttr, dest)); } }
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); * } */ }
public bool ContainsConnector(bool isInput, ConnectorObject connector) { if (isInput) { return(inputConveyors.Contains(connector)); } else { return(outputConveyors.Contains(connector)); } }
public void RemoveConnector(ConnectorObject connector) { if (ContainsConnector(true, connector)) { RemoveConnector(true, connector); } if (ContainsConnector(false, connector)) { RemoveConnector(false, connector); } }
/// <summary> /// Implementation of SearchOp.ExecuteQuery /// </summary> /// <param name="oclass">Object class</param> /// <param name="query">Query to execute</param> /// <param name="handler">Results handler</param> /// <param name="options">Operation options</param> public override void ExecuteQuery( ObjectClass oclass, string query, ResultsHandler handler, OperationOptions options) { ExchangeUtility.NullCheck(oclass, "oclass", this.configuration); // we handle accounts only if (!oclass.Is(ObjectClass.ACCOUNT_NAME)) { base.ExecuteQuery(oclass, query, handler, options); return; } ICollection <string> attsToGet = null; if (options != null && options.AttributesToGet != null) { attsToGet = CollectionUtil.NewList(options.AttributesToGet); } // delegate to get the exchange attributes if requested ResultsHandler filter = delegate(ConnectorObject cobject) { ConnectorObject filtered = ExchangeUtility.ReplaceAttributes( cobject, attsToGet, AttMapFromAD); filtered = this.AddExchangeAttributes(oclass, filtered, attsToGet); return(handler(filtered)); }; ResultsHandler handler2use = handler; OperationOptions options2use = options; if (options != null && options.AttributesToGet != null) { if (attsToGet.Contains(AttDatabase) || attsToGet.Contains(AttExternalMail) || attsToGet.Contains(AttRecipientType)) { // replace Exchange attributes with AD names var newAttsToGet = ExchangeUtility.FilterReplace(attsToGet, AttMap2AD); // we have to remove recipient type, as it is unknown to AD newAttsToGet.Remove(AttRecipientType); // build new op options var builder = new OperationOptionsBuilder(options); string[] attributesToGet = new string[newAttsToGet.Count]; newAttsToGet.CopyTo(attributesToGet, 0); builder.AttributesToGet = attributesToGet; options2use = builder.Build(); handler2use = filter; } } base.ExecuteQuery(oclass, query, handler2use, options2use); }
protected virtual Uid CreateTestUser(string username) { ICollection <ConnectorAttribute> createAttributes = GetTestCreateConnectorObject(username); ConnectorFacade facade = GetFacade(); Uid uid = facade.Create(ObjectClass.ACCOUNT, createAttributes, null); Assert.IsNotNull(uid); ConnectorObject co = facade.GetObject(ObjectClass.ACCOUNT, uid, null); Assert.AreEqual(co.Uid, uid); return(uid); }
internal virtual Uid Create(ConnectorObject connectorObject) { ConcurrentDictionary <string, Pair <ConnectorObject, DateTime> > storage = GetStore(connectorObject.ObjectClass); Pair <ConnectorObject, DateTime> item = Pair <ConnectorObject, DateTime> .Of(connectorObject, DateTime.Now); if (storage.ContainsKey(connectorObject.Uid.GetUidValue())) { throw (new AlreadyExistsException()).InitUid(connectorObject.Uid); } storage.TryAdd(connectorObject.Uid.GetUidValue(), item); return(new Uid(connectorObject.Uid.GetUidValue(), Convert.ToString(item.Second.ToLongTimeString()))); }
public void TestConnectorObject() { ConnectorObjectBuilder bld = new ConnectorObjectBuilder(); bld.SetUid("foo"); bld.SetName("fooToo"); ConnectorObject v1 = bld.Build(); ConnectorObject v2 = (ConnectorObject)CloneObject(v1); Assert.AreEqual(v1, v2); }
public void RemoveConnector(bool isInput, ConnectorObject connector) { if (isInput) { inputConveyors.Remove(connector); } else { outputConveyors.Remove(connector); } UpdateElectricityCost(); }
void ImportConnector(string tempDir, ConnectorObject co, Joint joint) { Component component = ImportComponent(tempDir, co.Component); Connector connector = new Connector(); connector.Component = component; connector.Joint = joint; connector.IsActive = co.IsActive; connector.WallThickness = co.WallThickness; connector.Diameter = co.Diameter; importRepo.ComponentRepo.SaveOrUpdate(component); }
/// <summary> /// Implementation of SynOp.Sync /// </summary> /// <param name="objClass">Object class</param> /// <param name="token">Sync token</param> /// <param name="handler">Sync results handler</param> /// <param name="options">Operation options</param> public override void Sync( ObjectClass objClass, SyncToken token, SyncResultsHandler handler, OperationOptions options) { ExchangeUtility.NullCheck(objClass, "oclass", this.configuration); // we handle accounts only if (!objClass.Is(ObjectClass.ACCOUNT_NAME)) { base.Sync(objClass, token, handler, options); return; } ICollection <string> attsToGet = null; if (options != null && options.AttributesToGet != null) { attsToGet = CollectionUtil.NewSet(options.AttributesToGet); } // delegate to get the exchange attributes if requested SyncResultsHandler xchangeHandler = delegate(SyncDelta delta) { if (delta.DeltaType == SyncDeltaType.DELETE) { return(handler(delta)); } // replace the ad attributes with exchange one and add recipient type ConnectorObject updated = ExchangeUtility.ReplaceAttributes(delta.Object, attsToGet, AttMapFromAD); updated = this.AddExchangeAttributes(objClass, updated, attsToGet); if (updated != delta.Object) { // build new sync delta, cause we changed the object SyncDeltaBuilder deltaBuilder = new SyncDeltaBuilder { DeltaType = delta.DeltaType, Token = delta.Token, Uid = delta.Uid, Object = updated }; delta = deltaBuilder.Build(); } return(handler(delta)); }; // call AD sync, use xchangeHandler base.Sync(objClass, token, xchangeHandler, options); }
/// <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 void testUpdate(ConnectorObject ticker) { if (inputConveyors.Count > 0) { if (inputConveyors[0].ID == ticker.ID) { time += WorldObjectManager.TickDeltaTime; if (time >= (linkerPipeType == PIPETYPE.Electric ? ELECTRIC_PIPE_TIME : MECHANICS_PIPE_TIME)) { time = 0; update(); } } } }
Connector ImportConnector(string tempDir, ConnectorObject co, Component component, Joint joint) { Connector connector = new Connector(); connector.Id = co.Id; connector.IsActive = co.IsActive; connector.WallThickness = co.WallThickness; connector.Diameter = co.Diameter; connector.Component = component; if (co.Joint != null && co.Joint.Id == joint.Id) { connector.Joint = joint; } return(connector); }
public void Sync(SyncOpContext context) { ExchangeConnector exconn = (ExchangeConnector)context.Connector; ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector; ICollection <string> attsToGet = null; if (context.Options != null && context.Options.AttributesToGet != null) { attsToGet = CollectionUtil.NewSet(context.Options.AttributesToGet); } // delegate to get the exchange attributes if requested SyncResultsHandler xchangeHandler = new SyncResultsHandler() { Handle = delta => { if (delta.DeltaType == SyncDeltaType.DELETE) { return(context.SyncResultsHandler.Handle(delta)); } // replace the ad attributes with exchange ones and add recipient type and database (if requested) ConnectorObject updated = ExchangeUtility.ConvertAdAttributesToExchange(delta.Object); //updated = this.AddExchangeAttributes(exconn, context.ObjectClass, updated, attsToGet); if (updated != delta.Object) { // build new sync delta, cause we changed the object SyncDeltaBuilder deltaBuilder = new SyncDeltaBuilder { DeltaType = delta.DeltaType, Token = delta.Token, Uid = delta.Uid, Object = updated }; delta = deltaBuilder.Build(); } return(context.SyncResultsHandler.Handle(delta)); } }; // call AD sync, use xchangeHandler adconn.SyncInternal(context.ObjectClass, context.SyncToken, xchangeHandler, context.Options, GetAdAttributesToReturn(adconn, context.ObjectClass, context.Options)); }
public override InteractResult OnActLeft(InteractionContext context) { // if I target a pipe with the wrench, I transform it to a connector set to input if (context.HasBlock && context.Block is BaseTransportPipeBlock && Utils.SearchForConnectedInventory(context.BlockPosition.Value) != null) { //Removing the block and add the connector World.DeleteBlock(context.BlockPosition.Value); ConnectorObject connector = WorldObjectManager.TryToAdd <ConnectorObject>(context.Player.User, context.BlockPosition.Value, Quaternion.Identity); // If the conenctor can't be added just reset the action if (connector == null) { World.SetBlock(context.Block.GetType(), context.BlockPosition.Value); return(InteractResult.NoOp); } // I instanciate the connector info with the info from the pipe TransportPipeInfo info = null; if (TransportPipeManager.pipesInfo.TryGetValue(context.BlockPosition.Value, out info)) { connector.info = info; context.Player.SendTemporaryMessage($"Set to input"); connector.mode = CONNECTOR_MODE.Input; BurnCalories(context.Player); UseDurability(1.0f, context.Player); return(InteractResult.Success); } else { // If the pipe don't contains any info I recreate the linker from the pipe and reset the action connector.Destroy(); World.SetBlock(context.Block.GetType(), context.BlockPosition.Value); Utils.RecreateLinker(context.BlockPosition.Value, new TransportPipeLinker()); } } // If I use the wrench on a connector if (context.HasTarget && context.Target is ConnectorObject) { // I process the config inside the connector class (context.Target as ConnectorObject).ProcessConfig(context); BurnCalories(context.Player); UseDurability(1.0f, context.Player); return(InteractResult.Success); } return(InteractResult.NoOp); }
public void TestConnectorObject() { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.SetName("myname"); builder.SetUid("myuid"); builder.AddAttribute(CreateTestAttribute()); ConnectorObject v1 = builder.Build(); ConnectorObject v2 = CreateTestNormalizer().NormalizeObject(v1); builder = new ConnectorObjectBuilder(); builder.SetName("myname"); builder.SetUid("myuid"); builder.AddAttribute(CreateNormalizedTestAttribute()); ConnectorObject expected = builder.Build(); Assert.AreEqual(expected, v2); Assert.IsFalse(expected.Equals(v1)); }
public static string GetRecipientType(ConnectorObject cobject) { long?recipientTypeDetails = ExchangeUtility.GetAttValue(ExchangeConnectorAttributes.AttMsExchRecipientTypeDetailsADName, cobject.GetAttributes()) as long?; switch (recipientTypeDetails) // see http://blogs.technet.com/b/benw/archive/2007/04/05/exchange-2007-and-recipient-type-details.aspx { case 1: return(ExchangeConnectorAttributes.RcptTypeMailBox); case 128: return(ExchangeConnectorAttributes.RcptTypeMailUser); case null: // we are dealing with user accounts, so we can assume that an account without Exchange information is an ordinary User case 65536: return(ExchangeConnectorAttributes.RcptTypeUser); default: LOG.Warn("Unknown recipientTypeDetails: {0} ({1})", recipientTypeDetails, ExchangeUtility.GetAttValue(ExchangeConnectorAttributes.AttMsExchRecipientTypeDetailsADName, cobject.GetAttributes())); return(null); } }
static TstAbstractConnector() { bool enabled = true; for (int i = 0; i < 100; i++) { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.SetUid(Convert.ToString(i)); builder.SetName(string.Format("user{0:D3}", i)); builder.AddAttribute(ConnectorAttributeBuilder.BuildEnabled(enabled)); IDictionary <string, object> mapAttribute = new Dictionary <string, object>(); mapAttribute["email"] = "*****@*****.**"; mapAttribute["primary"] = true; mapAttribute["usage"] = new List <String>() { "home", "work" }; builder.AddAttribute("emails", mapAttribute); ConnectorObject co = builder.Build(); collection[co.Name.GetNameValue()] = co; enabled = !enabled; } }
public void TestAttributeTypeMap() { ConnectorPoolManager.Dispose(); ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulConnector"); Assert.IsNotNull(info1); APIConfiguration config = info1.CreateDefaultAPIConfiguration(); config.ConnectorPoolConfiguration.MinIdle = 0; config.ConnectorPoolConfiguration.MaxIdle = 0; ConnectorFacade facade = ConnectorFacadeFactory.GetInstance().NewInstance(config); HashSet <ConnectorAttribute> createAttributes = new HashSet <ConnectorAttribute>(); IDictionary <string, object> mapAttribute = new Dictionary <string, object>(); mapAttribute["email"] = "*****@*****.**"; mapAttribute["primary"] = true; mapAttribute["usage"] = new List <String>() { "home", "work" }; createAttributes.Add(ConnectorAttributeBuilder.Build("emails", mapAttribute)); Uid uid = facade.Create(ObjectClass.ACCOUNT, createAttributes, null); Assert.AreEqual(uid.GetUidValue(), "*****@*****.**"); ConnectorObject co = facade.GetObject(ObjectClass.ACCOUNT, new Uid("0"), null); object value = ConnectorAttributeUtil.GetSingleValue(co.GetAttributeByName("emails")); Assert.IsTrue(value is IDictionary); Assert.IsTrue(((IDictionary)value)["usage"] is IList); }
public void TestSyncDelta() { ConnectorObjectBuilder objbuilder = new ConnectorObjectBuilder(); objbuilder.SetName("myname"); objbuilder.SetUid("myuid"); objbuilder.AddAttribute(CreateTestAttribute()); ConnectorObject obj = objbuilder.Build(); SyncDeltaBuilder builder = new SyncDeltaBuilder(); builder.DeltaType = (SyncDeltaType.DELETE); builder.Token = (new SyncToken("mytoken")); builder.Uid = (new Uid("myuid")); builder.Object = (obj); SyncDelta v1 = builder.Build(); SyncDelta v2 = CreateTestNormalizer().NormalizeSyncDelta(v1); builder = new SyncDeltaBuilder(); builder.DeltaType = (SyncDeltaType.DELETE); builder.Token = (new SyncToken("mytoken")); builder.Uid = (new Uid("myuid")); objbuilder = new ConnectorObjectBuilder(); objbuilder.SetName("myname"); objbuilder.SetUid("myuid"); objbuilder.AddAttribute(CreateNormalizedTestAttribute()); builder.Object = objbuilder.Build(); SyncDelta expected = builder.Build(); Assert.AreEqual(expected, v2); Assert.IsFalse(expected.Equals(v1)); }
/// <summary> /// Gets Recipient Type/Database from Exchange database, this method can be more general, but it is ok /// for out needs /// </summary> /// <param name="oc">object class, currently the moethod works for <see cref="ObjectClass.ACCOUNT"/> only</param> /// <param name="cobject">connector object to get the recipient type/database for</param> /// <param name="attToGet">attributes to get</param> /// <returns>Connector Object with recipient type added</returns> /// <exception cref="ConnectorException">In case of some troubles in powershell (if the /// user is not found we get this exception too)</exception> private ConnectorObject AddExchangeAttributes(ObjectClass oc, ConnectorObject cobject, IEnumerable <string> attToGet) { ExchangeUtility.NullCheck(oc, "name", this.configuration); ExchangeUtility.NullCheck(oc, "cobject", this.configuration); // we support ACCOUNT only or there is nothing to add if (!oc.Is(ObjectClass.ACCOUNT_NAME) || attToGet == null) { return(cobject); } // check it is not deleted object bool?deleted = ExchangeUtility.GetAttValue(AttIsDeleted, cobject.GetAttributes()) as bool?; if (deleted != null && deleted == true) { // do nothing, it is deleted object return(cobject); } ICollection <string> lattToGet = CollectionUtil.NewCaseInsensitiveSet(); CollectionUtil.AddAll(lattToGet, attToGet); foreach (string att in attToGet) { if (cobject.GetAttributeByName(att) != null && att != AttDatabase) { lattToGet.Remove(att); } } if (lattToGet.Count == 0) { return(cobject); } ConnectorObjectBuilder cobjBuilder = new ConnectorObjectBuilder(); cobjBuilder.AddAttributes(cobject.GetAttributes()); PSExchangeConnector.CommandInfo cmdInfo = PSExchangeConnector.CommandInfo.GetUser; // prepare the connector attribute list to get the command ICollection <ConnectorAttribute> attributes = new Collection <ConnectorAttribute> { cobject.Name }; // get the command Command cmd = ExchangeUtility.GetCommand(cmdInfo, attributes, this.configuration); ICollection <PSObject> foundObjects = this.InvokePipeline(cmd); PSObject user = null; if (foundObjects != null && foundObjects.Count == 1) { user = GetFirstElement(foundObjects); foreach (var info in user.Properties) { ConnectorAttribute att = GetAsAttribute(info); if (att != null && lattToGet.Contains(att.Name)) { cobjBuilder.AddAttribute(att); lattToGet.Remove(att.Name); } } if (lattToGet.Count == 0) { return(cobjBuilder.Build()); } } if (user == null) { // nothing to do return(cobject); } string rcptType = user.Members[AttRecipientType].Value.ToString(); foundObjects = null; // get detailed information if (rcptType == RcptTypeMailBox) { foundObjects = this.InvokePipeline(ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.GetMailbox, attributes, this.configuration)); } else if (rcptType == RcptTypeMailUser) { foundObjects = this.InvokePipeline(ExchangeUtility.GetCommand(PSExchangeConnector.CommandInfo.GetMailUser, attributes, this.configuration)); } if (foundObjects != null && foundObjects.Count == 1) { PSObject userDetails = GetFirstElement(foundObjects); foreach (var info in userDetails.Properties) { ConnectorAttribute att = GetAsAttribute(info); if (att != null && lattToGet.Contains(att.Name)) { cobjBuilder.AddAttribute(att); lattToGet.Remove(att.Name); } } } return(cobjBuilder.Build()); }
/// <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); }