Exemplo n.º 1
0
        public void CreateImageWithNativeAPI(Guid masterImageId, string imageTitle, Stream imageStream, string imageFileName, string imageExtension)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();
            Image            image            = librariesManager.GetImages().Where(i => i.Id == masterImageId).FirstOrDefault();

            if (image == null)
            {
                image = librariesManager.CreateImage(masterImageId);

                Album album = librariesManager.GetAlbums().FirstOrDefault();
                image.Parent = album;

                image.Title            = imageTitle;
                image.DateCreated      = DateTime.UtcNow;
                image.PublicationDate  = DateTime.UtcNow;
                image.LastModified     = DateTime.UtcNow;
                image.UrlName          = Regex.Replace(imageTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                image.MediaFileUrlName = Regex.Replace(imageFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                librariesManager.Upload(image, imageStream, imageExtension);

                librariesManager.SaveChanges();

                var bag = new Dictionary <string, string>();
                bag.Add("ContentType", typeof(Image).FullName);
                WorkflowManager.MessageWorkflow(masterImageId, typeof(Image), null, "Publish", false, bag);
            }
        }
        public Image CreateImageWithNativeAPI(CreateImageDto createImageDto)
        {
            //The album post is created as master. The masterImageId is assigned to the master version.
            LibrariesManager librariesManager = LibrariesManager.GetManager();
            Guid             imageId          = Guid.NewGuid();
            Image            image            = librariesManager.CreateImage(imageId);

            //Set the parent album.
            Album album = librariesManager.GetAlbums().SingleOrDefault();

            image.Parent = album;

            //Set the properties of the album post.
            image.Title            = createImageDto.Title;
            image.DateCreated      = DateTime.Now;
            image.PublicationDate  = DateTime.Now;
            image.LastModified     = DateTime.Now;
            image.UrlName          = Regex.Replace($"{createImageDto.Title}-{imageId}".ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            image.MediaFileUrlName = Regex.Replace(createImageDto.FileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

            //Upload the image file.
            // The imageExtension parameter must contain '.', for example '.jpeg'
            librariesManager.Upload(image, createImageDto.Stream, createImageDto.FileExtension);

            //Save the changes.
            librariesManager.SaveChanges();

            //Publish the Albums item. The live version acquires new ID.
            var bag = new Dictionary <string, string>();

            bag.Add("ContentType", typeof(Image).FullName);
            WorkflowManager.MessageWorkflow(imageId, typeof(Image), null, "Publish", false, bag);

            return(image);
        }
Exemplo n.º 3
0
        public Guid Upload(string imageTitle, Stream imageStream, string imageFileName, string imageExtension, string albumTitle)
        {
            CultureInfo culture = CultureInfo.InvariantCulture;

            LibrariesManager librariesManager = LibrariesManager.GetManager(LibrariesManager.GetDefaultProviderName());
            Album            album            = librariesManager.GetAlbums().Where(i => i.Title.Equals(albumTitle)).SingleOrDefault();

            Image image = librariesManager.CreateImage();

            image.Parent                      = album;
            image.Title[culture]              = imageTitle;
            image.DateCreated                 = DateTime.UtcNow;
            image.LastModified                = DateTime.UtcNow;
            image.PublicationDate             = DateTime.UtcNow;
            image.UrlName[culture]            = Regex.Replace(imageTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            image.MediaFileUrlName[culture]   = Regex.Replace(imageFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
            image.ApprovalWorkflowState.Value = "Published";

            librariesManager.Upload(image, imageStream, imageExtension);
            librariesManager.RecompileItemUrls(image);

            librariesManager.Lifecycle.Publish(image, culture);
            librariesManager.SaveChanges();

            return(image.Id);
        }
Exemplo n.º 4
0
        private Album GetProfileImagesAlbum(LibrariesManager manager)
        {
            var album = manager.GetAlbums().FirstOrDefault(l => l.Title == ProfileModel.ProfileImagesAlbumTitle);

            if (album == null)
            {
                album         = manager.CreateAlbum();
                album.Title   = ProfileModel.ProfileImagesAlbumTitle;
                album.UrlName = ProfileModel.ProfileImagesAlbumUrl;
            }

            return(album);
        }
        private void AddImageToProductItem(ProductItem product)
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();

            if (product == null)
            {
                return;        // Product does not exist
            }

            var defaultAlbum = librariesManager.GetAlbums().FirstOrDefault(a => a.Id == LibrariesModule.DefaultImagesLibraryId);

            Telerik.Sitefinity.Libraries.Model.Image image = UploadImage(librariesManager, "imageTitle1", "imageTitle1", "Some description", 0, Guid.Empty, defaultAlbum);

            product.CreateRelation(image, "ProductImage");
        }
Exemplo n.º 6
0
        /// <summary>
        /// The same logic can be found in PageTemplateHelper -> UpdateDefaultTemplateImages(). In need of a change do it in both places
        /// </summary>
        internal static void UpdateDefaultTemplateImages(LibrariesManager librariesManager)
        {
            var imagesToUpgrade = new List <string>
            {
                LayoutFileManager.TemplateImage1Column,
                LayoutFileManager.TemplateImage2Columns,
                LayoutFileManager.TemplateImage3Columns,
                LayoutFileManager.TemplateImage4Columns,
                LayoutFileManager.TemplateImageLeftSidebar,
                LayoutFileManager.TemplateImageRightSidebar,
                "default"
            };

            var templateThumbsImageLibrary = librariesManager.GetAlbums().FirstOrDefault(lib => lib.Id == LibrariesModule.DefaultTemplateThumbnailsLibraryId);

            if (templateThumbsImageLibrary != null)
            {
                var images = templateThumbsImageLibrary.Images().ToList();
                foreach (var imageToUpgrade in imagesToUpgrade)
                {
                    var image = images.FirstOrDefault(i => i.Title == "MVC_" + imageToUpgrade && i.Status == GenericContent.Model.ContentLifecycleStatus.Master);

                    if (image != null)
                    {
                        var iconResource = string.Format(CultureInfo.InvariantCulture, LayoutFileManager.PageTemplateIconPathFormat, imageToUpgrade);
                        if (Assembly.GetExecutingAssembly().GetManifestResourceNames().Any(mrn => mrn.Equals(iconResource, StringComparison.OrdinalIgnoreCase)))
                        {
                            using (var imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(iconResource))
                            {
                                using (var resourceImage = ImagesHelper.CurrentImageProcessor.GetImageFromStream(imageStream))
                                {
                                    var resourceImageStream = new MemoryStream();
                                    resourceImage.Save(resourceImageStream, System.Drawing.Imaging.ImageFormat.Png);

                                    librariesManager.Upload(image, resourceImageStream, ".png", true);
                                    librariesManager.Lifecycle.Publish(image);
                                    librariesManager.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }
        }
        private void CreateImage()
        {
            LibrariesManager librariesManager = LibrariesManager.GetManager();

            //Suppress permission checks to ensure code runs even by unauthorized users
            librariesManager.Provider.SuppressSecurityChecks = true;

            Image      image       = librariesManager.GetImages().Where(i => i.Title == imageTitle && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault();
            FileStream imageStream = new FileStream(ServerPath + "\\author.jpg", FileMode.Open);

            if (image == null)
            {
                //The album post is created as master. The masterImageId is assigned to the master version.
                image = librariesManager.CreateImage();
                var imageGuid = image.Id;
                //Set the parent album.
                Album album = librariesManager.GetAlbums().Where(i => i.Title == "Default Library").SingleOrDefault();
                image.Parent = album;

                //Set the properties of the album post.
                image.Title           = imageTitle;
                image.DateCreated     = DateTime.UtcNow;
                image.PublicationDate = DateTime.UtcNow;
                image.LastModified    = DateTime.UtcNow;
                image.UrlName         = Regex.Replace(imageTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                //Upload the image file.
                librariesManager.Upload(image, imageStream, ".jpg");

                //Save the changes.
                librariesManager.SaveChanges();

                //Publish the Albums item. The live version acquires new ID.
                var bag = new Dictionary <string, string>();
                bag.Add("ContentType", typeof(Image).FullName);
                WorkflowManager.MessageWorkflow(imageGuid, typeof(Image), null, "Publish", false, bag);
            }
        }
Exemplo n.º 8
0
 public override IQueryable <Library> GetLibraries(LibrariesManager libMgr)
 {
     return(libMgr.GetAlbums());
 }
Exemplo n.º 9
0
        private Album GetProfileImagesAlbum(LibrariesManager manager)
        {
            var album = manager.GetAlbums().FirstOrDefault(l => l.Title == ProfileModel.ProfileImagesAlbumTitle);
            if (album == null)
            {
                album = manager.CreateAlbum();
                album.Title = ProfileModel.ProfileImagesAlbumTitle;
                album.UrlName = ProfileModel.ProfileImagesAlbumUrl;
            }

            return album;
        }
        private Guid CreateImageNativeAPI(string imageTitle, Stream imageStream, string imageExtension, LibrariesManager librariesManager)
        {
            Album album = librariesManager.GetAlbums().Where(al => al.Title == "Facebook Users").FirstOrDefault();
            if (album == null)
            {
                Guid albumId = Guid.NewGuid();

                album = librariesManager.GetAlbums().Where(a => a.Id == albumId).FirstOrDefault();

                if (album == null)
                {
                    //Create the album.
                    album = librariesManager.CreateAlbum(albumId);

                    //Set the properties of the album.
                    album.Title = "Facebook Users";
                    album.DateCreated = DateTime.UtcNow;
                    album.LastModified = DateTime.UtcNow;
                    album.UrlName = Regex.Replace("Facebook Users".ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                    //Save the changes.
                    librariesManager.SaveChanges();
                }

                album = librariesManager.GetAlbum(albumId);
            }

                //The album post is created as master. The masterImageId is assigned to the master version.
                Image image = librariesManager.CreateImage();

                librariesManager.SaveChanges();
                librariesManager.Provider.SuppressSecurityChecks = true;
                //Set the parent album.

                //Set the properties of the profile image
                image.Title = imageTitle;
                image.DateCreated = DateTime.UtcNow;
                image.PublicationDate = DateTime.UtcNow;
                image.LastModified = DateTime.UtcNow;
                image.UrlName = Regex.Replace(imageTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                librariesManager.Provider.SuppressSecurityChecks = true;
                image.Parent = album;

                //Upload the image file.
                librariesManager.Upload(image, imageStream, imageExtension);

                //Save the changes.
                librariesManager.SaveChanges();

                //Publish the Albums item. The live version acquires new ID.
                var bag = new Dictionary<string, string>();
                bag.Add("ContentType", typeof(Image).FullName);
                WorkflowManager.MessageWorkflow(image.Id, typeof(Image), null, "Publish", false, bag);

                return image.Id;
        }
Exemplo n.º 11
0
        private Guid CreateImageNativeAPI(string imageTitle, Stream imageStream, string imageExtension, LibrariesManager librariesManager)
        {
            Album album = librariesManager.GetAlbums().Where(al => al.Title == "Facebook Users").FirstOrDefault();

            if (album == null)
            {
                Guid albumId = Guid.NewGuid();

                album = librariesManager.GetAlbums().Where(a => a.Id == albumId).FirstOrDefault();

                if (album == null)
                {
                    //Create the album.
                    album = librariesManager.CreateAlbum(albumId);

                    //Set the properties of the album.
                    album.Title        = "Facebook Users";
                    album.DateCreated  = DateTime.UtcNow;
                    album.LastModified = DateTime.UtcNow;
                    album.UrlName      = Regex.Replace("Facebook Users".ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                    //Save the changes.
                    librariesManager.SaveChanges();
                }

                album = librariesManager.GetAlbum(albumId);
            }

            //The album post is created as master. The masterImageId is assigned to the master version.
            Image image = librariesManager.CreateImage();


            librariesManager.SaveChanges();
            librariesManager.Provider.SuppressSecurityChecks = true;
            //Set the parent album.



            //Set the properties of the profile image
            image.Title           = imageTitle;
            image.DateCreated     = DateTime.UtcNow;
            image.PublicationDate = DateTime.UtcNow;
            image.LastModified    = DateTime.UtcNow;
            image.UrlName         = Regex.Replace(imageTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

            librariesManager.Provider.SuppressSecurityChecks = true;
            image.Parent = album;

            //Upload the image file.
            librariesManager.Upload(image, imageStream, imageExtension);

            //Save the changes.
            librariesManager.SaveChanges();

            //Publish the Albums item. The live version acquires new ID.
            var bag = new Dictionary <string, string>();

            bag.Add("ContentType", typeof(Image).FullName);
            WorkflowManager.MessageWorkflow(image.Id, typeof(Image), null, "Publish", false, bag);

            return(image.Id);
        }