internal bool TryGetExtensionUpdate(ExtensionData extensionData, out byte[] manifestBytes) { manifestBytes = null; this.CleanupCache(); ExtensionsCacheEntry extensionsCacheEntry = null; if (this.extensionsDictionary.TryGetValue(extensionData.MarketplaceAssetID, out extensionsCacheEntry)) { if (extensionData.ExtensionId != extensionsCacheEntry.ExtensionID) { ExtensionsCache.Tracer.TraceError <string, string, string>(0L, "ExtensionsCache.TryGetExtensionUpdate: Extension {0} ExtensionID property {1} does not match cache entry value {2}.", extensionData.MarketplaceAssetID, extensionData.ExtensionId, extensionsCacheEntry.ExtensionID); ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_MismatchedCacheMailboxExtensionId, extensionData.MarketplaceAssetID, new object[] { "ProcessUpdates", extensionData.MarketplaceAssetID, extensionData.ExtensionId, extensionsCacheEntry.ExtensionID }); } else if (extensionData.Version != null && extensionsCacheEntry.RequestedCapabilities != null && extensionsCacheEntry.Manifest != null && extensionData.Version < extensionsCacheEntry.Version && ExtensionData.CompareCapabilities(extensionsCacheEntry.RequestedCapabilities.Value, extensionData.RequestedCapabilities.Value) <= 0 && GetUpdates.IsValidUpdateState(new OmexConstants.AppState?(extensionsCacheEntry.State))) { manifestBytes = extensionsCacheEntry.Manifest; } } return(manifestBytes != null); }
private void MaintainCacheSize(ExtensionsCacheEntry entry) { int num = this.Size + entry.Size; if (num > 512000) { List <ExtensionsCacheEntry> list = new List <ExtensionsCacheEntry>(); foreach (KeyValuePair <string, ExtensionsCacheEntry> keyValuePair in this.extensionsDictionary) { ExtensionsCacheEntry value = keyValuePair.Value; list.Add(value); num -= value.Size; if (num <= 460800) { break; } } foreach (ExtensionsCacheEntry extensionsCacheEntry in list) { ExtensionsCache.Tracer.TraceDebug <string>(0L, "ExtensionsCache.MaintainCacheSize: Removing Extension {0}.", extensionsCacheEntry.MarketplaceAssetID); this.extensionsDictionary.Remove(extensionsCacheEntry.MarketplaceAssetID); } ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_ExtensionsCacheReachedMaxSize, null, new object[] { "ProcessUpdates" }); } this.Size = num; ExtensionsCache.Tracer.TraceDebug <int>(0L, "ExtensionsCache.MaintainCacheSize: Current cache size {0}.", this.Size); }
private void CleanupCache() { lock (this.extensionsDictionary.SyncRoot) { if (this.LastCacheCleanupTime.AddDays(1.0) < DateTime.UtcNow) { List <ExtensionsCacheEntry> list = new List <ExtensionsCacheEntry>(this.extensionsDictionary.Count); this.Size = 0; foreach (KeyValuePair <string, ExtensionsCacheEntry> keyValuePair in this.extensionsDictionary) { ExtensionsCacheEntry value = keyValuePair.Value; if (value.LastUpdateCheckTime.AddDays(14.0) < DateTime.UtcNow) { list.Add(value); } else { this.Size += value.Size; } } foreach (ExtensionsCacheEntry extensionsCacheEntry in list) { ExtensionsCache.Tracer.TraceDebug <string>(0L, "ExtensionsCache.CleanupCache: Removing Extension {0}.", extensionsCacheEntry.MarketplaceAssetID); this.extensionsDictionary.Remove(extensionsCacheEntry.MarketplaceAssetID); } ExtensionsCache.Tracer.TraceDebug <int>(0L, "ExtensionsCache.CleanupCache: Current cache size {0}.", this.Size); } } }
private void AddExtension(ExtensionsCacheEntry entry) { lock (this.extensionsDictionary.SyncRoot) { this.MaintainCacheSize(entry); this.extensionsDictionary.Add(entry.MarketplaceAssetID, entry); } }
internal bool TryGetEntry(string marketplaceAssetID, out ExtensionsCacheEntry extensionCacheEntry) { ExtensionsCacheEntry extensionsCacheEntry = null; if (this.extensionsDictionary.TryGetValue(marketplaceAssetID, out extensionsCacheEntry) && !InstalledExtensionTable.IsUpdateCheckTimeExpired(extensionsCacheEntry.LastUpdateCheckTime)) { extensionCacheEntry = extensionsCacheEntry; } else { extensionCacheEntry = null; } return(extensionCacheEntry != null); }
internal void Add(ExtensionData extensionData, OmexConstants.AppState state) { byte[] manifestBytes = extensionData.GetManifestBytes(); if (manifestBytes == null || manifestBytes.Length == 0) { throw new ArgumentNullException("extensionData Manifest"); } if (extensionData.Version == null) { throw new ArgumentNullException("extensionData Version"); } if (extensionData.RequestedCapabilities == null) { throw new ArgumentNullException("extensionData RequestedCapabilities"); } ExtensionsCache.Tracer.TraceDebug <string>(0L, "ExtensionsCache.Add: Adding Extension {0} from ExtensionData", extensionData.MarketplaceAssetID); ExtensionsCacheEntry entry = new ExtensionsCacheEntry(extensionData.MarketplaceAssetID, extensionData.ExtensionId, extensionData.Version, new RequestedCapabilities?(extensionData.RequestedCapabilities.Value), state, manifestBytes); this.AddExtension(entry); }
internal void Update(AppStateResponseAsset appStateResponseAsset) { if (appStateResponseAsset == null) { throw new ArgumentNullException("appStateResponseAsset"); } if (appStateResponseAsset.State == null) { throw new ArgumentNullException("appStateResponseAsset.State"); } if (appStateResponseAsset.Version == null) { throw new ArgumentNullException("appStateResponseAsset.Version"); } byte[] manifest = null; RequestedCapabilities?requestedCapabilities = null; ExtensionsCacheEntry extensionsCacheEntry = null; if (this.extensionsDictionary.TryGetValue(appStateResponseAsset.MarketplaceAssetID, out extensionsCacheEntry) && extensionsCacheEntry.Version == appStateResponseAsset.Version) { ExtensionsCache.Tracer.TraceDebug <string>(0L, "ExtensionsCache.Update: Since version is unchanged, getting properties from extension entry {0} for add", appStateResponseAsset.MarketplaceAssetID); requestedCapabilities = extensionsCacheEntry.RequestedCapabilities; if (GetUpdates.IsValidUpdateState(new OmexConstants.AppState?(appStateResponseAsset.State.Value))) { manifest = extensionsCacheEntry.Manifest; } else { manifest = null; } } ExtensionsCache.Tracer.TraceDebug <string>(0L, "ExtensionsCache.Update: Adding extension {0} from AppStateResponse", appStateResponseAsset.MarketplaceAssetID); ExtensionsCacheEntry entry = new ExtensionsCacheEntry(appStateResponseAsset.MarketplaceAssetID, appStateResponseAsset.ExtensionID, appStateResponseAsset.Version, requestedCapabilities, appStateResponseAsset.State.Value, manifest); this.AddExtension(entry); }
// Token: 0x06000BED RID: 3053 RVA: 0x00031178 File Offset: 0x0002F378 internal bool CacheSatisfiesRequest(UpdateRequestAsset requestAsset, List <ExtensionData> updates) { bool result = false; ExtensionsCacheEntry extensionsCacheEntry = null; if (this.extensionsCache.TryGetEntry(requestAsset.MarketplaceAssetID, out extensionsCacheEntry) && requestAsset.Version <= extensionsCacheEntry.Version && extensionsCacheEntry.Manifest != null) { if (requestAsset.ExtensionID != extensionsCacheEntry.ExtensionID) { GetUpdates.Tracer.TraceError <string, string, string>(0L, "GetUpdates.CacheSatisfiesRequest: Asset {0} extension ID {1} does not match the cache entry {2}", requestAsset.MarketplaceAssetID, requestAsset.ExtensionID, extensionsCacheEntry.ExtensionID); ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_MismatchedCacheMailboxExtensionId, requestAsset.MarketplaceAssetID, new object[] { "ProcessUpdates", this.GetLoggedMailboxIdentifier(), requestAsset.MarketplaceAssetID, requestAsset.ExtensionID, extensionsCacheEntry.ExtensionID }); result = true; } else if (requestAsset.Version == extensionsCacheEntry.Version) { GetUpdates.Tracer.TraceDebug <string>(0L, "GetUpdates.CacheSatisfiesRequest: Asset {0} version matches the cache entry", requestAsset.MarketplaceAssetID); result = true; } else if (requestAsset.Version < extensionsCacheEntry.Version && extensionsCacheEntry.Manifest != null) { if (ExtensionData.CompareCapabilities(extensionsCacheEntry.RequestedCapabilities.Value, requestAsset.RequestedCapabilities) > 0) { GetUpdates.Tracer.TraceDebug <string, RequestedCapabilities, RequestedCapabilities>(0L, "GetUpdates.CacheSatisfiesRequest: Asset cache entry requires more capabilities than installed asset. Asset ID: {0} Update: {1} Installed: {2}", requestAsset.MarketplaceAssetID, extensionsCacheEntry.RequestedCapabilities.Value, requestAsset.RequestedCapabilities); ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_MoreCapabilitiesSkipUpdate, requestAsset.MarketplaceAssetID, new object[] { "ProcessUpdates", this.GetLoggedMailboxIdentifier(), requestAsset.MarketplaceAssetID, requestAsset.RequestedCapabilities, extensionsCacheEntry.RequestedCapabilities.Value }); result = true; } else if (!GetUpdates.IsValidUpdateState(new OmexConstants.AppState?(extensionsCacheEntry.State))) { GetUpdates.Tracer.TraceDebug <string, OmexConstants.AppState>(0L, "GetUpdates.CacheSatisfiesRequest: Asset {0} cache entry AppState {1} is not valid for updates", requestAsset.MarketplaceAssetID, extensionsCacheEntry.State); ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_InvalidStateSkipUpdate, requestAsset.MarketplaceAssetID, new object[] { "ProcessUpdates", this.GetLoggedMailboxIdentifier(), requestAsset.MarketplaceAssetID, extensionsCacheEntry.State }); result = true; } else { GetUpdates.Tracer.TraceDebug <string>(0L, "GetUpdates.CacheSatisfiesRequest: Asset {0} will be updated from the cache", requestAsset.MarketplaceAssetID); ExtensionData updatedExtension = null; Exception ex = InstalledExtensionTable.RunClientExtensionAction(delegate { updatedExtension = ExtensionData.ParseOsfManifest(extensionsCacheEntry.Manifest, extensionsCacheEntry.Manifest.Length, requestAsset.MarketplaceAssetID, requestAsset.MarketplaceContentMarket, ExtensionType.MarketPlace, requestAsset.Scope, requestAsset.Enabled, requestAsset.DisableReason, string.Empty, requestAsset.Etoken); }); if (ex == null) { updates.Add(updatedExtension); result = true; } else { GetUpdates.Tracer.TraceError <string, Exception>(0L, "GetUpdates.CacheSatisfiesRequest: Parse of manifest failed for extension {0}. Exception: {1}", requestAsset.MarketplaceAssetID, ex); ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_CachedManifestParseFailed, requestAsset.MarketplaceAssetID, new object[] { "ProcessUpdates", requestAsset.MarketplaceAssetID, ExtensionDiagnostics.GetLoggedExceptionString(ex) }); } } } } return(result); }
internal void SubmitUpdateQuery(ICollection <ExtensionData> extensions, UpdateQueryContext queryContext) { if (extensions == null) { throw new ArgumentNullException("extensions"); } if (extensions.Count == 0) { throw new ArgumentException("extensions must contain one or more extensions"); } if (this.SkipSubmitUpdateQueryForTest) { this.SubmitCount = 0; } Dictionary <string, UpdateRequestAsset> dictionary = new Dictionary <string, UpdateRequestAsset>(extensions.Count); foreach (ExtensionData extensionData in extensions) { if (extensionData.Version == null) { ExtensionsCache.Tracer.TraceDebug <string>(0L, "ExtensionsCache.SubmitUpdateQuery: Extension {0} not added to query list because version is invalid", extensionData.MarketplaceAssetID); ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_InvalidVersionSubmitUpdateQuery, extensionData.MarketplaceAssetID, new object[] { "ProcessUpdates", ExtensionDiagnostics.GetLoggedMailboxIdentifier(queryContext.ExchangePrincipal), extensionData.MarketplaceAssetID }); } else { if (extensionData.Scope == null) { throw new ArgumentNullException("extensionData.Scope"); } if (extensionData.RequestedCapabilities == null) { throw new ArgumentNullException("extensionData.RequestedCapabilities"); } ExtensionsCacheEntry extensionsCacheEntry = null; if (this.extensionsDictionary.TryGetValue(extensionData.MarketplaceAssetID, out extensionsCacheEntry) && !InstalledExtensionTable.IsUpdateCheckTimeExpired(extensionsCacheEntry.LastUpdateCheckTime) && extensionsCacheEntry.Version == extensionData.Version) { ExtensionsCache.Tracer.TraceDebug <string>(0L, "ExtensionsCache.SubmitUpdateQuery: Extension {0} not added to query list because version matches recent cache entry", extensionData.MarketplaceAssetID); } else { UpdateRequestAsset updateRequestAsset = null; if (dictionary.TryGetValue(extensionData.MarketplaceAssetID, out updateRequestAsset)) { ExtensionsCache.Tracer.TraceDebug <string, string, string>(0L, "ExtensionsCache.SubmitUpdateQuery: Extension {0} not added to query list because asset with same MarketplaceAssetID is already in list. ExtensionIds with same asset id: {1} {2}", extensionData.MarketplaceAssetID, extensionData.ExtensionId, updateRequestAsset.ExtensionID); } else { dictionary.Add(extensionData.MarketplaceAssetID, new UpdateRequestAsset { MarketplaceContentMarket = extensionData.MarketplaceContentMarket, ExtensionID = extensionData.ExtensionId, MarketplaceAssetID = extensionData.MarketplaceAssetID, RequestedCapabilities = extensionData.RequestedCapabilities.Value, Version = extensionData.Version, DisableReason = extensionData.DisableReason, Enabled = extensionData.Enabled, Scope = extensionData.Scope.Value, Etoken = extensionData.Etoken }); } } } } if (dictionary.Count == 0) { ExtensionsCache.Tracer.TraceDebug(0L, "ExtensionsCache.SubmitUpdateQuery: UpdateRequestAssets count is 0. Updates query will not be started."); return; } queryContext.UpdateRequestAssets = dictionary; queryContext.DeploymentId = ExtensionDataHelper.GetDeploymentId(queryContext.Domain); this.QueueQueryItem(queryContext); }