예제 #1
0
        public static async Task <HttpResponseMessage> CreateObject(
            [HttpTrigger(AuthorizationLevel.Anonymous,

                         "post")] HttpRequestMessage req,

            ILogger log, ClaimsPrincipal claimsPrinciple)
        {
            try
            {
                log.LogInformation("User:" + claimsPrinciple.Identity.Name);
                var json = await req.Content.ReadAsStringAsync();

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

                objectInfo.createdBy = claimsPrinciple.Identity.Name;

                await CloudTableExtensions.AddOrUpdateToTable(objectInfo);


                return(req.CreateResponse(HttpStatusCode.Created, objectInfo));
            }
            catch (Exception e)
            {
                log.LogError(e.Message);
                log.LogError(e.StackTrace);

                return(req.CreateResponse(HttpStatusCode.InternalServerError, e.Message));

                throw e;
            }
        }
예제 #2
0
        public static async Task <List <ObjectInfo> > GetAllObject([HttpTrigger(AuthorizationLevel.Anonymous,
                                                                                "get")] HttpRequest req, ExecutionContext context, ILogger log, ClaimsPrincipal claimsPrinciple)
        {
            try
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                var item = await CloudTableExtensions.GetAllObject(claimsPrinciple.Identity.Name);

                stopWatch.Stop();

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



                TelemetryClient telemetryClient = telemetryFactory.GetClient(context);
                telemetryClient.TrackEvent("get-all-objects", metrics: metrics);

                //return req.CreateResponse(HttpStatusCode.OK, item);
                return(item.Select(i => i.MapFromTableEntity()).ToList());;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public static async Task <HttpResponseMessage> DeleteObject([HttpTrigger(AuthorizationLevel.Anonymous, "delete",
                                                                                 Route = "objects/{id}")] HttpRequestMessage req, string id,

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

            try
            {
                await CloudTableExtensions.DeleteObjFromTable(id, claimsPrinciple.Identity.Name);
            }
            catch (Exception ex)
            {
                throw ex;
            }


            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("delete-object", properties: props, metrics: metrics);

            return(req.CreateResponse(HttpStatusCode.OK));
        }
예제 #4
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));
        }
예제 #5
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));
        }
        public static async Task Run([TimerTrigger("0 0 * * * *")] TimerInfo myTimer, ILogger log, ClaimsPrincipal claimsPrinciple)
        {
            try
            {
                log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
                //Send Email At each 24 hour

                var item = await CloudTableExtensions.GetAllObject(claimsPrinciple.Identity.Name);


                var json        = Newtonsoft.Json.JsonConvert.SerializeObject(item);
                var emailSender = new EmailSender();
                await emailSender.SendEmailAsync(FunctionsSettings.ToEmail, "Azure function poc Data", json);

                log.LogInformation("Email Send");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }