Exemplo n.º 1
0
        public static ADRawEntry CreateFrom(SimpleADObject simpleADObject, IEnumerable <PropertyDefinition> properties)
        {
            ArgumentValidator.ThrowIfNull("simpleADObject", simpleADObject);
            ArgumentValidator.ThrowIfNull("properties", properties);
            ADPropertyBag adpropertyBag = new ADPropertyBag();

            SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> properties2 = simpleADObject.Properties;
            SimpleADObject.SimpleADProperty simpleADProperty;
            if (!properties2.TryGetValue(ADObjectSchema.Id.LdapDisplayName, out simpleADProperty))
            {
                throw new InvalidOperationException("dn is missing");
            }
            ValidationError validationError;
            ADObjectId      value = (ADObjectId)ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value as string, ADObjectSchema.Id, false, out validationError);

            adpropertyBag.SetField(ADObjectSchema.Id, value);
            foreach (PropertyDefinition propertyDefinition in properties)
            {
                ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)propertyDefinition;
                SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, adpropertyBag, properties2);
            }
            adpropertyBag.SetField(ADObjectSchema.ObjectState, simpleADObject.ObjectState);
            adpropertyBag.SetObjectVersion(simpleADObject.ExchangeVersion);
            return(new ADRawEntry(adpropertyBag)
            {
                OriginatingServer = simpleADObject.OriginatingServer,
                WhenReadUTC = new DateTime?(simpleADObject.WhenReadUTC),
                DirectoryBackendType = simpleADObject.DirectoryBackendType,
                IsCached = true
            });
        }
Exemplo n.º 2
0
        private static object ConvertSingleValue(SyncPropertyDefinition property, object value, out ValidationError error)
        {
            error = null;
            if (value is XmlValueAssignedPlan)
            {
                return(((XmlValueAssignedPlan)value).Plan);
            }
            if (value is XmlValueCompanyVerifiedDomain)
            {
                return(((XmlValueCompanyVerifiedDomain)value).Domain);
            }
            if (value is XmlValueDirSyncStatus)
            {
                return(SyncValueConvertor.ConvertDirSyncStatusToString(((XmlValueDirSyncStatus)value).DirSyncStatus));
            }
            if (value is AttributeSet)
            {
                return(SyncValueConvertor.ConvertAttributeSetToString((AttributeSet)value));
            }
            if (value is XmlValueValidationError)
            {
                return(((XmlValueValidationError)value).ErrorInfo);
            }
            if (value is XmlValueLicenseUnitsDetail)
            {
                return(SyncValueConvertor.ConvertXmlValueLicenseUnitsDetailToString((XmlValueLicenseUnitsDetail)value));
            }
            if (property == SyncSubscribedPlanSchema.Capability)
            {
                return(((XmlElement)value).OuterXml);
            }
            if (property == SyncCompanySchema.CompanyPartnership)
            {
                return(SyncValueConvertor.ConvertCompanyPartnershipToString((XmlValueCompanyPartnership)value));
            }
            if (property == SyncRecipientSchema.SipAddresses)
            {
                string text = (string)value;
                if (!string.IsNullOrEmpty(text) && !text.StartsWith(ProxyAddressPrefix.SIP.ToString() + ':', StringComparison.OrdinalIgnoreCase))
                {
                    value = ProxyAddressPrefix.SIP.ToString() + ':' + text;
                }
            }
            else
            {
                if (property.Type == typeof(RemoteRecipientType))
                {
                    return((RemoteRecipientType)value);
                }
                if (property.Type == typeof(RecipientTypeDetails))
                {
                    return((RecipientTypeDetails)value);
                }
                if (property.Type == typeof(MailboxAuditOperations))
                {
                    return((MailboxAuditOperations)value);
                }
                if (property.Type == typeof(ElcMailboxFlags))
                {
                    return((ElcMailboxFlags)value);
                }
                if (property.Type == typeof(DateTime?))
                {
                    return((DateTime?)value);
                }
                if (property.Type == typeof(DateTime))
                {
                    return((DateTime)value);
                }
                if (property.Type == typeof(EnhancedTimeSpan))
                {
                    return(TimeSpan.FromSeconds((double)((int)value)));
                }
                if (value is XmlValueRightsManagementTenantConfiguration)
                {
                    return(((XmlValueRightsManagementTenantConfiguration)value).RightsManagementTenantConfiguration);
                }
                if (value is XmlValueRightsManagementTenantKey)
                {
                    return(((XmlValueRightsManagementTenantKey)value).RightsManagementTenantKey);
                }
                if (value is XmlValueServiceInfo)
                {
                    return(((XmlValueServiceInfo)value).Info);
                }
                if (value is int || value is bool)
                {
                    return(value);
                }
                if (value is DirectoryReferenceAddressList)
                {
                    DirectoryReferenceAddressList directoryReferenceAddressList = (DirectoryReferenceAddressList)value;
                    if (!directoryReferenceAddressList.TargetDeleted)
                    {
                        return(new PropertyReference(directoryReferenceAddressList.Value, directoryReferenceAddressList.TargetClass, directoryReferenceAddressList.TargetDeleted));
                    }
                    return(null);
                }
                else if (value is DirectoryReferenceUserAndServicePrincipal)
                {
                    DirectoryReferenceUserAndServicePrincipal directoryReferenceUserAndServicePrincipal = (DirectoryReferenceUserAndServicePrincipal)value;
                    return(directoryReferenceUserAndServicePrincipal.Value);
                }
            }
            bool noConversionRequired = property.Type == typeof(byte[]) || property.Type == typeof(string);

            return(ADValueConvertor.ConvertFromADAndValidateSingleValue(value, property, noConversionRequired, out error));
        }
