private int ReadLcid()
 {
     if (this.mapiStore != null)
     {
         PropValue prop = this.mapiStore.GetProp(PropTag.SortLocaleId);
         if (!prop.IsNull() && !prop.IsError())
         {
             return(prop.GetInt());
         }
         return(0);
     }
     else
     {
         this.storeSession.Mailbox.Load(new PropertyDefinition[]
         {
             SortLCIDContext.SortLciPropertyDefinition
         });
         object obj = this.storeSession.Mailbox[SortLCIDContext.SortLciPropertyDefinition];
         if (obj == null || obj is PropertyError)
         {
             return(0);
         }
         return((int)obj);
     }
 }
Beispiel #2
0
 public static DateTime GetDateTimeOrDefault(PropValue pv)
 {
     if (pv.IsError() || pv.IsNull() || pv.Value == null)
     {
         return(DateTime.MinValue);
     }
     return(pv.GetDateTime());
 }
        public static byte[] GetDumpsterEntryIdFromFolderRec(FolderRec folderRec)
        {
            ArgumentValidator.ThrowIfNull("folderRec", folderRec);
            if (folderRec.AdditionalProps != null)
            {
                foreach (PropValueData data in folderRec.AdditionalProps)
                {
                    PropValue native = DataConverter <PropValueConverter, PropValue, PropValueData> .GetNative(data);

                    if (!native.IsNull() && !native.IsError() && native.PropTag == PropTag.IpmWasteBasketEntryId)
                    {
                        return(native.GetBytes());
                    }
                }
            }
            return(null);
        }
        protected override List <MailboxData> GetMailboxesForCurrentWindow(out int totalMailboxOnDatabaseCount, out int notInterestingMailboxCount, out int filteredMailboxCount, out int failedFilteringCount)
        {
            Guid activityId = Guid.NewGuid();

            PropTag[]     mailboxProperties = this.GetMailboxProperties();
            PropValue[][] mailboxes         = MailboxTableQuery.GetMailboxes("Client=TBA", base.DatabaseInfo, mailboxProperties);
            totalMailboxOnDatabaseCount = ((mailboxes == null) ? 0 : mailboxes.Length);
            notInterestingMailboxCount  = 0;
            filteredMailboxCount        = 0;
            failedFilteringCount        = 0;
            AssistantsLog.LogGetMailboxesQueryEvent(activityId, base.Assistant.NonLocalizedName, totalMailboxOnDatabaseCount, base.Assistant as AssistantBase);
            if (mailboxes == null)
            {
                return(new List <MailboxData>());
            }
            List <MailboxInformation> list3 = new List <MailboxInformation>(mailboxes.Length);
            Guid mailboxGuid = Guid.Empty;
            VariantConfigurationSnapshot snapshot    = VariantConfiguration.GetSnapshot(DatabaseSettingsContext.Get(base.DatabaseInfo.Guid), null, null);
            TimeSpan notInterestingLogInterval       = snapshot.MailboxAssistants.GetObject <IMailboxAssistantSettings>(base.AssistantType.Identifier, new object[0]).MailboxNotInterestingLogInterval;
            int      filteredMailboxCountLocal       = 0;
            int      notInterestingMailboxCountLocal = 0;
            string   traceMessage;

            foreach (PropValue[] propertiesForDelegateClosure2 in mailboxes)
            {
                try
                {
                    PropValue[] propertiesForDelegateClosure = propertiesForDelegateClosure2;
                    List <MailboxInformation> list           = list3;
                    base.CatchMeIfYouCan(delegate
                    {
                        PropValue mailboxProperty  = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.UserGuid);
                        PropValue mailboxProperty2 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.DisplayName);
                        string mailboxDisplayNameTracingOnlyUsage = (mailboxProperty2.IsNull() || mailboxProperty2.Value == null) ? string.Empty : mailboxProperty2.Value.ToString();
                        if (mailboxProperty.PropTag != PropTag.UserGuid || mailboxProperty2.PropTag != PropTag.DisplayName)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxNoGuidFilter, MailboxSlaFilterReasonType.NoGuid, new object[]
                            {
                                mailboxProperty.Value
                            });
                            filteredMailboxCountLocal++;
                            return;
                        }
                        byte[] bytes = mailboxProperty.GetBytes();
                        if (bytes != null && bytes.Length == 16)
                        {
                            mailboxGuid = new Guid(bytes);
                        }
                        if (MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.DateDiscoveredAbsentInDS).PropTag == PropTag.DateDiscoveredAbsentInDS)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxNotInDirectoryFilter, MailboxSlaFilterReasonType.NotInDirectory, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        PropValue mailboxProperty3 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.MailboxMiscFlags);
                        MailboxMiscFlags @int      = (MailboxMiscFlags)mailboxProperty3.GetInt(0);
                        if ((@int & MailboxMiscFlags.CreatedByMove) == MailboxMiscFlags.CreatedByMove)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxMoveDestinationFilter, MailboxSlaFilterReasonType.MoveDestination, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        MailboxMiscFlags mailboxMiscFlags = @int & (MailboxMiscFlags.DisabledMailbox | MailboxMiscFlags.SoftDeletedMailbox | MailboxMiscFlags.MRSSoftDeletedMailbox);
                        if (mailboxMiscFlags != MailboxMiscFlags.None)
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxInaccessibleFilter, MailboxSlaFilterReasonType.Inaccessible, new object[]
                            {
                                mailboxMiscFlags
                            });
                            filteredMailboxCountLocal++;
                            return;
                        }
                        IMailboxFilter mailboxFilter = this.AssistantType as IMailboxFilter;
                        if (mailboxFilter != null && mailboxProperty3.PropTag == PropTag.MailboxMiscFlags)
                        {
                            MailboxMiscFlags int2 = (MailboxMiscFlags)mailboxProperty3.GetInt();
                            bool flag             = (int2 & MailboxMiscFlags.ArchiveMailbox) == MailboxMiscFlags.ArchiveMailbox;
                            if (flag && !mailboxFilter.MailboxType.Contains(MailboxType.Archive))
                            {
                                this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxArchiveFilter, MailboxSlaFilterReasonType.Archive, new object[0]);
                                filteredMailboxCountLocal++;
                                return;
                            }
                        }
                        ControlData controlData = ControlData.Empty;
                        if (this.AssistantType.ControlDataPropertyDefinition != null)
                        {
                            PropValue mailboxProperty4 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, (PropTag)this.AssistantType.ControlDataPropertyDefinition.PropertyTag);
                            if (mailboxProperty4.PropTag == (PropTag)this.AssistantType.ControlDataPropertyDefinition.PropertyTag)
                            {
                                controlData = ControlData.CreateFromByteArray(mailboxProperty4.GetBytes());
                            }
                        }
                        TenantPartitionHint tenantPartitionHint = null;
                        PropValue mailboxProperty5 = MailboxTableQuery.GetMailboxProperty(propertiesForDelegateClosure, PropTag.PersistableTenantPartitionHint);
                        if (mailboxProperty5.PropTag == PropTag.PersistableTenantPartitionHint)
                        {
                            byte[] bytes2 = mailboxProperty5.GetBytes();
                            if (bytes2 != null && bytes2.Length != 0)
                            {
                                tenantPartitionHint = TenantPartitionHint.FromPersistablePartitionHint(bytes2);
                            }
                        }
                        MailboxInformation mailboxInformation2 = MailboxInformation.Create(mailboxProperty.GetBytes(), this.DatabaseInfo.Guid, mailboxProperty2.GetString(), controlData, propertiesForDelegateClosure, MailboxInformation.GetLastLogonTime(propertiesForDelegateClosure), tenantPartitionHint);
                        if (!this.DatabaseInfo.IsUserMailbox(mailboxInformation2.MailboxGuid))
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxNotUserFilter, MailboxSlaFilterReasonType.NotUser, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        if (mailboxInformation2.MailboxData.IsPublicFolderMailbox && (mailboxFilter == null || !mailboxFilter.MailboxType.Contains(MailboxType.PublicFolder)))
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxPublicFolderFilter, MailboxSlaFilterReasonType.PublicFolder, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        if (this.IsMailboxInDemandJob(mailboxInformation2.MailboxData))
                        {
                            this.LogStoreDriverMailboxFilterEvent(notInterestingLogInterval, activityId, mailboxGuid, mailboxDisplayNameTracingOnlyUsage, Strings.MailboxInDemandJobFilter, MailboxSlaFilterReasonType.InDemandJob, new object[0]);
                            filteredMailboxCountLocal++;
                            return;
                        }
                        if (this.AssistantType.MailboxExtendedProperties != null)
                        {
                            if (!this.AssistantType.IsMailboxInteresting(mailboxInformation2))
                            {
                                traceMessage = string.Format("{0}: {1} is not interesting for the assistant {2}.", this, mailboxGuid, this.Assistant.NonLocalizedName);
                                ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
                                DateTime utcNow = DateTime.UtcNow;
                                if (!this.notInterestingEventsLastLogDateTimes.ContainsKey(this.Assistant.NonLocalizedName) || utcNow - this.notInterestingEventsLastLogDateTimes[this.Assistant.NonLocalizedName] >= notInterestingLogInterval)
                                {
                                    AssistantsLog.LogMailboxNotInterestingEvent(activityId, this.Assistant.NonLocalizedName, this.Assistant as AssistantBase, mailboxGuid, mailboxDisplayNameTracingOnlyUsage);
                                    this.notInterestingEventsLastLogDateTimes[this.Assistant.NonLocalizedName] = utcNow;
                                }
                                notInterestingMailboxCountLocal++;
                                return;
                            }
                        }
                        else
                        {
                            traceMessage = string.Format("{0}: {1} mailbox properties are null, IsMailboxInteresting was not called.", this, mailboxGuid);
                            ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
                        }
                        traceMessage = string.Format("{0}: {1} is interesting for the assistant {2}.", this, mailboxGuid, this.Assistant.NonLocalizedName);
                        ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
                        AssistantsLog.LogMailboxInterestingEvent(activityId, this.Assistant.NonLocalizedName, this.Assistant as AssistantBase, null, mailboxGuid, mailboxDisplayNameTracingOnlyUsage);
                        list.Add(mailboxInformation2);
                    }, base.AssistantType.NonLocalizedName);
                }
                catch (AIException exception)
                {
                    failedFilteringCount++;
                    AssistantsLog.LogErrorEnumeratingMailboxes(base.Assistant, mailboxGuid, exception, true);
                }
                catch (Exception exception2)
                {
                    AssistantsLog.LogErrorEnumeratingMailboxes(base.Assistant, mailboxGuid, exception2, false);
                    throw;
                }
            }
            traceMessage = string.Format("{0}: {1} mailboxes after filtering", this, list3.Count);
            ExTraceGlobals.TimeBasedDatabaseDriverTracer.TraceDebug((long)this.GetHashCode(), traceMessage);
            if (this.firstIteration || base.AssistantType.WorkCycleCheckpoint < base.AssistantType.WorkCycle)
            {
                int count = list3.Count;
                list3 = list3.FindAll((MailboxInformation mailbox) => DateTime.UtcNow - mailbox.LastProcessedDate > base.AssistantType.WorkCycle - base.AssistantType.WorkCycleCheckpoint);
                this.firstIteration        = false;
                filteredMailboxCountLocal += count - list3.Count;
            }
            list3.Sort((MailboxInformation m1, MailboxInformation m2) => m1.LastProcessedDate.CompareTo(m2.LastProcessedDate));
            List <MailboxData> list2 = new List <MailboxData>();

            foreach (MailboxInformation mailboxInformation in list3)
            {
                list2.Add(mailboxInformation.MailboxData);
            }
            AssistantsLog.LogEndGetMailboxesEvent(activityId, base.Assistant.NonLocalizedName, list2.Count, base.Assistant as AssistantBase);
            filteredMailboxCount       = filteredMailboxCountLocal;
            notInterestingMailboxCount = notInterestingMailboxCountLocal;
            return(list2);
        }
