Esempio n. 1
0
        public static async Task Run([TimerTrigger("%PostGifsFunctionCron%")] TimerInfo myTimer, ILogger log)
        {
            var connectionString = Environment.GetEnvironmentVariable("TrendingGiphyBotConnectionString");
            var botToken         = Environment.GetEnvironmentVariable("BotToken");
            var hourOffsetString = Environment.GetEnvironmentVariable("HourOffset");
            var hourOffset       = int.Parse(hourOffsetString);
            var now = DateTime.Now.AddHours(-hourOffset);
            var validMinutesString  = Environment.GetEnvironmentVariable("ValidMinutes");
            var validMinutes        = validMinutesString.Split(',', options: StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var validHoursString    = Environment.GetEnvironmentVariable("ValidHours");
            var validHours          = validHoursString.Split(',', options: StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var validHoursAsMinutes = validHours.Select(s => s * 60);
            var allValidMinutes     = validMinutes.Concat(validHoursAsMinutes).ToList();
            var giphyRandomEndpoint = Environment.GetEnvironmentVariable("GiphyRandomEndpoint");
            var warningResponses    = Environment.GetEnvironmentVariable("WarningResponses").Split(',', options: StringSplitOptions.RemoveEmptyEntries).ToList();
            var logWrapper          = new LoggerWrapper(log);

            using (var context = new TrendingGiphyBotContext(connectionString))
                using (var giphyWrapper = new GiphyWrapper())
                    using (var discordWrapper = new DiscordWrapper(botToken))
                    {
                        var gifPostingHelper = new GifPostingHelper(logWrapper, context, giphyWrapper, discordWrapper, warningResponses);
                        var postGifsHelper   = new PostGifsHelper(gifPostingHelper);
                        await postGifsHelper.RunAsync(now, allValidMinutes, giphyRandomEndpoint);
                    }
        }
 public void SetUp()
 {
     _GifPostingHelper = new Mock <IGifPostingHelper>();
     _PostGifsHelper   = new PostGifsHelper(_GifPostingHelper.Object);
 }