示例#1
0
        public static Photo ProcessPhoto(int buildingId, byte[] imageBytes, ImageFormat format, string extension,
                                         BuildingFacade buildingFacade, PhotoFacade photoFacade)
        {
            var photoId = Guid.NewGuid();

            //resolutions
            var vectors = new List <Vector2>();

            vectors.Add(new Vector2(800, 600));
            vectors.Add(new Vector2(600, 395));
            vectors.Add(new Vector2(280, 190));
            vectors.Add(new Vector2(200, 150));
            vectors.Add(new Vector2(115, 85));
            vectors.Add(new Vector2(50, 50));

            //load image
            using (var stream = new MemoryStream(imageBytes))
            {
                stream.Position = 0;
                using (Image image = Image.FromStream(stream))
                {
                    foreach (var v in vectors)
                    {
                        using (Image resized = ImageScaler.Crop(image, v.X, v.Y,
                                                                ImageScaler.AnchorPosition.Center))
                        {
                            string fileName = string.Format("{0}-{1}x{2}{3}",
                                                            photoId, v.X, v.Y, extension);

                            //UploadPhoto would go here
                            SavePhoto(buildingId, resized, fileName, format);
                        }
                    }
                }
            }

            //create the db reference for the images.
            var photo = new Photo();

            photo.PhotoId    = photoId;
            photo.BuildingId = buildingId;
            photo.Extension  = extension.Replace(".", string.Empty);

            if (photoFacade.GetPhotos(buildingId).Count(p => p.IsPrimary) == 0)
            {
                photo.IsPrimary = true;
            }

            if (photo.IsPrimary)
            {
                var building = buildingFacade.GetBuilding(buildingId);
                building.PrimaryPhotoId        = photo.PhotoId;
                building.PrimaryPhotoExtension = photo.Extension;
                buildingFacade.Save();
            }

            photoFacade.AddPhoto(buildingId, photo);
            photoFacade.Save();
            return(photo);
        }
示例#2
0
        public static Photo ProcessPhoto(int buildingId, byte[] imageBytes, ImageFormat format, string extension,
			BuildingFacade buildingFacade, PhotoFacade photoFacade)
        {
            var photoId = Guid.NewGuid();

            //resolutions
            var vectors = new List<Vector2>();
            vectors.Add(new Vector2(800, 600));
            vectors.Add(new Vector2(600, 395));
            vectors.Add(new Vector2(280, 190));
            vectors.Add(new Vector2(200, 150));
            vectors.Add(new Vector2(115, 85));
            vectors.Add(new Vector2(50, 50));

            //load image
            using(var stream = new MemoryStream(imageBytes))
            {
                stream.Position = 0;
                using(Image image = Image.FromStream(stream))
                {
                    foreach(var v in vectors)
                    {
                        using(Image resized = ImageScaler.Crop(image, v.X, v.Y,
                                  ImageScaler.AnchorPosition.Center))
                        {
                            string fileName = string.Format("{0}-{1}x{2}{3}",
                                                photoId, v.X, v.Y, extension);

                            //UploadPhoto would go here
                            SavePhoto(buildingId, resized, fileName, format);
                        }
                    }
                }
            }

            //create the db reference for the images.
            var photo = new Photo();
            photo.PhotoId = photoId;
            photo.BuildingId = buildingId;
            photo.Extension = extension.Replace(".", string.Empty);

            if(photoFacade.GetPhotos(buildingId).Count(p => p.IsPrimary) == 0)
                photo.IsPrimary = true;

            if(photo.IsPrimary)
            {
                var building = buildingFacade.GetBuilding(buildingId);
                building.PrimaryPhotoId = photo.PhotoId;
                building.PrimaryPhotoExtension = photo.Extension;
                buildingFacade.Save();
            }

            photoFacade.AddPhoto(buildingId, photo);
            photoFacade.Save();
            return photo;
        }
 public void getAllPhotosTest()
 {
     Assert.AreEqual(0, photoFacade.GetPhotos().Count());
 }