Beispiel #5
0
        public override void CopyFolderProperties(FolderRecWrapper sourceFolderRecWrapper, ISourceFolder sourceFolder, IDestinationFolder destFolder, FolderRecDataFlags dataToCopy, out bool wasPropertyCopyingSkipped)
        {
            Guid empty  = Guid.Empty;
            bool isRoot = base.IsRoot;
            bool flag   = false;

            wasPropertyCopyingSkipped = false;
            FolderMapping folderMapping = sourceFolderRecWrapper as FolderMapping;

            while (folderMapping.WKFType != WellKnownFolderType.Root)
            {
                if (folderMapping.IsLegacyPublicFolder)
                {
                    return;
                }
                folderMapping = (folderMapping.Parent as FolderMapping);
            }
            if (destFolder == null)
            {
                if (!isRoot || ((FolderMapping)sourceFolderRecWrapper).IsSystemPublicFolder)
                {
                    MrsTracer.Service.Debug("Skipping final property copying for \"{0}\" folder since it's contents don't reside in this mailbox", new object[]
                    {
                        sourceFolderRecWrapper.FullFolderName
                    });
                    return;
                }
                throw new FolderCopyFailedPermanentException(sourceFolderRecWrapper.FullFolderName);
            }
            else
            {
                PropValueData[] props = destFolder.GetProps(new PropTag[]
                {
                    PropTag.ReplicaList,
                    PropTag.IpmWasteBasketEntryId
                });
                IDataConverter <PropValue, PropValueData> dataConverter = new PropValueConverter();
                PropValue nativeRepresentation = dataConverter.GetNativeRepresentation(props[0]);
                byte[]    array = nativeRepresentation.Value as byte[];
                if (!nativeRepresentation.IsNull() && !nativeRepresentation.IsError() && array != null)
                {
                    StorePropertyDefinition replicaList = CoreFolderSchema.ReplicaList;
                    string[] stringArrayFromBytes       = ReplicaListProperty.GetStringArrayFromBytes(array);
                    if (stringArrayFromBytes.Length > 0 && GuidHelper.TryParseGuid(stringArrayFromBytes[0], out empty))
                    {
                        flag = (empty == base.TargetMailboxGuid);
                    }
                }
                FolderStateSnapshot folderStateSnapshot = base.ICSSyncState[sourceFolderRecWrapper.EntryId];
                FolderState         state = folderStateSnapshot.State;
                if (sourceFolder.GetFolderRec(this.GetAdditionalFolderPtags(), GetFolderRecFlags.None).IsGhosted)
                {
                    folderStateSnapshot.State |= FolderState.IsGhosted;
                }
                else
                {
                    folderStateSnapshot.State &= ~FolderState.IsGhosted;
                }
                if (state != folderStateSnapshot.State)
                {
                    base.SaveICSSyncState(false);
                }
                if (!isRoot && !flag)
                {
                    return;
                }
                List <PropValueData> list = new List <PropValueData>(2);
                bool flag2 = false;
                if (flag)
                {
                    PropValue nativeRepresentation2 = dataConverter.GetNativeRepresentation(sourceFolder.GetProps(new PropTag[]
                    {
                        PropTag.PfProxy
                    })[0]);
                    if (!nativeRepresentation2.IsNull() && !nativeRepresentation2.IsError())
                    {
                        byte[] array2 = nativeRepresentation2.Value as byte[];
                        if (array2 != null && array2.Length == 16 && new Guid(array2) != Guid.Empty)
                        {
                            Guid a     = Guid.Empty;
                            bool flag3 = base.Flags.HasFlag(MailboxCopierFlags.CrossOrg);
                            if (flag3)
                            {
                                a = destFolder.LinkMailPublicFolder(LinkMailPublicFolderFlags.EntryId, sourceFolderRecWrapper.EntryId);
                            }
                            else
                            {
                                a = destFolder.LinkMailPublicFolder(LinkMailPublicFolderFlags.ObjectGuid, array2);
                            }
                            if (a != Guid.Empty)
                            {
                                list.Add(new PropValueData(PropTag.PfProxy, a.ToByteArray()));
                                list.Add(new PropValueData(PropTag.PfProxyRequired, true));
                                flag2 = true;
                            }
                            else
                            {
                                base.Report.Append(new ReportEntry(MrsStrings.ReportFailedToLinkADPublicFolder(sourceFolderRecWrapper.FullFolderName, BitConverter.ToString(array2), BitConverter.ToString(sourceFolderRecWrapper.EntryId)), ReportEntryType.Warning));
                            }
                        }
                    }
                }
                if (!flag2)
                {
                    list.Add(new PropValueData(PropTag.PfProxy, Guid.Empty.ToByteArray()));
                    list.Add(new PropValueData(PropTag.PfProxyRequired, false));
                }
                List <PropValueData> list2 = new List <PropValueData>(9);
                if (isRoot)
                {
                    if (!flag)
                    {
                        dataToCopy &= (FolderRecDataFlags.SecurityDescriptors | FolderRecDataFlags.FolderAcls | FolderRecDataFlags.ExtendedAclInformation);
                    }
                    list2.AddRange(list);
                }
                else
                {
                    byte[] sessionSpecificEntryId = this.hierarchyMailbox.GetSessionSpecificEntryId(sourceFolderRecWrapper.EntryId);
                    using (IDestinationFolder folder = this.hierarchyMailbox.GetFolder(sessionSpecificEntryId))
                    {
                        if (folder == null)
                        {
                            MrsTracer.Service.Error("Something deleted destination hierarchy folder from under us", new object[0]);
                            throw new UnexpectedErrorPermanentException(-2147221238);
                        }
                        if (list.Count > 0)
                        {
                            folder.SetProps(list.ToArray());
                        }
                    }
                }
                base.CopyFolderProperties(sourceFolderRecWrapper, sourceFolder, destFolder, dataToCopy, out wasPropertyCopyingSkipped);
                PropTag[] pta = new PropTag[]
                {
                    PropTag.DisablePeruserRead,
                    PropTag.OverallAgeLimit,
                    PropTag.RetentionAgeLimit,
                    PropTag.PfQuotaStyle,
                    PropTag.PfOverHardQuotaLimit,
                    PropTag.PfStorageQuota,
                    PropTag.PfMsgSizeLimit
                };
                foreach (PropValueData propValueData in sourceFolder.GetProps(pta))
                {
                    PropValue nativeRepresentation3 = dataConverter.GetNativeRepresentation(propValueData);
                    if (!nativeRepresentation3.IsNull() && !nativeRepresentation3.IsError())
                    {
                        if (propValueData.PropTag == 1721303043 && (int)propValueData.Value > 0)
                        {
                            propValueData.Value = (int)EnhancedTimeSpan.FromDays((double)((int)propValueData.Value)).TotalSeconds;
                        }
                        list2.Add(propValueData);
                    }
                }
                if (list2.Count > 0)
                {
                    destFolder.SetProps(list2.ToArray());
                }
                return;
            }
        }
