Example #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
            });
        }
Example #2
0
        internal void SetProperties(ADObject server)
        {
            ADPropertyBag adpropertyBag = new ADPropertyBag();

            adpropertyBag.SetIsReadOnly(false);
            foreach (PropertyDefinition propertyDefinition in this.Schema.AllProperties)
            {
                ADPropertyDefinition key = (ADPropertyDefinition)propertyDefinition;
                object value             = server.propertyBag.Contains(key) ? server.propertyBag[key] : null;
                adpropertyBag.SetField(key, value);
            }
            MultiValuedProperty <string> multiValuedProperty = adpropertyBag[ADObjectSchema.ObjectClass] as MultiValuedProperty <string>;

            if (multiValuedProperty == null || multiValuedProperty.Count == 0)
            {
                multiValuedProperty = new MultiValuedProperty <string>(this.MostDerivedObjectClass);
                adpropertyBag.SetField(ADObjectSchema.ObjectClass, multiValuedProperty);
            }
            if (adpropertyBag[ADObjectSchema.WhenChangedUTC] == null)
            {
                DateTime utcNow = DateTime.UtcNow;
                adpropertyBag.SetField(ADObjectSchema.WhenChangedUTC, utcNow);
                adpropertyBag.SetField(ADObjectSchema.WhenCreatedUTC, utcNow);
            }
            adpropertyBag.SetIsReadOnly(true);
            this.propertyBag = adpropertyBag;
        }
Example #3
0
        // Token: 0x06000E78 RID: 3704 RVA: 0x00045564 File Offset: 0x00043764
        private static ADRawEntry ADRawEntryFromPropValues(ADObjectId id, bool createReadOnly, PropValue[] propValues, IEnumerable <MbxPropertyDefinition> properties, List <ValidationError> errors)
        {
            string        fqdn          = LocalServerCache.LocalServer.Fqdn;
            ADPropertyBag adpropertyBag = new ADPropertyBag(createReadOnly, 16);

            adpropertyBag.SetField(ADObjectSchema.Id, id);
            foreach (PropValue propValue in propValues)
            {
                if (!propValue.IsError())
                {
                    MbxPropertyDefinition   mbxPropertyDefinition   = ObjectSchema.GetInstance <MbxRecipientSchema>().FindPropertyDefinitionByPropTag(propValue.PropTag);
                    PropertyValidationError propertyValidationError = mbxPropertyDefinition.ValidateValue(propValue.Value, true);
                    if (propertyValidationError != null)
                    {
                        errors.Add(propertyValidationError);
                    }
                    adpropertyBag.SetField(mbxPropertyDefinition, SimpleStoreValueConverter.ConvertValueFromStore(mbxPropertyDefinition, propValue.Value));
                }
            }
            MbxRecipientSession.PopulateCustomizedCalculatedProperties(adpropertyBag, properties);
            ADRawEntry adrawEntry = new ADRawEntry(adpropertyBag);

            adrawEntry.OriginatingServer = fqdn;
            adrawEntry.WhenReadUTC       = new DateTime?(DateTime.UtcNow);
            adrawEntry.ResetChangeTracking(true);
            return(adrawEntry);
        }
Example #4
0
        internal static MiniVirtualDirectory CreateFrom(ADObject virtualDirectory, ICollection <PropertyDefinition> propertyDefinitions, object[] propertyValues)
        {
            MiniVirtualDirectory             miniVirtualDirectory = new MiniVirtualDirectory();
            IEnumerable <PropertyDefinition> allProperties        = miniVirtualDirectory.Schema.AllProperties;
            ADPropertyBag adpropertyBag = new ADPropertyBag();

            adpropertyBag.SetIsReadOnly(false);
            foreach (PropertyDefinition propertyDefinition in allProperties)
            {
                ADPropertyDefinition key = (ADPropertyDefinition)propertyDefinition;
                object value             = virtualDirectory.propertyBag.Contains(key) ? virtualDirectory.propertyBag[key] : null;
                adpropertyBag.SetField(key, value);
            }
            MultiValuedProperty <string> multiValuedProperty = adpropertyBag[ADObjectSchema.ObjectClass] as MultiValuedProperty <string>;

            if (multiValuedProperty == null || multiValuedProperty.Count == 0)
            {
                multiValuedProperty = new MultiValuedProperty <string>(virtualDirectory.MostDerivedObjectClass);
                adpropertyBag.SetField(ADObjectSchema.ObjectClass, multiValuedProperty);
            }
            if (adpropertyBag[ADObjectSchema.WhenChangedUTC] == null)
            {
                DateTime utcNow = DateTime.UtcNow;
                adpropertyBag.SetField(ADObjectSchema.WhenChangedUTC, utcNow);
                adpropertyBag.SetField(ADObjectSchema.WhenCreatedUTC, utcNow);
            }
            if (propertyDefinitions != null && propertyValues != null)
            {
                adpropertyBag.SetProperties(propertyDefinitions, propertyValues);
            }
            adpropertyBag.SetIsReadOnly(true);
            miniVirtualDirectory.propertyBag = adpropertyBag;
            return(miniVirtualDirectory);
        }
