コード例 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Queue("fleeteventranks"), StorageAccount("sttfleetg5618_STORAGE")] ICollector <string> msg,
            ExecutionContext context,
            ILogger log)
        {
            log.LogInformation("Fleet event ranks started");
            var configuration = new Configuration(context.FunctionAppDirectory);
            var gameApi       = new GameApi(configuration.STTApiConfiguration);
            await gameApi.Login();

            var data = await gameApi.GetFleetMemberInfo();

            var userdailies = UserDailies.Load(data);
            var squadranks  = SquadEventRank.Load(data);

            log.LogInformation("Fleet event ranks users: " + userdailies.Count);

            var queueItem = new EventRankQueueItem()
            {
                UserDailies = userdailies, SquadEventRanks = squadranks
            };

            msg.Add(JsonConvert.SerializeObject(queueItem));

            return(new OkResult());
        }
コード例 #2
0
        public static void Run(
            [QueueTrigger("fleeteventranks", Connection = "sttfleetg5618_STORAGE")] EventRankQueueItem queueItem,
            [CosmosDB(
                 databaseName: "g5618-fleet",
                 collectionName: "fleetdata",
                 ConnectionStringSetting = "sttfleetg5618_COSMOSDB")] IEnumerable <FleetData> fleetDataList,
            [CosmosDB(
                 databaseName: "g5618-fleet",
                 collectionName: "fleetdata",
                 ConnectionStringSetting = "sttfleetg5618_COSMOSDB")] out FleetData updatedFleetData,
            ExecutionContext context,
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {queueItem}");
            var configuration = new Configuration(context.FunctionAppDirectory);

            FleetData fleetData = fleetDataList.FirstOrDefault(f => f.Ident == "current");

            if (fleetData == null)
            {
                fleetData = new FleetData()
                {
                    Ident = "current", Squads = new List <SquadHistory>()
                };
            }

            // Squads
            fleetData.Squads  = _UpdateSquadHistory(fleetData, queueItem.SquadEventRanks);
            fleetData.Players = _UpdatePlayerHistory(fleetData, queueItem.UserDailies);
            updatedFleetData  = fleetData;

            // try
            // {
            //     var t = _SendToDiscord(log, queueItem.UserDailies, fleetData, configuration.DiscordConfiguration.DiscordEventRanksWebhookUrl);
            //     Task.WaitAll(t);
            // }
            // catch (Exception e)
            // {
            //     log.LogError($"Send to Discord failed: {e.Message}");
            // }
        }