Ejemplo n.º 1
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "PostBlob/{title}")] HttpRequestMessage req, string title, ILogger log)
        {
            try
            {
                var multipartMemoryStreamProvider = await req.Content.ReadAsMultipartAsync().ConfigureAwait(false);

                var photoStream = await multipartMemoryStreamProvider.Contents[0].ReadAsStreamAsync().ConfigureAwait(false);

                var photo = await PhotosBlobStorageService.SavePhoto(photoStream, title).ConfigureAwait(false);

                log.LogInformation("Saved Photo to Blob Storage");

                await PhotoDatabaseService.InsertPhoto(photo).ConfigureAwait(false);

                log.LogInformation("Saved Photo to Database");

                return(new CreatedResult(photo.Url, photo));
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);

                return(new ObjectResult(e)
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError
                });
            }
        }
Ejemplo n.º 2
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "PostBlob/{title}")] HttpRequestMessage req, string title, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            try
            {
                var imageBlob = await JsonService.DeserializeMessage <PhotoBlobModel>(req).ConfigureAwait(false);

                var photo = await PhotosBlobStorageService.SavePhoto(imageBlob.Image, title).ConfigureAwait(false);

                photo.Tag1  = imageBlob.Tag1;
                photo.Tag2  = imageBlob.Tag2;
                photo.Tag3  = imageBlob.Tag3;
                photo.Tag4  = imageBlob.Tag4;
                photo.Tag5  = imageBlob.Tag5;
                photo.Tag6  = imageBlob.Tag6;
                photo.Tag7  = imageBlob.Tag7;
                photo.Tag8  = imageBlob.Tag8;
                photo.Tag9  = imageBlob.Tag9;
                photo.Tag10 = imageBlob.Tag10;

                photo.TagsSeperatedWithSpaces = imageBlob.TagsSeperatedWithSpaces;

                photo.CustomTag1  = imageBlob.CustomTag1;
                photo.CustomTag2  = imageBlob.CustomTag2;
                photo.CustomTag3  = imageBlob.CustomTag3;
                photo.CustomTag4  = imageBlob.CustomTag4;
                photo.CustomTag5  = imageBlob.CustomTag5;
                photo.CustomTag6  = imageBlob.CustomTag6;
                photo.CustomTag7  = imageBlob.CustomTag7;
                photo.CustomTag8  = imageBlob.CustomTag8;
                photo.CustomTag9  = imageBlob.CustomTag9;
                photo.CustomTag10 = imageBlob.CustomTag10;

                photo.CustomTagsSeperatedWithSpaces = imageBlob.CustomTagsSeperatedWithSpaces;
                photo.CreatedAtString = imageBlob.CreatedAtString;

                photo.City          = imageBlob.City;
                photo.LocationState = imageBlob.LocationState;
                photo.Country       = imageBlob.Country;
                photo.CityState     = imageBlob.CityState;

                photo.Lat  = imageBlob.Lat;
                photo.Long = imageBlob.Long;

                photo.BarcodeString = imageBlob.BarcodeString;


                await PhotoDatabaseService.InsertPhoto(photo).ConfigureAwait(false);

                return(new CreatedResult(photo.Url, photo));
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                return(new InternalServerErrorResult());
            }
        }
Ejemplo n.º 3
0
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestMessage req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            try
            {
                var photoList = PhotoDatabaseService.GetAllPhotos();
                return(new OkObjectResult(photoList));
            }
            catch
            {
                return(new InternalServerErrorResult());
            }
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            try
            {
                var photoList = await PhotoDatabaseService.GetAllPhotos();

                return(req.CreateResponse(HttpStatusCode.OK, photoList));
            }
            catch (System.Exception e)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, $"Get Photos Failed: {e.GetType().ToString()}: {e.Message}"));
            }
        }
Ejemplo n.º 5
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "PostPhoto/{title}")] HttpRequestMessage req, string title, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            try
            {
                var photoModel = await JsonService.DeserializeMessage <PhotoModel>(req).ConfigureAwait(false);

                await PhotoDatabaseService.InsertPhoto(photoModel).ConfigureAwait(false);

                return(new CreatedResult(photoModel.Url, photoModel));
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                return(new InternalServerErrorResult());
            }
        }
Ejemplo n.º 6
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "PostBlob/{title}")] HttpRequestMessage req, string title, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            try
            {
                var imageBlob = await JsonService.DeserializeMessage <PhotoBlobModel>(req);

                var photo = await PhotosBlobStorageService.SavePhoto(imageBlob.Image, title);

                await PhotoDatabaseService.InsertPhoto(photo);

                return(req.CreateResponse(HttpStatusCode.Created, photo));
            }
            catch (Exception e)
            {
                return(req.CreateResponse(HttpStatusCode.InternalServerError, $"Post Blob Failed: {e.GetType().ToString()}: {e.Message}"));
            }
        }
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "PostBlob/{title}")] HttpRequestMessage req, string title, ILogger log)
        {
            try
            {
                var imageBlob = await DeserializeMessage <PhotoBlobModel>(req).ConfigureAwait(false);

                log.LogInformation("Deserialized Image Blob");

                var photo = await PhotosBlobStorageService.SavePhoto(imageBlob.Image, title).ConfigureAwait(false);

                log.LogInformation("Saved Photo to Blob Storage");

                await PhotoDatabaseService.InsertPhoto(photo).ConfigureAwait(false);

                log.LogInformation("Saved Photo to Database");

                return(new CreatedResult(photo.Url, photo));
            }
            catch (Exception e)
            {
                log.LogError(e, e.Message);
                return(new InternalServerErrorResult());
            }
        }
Ejemplo n.º 8
0
 public GetPhotos(PhotoDatabaseService photoDatabaseService) => _photoDatabaseService = photoDatabaseService;
Ejemplo n.º 9
0
 public PostBlob(PhotosBlobStorageService photosBlobStorageService, PhotoDatabaseService photoDatabaseService) =>
 (_photosBlobStorageService, _photoDatabaseService) = (photosBlobStorageService, photoDatabaseService);