public static async System.Threading.Tasks.Task RunAsync(
        [EventHubTrigger("stegawiothub", Connection = "EventHubConnStr", ConsumerGroup = "azurefunctionsconsumergroup")] EventData eventHubMessage,
        DateTime enqueuedTimeUtc,
        Int64 sequenceNumber,
        string offset,
        ILogger log,
        ExecutionContext context)
    {
        log.LogInformation($"Event: {Encoding.UTF8.GetString(eventHubMessage.Body)}");
        // Metadata accessed by binding to EventData
        log.LogInformation($"EnqueuedTimeUtc={eventHubMessage.SystemProperties.EnqueuedTimeUtc}");
        log.LogInformation($"SequenceNumber={eventHubMessage.SystemProperties.SequenceNumber}");
        log.LogInformation($"Offset={eventHubMessage.SystemProperties.Offset}");
        // Metadata accessed by using binding expressions in method parameters
        log.LogInformation($"EnqueuedTimeUtc={enqueuedTimeUtc}");
        log.LogInformation($"SequenceNumber={sequenceNumber}");
        log.LogInformation($"Offset={offset}");

        var container    = ContainerHelper.Build(context);
        var repo         = (ICurrentLocationRepository)container.GetService(typeof(ICurrentLocationRepository));
        var userLocation = JsonConvert.DeserializeObject <UserLocation>(Encoding.UTF8.GetString(eventHubMessage.Body));
        var res          = await repo.SaveLocationAsync(userLocation);

        if (res)
        {
            log.LogInformation($"Successfully stored location. User: {userLocation.UserId}. Lat: {userLocation.Location.gpsLat}. Long: {userLocation.Location.gpsLong}.");
        }
        else
        {
            log.LogError($"Failed to save user location.");
        }
    }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] UserLocation userLocation,
            ILogger log,
            ExecutionContext context)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            var container    = ContainerHelper.Build(context);
            var locationRepo = (ICurrentLocationRepository)container.GetService(typeof(ICurrentLocationRepository));
            var mapsRepo     = (IAzureMapsRepository)container.GetService(typeof(IAzureMapsRepository));

            var assistantsDTO = await locationRepo.GetUsers(UserType.CareRecipient);

            var assistantsLocations = assistantsDTO.Select(t => t.ToUserLocation());
            var closestUserIds      = await mapsRepo.GetClosestUserIds(assistantsLocations, userLocation);

            var requestObject = new RequestHelpPushNotification()
            {
                SourceDeviceId  = userLocation.UserId.ToString(),
                TargetDeviceIds = closestUserIds.ToArray(),
                Type            = "RequestNearbyHelp",
            };

            var nextBodySerialized = JsonConvert.SerializeObject(requestObject);

            var(nextStatus, nextResponseMessage) = await HttpClientHelper.PostAsync(requestHelpPushUrl, nextBodySerialized);

            if (nextStatus == System.Net.HttpStatusCode.OK ||
                nextStatus == System.Net.HttpStatusCode.Created ||
                nextStatus == System.Net.HttpStatusCode.Accepted)
            {
                return((ActionResult) new OkObjectResult($"Successfully triggered the next step. Push Notifications. Body used : {nextBodySerialized}"));
            }

            return((ActionResult) new BadRequestObjectResult($"Failed to trigger the next step. Push Notifications. Body used : {nextBodySerialized}"));
        }
예제 #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] UserLocation userLocation,
            ILogger log,
            ExecutionContext context)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            var container = ContainerHelper.Build(context);
            var repo      = (ICurrentLocationRepository)container.GetService(typeof(ICurrentLocationRepository));
            var res       = await repo.SaveLocationAsync(userLocation);

            if (res)
            {
                return((ActionResult) new OkObjectResult($"Done."));
            }
            else
            {
                log.LogError($"Failed to save user location.");
                return(new BadRequestObjectResult("We messed up."));
            }
        }
예제 #4
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] Acknowledge acknowledge,
            ILogger log,
            ExecutionContext context)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var container       = ContainerHelper.Build(context);
            var acknowledgeRepo = (IAcknoledgeRepository)container.GetService(typeof(IAcknoledgeRepository));
            var mapsRepo        = (IAzureMapsRepository)container.GetService(typeof(IAzureMapsRepository));

            try
            {
                var res = await acknowledgeRepo.SaveAcknowledgeAsync(acknowledge);

                var getDirectionsResponse = await mapsRepo.GetPedestrianDirections(acknowledge.CareTakerLocation, acknowledge.CareRecipientLocation);

                var directionsPathAsGeoJson = getDirectionsResponse.GetRouteAsGeoJson();

                var(nextStatus, nextResponseMessage) = await HttpClientHelper.PostAsync(showDirectionsPushUrl, directionsPathAsGeoJson);

                if (nextStatus == System.Net.HttpStatusCode.OK ||
                    nextStatus == System.Net.HttpStatusCode.Created ||
                    nextStatus == System.Net.HttpStatusCode.Accepted)
                {
                    return((ActionResult) new OkObjectResult(new AcknowledgeResponse {
                        DestinationPath = directionsPathAsGeoJson
                    }));
                }

                return((ActionResult) new BadRequestObjectResult($"Failed to trigger the next step. Show Directions. Body used : {directionsPathAsGeoJson}"));
            }
            catch (StorageException)
            {
                return((ActionResult) new OkObjectResult("Help is already dispatched. Thank you!"));
            }
        }