示例#1
0
        public static async Task <HttpResponseMessage> CreateToDo(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "api/todos")] HttpRequestMessage req,
            [Table("todotable", Connection = "MyTable")] CloudTable table,
            TraceWriter log,
            ExecutionContext context)
        {
            TelemetryClient telemetryClient = telemetryFactory.GetClient();

            try
            {
                Stopwatch stopWatch = new Stopwatch();
                var       json      = await req.Content.ReadAsStringAsync();

                var todo = JsonConvert.DeserializeObject <ToDo>(json);
                table.AddOrUpdateToDoToTable(todo);
                stopWatch.Stop();

                var metrics = new Dictionary <string, double> {
                    { "processingTime", stopWatch.Elapsed.TotalMilliseconds }
                };

                var props = new Dictionary <string, string> {
                    { "todo-id", todo.id }
                };


                telemetryClient.TrackEvent("create-todo", metrics: metrics);
                return(req.CreateResponse(HttpStatusCode.Created, todo));
            }
            catch (Exception e)
            {
                telemetryClient.TrackException(e);
                return(req.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
示例#2
0
        public static async Task <HttpResponseMessage> SetCompleteToDo(
            [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "api/todos/{id}")] HttpRequestMessage req,
            [Table("todotable", Connection = "MyTable")] CloudTable table,
            string id,
            TraceWriter log)
        {
            Stopwatch stopWatch = new Stopwatch();
            var       json      = await req.Content.ReadAsStringAsync();

            var item = JsonConvert.DeserializeObject <ToDo>(json);

            var oldItem = table.GetToDoFromTable(id);

            oldItem.isComplete = item.isComplete;

            table.AddOrUpdateToDoToTable(oldItem);
            stopWatch.Stop();

            var metrics = new Dictionary <string, double> {
                { "processingTime", stopWatch.Elapsed.TotalMilliseconds }
            };

            var props = new Dictionary <string, string> {
                { "todo-id", id }
            };

            TelemetryClient telemetryClient = telemetryFactory.GetClient();

            telemetryClient.TrackEvent("complete-todo", properties: props, metrics: metrics);

            return(req.CreateResponse(HttpStatusCode.OK, oldItem));
        }