/// <summary> /// Handles index management for all media events - basically handling saving/copying/trashing/deleting /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void MediaCacheRefresherCacheUpdated(MediaCacheRefresher sender, CacheRefresherEventArgs e) { if (Suspendable.ExamineEvents.CanIndex == false) { return; } switch (e.MessageType) { case MessageType.RefreshById: var c1 = ApplicationContext.Current.Services.MediaService.GetById((int)e.MessageObject); if (c1 != null) { ReIndexForMedia(c1, c1.Trashed == false); } break; case MessageType.RemoveById: var c2 = ApplicationContext.Current.Services.MediaService.GetById((int)e.MessageObject); if (c2 != null) { //This is triggered when the item has trashed. // So we need to delete the index from all indexes not supporting unpublished content. DeleteIndexForEntity(c2.Id, true); //We then need to re-index this item for all indexes supporting unpublished content ReIndexForMedia(c2, false); } break; case MessageType.RefreshByJson: var jsonPayloads = MediaCacheRefresher.DeserializeFromJsonPayload((string)e.MessageObject); if (jsonPayloads.Any()) { foreach (var payload in jsonPayloads) { switch (payload.Operation) { case MediaCacheRefresher.OperationType.Saved: var media1 = ApplicationContext.Current.Services.MediaService.GetById(payload.Id); if (media1 != null) { ReIndexForMedia(media1, media1.Trashed == false); } break; case MediaCacheRefresher.OperationType.Trashed: //keep if trashed for indexes supporting unpublished //(delete the index from all indexes not supporting unpublished content) DeleteIndexForEntity(payload.Id, true); //We then need to re-index this item for all indexes supporting unpublished content var media2 = ApplicationContext.Current.Services.MediaService.GetById(payload.Id); if (media2 != null) { ReIndexForMedia(media2, false); } break; case MediaCacheRefresher.OperationType.Deleted: //permanently remove from all indexes DeleteIndexForEntity(payload.Id, false); break; default: throw new ArgumentOutOfRangeException(); } } } break; case MessageType.RefreshByInstance: case MessageType.RemoveByInstance: case MessageType.RefreshAll: default: //We don't support these, these message types will not fire for media break; } }