コード例 #1
0
        internal async Task Send(int userId, string title, string text, string url, string icon, object data = null)
        {
            var not = new Notification(title, text, url, icon, null, data);

            if (!doubleChecker.HasNeverBeenSeen(userId, not))
            {
                return;
            }

            try
            {
                using (var context = new HypixelContext())
                {
                    var devices = context.Users.Where(u => u.Id == userId).SelectMany(u => u.Devices);
                    foreach (var item in devices)
                    {
                        Console.WriteLine("sending to " + item.UserId);
                        var success = await TryNotifyAsync(item.Token, not);

                        if (success)
                        {
                            return;
                        }
                        dev.Logger.Instance.Error("Sending pushnotification failed to");
                        dev.Logger.Instance.Error(JsonConvert.SerializeObject(item));
                        context.Remove(item);
                    }
                    await context.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
                dev.Logger.Instance.Error($"Could not send {not.body} to {userId}");
            }
        }
コード例 #2
0
        public async override Task Execute(MessageData data)
        {
            using (var context = new HypixelContext())
            {
                var name = data.GetAs <string>();

                var device = data.User.Devices.Where(d => d.Name == name).FirstOrDefault();
                if (device != null)
                {
                    context.Remove(device);
                }
                await context.SaveChangesAsync();

                await data.Ok();
            }
        }