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); }
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 Guid UploadTorrentFile(string torrentTitle, Stream torrentFileStream, string torrentFileName, string torrentExtention, string torrentLibrary) { CultureInfo culture = CultureInfo.InvariantCulture; LibrariesManager librariesManager = LibrariesManager.GetManager(LibrariesManager.GetDefaultProviderName()); DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().Where(l => l.Title.Equals(torrentLibrary)).SingleOrDefault(); Document document = librariesManager.CreateDocument(); document.Parent = documentLibrary; document.Title = torrentTitle; document.DateCreated = DateTime.UtcNow; document.PublicationDate = DateTime.UtcNow; document.LastModified = DateTime.UtcNow; document.UrlName = Regex.Replace(torrentTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); document.MediaFileUrlName = Regex.Replace(torrentFileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); librariesManager.Upload(document, torrentFileStream, torrentExtention); librariesManager.RecompileAndValidateUrls(document); document.ApprovalWorkflowState.Value = "Published"; librariesManager.Lifecycle.Publish(document, culture); librariesManager.SaveChanges(); return(document.Id); }
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); }
/// <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); }
private void ProcessCallback(FormDataCollection kCallbackFormData) { string krakenCallbackId = kCallbackFormData.Get("id"); string fileName = kCallbackFormData.Get("file_name"); string krakedUrl = kCallbackFormData.Get("kraked_url"); bool success = Boolean.Parse(kCallbackFormData.Get("success")); string error = kCallbackFormData.Get("error"); Guid albumId = Global.KrakenCallbackIds[krakenCallbackId]; Global.KrakenCallbackIds.Remove(krakenCallbackId); if (success == false || error != null) { return; } LibrariesManager _librariesManager = LibrariesManager.GetManager(); _librariesManager.Provider.SuppressSecurityChecks = true; Album album = _librariesManager.GetAlbum(albumId); var albumProvider = (LibrariesDataProvider)album.Provider; Image image = _librariesManager.GetImage(Guid.Parse(Path.GetFileNameWithoutExtension(krakedUrl))); if (!Regex.IsMatch(krakedUrl, @"https?://(?:api-worker-\d|dl).kraken.io/" + krakenCallbackId + "/" + image.Id.ToString() + @"\.(?:jpg|jpeg|png|gif|svg)")) { return; } using (var webClient = new WebClient()) using (var stream = webClient.OpenRead(krakedUrl)) { //Check out the master to get a temp version. Image temp = _librariesManager.Lifecycle.CheckOut(image) as Image; //Make the modifications to the temp version. _librariesManager.Upload(temp, stream, Path.GetExtension(fileName)); //Checkin the temp and get the updated master version. //After the check in the temp version is deleted. _librariesManager.Lifecycle.CheckIn(temp); _librariesManager.SaveChanges(); // Check to see if this image is already published. // If it is, we need to publish the "Master" to update "Live" if (image.GetWorkflowState() == "Published") { var bag = new Dictionary <string, string>(); bag.Add("ContentType", typeof(Image).FullName); WorkflowManager.MessageWorkflow(image.Id, typeof(Image), albumProvider.Name, "Publish", false, bag); } } _librariesManager.Provider.SuppressSecurityChecks = false; }
private void UploadImageFile(LibrariesManager libManager, MediaContent mediaItem) { var imageResource = "ProductsIntegrationTests.Images.1.jpg"; var assembly = this.GetType().Assembly; var stream = assembly.GetManifestResourceStream(imageResource); libManager.Upload(mediaItem, stream, ".jpg"); }
private bool ProcessImagesInternal(string providerName) { string transactionName = string.Format("imageoptimization_{0}", providerName); LibrariesManager librariesManager = LibrariesManager.GetManager(providerName, transactionName); bool itemsProcessed = false; int processedImages = 0; IEnumerable <Image> images = librariesManager.GetImages().Where(i => i.Status == ContentLifecycleStatus.Master && ((i.GetValue <object>(ImageOptimizationConstants.IsOptimizedFieldName) == null) || !i.GetValue <bool>(ImageOptimizationConstants.IsOptimizedFieldName))).Take(this.batchSize); foreach (var image in images) { try { this.BuildTrace(string.Format("{0} - Attempting to optimize image {1} ({2})", DateTime.UtcNow.ToString("yyyy-MM-dd-T-HH:mm:ss"), image.Title, image.Id)); Image master = image; Image temp = librariesManager.Lifecycle.CheckOut(image) as Image; Stream sourceImageStream = librariesManager.Download(image.Id); librariesManager.Upload(temp, sourceImageStream, image.Extension, true); temp.SetValue(ImageOptimizationConstants.IsOptimizedFieldName, true); master = librariesManager.Lifecycle.CheckIn(temp) as Image; ProcessReplacedImageTranslations(librariesManager, master); if (master.ApprovalWorkflowState == "Published") { librariesManager.Lifecycle.Publish(master); } this.BuildTrace(string.Format("{0} - Image {1} ({2}) has been optimized", DateTime.UtcNow.ToString("yyyy-MM-dd-T-HH:mm:ss"), image.Title, image.Id)); if (processedImages % 5 == 0) { TransactionManager.CommitTransaction(transactionName); } processedImages += 1; } catch (Exception ex) { this.BuildTrace(string.Format("Optimization of image {0} ({1}) failed with exception {2}", image.Title, image.Id, ex.Message), true); } this.WriteTraceLog(); itemsProcessed = true; } TransactionManager.CommitTransaction(transactionName); return(itemsProcessed); }
private void ProcessReplacedImageTranslations(LibrariesManager librariesManager, Image image) { Guid defaultFileId = image.FileId; IEnumerable <MediaFileLink> links = image.MediaFileLinks.Where(mfl => mfl.FileId != defaultFileId); // process image translations that have replaced image for translation foreach (var linkItem in links) { IList <int> proccessedCultures = new List <int>(); if (!proccessedCultures.Contains(linkItem.Culture)) { using (new CultureRegion(linkItem.Culture)) { CultureInfo currentCultureInfo = new CultureInfo(linkItem.Culture); try { this.BuildTrace(string.Format("{0} - Attempting to optimize image {1} ({2}) in culture {3}", DateTime.UtcNow.ToString("yyyy-MM-dd-T-HH:mm:ss"), image.Title, image.Id, currentCultureInfo.Name)); Image translatedMaster = (linkItem.MediaContent.OriginalContentId == Guid.Empty ? linkItem.MediaContent : librariesManager.GetMediaItem(linkItem.MediaContent.OriginalContentId)) as Image; Image translatedTemp = librariesManager.Lifecycle.CheckOut(translatedMaster) as Image; Stream translationSourceImageStream = librariesManager.Download(linkItem.MediaContentId); librariesManager.Upload(translatedTemp, translationSourceImageStream, image.Extension, false); translatedTemp.SetValue(ImageOptimizationConstants.IsOptimizedFieldName, true); translatedMaster = librariesManager.Lifecycle.CheckIn(translatedTemp) as Image; if (translatedMaster.ApprovalWorkflowState.GetString(currentCultureInfo, false) == "Published") { librariesManager.Lifecycle.Publish(translatedMaster, currentCultureInfo); } proccessedCultures.Add(linkItem.Culture); this.BuildTrace(string.Format("{0} - Image {1} ({2}) in culture {3} has been optimized", DateTime.UtcNow.ToString("yyyy-MM-dd-T-HH:mm:ss"), image.Title, image.Id, currentCultureInfo.Name)); } catch (Exception ex) { this.BuildTrace(string.Format("Optimization of image {0} ({1}) in culture {2} failed with exception {3}", image.Title, image.Id, currentCultureInfo.Name, ex.Message), true); } } } } }
/// <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); } }
public Document CreateDocumentNativeAPI(CreateDocumentDto createDocumentDto) { //The document is created as master. The masterDocumentId is assigned to the master version. LibrariesManager librariesManager = LibrariesManager.GetManager(); Guid documentId = Guid.NewGuid(); Document document = document = librariesManager.CreateDocument(documentId); //Set the parent document library. DocumentLibrary documentLibrary = librariesManager.GetDocumentLibraries().SingleOrDefault(); document.Parent = documentLibrary; //Set the properties of the document. document.Title = createDocumentDto.Title; document.DateCreated = DateTime.UtcNow; document.PublicationDate = DateTime.UtcNow; document.LastModified = DateTime.UtcNow; document.UrlName = Regex.Replace($"{createDocumentDto.Title}-{documentId}".ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); document.MediaFileUrlName = Regex.Replace(createDocumentDto.FileName.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); //Upload the document file. librariesManager.Upload(document, createDocumentDto.Stream, createDocumentDto.FileExtension); //Recompiles and validates the url of the document. librariesManager.RecompileAndValidateUrls(document); //Save the changes. librariesManager.SaveChanges(); //Publish the DocumentLibraries item. The live version acquires new ID. var bag = new Dictionary <string, string>(); bag.Add("ContentType", typeof(Document).FullName); WorkflowManager.MessageWorkflow(documentId, typeof(Document), null, "Publish", false, bag); return(document); }
public override void ExecuteTask() { LibrariesManager _librariesManager = LibrariesManager.GetManager(); Album album = _librariesManager.GetAlbum(this.AlbumId); var albumProvider = (LibrariesDataProvider)album.Provider; var images = album.Images().Where(i => i.Status == ContentLifecycleStatus.Master && !i.GetValue <bool>("Optimized")); _itemsCount = images.Count(); AlbumOptimizationConfig _albumOptimaztionConfig = Config.Get <AlbumOptimizationConfig>(); int _imageQuality = 100; if (_albumOptimaztionConfig.ImageQuality != null) { _imageQuality = _albumOptimaztionConfig.ImageQuality; } foreach (Telerik.Sitefinity.Libraries.Model.Image image in images) { // Pull the Stream of the image from the provider. // This saves us from having to care about BlobStorage Stream imageData = albumProvider.Download(image); using (MemoryStream compressed = new MemoryStream()) { MagickReadSettings magickSettings = new MagickReadSettings(); switch (image.Extension) { case ".png": magickSettings.Format = MagickFormat.Png; break; case ".jpg": magickSettings.Format = MagickFormat.Jpg; break; case ".jpeg": magickSettings.Format = MagickFormat.Jpeg; break; case ".bmp": magickSettings.Format = MagickFormat.Bmp; break; default: magickSettings.Format = MagickFormat.Jpg; break; } using (MagickImage img = new MagickImage(imageData, magickSettings)) { img.Quality = _imageQuality; img.Write(compressed); if (compressed == null) { UpdateProgress(); continue; } //Check out the master to get a temp version. Image temp = _librariesManager.Lifecycle.CheckOut(image) as Telerik.Sitefinity.Libraries.Model.Image; //Make the modifications to the temp version. _librariesManager.Upload(temp, compressed, image.Extension); temp.SetValue("Optimized", true); //Checkin the temp and get the updated master version. //After the check in the temp version is deleted. _librariesManager.Lifecycle.CheckIn(temp); _librariesManager.SaveChanges(); // Check to see if this image is already published. // If it is, we need to publish the "Master" to update "Live" if (image.GetWorkflowState() == "Published") { var bag = new Dictionary <string, string>(); bag.Add("ContentType", typeof(Telerik.Sitefinity.Libraries.Model.Image).FullName); WorkflowManager.MessageWorkflow(image.Id, typeof(Telerik.Sitefinity.Libraries.Model.Image), albumProvider.Name, "Publish", false, bag); } } } UpdateProgress(); } }
public override void ExecuteTask() { KrakenConfig _kConfig = Config.Get <KrakenConfig>(); LibrariesManager _librariesManager = LibrariesManager.GetManager(); string key = _kConfig.APIKey; string secret = _kConfig.APISecret; bool useCallbacks = _kConfig.UseCallbacks; bool useLossy = _kConfig.LossyOptimization; Kraken k = new Kraken(key, secret); Album album = _librariesManager.GetAlbum(this.AlbumId); var albumProvider = (LibrariesDataProvider)album.Provider; var images = album.Images().Where(i => i.Status == ContentLifecycleStatus.Master); _itemsCount = images.Count(); foreach (Image image in images) { KrakenRequest kr = new KrakenRequest(); kr.Lossy = useLossy; if (_kConfig.UseCallbacks) { kr.CallbackUrl = _kConfig.CallbackURL; } else { kr.Wait = true; } // Pull the Stream of the image from the provider. // This saves us from having to care about BlobStorage Stream imageData = albumProvider.Download(image); // Can't trust the length of Stream. Converting to a MemoryStream using (MemoryStream ms = new MemoryStream()) { imageData.CopyTo(ms); kr.File = ms.ToArray(); } var response = k.Upload(kr, image.Id.ToString(), image.Extension); if (_kConfig.UseCallbacks) { Global.KrakenCallbackIds.Add(response.Id, album.Id); } else { if (response.Success == false || response.Error != null) { UpdateProgress(); continue; } using (var webClient = new WebClient()) using (var stream = webClient.OpenRead(response.KrakedUrl)) { //Check out the master to get a temp version. Image temp = _librariesManager.Lifecycle.CheckOut(image) as Image; //Make the modifications to the temp version. _librariesManager.Upload(temp, stream, Path.GetExtension(response.KrakedUrl)); //Checkin the temp and get the updated master version. //After the check in the temp version is deleted. _librariesManager.Lifecycle.CheckIn(temp); _librariesManager.SaveChanges(); // Check to see if this image is already published. // If it is, we need to publish the "Master" to update "Live" if (image.GetWorkflowState() == "Published") { var bag = new Dictionary <string, string>(); bag.Add("ContentType", typeof(Image).FullName); WorkflowManager.MessageWorkflow(image.Id, typeof(Image), albumProvider.Name, "Publish", false, bag); } } } UpdateProgress(); } }
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; }
public static Guid CreateDocumentNativeAPI(Stream documentStream, string fileExtension) { LibrariesManager librariesManager = LibrariesManager.GetManager(); librariesManager.Provider.SuppressSecurityChecks = true; WorkflowManager.GetManager().Provider.SuppressSecurityChecks = true; Guid documentId = Guid.Empty; try { var documentLibrary = librariesManager.GetDocumentLibraries().Where(x => x.Title == "Image requests uploaded").FirstOrDefault(); #region create document library //create document library if it doesnt exist if (documentLibrary == null) { documentLibrary = librariesManager.CreateDocumentLibrary(); documentLibrary.Title = "Image requests uploaded"; documentLibrary.DateCreated = DateTime.UtcNow; documentLibrary.LastModified = DateTime.UtcNow; documentLibrary.UrlName = Regex.Replace(documentLibrary.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); //Recompiles and validates the url of the library. librariesManager.RecompileAndValidateUrls(documentLibrary); //Save the changes. librariesManager.SaveChanges(); } #endregion documentId = Guid.NewGuid(); var document = librariesManager.CreateDocument(documentId); document.Parent = documentLibrary; document.Title = "Resume-" + documentId.ToString(); document.DateCreated = DateTime.UtcNow; document.PublicationDate = DateTime.UtcNow; document.LastModified = DateTime.UtcNow; document.UrlName = Regex.Replace(document.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); document.MediaFileUrlName = Regex.Replace((document.Title + fileExtension).ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-"); //Upload the document file. librariesManager.Upload(document, documentStream, fileExtension); //Recompiles and validates the url of the document. librariesManager.RecompileAndValidateUrls(document); librariesManager.Lifecycle.Publish(document); //Save the changes. librariesManager.SaveChanges(); //Publish the DocumentLibraries item. The live version acquires new ID. var bag = new Dictionary <string, string>(); bag.Add("ContentType", typeof(Document).FullName); WorkflowManager.MessageWorkflow(documentId, typeof(Document), null, "Publish", false, bag); } catch (Exception ex) { Log.Write(ex, System.Diagnostics.TraceEventType.Error); return(documentId); } finally { librariesManager.Provider.SuppressSecurityChecks = false; WorkflowManager.GetManager().Provider.SuppressSecurityChecks = false; } return(documentId); }
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; }
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); }