示例#1
0
        public async Task <IActionResult> AddSample(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req)
        {
            try
            {
                // Track an Event
                TelemetryClientWrapper.Instance.TrackEvent("Received new sample request");

                var model = await GetFormBody <AddSampleViewModel>(req);

                if (model != null)
                {
                    TelemetryClientWrapper.Instance.TrackEvent("Saving to database");
                    var sample = await _sampleRepository.AddAsync(new Sample(model.Email, model.Password));

                    var sampleVm = _mapper.Map <SampleViewModel>(sample);

                    return(new OkObjectResult(sampleVm));
                }
            }
            catch (Exception ex)
            {
                // Track an Exception
                TelemetryClientWrapper.Instance.TrackException(new System.InvalidOperationException("Background Thread Exception"));
                throw ex;
            }
            return(new BadRequestObjectResult(""));
        }
示例#2
0
        public static async Task InsertAsync(ILogger logger, ISampleRepository repository, int count)
        {
            logger.LogInformation("Before measure");

            var data = SampleEntity.CreateList(count);

            using var tx = new TransactionScope(TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled);

            var sw = new Stopwatch();

            sw.Start();

            await repository.AddAsync(data);

            sw.Stop();

            tx.Complete();

            logger.LogMetric("InsertPerformance", sw.ElapsedMilliseconds, new Dictionary <string, object>
            {
                { "Repository", repository.GetType().Name },
                { "Count", count }
            });
            logger.LogInformation("After measure");
        }