Ejemplo n.º 1
0
        public void HandleEvent(ContainerMonitorEvent containerEvent)
        {
            switch (containerEvent.Type)
            {
            case "start":
                AttachNotifiersForContainer(containerEvent.Container);
                break;

            case "die":
                RemoveNotifiersForContainer(containerEvent.Container);
                break;

            default:
                Console.WriteLine("Unknown event");
                break;
            }
        }
Ejemplo n.º 2
0
        public ContainerEventsMonitor MonitorContainerEvents()
        {
            var tokenSource = new CancellationTokenSource();
            var monitor     = new ContainerEventsMonitor(tokenSource);

            var progress = new Progress <JSONMessage>(async message =>
            {
                var container = await GetContainerById(message.ID);
                var e         = new ContainerMonitorEvent()
                {
                    ID        = message.ID,
                    Type      = message.Status,
                    Container = container
                };

                monitor.OnEvent?.Invoke(e);
            });

            var filters = new Dictionary <string, IDictionary <string, bool> >()
            {
                {
                    "type", new Dictionary <string, bool>()
                    {
                        { "container", true }
                    }
                },
                {
                    "event", new Dictionary <string, bool>()
                    {
                        { "start", true },
                        { "die", true },
                    }
                },
            };

            var eventParams = new ContainerEventsParameters()
            {
                Filters = filters,
            };

            _ = _Client.System.MonitorEventsAsync(eventParams, progress, tokenSource.Token);

            return(monitor);
        }