Example #5
0
        public ADRawEntry Convert(IList <PropValue> properties)
        {
            ADPropertyBag adpropertyBag = new ADPropertyBag();
            Guid          guid          = Guid.Empty;

            for (int i = 0; i < properties.Count; i++)
            {
                ADPropertyDefinition adpropertyDefinition = this.adProperties[i];
                object obj = this.ConvertValue(adpropertyDefinition, properties[i]);
                if (adpropertyDefinition == NspiPropertyMap.objectGuidPropertyDefinition)
                {
                    guid = (Guid)obj;
                }
                else
                {
                    adpropertyBag.SetField(adpropertyDefinition, obj);
                }
            }
            adpropertyBag.SetField(ADObjectSchema.Id, new ADObjectId(guid));
            return(new ADRawEntry(adpropertyBag));
        }
        public static ADRawEntry PerformADLookup(ADObjectId identity, List <ADPropertyDefinition> properties)
        {
            ADUser        aduser        = (ADUser)TemplateTenantConfiguration.GetLocalTempateUser().Clone();
            ADPropertyBag adpropertyBag = new ADPropertyBag();

            foreach (ADPropertyDefinition adpropertyDefinition in properties)
            {
                adpropertyBag.SetField(adpropertyDefinition, aduser[adpropertyDefinition]);
                if (adpropertyDefinition.IsCalculated)
                {
                    foreach (ProviderPropertyDefinition providerPropertyDefinition in adpropertyDefinition.SupportingProperties)
                    {
                        ADPropertyDefinition adpropertyDefinition2 = (ADPropertyDefinition)providerPropertyDefinition;
                        adpropertyBag.SetField(adpropertyDefinition2, aduser[adpropertyDefinition2]);
                    }
                }
            }
            ADRawEntry adrawEntry = new ADRawEntry(adpropertyBag);

            adrawEntry.SetId(identity);
            adrawEntry.ValidateRead();
            adrawEntry.ResetChangeTracking(true);
            return(adrawEntry);
        }
Example #7
0
        // Token: 0x06000EFF RID: 3839 RVA: 0x000484C4 File Offset: 0x000466C4
        private ADRawEntry ADRawEntryFromMservRecords(ulong puid, IList <MservRecord> mservRecords, IEnumerable <MServPropertyDefinition> properties, string originatingServerName, List <ValidationError> errors)
        {
            ADObjectId    adobjectIdFromPuid = ConsumerIdentityHelper.GetADObjectIdFromPuid(puid);
            ADPropertyBag adpropertyBag      = new ADPropertyBag(this.isReadOnly, 16);

            adpropertyBag.SetField(ADObjectSchema.Id, adobjectIdFromPuid);
            adpropertyBag.SetField(MServRecipientSchema.Puid, puid);
            foreach (MservRecord mservRecord in mservRecords)
            {
                object value = mservRecord;
                ProviderPropertyDefinition providerPropertyDefinition;
                switch (mservRecord.ResourceId)
                {
                case 0:
                    if (mservRecord.SourceKey == null)
                    {
                        providerPropertyDefinition = MServRecipientSchema.MservPrimaryRecord;
                    }
                    else
                    {
                        providerPropertyDefinition = MServRecipientSchema.MservEmailAddressesRecord;
                        value = new MultiValuedProperty <MservRecord>
                        {
                            mservRecord
                        };
                    }
                    break;

                case 1:
                    providerPropertyDefinition = MServRecipientSchema.MservSoftDeletedPrimaryRecord;
                    break;

                case 2:
                case 3:
                case 5:
                case 6:
                    goto IL_D0;

                case 4:
                    providerPropertyDefinition = MServRecipientSchema.MservCalendarRecord;
                    break;

                case 7:
                    providerPropertyDefinition = MServRecipientSchema.MservSecondaryRecord;
                    break;

                case 8:
                    providerPropertyDefinition = MServRecipientSchema.MservSoftDeletedCalendarRecord;
                    break;

                default:
                    goto IL_D0;
                }
                PropertyValidationError propertyValidationError = providerPropertyDefinition.ValidateValue(value, true);
                if (propertyValidationError != null)
                {
                    errors.Add(propertyValidationError);
                }
                adpropertyBag.SetField(providerPropertyDefinition, value);
                continue;
IL_D0:
                throw new NotSupportedException("Unexpected record received:" + mservRecord.ToString());
            }
            ADRawEntry adrawEntry = new ADRawEntry(adpropertyBag);

            adrawEntry.OriginatingServer = originatingServerName;
            adrawEntry.WhenReadUTC       = new DateTime?(DateTime.UtcNow);
            adrawEntry.IsCached          = false;
            adrawEntry.ValidateRead(errors, properties);
            adrawEntry.ResetChangeTracking(true);
            return(adrawEntry);
        }
