コード例 #1
0
        public async Task <OneSignalNotificationResponse> PushNotification(List <string> playerIds, string message, bool isAdminNotification, int requestId, int requestType)
        {
            if (!playerIds.Any())
            {
                return(null);
            }
            var id = await _appConfig.GetAsync(ConfigurationTypes.Notification);

            var request = new Request(string.Empty, ApiUrl, HttpMethod.Post);

            var body = new OneSignalNotificationBody
            {
                app_id   = id.Value,
                contents = new Contents
                {
                    en = message
                },
                include_player_ids = playerIds.ToArray()
            };

            if (isAdminNotification)
            {
                // Add the action buttons
                body.data    = new { requestid = requestId, requestType = requestType };
                body.buttons = new[]
                {
                    new Button {
                        id = "approve", text = "Approve Request"
                    },
                    new Button {
                        id = "deny", text = "Deny Request"
                    },
                };
            }

            request.AddJsonBody(body);

            var result = await _api.Request <OneSignalNotificationResponse>(request);

            return(result);
        }
コード例 #2
0
        public async Task <string> GetTvBackground(string tvdbId)
        {
            var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async() => await _configRepository.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));

            var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}tv{tvdbId}", async() => await _fanartTvApi.GetTvImages(int.Parse(tvdbId), key.Value), DateTime.Now.AddDays(1));

            if (images == null)
            {
                return(string.Empty);
            }

            if (images.showbackground?.Any() ?? false)
            {
                var enImage = images.showbackground.Where(x => x.lang == "en").OrderByDescending(x => x.likes).Select(x => x.url).FirstOrDefault();
                if (enImage == null)
                {
                    return(images.showbackground.OrderByDescending(x => x.likes).Select(x => x.url).FirstOrDefault());
                }
                return(enImage);
            }

            return(string.Empty);
        }