Ejemplo n.º 1
0
        private void FaceImagePublishCreateEvent(object sender, ContentEventArgs e)
        {
            ContentData          content     = e.Content as ContentData;
            SaveContentEventArgs savingEvent = e as SaveContentEventArgs;

            if ((savingEvent.Action & EPiServer.DataAccess.SaveAction.CheckOut) != EPiServer.DataAccess.SaveAction.Default || content == null || ContentReference.IsNullOrEmpty(e.ContentLink))
            {
                return;
            }
            Dictionary <string, EPiFaceImageAttribute> faceImageProperties = ListFaceImageProperties(e);

            if (faceImageProperties.Count == 0)
            {
                return;
            }

            ContentAssetFolder contentAssetFolder = _contentAssetHelperInj.Service.GetOrCreateAssetFolder(e.ContentLink);

            if (contentAssetFolder == null)
            {
                return;
            }
            foreach (var faceImagePropertyDef in faceImageProperties)
            {
                ContentReference imageReference = content.GetPropertyValue <ContentReference>(faceImagePropertyDef.Key);
                if (ContentReference.IsNullOrEmpty(imageReference))
                {
                    continue;
                }

                ImageData image;
                if (!_contentLoaderInj.Service.TryGet(imageReference, out image) || image.GetOriginalType() == typeof(FaceImageData) || image.BinaryData == null)
                {
                    continue;
                }

                Image imageDetails = Image.FromStream(new MemoryStream(image.BinaryData.ReadAllBytes()));
                if (imageDetails == null)
                {
                    continue;
                }

                byte[] faceResizedImage;

                if (!TryToDetectFaceAndResizeImage(faceImagePropertyDef, image, imageDetails, out faceResizedImage))
                {
                    continue;
                }

                ContentReference faceImageId = CreateFaceMediaFile(contentAssetFolder, image, faceResizedImage);
                content[faceImagePropertyDef.Key] = faceImageId;
            }
        }
 private static void DeleteContentInAssetFolders(IEnumerable <ContentReference> contentReferences, ContentAssetHelper assetHelper,
                                                 IContentRepository repo, StringBuilder sb, IBlobFactory blobFactory)
 {
     foreach (ContentReference reference in contentReferences)
     {
         ContentAssetFolder folder = assetHelper.GetAssetFolder(reference);
         if (folder != null && folder.ContentLink != null)
         {
             var folderContents = repo.GetDescendents(folder.ContentLink);
             DeleteBlobs(folderContents, repo, sb, blobFactory);
         }
     }
 }
Ejemplo n.º 3
0
        private ContentReference CreateFaceMediaFile(ContentAssetFolder contentAssetFolder, ImageData image, byte[] faceResizedImage)
        {
            FaceImageData faceImage = _contentRepositoryInj.Service.GetDefault <FaceImageData>(contentAssetFolder.ContentLink);

            faceImage.Name = $"autogenerated_{image.Name}";

            Blob imageBlob = _blobFactoryInj.Service.CreateBlob(faceImage.BinaryDataContainer, ".png");

            using (Stream blobWriter = imageBlob.OpenWrite())
                using (MemoryStream memoryStream = new MemoryStream(faceResizedImage))
                {
                    memoryStream.CopyTo(blobWriter);
                }
            faceImage.BinaryData = imageBlob;
            ContentReference faceImageId = _contentRepositoryInj.Service.Save(faceImage, EPiServer.DataAccess.SaveAction.Publish);

            return(faceImageId);
        }
Ejemplo n.º 4
0
        // POST api/<controller>
        public ReviewData Post(ReviewData reviewData)
        {
            string language = Language;

            ContentReference   contentLink = _referenceConverter.GetContentLink(reviewData.ContentId, CatalogContentType.CatalogEntry, 0);
            ContentAssetFolder assetFolder = _contentAssetHelper.GetOrCreateAssetFolder(contentLink);
            EntryContentBase   product     = _contentRepository.Get <EntryContentBase>(contentLink, new CultureInfo(language));

            Review newReview = _contentRepository.GetDefault <Review>(assetFolder.ContentLink, new CultureInfo(language));

            newReview.Rating  = reviewData.Rating;
            newReview.Heading = reviewData.Heading;
            newReview.Text    = reviewData.Text;
            //TODO: Get currentuser, need to be logedin to post review
            newReview.UserDisplayName = reviewData.UserName;
            newReview.Name            = newReview.UserDisplayName + "(" + DateTime.Now.ToShortDateString() + ")";
            newReview.ReviewDate      = DateTime.Now;
            ContentReference cf           = _contentRepository.Save(newReview, SaveAction.Publish, AccessLevel.NoAccess);
            Review           postedReview = _contentRepository.Get <Review>(cf, new CultureInfo(language));

            if (postedReview != null)
            {
                ReviewData review = new ReviewData
                {
                    ContentId  = postedReview.ContentId,
                    Rating     = postedReview.Rating,
                    Heading    = postedReview.Heading,
                    Text       = postedReview.Text,
                    UserName   = postedReview.UserDisplayName,
                    ReviewDate = postedReview.ReviewDate
                };
                UpdateProductWithAverageReview(product, language);
                return(review);
            }

            return(null);
        }