Exemplo n.º 3
0
        public static TObject CreateFrom <TObject>(SimpleADObject simpleADObject, ADObjectSchema schema, IEnumerable <PropertyDefinition> additionalProperties) where TObject : ADRawEntry, new()
        {
            ArgumentValidator.ThrowIfNull("simpleADObject", simpleADObject);
            if (typeof(TObject).Equals(typeof(ADRawEntry)))
            {
                throw new ArgumentException("TObject cannot be ADRawEntry");
            }
            ADPropertyBag adpropertyBag = new ADPropertyBag();

            SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> properties = simpleADObject.Properties;
            SimpleADObject.SimpleADProperty simpleADProperty;
            if (!properties.TryGetValue(ADObjectSchema.Id.LdapDisplayName, out simpleADProperty))
            {
                throw new InvalidOperationException("dn is missing");
            }
            ValidationError validationError;
            ADObjectId      value = (ADObjectId)ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value as string, ADObjectSchema.Id, false, out validationError);

            adpropertyBag.SetField(ADObjectSchema.Id, value);
            adpropertyBag.SetField(ADObjectSchema.ObjectState, simpleADObject.ObjectState);
            adpropertyBag.SetObjectVersion(simpleADObject.ExchangeVersion);
            TObject tobject = Activator.CreateInstance <TObject>();
            IEnumerable <PropertyDefinition> enumerable;

            if (schema != null)
            {
                enumerable = schema.AllProperties;
            }
            else
            {
                enumerable = ((ADObject)((object)tobject)).Schema.AllProperties;
            }
            if (additionalProperties != null)
            {
                enumerable = enumerable.Concat(additionalProperties);
            }
            foreach (PropertyDefinition propertyDefinition in enumerable)
            {
                ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)propertyDefinition;
                SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, adpropertyBag, properties);
            }
            if (tobject is MiniObject)
            {
                adpropertyBag.SetIsReadOnly(true);
            }
            if (schema != null || (!(tobject is ADRecipient) && !(tobject is MiniRecipient)))
            {
                tobject = (TObject)((object)ADObjectFactory.CreateAndInitializeConfigObject <TObject>(adpropertyBag, tobject, null));
            }
            else
            {
                tobject = (TObject)((object)ADObjectFactory.CreateAndInitializeRecipientObject <TObject>(adpropertyBag, tobject, null));
            }
            tobject.OriginatingServer    = simpleADObject.OriginatingServer;
            tobject.WhenReadUTC          = new DateTime?(simpleADObject.WhenReadUTC);
            tobject.DirectoryBackendType = simpleADObject.DirectoryBackendType;
            tobject.IsCached             = true;
            tobject.ValidateRead();
            tobject.ResetChangeTracking();
            return(tobject);
        }
Exemplo n.º 4
0
        private static void AddPropertyToPropertyBag(ADPropertyDefinition propertyDefinition, PropertyBag propertyBag, SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> lookup)
        {
            if (propertyBag.Contains(propertyDefinition))
            {
                return;
            }
            if (propertyDefinition.IsCalculated)
            {
                foreach (ProviderPropertyDefinition providerPropertyDefinition in propertyDefinition.SupportingProperties)
                {
                    ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)providerPropertyDefinition;
                    SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, propertyBag, lookup);
                }
                return;
            }
            if (string.IsNullOrEmpty(propertyDefinition.LdapDisplayName))
            {
                return;
            }
            SimpleADObject.SimpleADProperty simpleADProperty;
            if (!lookup.TryGetValue(propertyDefinition.LdapDisplayName, out simpleADProperty) || simpleADProperty == null)
            {
                propertyBag.SetField(propertyDefinition, null);
                return;
            }
            if (simpleADProperty.Value == null)
            {
                propertyBag.SetField(propertyDefinition, null);
                return;
            }
            object value5;

            if (propertyDefinition.IsMultivalued)
            {
                ArrayList arrayList     = new ArrayList();
                ArrayList invalidValues = new ArrayList();
                if (propertyDefinition.IsBinary)
                {
                    List <byte[]> list = simpleADProperty.Value as List <byte[]>;
                    if (list == null)
                    {
                        return;
                    }
                    using (List <byte[]> .Enumerator enumerator2 = list.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            byte[]          value = enumerator2.Current;
                            ValidationError validationError;
                            object          value2 = ADValueConvertor.ConvertFromADAndValidateSingleValue(value, propertyDefinition, propertyDefinition.Type == typeof(byte[]), out validationError);
                            arrayList.Add(value2);
                        }
                        goto IL_17F;
                    }
                }
                List <string> list2 = simpleADProperty.Value as List <string>;
                if (list2 == null)
                {
                    return;
                }
                foreach (string value3 in list2)
                {
                    ValidationError validationError2;
                    object          value4 = ADValueConvertor.ConvertFromADAndValidateSingleValue(value3, propertyDefinition, propertyDefinition.Type == typeof(string), out validationError2);
                    arrayList.Add(value4);
                }
IL_17F:
                MultiValuedPropertyBase multiValuedPropertyBase = ADValueConvertor.CreateGenericMultiValuedProperty(propertyDefinition, true, arrayList, invalidValues, null);
                multiValuedPropertyBase.IsCompletelyRead        = true;
                value5 = multiValuedPropertyBase;
            }
            else
            {
                ValidationError validationError3;
                value5 = ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value, propertyDefinition, propertyDefinition.Type == (propertyDefinition.IsBinary ? typeof(byte[]) : typeof(string)), out validationError3);
            }
            propertyBag.SetField(propertyDefinition, value5);
        }