Example #1
0
 private void WriteTextureToFile(string fileName)
 {
     if (originalTexture != null)
     {
         PhotoConverter.SaveImageAs(originalTexture, fileName);
     }
 }
        public void Convert_WithDto_CreatesPhoto()
        {
            var converter = new PhotoConverter(_conversions);

            var body           = "Canon 6D";
            var aperture       = 4;
            var shutterSpeed   = 200;
            var focalLength    = 35;
            var lens           = "EF 35mm";
            var isoSpeedRating = 100;

            var photo = converter.Convert(new PhotoDto
            {
                Body           = body,
                DateYear       = 2000,
                DateMonth      = 07,
                DateDay        = 03,
                Aperture       = aperture,
                ShutterSpeed   = shutterSpeed,
                FocalLength    = focalLength,
                Lens           = lens,
                IsoSpeedRating = isoSpeedRating
            });

            photo.Body.Should().Be(body);
            photo.TakenAt.Should().Be(DateTime.Parse("03-July-2000"));
            photo.Aperture.Should().Be(aperture);
            photo.ShutterSpeed.Should().Be(shutterSpeed);
            photo.FocalLength.Should().Be(focalLength);
            photo.Lens.Should().Be(lens);
            photo.IsoSpeedRating.Should().Be(isoSpeedRating);
        }
Example #3
0
        public void SetTheCorrectValuesToTheReturnedVieModelProperties_WhenPhotoIsProvided()
        {
            // Arrange
            var photoMock = new Mock <Photo>();

            photoMock.Object.Id        = Guid.NewGuid();
            photoMock.Object.UserId    = "test userId";
            photoMock.Object.Path      = "test path";
            photoMock.Object.Likes     = 0;
            photoMock.Object.CreatedOn = DateTime.UtcNow;
            photoMock.Object.IsDeleted = true;

            IPhotoConverter photoConverter = new PhotoConverter();

            // Act
            PhotoViewModel resultViewModel = photoConverter.ConvertToViewModel(photoMock.Object);

            // Assert
            Assert.AreEqual(photoMock.Object.Id, resultViewModel.Id);
            Assert.AreEqual(photoMock.Object.UserId, resultViewModel.UserId);
            Assert.AreEqual(photoMock.Object.Path, resultViewModel.Path);
            Assert.AreEqual(photoMock.Object.Likes, resultViewModel.Likes);
            Assert.AreEqual(photoMock.Object.CreatedOn, resultViewModel.CreatedOn);
            Assert.AreEqual(photoMock.Object.IsDeleted, resultViewModel.IsDeleted);
        }
Example #4
0
        private void SerializeGeneratedWorkaround(Material material, string masterFileName, List <string> supportFiles)
        {
            // This is method is needed because of this issue:
            // (



            if (material is MaterialGroup)
            {
                foreach (Material m in ((MaterialGroup)material).Children)
                {
                    SerializeGeneratedWorkaround(m, masterFileName, supportFiles);
                }
            }
            else
            {
                Brush brush = null;
                if (material is DiffuseMaterial)
                {
                    DiffuseMaterial dm = (DiffuseMaterial)material;
                    brush = dm.Brush;
                }
                else if (material is EmissiveMaterial)
                {
                    EmissiveMaterial em = (EmissiveMaterial)material;
                    brush = em.Brush;
                }
                else if (material is SpecularMaterial)
                {
                    SpecularMaterial sm = (SpecularMaterial)material;
                    brush = sm.Brush;
                }

                if (brush is ImageBrush)
                {
                    ImageBrush ib = (ImageBrush)brush;

                    // NOTE: Other forms of memory-generated bitmaps may need the same treatment.
                    if (ib.ImageSource is CachedBitmap)
                    {
                        CachedBitmap cb = (CachedBitmap)ib.ImageSource;
                        // Generate new file Name
                        int    fileIndex = supportFiles.Count;
                        string fileName  = masterFileName.Replace(".xaml", "_support_")
                                           + fileIndex.ToString() + ".png";
                        // Save as an image file (PNG to keep transparency)

                        PhotoConverter.SaveImageAs(cb, fileName);

                        // Remember the name
                        supportFiles.Add(fileName);
                        // Now replace this in the old brush
                        ib.ImageSource  = new BitmapImage(new Uri(fileName, UriKind.RelativeOrAbsolute));
                        ib.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox;
                    }
                }
                // The default case is for this to be a NO-OP
            }
        }
