public MsoMainStreamCookie ReadMostRecentCookie() { MsoMainStreamCookieContainer msoMainStreamCookieContainer = this.cookieSession.GetMsoMainStreamCookieContainer(base.ServiceInstanceName); MultiValuedProperty <byte[]> multiValuedProperty = this.RetrievePersistedCookies(msoMainStreamCookieContainer); if (multiValuedProperty.Count == 0) { return(null); } MsoMainStreamCookie msoMainStreamCookie = null; foreach (byte[] storageCookie in multiValuedProperty) { MsoMainStreamCookie msoMainStreamCookie2 = null; Exception ex = null; if (MsoMainStreamCookie.TryFromStorageCookie(storageCookie, out msoMainStreamCookie2, out ex) && string.Equals(base.ServiceInstanceName, msoMainStreamCookie2.ServiceInstanceName, StringComparison.OrdinalIgnoreCase) && (msoMainStreamCookie == null || msoMainStreamCookie.TimeStamp < msoMainStreamCookie2.TimeStamp)) { msoMainStreamCookie = msoMainStreamCookie2; } } if (msoMainStreamCookie != null) { base.SyncPropertySetVersion = msoMainStreamCookie.SyncPropertySetVersion; base.IsSyncPropertySetUpgrading = msoMainStreamCookie.IsSyncPropertySetUpgrading; return(msoMainStreamCookie); } return(null); }
public static MsoMainStreamCookie FromStorageCookie(byte[] storageCookie) { Exception ex = null; MsoMainStreamCookie result = null; if (!MsoMainStreamCookie.TryFromStorageCookie(storageCookie, out result, out ex)) { throw ex; } return(result); }
public override void WriteCookie(byte[] cookie, IEnumerable <string> filteredContextIds, DateTime timestamp, bool isUpgradingCookie, ServerVersion version, bool more) { if (cookie == null || cookie.Length == 0) { throw new ArgumentNullException("cookie"); } MsoMainStreamCookieContainer msoMainStreamCookieContainer = this.cookieSession.GetMsoMainStreamCookieContainer(base.ServiceInstanceName); MultiValuedProperty <byte[]> multiValuedProperty = this.RetrievePersistedCookies(msoMainStreamCookieContainer); List <MsoMainStreamCookieWithIndex> list = new List <MsoMainStreamCookieWithIndex>(); for (int i = multiValuedProperty.Count - 1; i >= 0; i--) { MsoMainStreamCookie msoMainStreamCookie = null; Exception ex = null; if (MsoMainStreamCookie.TryFromStorageCookie(multiValuedProperty[i], out msoMainStreamCookie, out ex) && string.Equals(base.ServiceInstanceName, msoMainStreamCookie.ServiceInstanceName, StringComparison.OrdinalIgnoreCase)) { list.Add(new MsoMainStreamCookieWithIndex(msoMainStreamCookie, i)); } } List <MsoMainStreamCookieWithIndex> list2 = this.SortMainStreamCookieList(list); if (list2.Count >= 2) { MsoMainStreamCookieWithIndex msoMainStreamCookieWithIndex = list2[list2.Count - 1]; MsoMainStreamCookieWithIndex msoMainStreamCookieWithIndex2 = list2[list2.Count - 2]; if (msoMainStreamCookieWithIndex.Cookie.TimeStamp < new DateTime(msoMainStreamCookieWithIndex2.Cookie.TimeStamp.Ticks + this.cookieHistoryInterval.Ticks, DateTimeKind.Utc)) { multiValuedProperty.RemoveAt(msoMainStreamCookieWithIndex.Index); } else if (list2.Count >= this.maxCookieHistoryCount) { multiValuedProperty.RemoveAt(list2[0].Index); } } base.UpdateSyncPropertySetVersion(isUpgradingCookie, version, more); MsoMainStreamCookie msoMainStreamCookie2 = new MsoMainStreamCookie(base.ServiceInstanceName, cookie, timestamp, base.SyncPropertySetVersion, base.IsSyncPropertySetUpgrading); multiValuedProperty.Add(msoMainStreamCookie2.ToStorageCookie()); this.cookieSession.Save(msoMainStreamCookieContainer); this.LogPersistCookieEvent(); }