Пример #1
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            string fileName     = req.Query["name"];
            string blockSizeStr = req.Query["block"];

            int blockSize;

            if (!int.TryParse(blockSizeStr, out blockSize))
            {
                blockSize = 1024 * 10;
            }

            Stopwatch sw       = Stopwatch.StartNew();
            int       fileSize = await DiskHelper.DiskReadAsync(fileName, blockSize).ConfigureAwait(false);

            sw.Stop();

            double time   = fileSize == 0 ? 0.0 : sw.Elapsed.TotalMilliseconds;
            string result = $"{time:n2}";

            if (time == 0.0)
            {
                result += $", {Path.Combine(Path.GetTempPath(), fileName)}";
                result += $", {Environment.MachineName}";
            }

            return(fileName != null
                ? (ActionResult) new OkObjectResult($"{result}")
                : new BadRequestObjectResult("Please pass a name on the query string or in the request body"));
        }