Example #5
0
        public void ThrowArgumentNullException_WhenPhotoIsNull()
        {
            // Arrange
            IPhotoConverter photoConverter = new PhotoConverter();

            // Act, Assert
            Assert.Throws <ArgumentNullException>(() => photoConverter.ConvertToViewModel(null));
        }
Example #6
0
        public void CreateAnInstanceOfPhotoViewModel_WhenPhotoIsProvided()
        {
            // Arrange
            var photoMock = new Mock <Photo>();

            IPhotoConverter photoConverter = new PhotoConverter();

            // Act, Assert
            Assert.IsInstanceOf <PhotoViewModel>(photoConverter.ConvertToViewModel(photoMock.Object));
        }
        public void Convert_WithBodyName_CalculatesCropMultiplier(string body, double expectedConversion)
        {
            var converter = new PhotoConverter(_conversions);

            converter.Convert(new PhotoDto {
                Body = body, DateYear = 2000, DateMonth = 07, DateDay = 03
            })
            .CropMultiplier
            .Should()
            .Be(expectedConversion);
        }
        public IActionResult UploadImage(IFormFile files, Photo photo)
        {
            if (files != null)
            {
                if (files.Length > 0)
                {
                    //Getting FileName
                    var fileName = Path.GetFileName(files.FileName);

                    //Assigning Unique Filename (Guid)
                    //var myUniqueFileName = Convert.ToString(Guid.NewGuid());
                    var myUniqueFileName = "original";

                    //Getting file Extension
                    var fileExtension = Path.GetExtension(fileName);

                    // concatenating  FileName + FileExtension
                    var newFileName = String.Concat(myUniqueFileName, fileExtension);

                    // Combines two strings into a path.
                    var filepath =
                        new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images")).Root + $@"{newFileName}";

                    using (FileStream fs = System.IO.File.Create(filepath))
                    {
                        files.CopyTo(fs);
                        fs.Flush();
                    }

                    photo.PhotoID     = 1;
                    photo.UploadPhoto = "/images/" + newFileName;
                }
            }

            var invert = new PhotoConverter();

            //photo.DitherPhoto = invert.DoDithering(photo.UploadPhoto);

            photo.InvertedPhoto = invert.InvertImage(photo.UploadPhoto);

            photo.GrayScale = invert.GrayScale(photo.InvertedPhoto);

            photo.DitherPhoto = invert.Halftone(photo.GrayScale);

            invert.SaveImage(photo.DitherPhoto);

            return(View(photo));
        }
Example #9
0
 public static PhotoEntity ToPhotoEntity(this PhotoViewModel photoViewModel)
 {
     return(PhotoConverter.ToPhotoEntity(photoViewModel));
 }
Example #10
0
        /// <summary>
        /// returns list of items found in database of this product type
        /// </summary>
        /// <returns>The items.</returns>
        /// <param name="productType">Product type.</param>
        private List <Item> GetItems(string productType)
        {
            /*
             * SQL ITEMS TABLE ORGANIZATION
             * ItemID
             * ItemType
             * ItemName
             * ItemPrice
             * ItemDescription
             */

            List <Item> items = new List <Item>();

            using (SqlConnection cnn = new SqlConnection(GSettings.connectionString))
            {
                cnn.Open();
                Console.WriteLine("connection opened for loading products of " + productType + "!");

                string query = "SELECT * FROM dbo.Items " +
                               "WHERE ItemType=@ProductType";

                SqlCommand cmd = new SqlCommand(query, cnn);

                cmd.Parameters.AddWithValue("@ProductType", productType);

                var reader = cmd.ExecuteReader();

                // for creating byte[] of images of products to form item object
                photoConverter = new PhotoConverter(productType);

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int    id          = reader.GetInt32(0);
                        string type        = reader.GetString(1);
                        string name        = reader.GetString(2);
                        int    price       = reader.GetInt32(3);
                        string description = reader.GetString(4);

                        // find a pic of this product for user
                        byte[] pic = photoConverter.ConvertImageToBytes(name);

                        // make a picture but its unpleasant for user
                        //    if (pic == null)
                        //        pic = photoConverter.PicNotFound;

                        Item adding = new Item(id, name, price, type, description);
                        adding.Pic = pic;

                        items.Add(adding);
                    }
                }
                else
                {
                    // if smth went absolutely wrong
                    return(null);
                }

                Console.WriteLine("connection closed for forming list of items!");
                cnn.Close();
            }

            return(items);
        }