示例#1
0
        // Token: 0x06001074 RID: 4212 RVA: 0x0005FDBC File Offset: 0x0005DFBC
        public static bool TryDeserialize(string record, out GroupMetricsCookie cookie)
        {
            cookie = null;
            string[] array = record.Split(GroupMetricsCookie.RecordSeparator, 3);
            if (3 != array.Length)
            {
                return(false);
            }
            DateTime lastDeltaSync;

            if (!GroupMetricsCookie.TryParseDateTime(array[1], out lastDeltaSync))
            {
                return(false);
            }
            DateTime lastFullSync;

            if (!GroupMetricsCookie.TryParseDateTime(array[2], out lastFullSync))
            {
                return(false);
            }
            cookie = new GroupMetricsCookie(array[0]);
            cookie.LastDeltaSync = lastDeltaSync;
            cookie.LastFullSync  = lastFullSync;
            return(true);
        }
        // Token: 0x0600108D RID: 4237 RVA: 0x00060BB8 File Offset: 0x0005EDB8
        private bool TryParseCookieString(string cookieString, string path, string domain, out GroupMetricsCookie cookie)
        {
            cookie = null;
            if (string.IsNullOrEmpty(cookieString))
            {
                return(false);
            }
            if (!GroupMetricsCookie.TryDeserialize(cookieString, out cookie))
            {
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_UnableToDeserializeGroupMetricsCookie, null, new object[]
                {
                    this.GetOrganizationIdString(),
                    path,
                    domain
                });
                return(false);
            }
            TimeSpan timeSpan = cookie.LastDeltaSync - DateTime.UtcNow;

            if (timeSpan > GroupMetricsGenerator.CookieLifetime)
            {
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_GroupMetricsCookieExpired, null, new object[]
                {
                    this.GetOrganizationIdString(),
                    domain,
                    cookie.LastDeltaSync,
                    timeSpan,
                    GroupMetricsGenerator.CookieLifetime
                });
                return(false);
            }
            return(true);
        }
        // Token: 0x06001085 RID: 4229 RVA: 0x0006036C File Offset: 0x0005E56C
        internal bool GenerateGroupList(bool delta, out bool tryAgain, IList <GroupMetricsCookie> updatedCookies)
        {
            IList <string> list = GroupMetricsGenerator.GetDomains();

            this.currentCookiePathCollection     = list.ConvertAll((string domain) => this.GetCookiePath(domain));
            this.hasDownloadedCookiesFromMailbox = false;
            bool result;

            try
            {
                using (LazyWriter lazyWriter = new LazyWriter(this.changedGroupListPath))
                {
                    foreach (string domain2 in list)
                    {
                        string             cookiePath = this.GetCookiePath(domain2);
                        GroupMetricsCookie groupMetricsCookie;
                        if (delta)
                        {
                            groupMetricsCookie = this.LoadCookie(cookiePath, domain2);
                            if (groupMetricsCookie == null)
                            {
                                tryAgain = true;
                                return(false);
                            }
                        }
                        else
                        {
                            groupMetricsCookie = new GroupMetricsCookie(domain2);
                        }
                        if (!this.GenerateChangedGroupList(domain2, groupMetricsCookie, lazyWriter, delta))
                        {
                            tryAgain = false;
                            return(false);
                        }
                        updatedCookies.Add(groupMetricsCookie);
                    }
                    if (!delta && !this.TenantHasChangedGroups())
                    {
                        this.lastSyncType = GroupMetricsSyncType.Empty;
                        GroupMetricsUtility.DeleteDirectory(this.tenantDirectory);
                    }
                    else if (!this.TenantHasChangedGroups())
                    {
                        lazyWriter.WriteLine("");
                    }
                    tryAgain = false;
                    result   = true;
                }
            }
            catch (LazyWriterException)
            {
                tryAgain = false;
                result   = false;
            }
            return(result);
        }
        // Token: 0x0600108B RID: 4235 RVA: 0x00060A64 File Offset: 0x0005EC64
        private GroupMetricsCookie LoadCookie(string path, string domain)
        {
            string             cookieString = this.ReadCookieString(path, domain);
            GroupMetricsCookie result       = null;

            if (!this.TryParseCookieString(cookieString, path, domain, out result))
            {
                this.DeleteCookieFile(path, domain);
            }
            return(result);
        }
        // Token: 0x06001090 RID: 4240 RVA: 0x00060DF0 File Offset: 0x0005EFF0
        private void SaveCookie(string path, string domain, GroupMetricsCookie cookie)
        {
            string    value = cookie.Serialize();
            Exception ex    = null;

            try
            {
                string directoryName = Path.GetDirectoryName(path);
                Directory.CreateDirectory(directoryName);
                using (StreamWriter streamWriter = new StreamWriter(path))
                {
                    streamWriter.WriteLine(value);
                }
            }
            catch (IOException ex2)
            {
                ex = ex2;
            }
            catch (UnauthorizedAccessException ex3)
            {
                ex = ex3;
            }
            catch (SecurityException ex4)
            {
                ex = ex4;
            }
            if (ex != null)
            {
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_UnableToSaveGroupMetricsCookie, null, new object[]
                {
                    this.GetOrganizationIdString(),
                    path,
                    domain,
                    ex.GetType().FullName,
                    ex.Message
                });
            }
        }
        // Token: 0x06001093 RID: 4243 RVA: 0x00060F1C File Offset: 0x0005F11C
        private bool GenerateChangedGroupList(string domain, GroupMetricsCookie cookie, LazyWriter changedWriter, bool delta)
        {
            DateTime dateTime = delta ? cookie.LastDeltaSync : cookie.LastFullSync;

            if (default(DateTime) != dateTime)
            {
                dateTime = dateTime.AddHours(-1.0);
            }
            DateTime utcNow = DateTime.UtcNow;

            cookie.LastDeltaSync = utcNow;
            if (!delta)
            {
                cookie.LastFullSync = utcNow;
            }
            string entriesFilePath = ADCrawler.GetEntriesFilePath(base.RunData.RunFolderPath, "DistributionList");

            try
            {
                using (XmlReader xmlReader = XmlReader.Create(entriesFilePath))
                {
                    if (xmlReader.ReadToFollowing("ADEntry"))
                    {
                        do
                        {
                            string        attribute     = xmlReader.GetAttribute(GrammarRecipientHelper.LookupProperties[2].Name);
                            string        attribute2    = xmlReader.GetAttribute(GrammarRecipientHelper.LookupProperties[0].Name);
                            Guid          guid          = new Guid(xmlReader.GetAttribute(GrammarRecipientHelper.LookupProperties[3].Name));
                            RecipientType recipientType = (RecipientType)Enum.Parse(typeof(RecipientType), xmlReader.GetAttribute(GrammarRecipientHelper.LookupProperties[4].Name));
                            string        attribute3    = xmlReader.GetAttribute(GrammarRecipientHelper.LookupProperties[7].Name);
                            string        attribute4    = xmlReader.GetAttribute(GrammarRecipientHelper.LookupProperties[8].Name);
                            base.Logger.TraceDebug(this, "GroupMetricsGenerator.GenerateChangedGroupList read AD entry - displayName='{0}', distinguishedName='{1}', smtpAddress='{2}', objectGuid='{3}', recipientType='{4}', whenChangedUTCString='{5}'", new object[]
                            {
                                attribute2,
                                attribute4,
                                attribute,
                                guid,
                                recipientType,
                                attribute3
                            });
                            DateTime utcNow2 = DateTime.UtcNow;
                            bool     flag    = GroupMetricsCookie.TryParseDateTime(attribute3, out utcNow2);
                            if (!delta || !flag || utcNow2 > dateTime || RecipientType.DynamicDistributionGroup == recipientType)
                            {
                                this.changedGroups++;
                                changedWriter.WriteLine(attribute4);
                                base.Logger.TraceDebug(this, "GroupMetricsGenerator.GenerateChangedGroupList write AD entry to changed list- displayName='{0}', distinguishedName='{1}', smtpAddress='{2}', objectGuid='{3}', recipientType='{4}', whenChangedUTCString='{5}'", new object[]
                                {
                                    attribute2,
                                    attribute4,
                                    attribute,
                                    guid,
                                    recipientType,
                                    attribute3
                                });
                            }
                        }while (xmlReader.ReadToFollowing("ADEntry"));
                    }
                }
            }
            catch (Exception ex)
            {
                this.exception = ex;
                GroupMetricsGenerator.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_UnableToGetListOfChangedGroupsForDomain, null, new object[]
                {
                    domain,
                    this.GetOrganizationIdString(),
                    ex.GetType().FullName,
                    ex.Message
                });
                return(false);
            }
            return(true);
        }