Example #8
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);
        }
Example #9
0
        private IEnumerable <ADRawEntry> ReadSpecialObjects()
        {
            ADObjectId exchangeServiceObject = base.RootOrgConfigurationSession.ConfigurationNamingContext.GetChildId("Services").GetChildId("Microsoft Exchange");
            int        numberOfLinksToRead   = 1500;
            int        rangeStart            = 0;
            int        rangeEnd = rangeStart + numberOfLinksToRead - 1;

            ADPropertyDefinition[] propertiesToRetrieve = new ADPropertyDefinition[]
            {
                ADObjectSchema.Id
            };
            ADObjectId configUnitDn = new ADObjectId(this.PageToken.TenantConfigUnitObjectGuid);
            ADRawEntry dnResolve    = base.TenantConfigurationSession.ReadADRawEntry(configUnitDn, propertiesToRetrieve);

            configUnitDn = dnResolve.Id;
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <ADObjectId>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects tenant CU DN = {0}", configUnitDn);
            MultiValuedProperty <LinkMetadata> resultValues = new MultiValuedProperty <LinkMetadata>();
            ADRawEntry entry       = null;
            long       maxEntryUSN = 0L;
            bool       done        = false;

            while (!done)
            {
                ADPropertyDefinition      adpropertyDefinition = RangedPropertyHelper.CreateRangedProperty(ADRecipientSchema.LinkMetadata, new IntRange(rangeStart, rangeEnd));
                List <PropertyDefinition> list = new List <PropertyDefinition>();
                list.Add(adpropertyDefinition);
                list.Add(ADRecipientSchema.UsnChanged);
                entry = base.RootOrgConfigurationSession.RetrieveTenantRelocationSyncObject(exchangeServiceObject, list);
                ExTraceGlobals.TenantRelocationTracer.TraceDebug <string>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects object read: {0}", entry.Id.DistinguishedName);
                if ((long)entry[ADRecipientSchema.UsnChanged] < this.PageToken.SpecialObjectsUSN)
                {
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug <object, long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects USNChanged({0} < this.PageToken.SpecialObjectsUSN({1})", entry[ADRecipientSchema.UsnChanged], this.PageToken.SpecialObjectsUSN);
                    break;
                }
                MultiValuedProperty <LinkMetadata> multiValuedProperty = (MultiValuedProperty <LinkMetadata>)entry[adpropertyDefinition];
                foreach (LinkMetadata linkMetadata in multiValuedProperty)
                {
                    if (linkMetadata.LocalUpdateSequenceNumber >= this.PageToken.SpecialObjectsUSN)
                    {
                        ADObjectId adobjectId = new ADObjectId(linkMetadata.TargetDistinguishedName);
                        if (adobjectId.IsDescendantOf(configUnitDn))
                        {
                            ExTraceGlobals.TenantRelocationTracer.TraceDebug <string, long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects valid link found: {0}, USN={1}", linkMetadata.TargetDistinguishedName, linkMetadata.LocalUpdateSequenceNumber);
                            if (linkMetadata.LocalUpdateSequenceNumber > maxEntryUSN)
                            {
                                maxEntryUSN = linkMetadata.LocalUpdateSequenceNumber;
                            }
                            resultValues.Add(linkMetadata);
                        }
                    }
                }
                if (multiValuedProperty.ValueRange != null && multiValuedProperty.ValueRange.UpperBound != 2147483647)
                {
                    rangeStart += numberOfLinksToRead;
                    rangeEnd    = rangeStart + numberOfLinksToRead - 1;
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug <int, int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects retrieve next page: rangeStart={0}, rangeEnd={1}", rangeStart, rangeEnd);
                }
                else
                {
                    done = true;
                    ExTraceGlobals.TenantRelocationTracer.TraceDebug((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects page retrieval ends");
                }
            }
            this.PageToken.SpecialObjectsUSN = ((maxEntryUSN == 0L) ? long.MaxValue : (maxEntryUSN + 1L));
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <long>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects SpecialObjectsUSN is set to {0}", this.PageToken.SpecialObjectsUSN);
            ExTraceGlobals.TenantRelocationTracer.TraceDebug <int>((long)SyncConfiguration.TraceId, "TenantRelocationSyncConfiguration.ReadSpecialObjects Number of values found = {0}", resultValues.Count);
            if (resultValues.Count > 0)
            {
                ADPropertyBag propertyBag = new ADPropertyBag();
                propertyBag.SetField(ADObjectSchema.Id, entry.Id);
                propertyBag.SetField(ADRecipientSchema.UsnChanged, entry[ADRecipientSchema.UsnChanged]);
                propertyBag.SetField(ADRecipientSchema.LinkMetadata, resultValues);
                propertyBag.SetField(SyncObjectSchema.Deleted, false);
                TenantRelocationSyncObject specialObject = new TenantRelocationSyncObject(propertyBag, new DirectoryAttribute[0]);
                yield return(specialObject);
            }
            yield break;
        }