예제 #1
0
        private async void Overlay_OnWebSocketConnectedOccurred(object sender, EventArgs e)
        {
            IOverlayEndpointService overlay = (IOverlayEndpointService)sender;

            this.OnOverlayConnectedOccurred(overlay, new EventArgs());

            Logger.Log("Client connected to Overlay Endpoint - " + overlay.Name);

            overlay.StartBatching();
            foreach (OverlayWidgetModel widget in ChannelSession.Settings.OverlayWidgets.Where(ow => ow.OverlayName.Equals(overlay.Name)))
            {
                try
                {
                    if (widget.IsEnabled)
                    {
                        await widget.ShowItem();

                        await widget.LoadCachedData();

                        await widget.UpdateItem();
                    }
                }
                catch (Exception ex) { Logger.Log(ex); }
            }
            await overlay.EndBatching();
        }
예제 #2
0
        private async Task WidgetsBackgroundUpdate(CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            UserViewModel user = ChannelSession.GetCurrentUser();

            foreach (var widgetGroup in ChannelSession.Settings.OverlayWidgets.GroupBy(ow => ow.OverlayName))
            {
                IOverlayEndpointService overlay = this.GetOverlay(widgetGroup.Key);
                if (overlay != null)
                {
                    overlay.StartBatching();
                    foreach (OverlayWidgetModel widget in widgetGroup)
                    {
                        try
                        {
                            if (!widget.Item.IsInitialized)
                            {
                                await widget.Initialize();
                            }

                            if (widget.IsEnabled)
                            {
                                if (!widget.Item.IsEnabled)
                                {
                                    await widget.Enable();
                                }
                                else if (widget.SupportsRefreshUpdating && widget.RefreshTime > 0 && (this.updateSeconds % widget.RefreshTime) == 0)
                                {
                                    await widget.UpdateItem();
                                }
                            }
                            else
                            {
                                if (widget.Item.IsEnabled)
                                {
                                    await widget.Disable();
                                }
                            }
                        }
                        catch (Exception ex) { Logger.Log(ex); }
                    }
                    await overlay.EndBatching();
                }
            }

            this.updateSeconds++;
        }