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 List <Image> GetImagesFromAlbum(string albumTitle) { LibrariesManager lm = LibrariesManager.GetManager(); return(lm.GetImages() .Where(i => i.Status == ContentLifecycleStatus.Live && i.Parent.Title == albumTitle).ToList()); }
public string CreateOffice() { string result = "Office created successfully"; try { // Set a transaction name and get the version manager var transactionName = "someTransactionName"; var versionManager = VersionManager.GetManager(null, transactionName); // Set the culture name for the multilingual fields var cultureName = "en"; Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(this.ProviderName, transactionName); DynamicContent officeItem = dynamicModuleManager.CreateDataItem(this.OfficeType); // This is how values for the properties are set officeItem.SetString("Title", "New York", cultureName); officeItem.SetString("Info", LOREM_IPSUM, cultureName); Address address = new Address(); CountryElement addressCountry = Telerik.Sitefinity.Configuration.Config.Get <LocationsConfig>().Countries.Values.First(x => x.Name == "United States"); address.CountryCode = addressCountry.IsoCode; address.StateCode = addressCountry.StatesProvinces.Values.First().Abbreviation; address.City = "New York City"; address.Street = "Baker Street"; address.Zip = "12345"; officeItem.SetValue("Address", address); // Get related item manager LibrariesManager pictureManager = LibrariesManager.GetManager("OpenAccessDataProvider"); var pictureItem = pictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master && i.Title.Contains("New York")); if (pictureItem != null) { // This is how we relate an item officeItem.CreateRelation(pictureItem, "Picture"); } officeItem.SetString("UrlName", "new-york", cultureName); officeItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); officeItem.SetValue("PublicationDate", DateTime.UtcNow); officeItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft", new CultureInfo(cultureName)); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(officeItem, false); TransactionManager.CommitTransaction(transactionName); } catch (Exception ex) { return(ex.Message.ToString()); } return(result); }
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); }
public void SetTorrentImage(LibrariesManager imageManager, DynamicContent torrentItem) { var imageItem = imageManager .GetImages() .FirstOrDefault(i => i.Status == ContentLifecycleStatus.Master); if (imageItem != null) { torrentItem.CreateRelation(imageItem, "Image"); } }
private void CreateAuthor(string[] values) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = String.Empty; string name = values[6], bio = values[8], jobTitle = values[7]; DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); //Suppress permission checks to ensure code runs even by unauthorized users dynamicModuleManager.Provider.SuppressSecurityChecks = true; Type authorType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Authors.Author"); DynamicContent authorItem = dynamicModuleManager.CreateDataItem(authorType); // This is how values for the properties are set authorItem.SetValue("Name", name); authorItem.SetValue("Bio", bio); authorItem.SetValue("JobTitle", jobTitle); LibrariesManager avatarManager = LibrariesManager.GetManager(); var avatarItem = avatarManager.GetImages().FirstOrDefault(i => i.Title == imageTitle && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (avatarItem == null) { CreateImage(); avatarItem = avatarManager.GetImages().FirstOrDefault(i => i.Title == imageTitle && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); } // This is how we relate an item authorItem.CreateRelation(avatarItem, "Avatar"); authorItem.SetString("UrlName", "SomeUrlName"); authorItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); authorItem.SetValue("PublicationDate", DateTime.Now); authorItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); // You need to call SaveChanges() in order for the items to be actually persisted to data store dynamicModuleManager.SaveChanges(); }
private static void DeleteImage() { LibrariesManager manager = LibrariesManager.GetManager(); var imageToDelete = manager.GetImages().FirstOrDefault(i => i.Id == ProductsIntegrationTests.imageId); if (imageToDelete != null) { manager.DeleteImage(imageToDelete); manager.SaveChanges(); } }
public Image GetById(Guid masterImageId) { LibrariesManager librariesManager = LibrariesManager.GetManager(); Image image = librariesManager.GetImages().Where(i => i.Id == masterImageId).FirstOrDefault(); if (image != null) { image = librariesManager.Lifecycle.GetLive(image) as Image; } return(image); }
public void CreateFestival() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type festivalType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.FestivalType); DynamicContent festivalItem = dynamicModuleManager.CreateDataItem(festivalType, HierarchicalDynamicContentTests.FestivalId, dynamicModuleManager.Provider.ApplicationName); festivalItem.SetValue("Name", "Test Name"); festivalItem.SetValue("Description", "Test Description"); festivalItem.SetValue("From", DateTime.Now); festivalItem.SetValue("To", DateTime.Now); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { festivalItem.CreateRelation(mainPictureItem, "MainPicture"); } Address address = new Address(); CountryElement addressCountry = Config.Get <LocationsConfig>().Countries.Values.First(x => x.Name == "United States"); address.CountryCode = addressCountry.IsoCode; address.StateCode = addressCountry.StatesProvinces.Values.First().Abbreviation; address.City = "Test City"; address.Street = "Test Street"; address.Zip = "12345"; address.Latitude = 0.00; address.Longitude = 0.00; address.MapZoomLevel = 8; festivalItem.SetValue("Address", address); festivalItem.SetString("UrlName", "TestUrlName"); festivalItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); festivalItem.SetValue("PublicationDate", DateTime.Now); festivalItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualFestival = dynamicModuleManager.GetDataItem(festivalType, festivalItem.Id); Assert.IsNotNull(actualFestival); Assert.AreEqual(festivalItem.GetValue("Name").ToString(), actualFestival.GetValue("Name").ToString()); Assert.AreEqual(festivalItem.GetValue("Description").ToString(), actualFestival.GetValue("Description").ToString()); Assert.AreEqual(festivalItem.GetValue("From"), actualFestival.GetValue("From")); Assert.AreEqual(festivalItem.GetValue("To"), actualFestival.GetValue("To")); Assert.AreEqual(festivalItem.GetValue("MainPicture"), actualFestival.GetValue("MainPicture")); Assert.AreEqual(festivalItem.GetValue("Address"), actualFestival.GetValue("Address")); Assert.AreEqual(festivalItem.GetValue("UrlName").ToString(), actualFestival.GetValue("UrlName").ToString()); Assert.AreEqual(festivalItem.GetValue("Owner"), actualFestival.GetValue("Owner")); Assert.AreEqual(festivalItem.GetValue("PublicationDate"), actualFestival.GetValue("PublicationDate")); }
public static string GetCurrentSiteFav() { var provider = LibrariesManager.GetManager().Provider.Name; LibrariesManager librariesManager = LibrariesManager.GetManager(provider); Telerik.Sitefinity.Libraries.Model.Image img = new Telerik.Sitefinity.Libraries.Model.Image(); img = librariesManager.GetImages().Where(i => i.Extension == ".ico" && i.Title.ToString().ToLower() == "favicon" && i.Status == ContentLifecycleStatus.Live && i.Visible).FirstOrDefault(); string url = "/favicon.ico"; if (img != null) { url = img.MediaUrl; } else { img = librariesManager.GetImages().Where(i => i.Title.ToString().ToLower() == "favicon" && i.Status == ContentLifecycleStatus.Live && i.Visible).FirstOrDefault(); if (img != null) { url = img.MediaUrl; } } return(url); }
public void CreateStore(string storeName, string street, string zip, string city, string countryCode, string stateCode, double latitude, double longitude, int mapZoomLevel, string urlName, string phone, string imageTitle) { // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = String.Empty; // Set the culture name for the multilingual fields var cultureName = "en"; Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName); Type shopType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Stores.Store"); DynamicContent shopItem = dynamicModuleManager.CreateDataItem(shopType); // This is how values for the properties are set shopItem.SetString("Title", storeName, cultureName); LibrariesManager libraryManager = LibrariesManager.GetManager(); var image = libraryManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Title == imageTitle); if (image != null) { shopItem.AddImage("StoreImage", image.Id); } Telerik.Sitefinity.GeoLocations.Model.Address myAddress = new Telerik.Sitefinity.GeoLocations.Model.Address(); myAddress.City = city; myAddress.CountryCode = countryCode; myAddress.StateCode = stateCode; myAddress.MapZoomLevel = mapZoomLevel; myAddress.Latitude = latitude; myAddress.Longitude = longitude; myAddress.Street = street; myAddress.Zip = zip; shopItem.SetValue("Address", myAddress); shopItem.SetString("UrlName", urlName, cultureName); shopItem.SetString("Phone", phone, cultureName); shopItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); shopItem.SetValue("PublicationDate", DateTime.Now); ILifecycleDataItem publishedFrontendContentItem = dynamicModuleManager.Lifecycle.Publish(shopItem); shopItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.SaveChanges(); }
public void CreateCity() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type cityType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.CityType); DynamicContent cityItem = dynamicModuleManager.CreateDataItem(cityType, HierarchicalDynamicContentTests.CityId, dynamicModuleManager.Provider.ApplicationName); cityItem.SetValue("Name", "Test Name"); cityItem.SetValue("History", "Test History"); Address location = new Address(); CountryElement locationCountry = Config.Get <LocationsConfig>().Countries.Values.First(x => x.Name == "United States"); location.CountryCode = locationCountry.IsoCode; location.StateCode = locationCountry.StatesProvinces.Values.First().Abbreviation; location.City = "Test City"; location.Street = "Test Street"; location.Zip = "12345"; location.Latitude = 0.00; location.Longitude = 0.00; location.MapZoomLevel = 8; cityItem.SetValue("Location", location); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { cityItem.CreateRelation(mainPictureItem, "MainPicture"); } cityItem.SetString("UrlName", "TestUrlName"); cityItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); cityItem.SetValue("PublicationDate", DateTime.Now); cityItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualCity = dynamicModuleManager.GetDataItem(cityType, cityItem.Id); Assert.IsNotNull(actualCity); Assert.AreEqual(cityItem.GetValue("Name").ToString(), actualCity.GetValue("Name").ToString()); Assert.AreEqual(cityItem.GetValue("History").ToString(), actualCity.GetValue("History").ToString()); Assert.AreEqual(cityItem.GetValue("Location"), actualCity.GetValue("Location")); Assert.AreEqual(cityItem.GetValue("MainPicture"), actualCity.GetValue("MainPicture")); Assert.AreEqual(cityItem.GetValue("UrlName").ToString(), actualCity.GetValue("UrlName").ToString()); Assert.AreEqual(cityItem.GetValue("Owner"), actualCity.GetValue("Owner")); Assert.AreEqual(cityItem.GetValue("PublicationDate"), actualCity.GetValue("PublicationDate")); }
public static void CreateStory(SuccessStoryWidgetViewModel successStoryWidgetViewModel) { var transactionName = "Submit"; var providerName = "OpenAccessDataProvider"; var versionManager = VersionManager.GetManager(providerName, transactionName); var dynamicModuleProviderName = "OpenAccessProvider"; DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(dynamicModuleProviderName, transactionName); using (new ElevatedModeRegion(dynamicModuleManager)) //ElevatedModeRegion is set to override access restrictions for given users { Type successStoryType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.SuccessStories.SuccessStory"); DynamicContent successStoryItem = dynamicModuleManager.CreateDataItem(successStoryType); successStoryItem.SetValue("Title", successStoryWidgetViewModel.Title); successStoryItem.SetValue("Description", successStoryWidgetViewModel.Description); successStoryItem.SetValue("SummaryDescription", successStoryWidgetViewModel.SummaryDescription); successStoryItem.SetValue("ProductsUsed", successStoryWidgetViewModel.ProductsUsed); successStoryItem.SetValue("Company", successStoryWidgetViewModel.Company); successStoryItem.SetValue("CompanyWebsite", successStoryWidgetViewModel.CompanyWebsite); successStoryItem.SetValue("Industry", successStoryWidgetViewModel.Industry); // Get related item manager LibrariesManager thumbnailManager = LibrariesManager.GetManager(); var thumbnailItem = thumbnailManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (thumbnailItem != null) { // This is how we relate an item successStoryItem.CreateRelation(thumbnailItem, "Thumbnail"); } //Trimming spaces from the Title, then setting it to Lowercase with the .ToLower() method, so it can be used as a unique URL for a newly submitted Success Story var urlName = successStoryWidgetViewModel.Title; var urlNameNoSpaces = urlName.Replace(" ", ""); successStoryItem.SetString("UrlName", urlNameNoSpaces.ToLower()); successStoryItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); successStoryItem.SetValue("PublicationDate", DateTime.UtcNow); successStoryItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); versionManager.CreateVersion(successStoryItem, true); TransactionManager.CommitTransaction(transactionName); } }
public void CreateCountry() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type countryType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.CountryType); DynamicContent countryItem = dynamicModuleManager.CreateDataItem(countryType, HierarchicalDynamicContentTests.CountryId, dynamicModuleManager.Provider.ApplicationName); countryItem.SetValue("Name", "Test country"); countryItem.SetValue("Description", "Test Description"); Address location = new Address(); location.Latitude = 0.00; location.Longitude = 0.00; location.MapZoomLevel = 8; countryItem.SetValue("Location", location); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { countryItem.CreateRelation(mainPictureItem, "MainPicture"); } countryItem.SetString("UrlName", "TestUrlName"); countryItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); countryItem.SetValue("PublicationDate", DateTime.Now); countryItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualCountry = dynamicModuleManager.GetDataItem(countryType, countryItem.Id); Assert.IsNotNull(actualCountry); Assert.AreEqual(countryItem.GetValue("Name").ToString(), actualCountry.GetValue("Name").ToString()); Assert.AreEqual(countryItem.GetValue("Description").ToString(), actualCountry.GetValue("Description").ToString()); Assert.AreEqual(countryItem.GetValue("Location"), actualCountry.GetValue("Location")); Assert.AreEqual(countryItem.GetValue("MainPicture"), actualCountry.GetValue("MainPicture")); Assert.AreEqual(countryItem.GetValue("UrlName").ToString(), actualCountry.GetValue("UrlName").ToString()); Assert.AreEqual(countryItem.GetValue("Owner"), actualCountry.GetValue("Owner")); Assert.AreEqual(countryItem.GetValue("PublicationDate"), actualCountry.GetValue("PublicationDate")); }
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); } }
/// <summary> /// Updates the OG item model. /// </summary> /// <param name="itemsType">Type of the item</param> /// <param name="ogModel">The open graph model</param> /// <param name="pageUrl">The url</param> /// <returns> true or false</returns> private bool GetDataItemByType(Type itemsType, OpengraphModuleConfig ogModel, string pageUrl) { switch (itemsType.FullName) { //Default type case "Telerik.Sitefinity.News.Model.NewsItem": NewsManager newsManager = NewsManager.GetManager(); List <Telerik.Sitefinity.News.Model.NewsItem> items = newsManager.GetNewsItems().Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true).ToList(); Telerik.Sitefinity.News.Model.NewsItem item = items.FirstOrDefault(newsItem => newsItem.ItemDefaultUrl == pageUrl); if (item == null) { return(false); } //Default openGraphModel.ogTitle = item.Title.ToString(); //Given property if (item.DoesFieldExist(ogModel.TitlePropertyName)) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>(ogModel.TitlePropertyName).ToString(); } } //Default OG prop if (item.DoesFieldExist("OpenGraphTitle")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphTitle").ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>("OpenGraphTitle").ToString(); } } //OG prop if (item.DoesFieldExist("LgszOpenGraphTitle")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphTitle").ToString())) { openGraphModel.ogTitle = item.GetValue <Lstring>("LgszOpenGraphTitle").ToString(); } } //Default openGraphModel.ogDescription = item.Summary != null?item.Summary.ToString() : openGraphDefaultDescription; //Given property if (item.DoesFieldExist(ogModel.DescriptionPropertyName)) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>(ogModel.DescriptionPropertyName).ToString(); } } //Default OG prop if (item.DoesFieldExist("OpenGraphDescription")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("OpenGraphDescription").ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>("OpenGraphDescription").ToString(); } } //OG prop if (item.DoesFieldExist("LgszOpenGraphDescription")) { if (!String.IsNullOrEmpty(item.GetValue <Lstring>("LgszOpenGraphDescription").ToString())) { openGraphModel.ogDescription = item.GetValue <Lstring>("LgszOpenGraphDescription").ToString(); } } Telerik.Sitefinity.Libraries.Model.Image image = null; IDataItem newsImage = null; openGraphModel.ogImage = openGraphDefaultImage; if (item.DoesFieldExist(ogModel.ImagePropertyName)) { if (item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null) { newsImage = item.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault(); } } if (item.DoesFieldExist("OpenGraphImage")) { if (item.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null) { newsImage = item.GetRelatedItems("OpenGraphImage").FirstOrDefault(); } } if (item.DoesFieldExist("LgszOpenGraphImage")) { if (item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null) { newsImage = item.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault(); } } if (newsImage != null) { image = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == newsImage.Id); } if (image != null) { openGraphModel.ogImage = image.Url; } return(true); default: DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); try { string redirectUrl; DynamicContent currentDynamicItem = dynamicModuleManager.Provider.GetItemFromUrl(itemsType, pageUrl, true, out redirectUrl) as DynamicContent; if (currentDynamicItem == null) { return(false); } //Given property openGraphModel.ogTitle = openGraphDefaultTitle; if (!String.IsNullOrEmpty(ogModel.TitlePropertyName)) { openGraphModel.ogTitle = ParseFieldTags(ogModel.TitlePropertyName, currentDynamicItem); } //Default OG prop if (currentDynamicItem.DoesFieldExist("OpenGraphTitle")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString())) { openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("OpenGraphTitle").ToString(); } } //OG prop if (currentDynamicItem.DoesFieldExist("LgszOpenGraphTitle")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString())) { openGraphModel.ogTitle = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphTitle").ToString(); } } //Default openGraphModel.ogDescription = openGraphDefaultDescription; if (!String.IsNullOrEmpty(ogModel.DescriptionPropertyName)) { openGraphModel.ogDescription = ParseFieldTags(ogModel.DescriptionPropertyName, currentDynamicItem); } //Default OG prop if (currentDynamicItem.DoesFieldExist("OpenGraphDescription")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString())) { openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("OpenGraphDescription").ToString(); } } //OG prop if (currentDynamicItem.DoesFieldExist("LgszOpenGraphDescription")) { if (!String.IsNullOrEmpty(currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString())) { openGraphModel.ogDescription = currentDynamicItem.GetValue <Lstring>("LgszOpenGraphDescription").ToString(); } } Telerik.Sitefinity.Libraries.Model.Image img = null; IDataItem dynamicContentImage = null; openGraphModel.ogImage = openGraphDefaultImage; if (currentDynamicItem.DoesFieldExist(ogModel.ImagePropertyName)) { if (currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems(ogModel.ImagePropertyName).FirstOrDefault(); } } if (currentDynamicItem.DoesFieldExist("OpenGraphImage")) { if (currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems("OpenGraphImage").FirstOrDefault(); } } if (currentDynamicItem.DoesFieldExist("LgszOpenGraphImage")) { if (currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault() != null) { dynamicContentImage = currentDynamicItem.GetRelatedItems("LgszOpenGraphImage").FirstOrDefault(); } } if (dynamicContentImage != null) { img = _liberariesManager.GetImages().FirstOrDefault(ogImg => ogImg.Id == dynamicContentImage.Id); } if (img != null) { openGraphModel.ogImage = img.Url; } return(true); } catch (Exception) { return(false); } } }
public void Upload(TorrentUploaderWidgetModel torrent) { string torrentExtention = Path.GetExtension(torrent.TorrentFile.FileName); string torrentTitle = Path.GetFileNameWithoutExtension(torrent.TorrentFile.FileName); Guid torrentFileId = this._documentService.UploadTorrentFile(torrentTitle, torrent.TorrentFile.InputStream, torrent.TorrentFile.FileName, torrentExtention, TORRENT_FILE_LIBRARY); string imageExtention = Path.GetExtension(torrent.CoverImage.FileName); string imageTitle = Path.GetFileNameWithoutExtension(torrent.CoverImage.FileName); Guid torrentImageId = this._imageService.Upload(imageTitle, torrent.CoverImage.InputStream, torrent.CoverImage.FileName, imageExtention, TORRENT_COVER_IMAGE_ALBUM); // Set the provider name for the DynamicModuleManager here. All available providers are listed in // Administration -> Settings -> Advanced -> DynamicModules -> Providers var providerName = String.Empty; // Set a transaction name and get the version manager var transactionName = "someTransactionName"; var versionManager = VersionManager.GetManager(null, transactionName); DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName); Type torrentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Torrents.Torrent"); DynamicContent torrentItem = dynamicModuleManager.CreateDataItem(torrentType); // This is how values for the properties are set torrentItem.SetValue("Title", torrent.Title); torrentItem.SetValue("Description", torrent.Description); LibrariesManager torrentFileManager = LibrariesManager.GetManager(); var torrentFileItem = torrentFileManager.GetDocuments().FirstOrDefault(i => i.Id == torrentFileId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (torrentFileItem != null) { torrentItem.CreateRelation(torrentFileItem, "TorrentFile"); } LibrariesManager imageManager = LibrariesManager.GetManager(); var imageItem = imageManager.GetImages().FirstOrDefault(i => i.Id == torrentImageId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (imageItem != null) { torrentItem.CreateRelation(imageItem, "Image"); } torrentItem.SetString("UrlName", Guid.NewGuid().ToString()); torrentItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); torrentItem.SetValue("PublicationDate", DateTime.UtcNow); // Create a version and commit the transaction in order changes to be persisted to data store torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, false); // We can now call the following to publish the item ILifecycleDataItem publishedTorrentItem = dynamicModuleManager.Lifecycle.Publish(torrentItem); // You need to set appropriate workflow status torrentItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); // Create a version and commit the transaction in order changes to be persisted to data store versionManager.CreateVersion(torrentItem, true); TransactionManager.CommitTransaction(transactionName); }
/// <summary> /// Gets the image. /// </summary> /// <returns></returns> protected virtual SfImage GetImage() { LibrariesManager librariesManager = LibrariesManager.GetManager(this.ImageProviderName); return(librariesManager.GetImages().Where(i => i.Id == this.ImageId).Where(PredefinedFilters.PublishedItemsFilter <Telerik.Sitefinity.Libraries.Model.Image>()).FirstOrDefault()); }
public void CreateHotel() { DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(); Type hotelType = TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.HotelType); DynamicContent hotelItem = dynamicModuleManager.CreateDataItem(hotelType, HierarchicalDynamicContentTests.HotelId, dynamicModuleManager.Provider.ApplicationName); hotelItem.SetValue("Name", "Test Name"); hotelItem.SetValue("Overview", "Test Overview"); hotelItem.SetValue("Checkin", "Test Checkin"); hotelItem.SetValue("Checkout", "Test Checkout"); hotelItem.SetValue("FoodAndDrink", new string[] { "Option2" }); hotelItem.SetValue("Activities", new string[] { "Option2" }); hotelItem.SetValue("Rating", 25); TaxonomyManager taxonomyManager = TaxonomyManager.GetManager(); var Tag = taxonomyManager.GetTaxa <FlatTaxon>().Where(t => t.Taxonomy.Name == "Tags").FirstOrDefault(); if (Tag != null) { hotelItem.Organizer.AddTaxa("Tags", Tag.Id); } Address location = new Address(); CountryElement locationCountry = Config.Get <LocationsConfig>().Countries.Values.First(x => x.Name == "United States"); location.CountryCode = locationCountry.IsoCode; location.StateCode = locationCountry.StatesProvinces.Values.First().Abbreviation; location.City = "Test City"; location.Street = "Test Street"; location.Zip = "12345"; location.Latitude = 0.00; location.Longitude = 0.00; location.MapZoomLevel = 8; hotelItem.SetValue("Location", location); LibrariesManager mainPictureManager = LibrariesManager.GetManager(); var mainPictureItem = mainPictureManager.GetImages().FirstOrDefault(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master); if (mainPictureItem != null) { hotelItem.CreateRelation(mainPictureItem, "MainPicture"); } hotelItem.SetString("UrlName", "TestUrlName"); hotelItem.SetValue("Owner", SecurityManager.GetCurrentUserId()); hotelItem.SetValue("PublicationDate", DateTime.Now); hotelItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft"); dynamicModuleManager.SaveChanges(); var actualHotel = dynamicModuleManager.GetDataItem(hotelType, hotelItem.Id); Assert.IsNotNull(actualHotel); Assert.AreEqual(hotelItem.GetValue("Name").ToString(), actualHotel.GetValue("Name").ToString()); Assert.AreEqual(hotelItem.GetValue("Overview").ToString(), actualHotel.GetValue("Overview").ToString()); Assert.AreEqual(hotelItem.GetValue("Checkin").ToString(), actualHotel.GetValue("Checkin").ToString()); Assert.AreEqual(hotelItem.GetValue("Checkout").ToString(), actualHotel.GetValue("Checkout").ToString()); Assert.AreEqual(hotelItem.GetValue("FoodAndDrink").ToString(), actualHotel.GetValue("FoodAndDrink").ToString()); Assert.AreEqual(hotelItem.GetValue("Activities").ToString(), actualHotel.GetValue("Activities").ToString()); Assert.AreEqual(hotelItem.GetValue("Rating"), actualHotel.GetValue("Rating")); Assert.AreEqual(hotelItem.GetValue("MainPicture"), actualHotel.GetValue("MainPicture")); Assert.AreEqual(hotelItem.GetValue("Location"), actualHotel.GetValue("Location")); Assert.AreEqual(hotelItem.GetValue("UrlName").ToString(), actualHotel.GetValue("UrlName").ToString()); Assert.AreEqual(hotelItem.GetValue("Owner"), actualHotel.GetValue("Owner")); Assert.AreEqual(hotelItem.GetValue("PublicationDate"), actualHotel.GetValue("PublicationDate")); }
public static Telerik.Sitefinity.Libraries.Model.Image GetImage(string imageProviderName, Guid imageId) { LibrariesManager librariesManager = LibrariesManager.GetManager(imageProviderName); return(librariesManager.GetImages().Where(i => i.Id == imageId).FirstOrDefault()); }