Beispiel #6
0
        private object ConvertValue(ADPropertyDefinition propertyDefinition, PropValue propValue)
        {
            if (propValue.IsError() || propValue.IsNull())
            {
                return(null);
            }
            PropType propType = propValue.PropType;

            object[] values;
            if (propType <= PropType.SysTime)
            {
                if (propType <= PropType.Boolean)
                {
                    if (propType != PropType.Int && propType != PropType.Boolean)
                    {
                        goto IL_174;
                    }
                }
                else
                {
                    switch (propType)
                    {
                    case PropType.AnsiString:
                        values = new object[]
                        {
                            this.encoding.GetString(propValue.GetBytes())
                        };
                        goto IL_18F;

                    case PropType.String:
                        break;

                    default:
                        if (propType != PropType.SysTime)
                        {
                            goto IL_174;
                        }
                        break;
                    }
                }
            }
            else if (propType <= PropType.Binary)
            {
                if (propType != PropType.Guid)
                {
                    if (propType != PropType.Binary)
                    {
                        goto IL_174;
                    }
                    values = new object[]
                    {
                        propValue.RawValue
                    };
                    goto IL_18F;
                }
            }
            else
            {
                switch (propType)
                {
                case PropType.AnsiStringArray:
                    values = Array.ConvertAll <byte[], object>(propValue.GetBytesArray(), (byte[] bytesValue) => this.encoding.GetString(bytesValue));
                    goto IL_18F;

                case PropType.StringArray:
                    values = Array.ConvertAll <string, object>(propValue.GetStringArray(), (string stringValue) => stringValue);
                    goto IL_18F;

                default:
                    if (propType != PropType.BinaryArray)
                    {
                        goto IL_174;
                    }
                    values = Array.ConvertAll <byte[], object>(propValue.GetBytesArray(), (byte[] bytesValue) => bytesValue);
                    goto IL_18F;
                }
            }
            values = new object[]
            {
                propValue.RawValue.ToString()
            };
            goto IL_18F;
IL_174:
            throw new InvalidOperationException(string.Format("Property type {0} is not supported", propValue.GetType()));
            object result;

            try
            {
IL_18F:
                result = ADValueConvertor.GetValueFromDirectoryAttributeValues(propertyDefinition, values);
            }
            catch (DataValidationException arg)
            {
                NspiPropertyMap.Tracer.TraceWarning <string, DataValidationException>((long)this.GetHashCode(), "Unable to handle property {0} because it has invalid value, exception: {1}", propertyDefinition.Name, arg);
                result = null;
            }
            return(result);
        }