Exemple #1
0
        public static async Task<HttpResponseMessage> BattlePostAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "battles")]HttpRequestMessage req,
            [Table("PredictedInfo")] IQueryable<PredictedInfo> predictedInfo,
            [Table("Tags")] IQueryable<Tag> tags,
            [Table("BattleResult")]ICollector<BattleResultInfo> outBattleResultTable,
            TraceWriter log)
        {
            dynamic data = await req.Content.ReadAsAsync<object>();
            string nameX = data.nameX;
            string nameY = data.nameY;
            var infoX = predictedInfo.Where(x => x.PartitionKey == "Upload" && x.RowKey == nameX).First();
            var infoY = predictedInfo.Where(x => x.PartitionKey == "Upload" && x.RowKey == nameY).First();
            var unitX = BattleLogic.AnalyzeParameter(infoX, tags.ToList());
            var unitY = BattleLogic.AnalyzeParameter(infoY, tags.ToList());
            var imageX = ImageInfo.FromNameAndResult(nameX, infoX);
            var imageY = ImageInfo.FromNameAndResult(nameY, infoY);
            var invertedTicks = string.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks);
            var resultId = invertedTicks + "-" + Guid.NewGuid();
            log.Info(JsonConvert.SerializeObject(unitX));
            log.Info(JsonConvert.SerializeObject(unitY));

            var result = BattleLogic.Battle(unitX, unitY);
            log.Info(JsonConvert.SerializeObject(result));

            var resultInfo = new BattleResultInfo()
            {
                PartitionKey = nameX,
                RevFlag = false,
                ThumbnailUrlX = imageX.ThumbnailUrl,
                ThumbnailUrlY = imageY.ThumbnailUrl,
                RowKey = resultId,
                Result = result
            };
            outBattleResultTable.Add(resultInfo);
            // 検索の便宜上、対戦相手側のキーをパーティションとしたレコードを生成する
            // XXX 効果検証(有効ではない可能性がある)
            var resultInfoR = new BattleResultInfo()
            {
                PartitionKey = nameY,
                RevFlag = true,
                ThumbnailUrlX = imageX.ThumbnailUrl,
                ThumbnailUrlY = imageY.ThumbnailUrl,
                RowKey = resultId,
                Result = result
            };
            outBattleResultTable.Add(resultInfoR);

            return req.CreateJsonResponse(HttpStatusCode.OK, new
            {
                ResultId = resultInfo.RowKey
            });
        }
        public static HttpResponseMessage ImageParameter(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "images/parameter/{name}")] HttpRequestMessage req,
            string name,
            [Table("PredictedInfo")] IQueryable <PredictedInfo> predictedInfo,
            [Table("Tags")] IQueryable <Tag> tags,
            TraceWriter log)
        {
            var blobName = name;
            var info     = predictedInfo.Where(x => x.PartitionKey == "Upload" && x.RowKey == blobName).First();
            var unit     = BattleLogic.AnalyzeParameter(info, tags.ToList());

            log.Info(JsonConvert.SerializeObject(unit));

            return(req.CreateJsonResponse(HttpStatusCode.OK, unit));
        }