Exemplo n.º 1
0
        internal async Task StartAction(WillAppearEvent evt)
        {
            if (actions == null)
            {
                actions = configuration.Actions?.ToDictionary(x => x.UUID, x => x, StringComparer.OrdinalIgnoreCase) ?? new Dictionary <string, ActionDefinition>();
            }

            try
            {
                if (!actions.TryGetValue(evt.Action, out var definition))
                {
                    logger.LogError("No action handler registered for '{ActionUUID}'", evt.Action);
                    return;
                }

                var scope = serviceProvider.CreateScope();
                // we find action details here!!

                var manager = scope.ServiceProvider.GetRequiredService <IActionManagerProvider>();

                await manager.Initialize(definition, evt);

                scopes.Add(evt.Context, scope);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void OnWillAppear(WillAppearEvent willAppearEvent)
 {
     try
     {
         OnSettingsChanged(willAppearEvent.Payload.Settings.ToObject <MyActionSettings>());
     }
     catch
     {
     }
 }
Exemplo n.º 3
0
        public async void Action_OnWillAppearEvent_ReturnsShowOkMessage()
        {
            // Setup
            var uuid = Guid.NewGuid().ToString("N");

            (StreamDeckSoftwareEmulator emulator, StreamDeckClient client) = await ConnectAsync(51364, uuid);

            var streamDeckEvent = new WillAppearEvent("testAction", "context", "device", new AppearancePayload(new Coordinates(0, 0), 0, false));

            using (emulator)
                using (client)
                {
                    // Act
                    emulator.SendEvent(streamDeckEvent);
                    var message = emulator.ReceiveMessage <ShowOkMessage>();

                    // Assert
                    Assert.Equal(MessageEventType.ShowOk, message.Event);
                }
        }