コード例 #1
0
        /// <summary>
        /// Uploads the avatar.
        /// </summary>
        /// <param name="uploadedImage">The uploaded image.</param>
        /// <param name="username">The username.</param>
        /// <returns></returns>
        private Image UploadAvatar(HttpPostedFileBase uploadedImage, string username)
        {
            this.ValidateImage(uploadedImage);

            LibrariesManager librariesManager = LibrariesManager.GetManager(LibrariesModule.SystemLibrariesProviderName);

            Image image;

            using (new ElevatedModeRegion(librariesManager))
            {
                image = librariesManager.CreateImage();

                image.Parent = this.GetProfileImagesAlbum(librariesManager);

                image.Title           = string.Format("{0}_avatar_{1}", username, Guid.NewGuid());
                image.DateCreated     = DateTime.UtcNow;
                image.PublicationDate = DateTime.UtcNow;
                image.LastModified    = DateTime.UtcNow;
                image.UrlName         = Regex.Replace(image.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");

                // Upload the image file.
                librariesManager.Upload(image, uploadedImage.InputStream, Path.GetExtension(uploadedImage.FileName));

                image = librariesManager.Lifecycle.Publish(image) as Image;

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

            return(image);
        }
コード例 #2
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);
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        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);
        }
        private Image UploadImage(LibrariesManager manager, string iTitle, string iUrlName, string iDescription, long iTotalSize, Guid iOwner, Album album)
        {
            var mediaItem = manager.CreateImage(ProductsIntegrationTests.imageId);

            mediaItem.Title       = iTitle;
            mediaItem.UrlName     = iUrlName;
            mediaItem.Description = iDescription;
            mediaItem.Parent      = album;
            manager.RecompileItemUrls <Image>(mediaItem);

            UploadImageFile(manager, mediaItem);
            iTotalSize = mediaItem.TotalSize;
            iOwner     = mediaItem.Owner;

            manager.SaveChanges();

            return(mediaItem);
        }
コード例 #6
0
        private Image UploadTemplateImage(LibrariesManager libraryManager, Album templateThumbsImageLibrary, string templateName, string iconResource)
        {
            Image image = null;

            var suppressSecurityChecks = libraryManager.Provider.SuppressSecurityChecks;

            try
            {
                libraryManager.Provider.SuppressSecurityChecks = true;

                image                       = libraryManager.CreateImage();
                image.Parent                = templateThumbsImageLibrary;
                image.Title                 = templateName;
                image.UrlName               = templateName.ToLower().Replace(' ', '-');
                image.Description           = "Description_" + templateName;
                image.AlternativeText       = "AltText_" + templateName;
                image.ApprovalWorkflowState = "Published";
                libraryManager.RecompileItemUrls <Image>(image);

                using (var imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(iconResource))
                {
                    using (var resourceImage = System.Drawing.Image.FromStream(imageStream))
                    {
                        var resourceImageStream = new MemoryStream();
                        resourceImage.Save(resourceImageStream, System.Drawing.Imaging.ImageFormat.Png);

                        libraryManager.Upload(image, resourceImageStream, ".png");
                        libraryManager.Lifecycle.Publish(image);
                        libraryManager.SaveChanges();
                    }
                }
            }
            finally
            {
                libraryManager.Provider.SuppressSecurityChecks = suppressSecurityChecks;
            }

            return(image);
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        private Image UploadTemplateImage(LibrariesManager libraryManager, Album templateThumbsImageLibrary, string templateName, string iconResource)
        {
            Image image = null;

            var suppressSecurityChecks = libraryManager.Provider.SuppressSecurityChecks;
            try
            {
                libraryManager.Provider.SuppressSecurityChecks = true;

                image = libraryManager.CreateImage();
                image.Parent = templateThumbsImageLibrary;
                image.Title = templateName;
                image.UrlName = templateName.ToLower().Replace(' ', '-');
                image.Description = "Description_" + templateName;
                image.AlternativeText = "AltText_" + templateName;
                image.ApprovalWorkflowState = "Published";
                libraryManager.RecompileItemUrls<Image>(image);

                using (var imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(iconResource))
                {
                    using (var resourceImage = System.Drawing.Image.FromStream(imageStream))
                    {
                        var resourceImageStream = new MemoryStream();
                        resourceImage.Save(resourceImageStream, System.Drawing.Imaging.ImageFormat.Png);

                        libraryManager.Upload(image, resourceImageStream, ".png");
                        libraryManager.Lifecycle.Publish(image);
                        libraryManager.SaveChanges();
                    }
                }
            }
            finally
            {
                libraryManager.Provider.SuppressSecurityChecks = suppressSecurityChecks;
            }

            return image;
        }
コード例 #9
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;
        }
        private Image UploadImage(LibrariesManager manager, string iTitle, string iUrlName, string iDescription, long iTotalSize, Guid iOwner, Album album)
        {
            var mediaItem = manager.CreateImage(ProductsIntegrationTests.imageId);
            mediaItem.Title = iTitle;
            mediaItem.UrlName = iUrlName;
            mediaItem.Description = iDescription;
            mediaItem.Parent = album;
            manager.RecompileItemUrls<Image>(mediaItem);

            UploadImageFile(manager, mediaItem);
            iTotalSize = mediaItem.TotalSize;
            iOwner = mediaItem.Owner;

            manager.SaveChanges();

            return mediaItem;
        }
コード例 #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);
        }