Build() публичный Метод

public Build ( ) : ConnectorAttribute
Результат ConnectorAttribute
        /// <summary>
        /// Concatenates two attributes' values 
        /// </summary>
        /// <param name="ca1">Must be non null</param>
        /// <param name="ca2">May be null</param>
        /// <returns>new attribute with name of ca1 and value of ca1 + ca2</returns>
        public ConnectorAttribute AttConcat(ConnectorAttribute ca1, ConnectorAttribute ca2)
        {
            ConnectorAttributeBuilder builder = new ConnectorAttributeBuilder();
            Assert.IsNotNull(ca1);
            if (ca2 == null)
            {
                // if the second is null, just build up a dummy one
                ca2 = ConnectorAttributeBuilder.Build(ca1.Name);
            }

            Assert.AreEqual(ca1.Name, ca2.Name);
            builder.Name = ca1.Name;
            builder.AddValue(ca1.Value);
            builder.AddValue(ca2.Value);

            return builder.Build();
        }
Пример #2
0
 public static ConnectorAttribute Build(String name,
     ICollection<object> val)
 {
     ConnectorAttributeBuilder bld = new ConnectorAttributeBuilder();
     bld.Name = name;
     bld.AddValue(val);
     return bld.Build();
 }
Пример #3
0
 public static ConnectorAttribute Build(String name,
     params Object[] args)
 {
     ConnectorAttributeBuilder bld = new ConnectorAttributeBuilder();
     bld.Name = name;
     bld.AddValue(args);
     return bld.Build();
 }
        /// <summary>
        /// Renames the connector attribute to new name
        /// </summary>
        /// <param name="cattribute">ConnectorAttribute to be renamed</param>
        /// <param name="newName">New attribute name</param>
        /// <returns>Renamed ConnectorAttribute</returns>
        /// <exception cref="ArgumentNullException">If some of the params is null</exception>
        internal static ConnectorAttribute RenameAttribute(ConnectorAttribute cattribute, string newName)
        {
            Assertions.NullCheck(cattribute, "cattribute");
            Assertions.NullCheck(newName, "newName");

            var attBuilder = new ConnectorAttributeBuilder();
            attBuilder.AddValue(cattribute.Value);
            attBuilder.Name = newName;
            return attBuilder.Build();
        }
Пример #5
0
        /// <summary>
        /// Renames the connector attribute to new name; transforms value by keeping Common Name only
        /// </summary>
        /// <param name="cattribute">ConnectorAttribute to be renamed</param>
        /// <param name="newName">New attribute name</param>
        /// <returns>Renamed and transformed ConnectorAttribute</returns>
        /// <exception cref="ArgumentNullException">If some of the params is null</exception>
        internal static ConnectorAttribute ExtractCommonName(ConnectorAttribute cattribute, string newName)
        {
            Assertions.NullCheck(cattribute, "cattribute");
            Assertions.NullCheck(newName, "newName");

            var attBuilder = new ConnectorAttributeBuilder();
            if (cattribute.Value != null)
            {
                ICollection<object> convertedValues = new List<object>();
                foreach (object oldValue in cattribute.Value)
                {
                    if (oldValue != null)       // should be always the case
                    {
                        convertedValues.Add(ExtractCommonName(oldValue.ToString()));
                    }
                }
                attBuilder.AddValue(convertedValues);
            }
            attBuilder.Name = newName;
            return attBuilder.Build();
        }
Пример #6
0
        // creates a collection of attributes that correspond to the original ones, but resolves ADD/DELETE using existing values of psuser
        public ICollection<ConnectorAttribute> DetermineNewAttributeValues(UpdateOpContext context, ConnectorObject originalObject)
        {
            if (context.UpdateType == UpdateType.REPLACE)
            {
                // TODO check multivaluedness and updateability (as below)
                return new List<ConnectorAttribute>(context.Attributes);
            }
            else
            {
                Boolean add;
                if (context.UpdateType == UpdateType.ADD)
                {
                    add = true;
                }
                else if (context.UpdateType == UpdateType.DELETE)
                {
                    add = false;
                }
                else
                {
                    throw new ArgumentException("Unsupported update type: " + context.UpdateType);
                }

                Schema schema = null;
                ICollection<ConnectorAttribute> rv = new List<ConnectorAttribute>(context.Attributes.Count);
                foreach (ConnectorAttribute attribute in context.Attributes)
                {
                    ConnectorAttribute originalAttribute = originalObject.GetAttributeByName(attribute.Name);
                    IList<object> newValues = originalAttribute != null && originalAttribute.Value != null ? new List<object>(originalAttribute.Value) : new List<object>();
                    Boolean changed = false;
                    if (attribute.Value != null)
                    {
                        foreach (object item in attribute.Value)
                        {
                            if (add)
                            {
                                if (newValues.Contains(item))
                                {
                                    LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Trying to add value from " + attribute.Name + " that is already there: " + item);
                                }
                                else
                                {
                                    newValues.Add(item);
                                    changed = true;
                                }
                            }
                            else
                            {
                                if (!newValues.Contains(item))
                                {
                                    LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Trying to remove value from " + attribute.Name + " that is not there: " + item);
                                }
                                else
                                {
                                    newValues.Remove(item);
                                    changed = true;
                                }
                            }
                        }
                    }
                    if (changed)
                    {
                        ConnectorAttributeBuilder b = new ConnectorAttributeBuilder();
                        b.Name = attribute.Name;
                        b.AddValue(newValues);
                        ConnectorAttribute modified = b.Build();

                        if (schema == null)
                        {
                            ExchangeConnector connector = (ExchangeConnector)context.Connector;
                            schema = connector.Schema();
                        }
                        ObjectClassInfo oci = schema.FindObjectClassInfo(context.ObjectClass.Type);
                        if (oci == null)
                        {
                            throw new InvalidOperationException("No object class info for " + context.ObjectClass.Type + " in the schema");
                        }
                        var cai = ConnectorAttributeInfoUtil.Find(attribute.Name, oci.ConnectorAttributeInfos);
                        if (cai == null)
                        {
                            throw new InvalidOperationException("No connector attribute info for " + context.ObjectClass.Type + " in the schema");
                        }

                        if (!cai.IsUpdateable)
                        {
                            throw new ConnectorSecurityException("Attempt to update a non-updateable attribute (" + attribute.Name + "): " +
                                CollectionUtil.Dump(newValues));
                        }

                        if (newValues.Count > 1 && !cai.IsMultiValued)
                        {
                            throw new InvalidAttributeValueException("More than one value in a single-valued attribute (" + attribute.Name + "): " +
                                    CollectionUtil.Dump(newValues));
                        }
                        rv.Add(modified);
                    }
                }
                return rv;
            }
        }