Example #1
0
        public static async Task <HttpResponseMessage> UpdateObject([HttpTrigger(AuthorizationLevel.Anonymous,
                                                                                 "put", Route = "objects/{id}")] HttpRequestMessage req,
                                                                    string id,
                                                                    ILogger log, ExecutionContext context, ClaimsPrincipal claimsPrincipal)
        {
            Stopwatch stopWatch = new Stopwatch();

            var json = await req.Content.ReadAsStringAsync();

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

            var oldItem = await CloudTableExtensions.GetObjFromTable(id, claimsPrincipal.Identity.Name);

            item.id         = id;                 // ensure item id matches id passed in
            item.isComplete = oldItem.isComplete; // ensure we don't change isComplete
            item.createdBy  = claimsPrincipal.Identity.Name;
            await CloudTableExtensions.AddOrUpdateToTable(item);

            stopWatch.Stop();

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

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

            TelemetryClient telemetryClient = telemetryFactory.GetClient(context);

            telemetryClient.TrackEvent("update-object", properties: props, metrics: metrics);
            return(req.CreateResponse(HttpStatusCode.OK, item));
        }
Example #2
0
        public static async Task <HttpResponseMessage> GetObject([HttpTrigger(AuthorizationLevel.Anonymous,
                                                                              Route = "GetObject/{id}")] HttpRequestMessage req, string id,

                                                                 ILogger log, ClaimsPrincipal claimsPrinciple, ExecutionContext context)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            var item = await CloudTableExtensions.GetObjFromTable(id, claimsPrinciple.Identity.Name);

            stopWatch.Stop();

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

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

            TelemetryClient telemetryClient = telemetryFactory.GetClient(context);

            telemetryClient.TrackEvent("get-object", metrics: metrics);

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