Example #1
0
        public async Task Connect()
        {
            if (hubConnection.State == HubConnectionState.Connected)
            {
                return;
            }

            hubConnection.On <string>("AlertReceived", (user) =>
            {
                OnAlertReceived?.Invoke(this, new EventArgs());
            });

            hubConnection.On <string>("Celebrate", (user) =>
            {
                OnCelebrateReceived?.Invoke(this, new EventArgs());
            });


            try
            {
                await hubConnection.StartAsync();

                Console.WriteLine("Connected to GarageHub");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error connecting to GarageHub");
                Console.WriteLine(ex);
            }
        }
Example #2
0
        public static void SendAlert(object sender, AlertArgs alertArgs)
        {
            if (DbContext.Alerts.ContainsKey(alertArgs.Host))
            {
                DbContext.Alerts[alertArgs.Host].Add(new KH2FMCrowdControl.Data.KHAlert {
                    Viewer = alertArgs.Viewer, Item = alertArgs.Item, ImageUrl = alertArgs.ImageUrl
                });

                while (DbContext.Alerts[alertArgs.Host].Count > DbContext.AlertSettings[alertArgs.Host].AlertCount)
                {
                    DbContext.Alerts[alertArgs.Host].RemoveAt(0);
                }
            }

            OnAlertReceived?.Invoke(sender, alertArgs);
        }
Example #3
0
 public async Task AlertBroadcaster(string user)
 {
     OnAlertReceived?.Invoke(this, new EventArgs());
     await Clients.All.SendAsync("AlertReceived", user);
 }