public async Task QueueEvent_DeQueue() { // Arrange var compassEvent = new CompassEvent { EventName = "test" }; var queuedEvents = new QueuedEvents() { Events = new List <CompassEvent>() { compassEvent } }; A.CallTo(() => _dataStore.GetQueuedEventsAsync()) .Returns(Task.FromResult(queuedEvents)); // Act await _sut.DeQueueEventAsync(compassEvent); // Assert A.CallTo(() => _dataStore.UpsertAsync(queuedEvents)) .MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _dataStore.UpsertAsync(A <QueuedEvents> .That.Matches(arg => !arg.Events.Contains(compassEvent)))) .MustHaveHappened(Repeated.Exactly.Once); }
// TODO: not currently called. internal void FireQueuedEvents() { // IsLoadingEntity will still be true when this occurs. if (!QueuedEvents.Any()) { return; } var events = QueuedEvents; _queuedEvents = new List <Action>(); events.ForEach(a => a()); // in case any of the previously queued events spawned other events. FireQueuedEvents(); }
/// <summary> /// Queues up an uninstallation of a Content Pack. /// </summary> /// <param name="contentToUninstall">The Content Pack to uninstall</param> internal static void UninstallContent(ContentPack contentToUninstall) { ConditionalLog($"UninstallContent {contentToUninstall.DisplayName}"); // Check if this content is already queued up for uninstall if (contentToUninstall.InstallStatus.HasFlag(InstallationStatus.UninstallQueued)) { return; } StartEditorUpdates(); contentToUninstall.InstallStatus |= InstallationStatus.UninstallQueued; QueuedEvents.Add(new ContentEvent { action = PackageAction.Remove, targetPack = contentToUninstall }); OnContentChanged?.Invoke(); }
/// <summary> /// Called internally to go from installing a package to installing a sample. /// </summary> /// <param name="contentToInstall">The Content Pack that contains a sample to install</param> static void InstallContentSample(ContentPack contentToInstall) { ConditionalLog($"InstallContentSample {contentToInstall.DisplayName}"); // Content must be installed or installing to add a sample if (!(contentToInstall.InstallStatus.HasFlag(InstallationStatus.Installed) || contentToInstall.InstallStatus.HasFlag(InstallationStatus.Installing))) { return; } StartEditorUpdates(); contentToInstall.InstallStatus |= InstallationStatus.InstallQueued; // We stick the sample event at the beginning of the list because it happens automatically after an install QueuedEvents.Insert(0, new ContentEvent { action = PackageAction.SampleInstall, targetPack = contentToInstall }); OnContentChanged?.Invoke(); }
/// <summary> /// Called internally to go from installing a package to making it writeable. /// </summary> /// <param name="contentToEmbed">The Content Pack to make a writeable package</param> static void EmbedContent(ContentPack contentToEmbed) { ConditionalLog($"EmbedContent {contentToEmbed.DisplayName}"); // Content must be installed or installing to embed if (!(contentToEmbed.InstallStatus.HasFlag(InstallationStatus.Installed) || contentToEmbed.InstallStatus.HasFlag(InstallationStatus.Installing))) { return; } StartEditorUpdates(); contentToEmbed.InstallStatus |= InstallationStatus.InstallQueued; // We stick the embed event at the beginning of the list because it happens automatically after an install QueuedEvents.Insert(0, new ContentEvent { action = PackageAction.Embed, targetPack = contentToEmbed }); OnContentChanged?.Invoke(); }
private static bool ThereAreNoEvents(QueuedEvents queuedEvents) { return(queuedEvents?.Events == null || queuedEvents.Events.Count < 1); }
private async Task <IEnumerable <CompassEvent> > GetEventsToReplay(ServiceSubscription serviceSubscription, QueuedEvents queuedEvents) { var registeredApplication = await _dataStore.GetRegisteredApplicationAsync(serviceSubscription.ApplicationToken); var eventsToReplay = queuedEvents.Events.Where( queuedEvent => serviceSubscription.SubscribedEvents.Contains(queuedEvent.EventName) || registeredApplication.LastEventsSubscribed.Contains(queuedEvent.EventName)); return(eventsToReplay); }
private async Task ProcessQueuedEvents(ServiceSubscription serviceSubscription, QueuedEvents queuedEvents) { var eventsToReplay = await GetEventsToReplay(serviceSubscription, queuedEvents); var parallelRequests = new List <Task>(); foreach (var compassEvent in eventsToReplay) { parallelRequests.Add(SendEvent(serviceSubscription, compassEvent)); } await Task.WhenAll(parallelRequests); }
public async Task ReplayQueuedEvents_OnlySendSuppliedEvents() { // Arrange var serviceSubscription = new ServiceSubscription { ApplicationUri = new Uri("http://www.example.com/"), SubscribedEvents = new List <string>() { "test" }, ApplicationToken = Guid.NewGuid() }; var compassEvents = new List <CompassEvent>() { new CompassEvent { ApplicationToken = Guid.NewGuid(), EventName = "test", Identifier = Guid.NewGuid(), Payload = new { test = "test" } }, new CompassEvent { ApplicationToken = Guid.NewGuid(), EventName = "test2", Identifier = Guid.NewGuid(), Payload = new { test2 = "test" } } }; var queuedEvent = new QueuedEvents { Events = compassEvents }; A.CallTo(() => _dataStore.GetQueuedEventsAsync()) .Returns(queuedEvent); A.CallTo(() => _dataStore.GetRegisteredApplicationAsync(serviceSubscription.ApplicationToken)) .Returns(Task.FromResult( new RegisteredApplication() { LastEventsSubscribed = new List <string>() { "test" } })); // Act await _sut.ReplayQueuedEvents(serviceSubscription); // Assert A.CallTo(() => _sendToEndpointService.SendToEndpointAsync( A <List <ServiceSubscription> > .That.IsSameSequenceAs( new List <ServiceSubscription> { serviceSubscription }), compassEvents[0])) .MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _sendToEndpointService.SendToEndpointAsync( A <List <ServiceSubscription> > .That.IsSameSequenceAs( new List <ServiceSubscription> { serviceSubscription }), compassEvents[1])) .MustNotHaveHappened(); }
/// <summary> /// Called when the list of available and installed packages is ready. /// Updates the installation status of all Content Packs to match with this data. /// </summary> static void CompleteStatusEvent() { s_StatusInitialized = true; s_StatusRequested = false; var listRequest = s_CurrentEvent.request as ListRequest; if (listRequest == null) { return; } if (listRequest.Status == StatusCode.Failure) { OnStatusUpdate?.Invoke(false, listRequest.Error.message); return; } var packageCollection = listRequest.Result; // Gather all content packs var contentPackGuids = AssetDatabase.FindAssets(k_CollectionSearchFilter); AvailableContentPacks.Clear(); foreach (var guid in contentPackGuids) { var assetPath = AssetDatabase.GUIDToAssetPath(guid); var currentContentPack = AssetDatabase.LoadAssetAtPath <ContentPack>(assetPath); currentContentPack.Path = assetPath.ToLower(); AvailableContentPacks.Add(currentContentPack); } // See which ones are already installed // Update our list of packs foreach (var currentContentPack in AvailableContentPacks) { // If package collection contains content pack, it is installed, otherwise it is not currentContentPack.InstallStatus = InstallationStatus.Unknown; var installedPackage = packageCollection.FirstOrDefault(package => package.name == currentContentPack.PackageName); if (installedPackage != null) { currentContentPack.InstallStatus |= InstallationStatus.Installed; var contentPackVersion = currentContentPack.Version; if (string.IsNullOrEmpty(contentPackVersion) || contentPackVersion == k_AutoPreviewVersion) { if (string.IsNullOrEmpty(installedPackage.versions.verified) || contentPackVersion == k_AutoPreviewVersion) { contentPackVersion = installedPackage.versions.latestCompatible; } else { contentPackVersion = installedPackage.versions.verified; } currentContentPack.AutoVersion = contentPackVersion; } else { currentContentPack.AutoVersion = ""; } if (installedPackage.version != contentPackVersion) { currentContentPack.InstallStatus |= InstallationStatus.DifferentVersion; } } // Check if an installation action is queued var contentEvent = QueuedEvents.Find(currentEvent => currentEvent.targetPack == currentContentPack); if (contentEvent != null) { if (contentEvent.action == PackageAction.Add) { currentContentPack.InstallStatus |= InstallationStatus.InstallQueued; } else { currentContentPack.InstallStatus |= InstallationStatus.UninstallRequested; } } } // Gather all products var contentProductGuids = AssetDatabase.FindAssets(k_ProductSearchFilter); AvailableContentProducts.Clear(); foreach (var guid in contentProductGuids) { var currentContentProduct = AssetDatabase.LoadAssetAtPath <ContentProduct>(AssetDatabase.GUIDToAssetPath(guid)); AvailableContentProducts.Add(currentContentProduct); } OnStatusUpdate?.Invoke(true, "Successfully updated content packs status"); }