public void TearDown()
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();

            var hotel = dynamicModuleManager
                        .GetDataItems(TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.HotelType))
                        .FirstOrDefault(x => x.Id == HierarchicalDynamicContentTests.HotelId);

            var restaurant = dynamicModuleManager
                             .GetDataItems(TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.RestaurantType))
                             .FirstOrDefault(x => x.Id == HierarchicalDynamicContentTests.RestaurantId);

            var city = dynamicModuleManager
                       .GetDataItems(TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.CityType))
                       .FirstOrDefault(x => x.Id == HierarchicalDynamicContentTests.CityId);

            var festival = dynamicModuleManager
                           .GetDataItems(TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.FestivalType))
                           .FirstOrDefault(x => x.Id == HierarchicalDynamicContentTests.FestivalId);

            var country = dynamicModuleManager
                          .GetDataItems(TypeResolutionService.ResolveType(HierarchicalDynamicContentTests.CountryType))
                          .FirstOrDefault(x => x.Id == HierarchicalDynamicContentTests.CountryId);

            if (hotel != null)
            {
                HierarchicalDynamicContentTests.DeleteDataItem(hotel, dynamicModuleManager);
            }

            if (restaurant != null)
            {
                HierarchicalDynamicContentTests.DeleteDataItem(restaurant, dynamicModuleManager);
            }

            if (festival != null)
            {
                HierarchicalDynamicContentTests.DeleteDataItem(festival, dynamicModuleManager);
            }

            if (city != null)
            {
                HierarchicalDynamicContentTests.DeleteCity(city, dynamicModuleManager);
            }

            if (country != null)
            {
                HierarchicalDynamicContentTests.DeleteCountry(country, dynamicModuleManager);
            }
        }
示例#2
0
        public static List <DynamicContent> GetCurrentSiteItems(string dynamicType, string dataSource)
        {
            Type itemType       = TypeResolutionService.ResolveType(dynamicType);
            var  managerArticle = TaxonomyManager.GetManager();

            MultisiteContext multisiteContext = SystemManager.CurrentContext as MultisiteContext;
            var providerName = multisiteContext.CurrentSite.GetProviders(dataSource).Select(p => p.ProviderName);

            // Set a transaction name
            var transactionName = Guid.NewGuid(); // I often using Guid.NewGuid()


            // Set the culture name for the multilingual fields
            var cultureName = "";

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName.FirstOrDefault(), transactionName.ToString());
            Type type = TypeResolutionService.ResolveType(dynamicType);

            // This is how we get the consultant items through filtering
            var myFilteredCollection = dynamicModuleManager.GetDataItems(type).Where(c => c.Status == ContentLifecycleStatus.Live & c.Visible);

            return(myFilteredCollection.ToList());
        }
        public void CreateItem(string title, string[] relatedColors)
        {
            var providerName = string.Empty;

            if (ServerOperations.MultiSite().CheckIsMultisiteMode())
            {
                providerName = "dynamicContentProvider";
            }

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type           itemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Module2.Item");
            DynamicContent itemItem = dynamicModuleManager.CreateDataItem(itemType);

            itemItem.SetValue("Title", title);

            DynamicModuleManager relatedColorManager = DynamicModuleManager.GetManager(providerName);
            var relatedColorType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Module1.Color");

            foreach (var relatedColor in relatedColors)
            {
                var relatedColorItem = relatedColorManager.GetDataItems(relatedColorType).Where("Status = Master AND Title = \"" + relatedColor + "\"").First();

                itemItem.CreateRelation(relatedColorItem, "RelatedColor");
                dynamicModuleManager.SaveChanges();
            }

            itemItem.SetString("UrlName", Regex.Replace(title.ToLower(), urlNameCharsToReplace, urlNameReplaceString));
            itemItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
            itemItem.SetValue("PublicationDate", DateTime.Now);
            itemItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
            dynamicModuleManager.Lifecycle.Publish(itemItem);

            dynamicModuleManager.SaveChanges();
        }
示例#4
0
        /// <summary>
        /// Creates a new hotel item.
        /// </summary>
        /// <param name="parentId">The id of the city.</param>
        /// <param name="title">The title of the hotel.</param>
        public void CreateHotel(Guid parentId, string title)
        {
            var providerName = string.Empty;

            if (ServerOperations.MultiSite().CheckIsMultisiteMode())
            {
                providerName = "dynamicContentProvider";
            }

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type           hotelType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Booking.Hotel");
            DynamicContent hotelItem = dynamicModuleManager.CreateDataItem(hotelType);

            hotelItem.SetValue("Title", title);
            hotelItem.SetString("UrlName", Regex.Replace(title.ToLower(), urlNameCharsToReplace, urlNameReplaceString));
            hotelItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
            hotelItem.SetValue("PublicationDate", DateTime.Now);

            hotelItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");

            Type           cityType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Booking.City");
            DynamicContent parent   = dynamicModuleManager.GetDataItems(cityType)
                                      .First(i => i.Id == parentId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master);

            hotelItem.SetParent(parent.Id, cityType.FullName);

            dynamicModuleManager.Lifecycle.Publish(hotelItem);
            dynamicModuleManager.SaveChanges();
        }
示例#5
0
        public void DynamicWidgets_ContentLocationService_MultipleItemsSelectedFromWidget()
        {
            int expectedLocationsCount;

            try
            {
                for (int i = 1; i <= 3; i++)
                {
                    ServerOperationsFeather.DynamicModuleBooking().CreateCountry(CountryName + i.ToString(CultureInfo.InvariantCulture));
                }

                Type countryType = TypeResolutionService.ResolveType(ResolveTypeCountry);

                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                var countryItem1Id = dynamicModuleManager.GetDataItems(countryType).Where("Title = \"" + CountryName + "1\"").First().Id;
                var countryItem2Id = dynamicModuleManager.GetDataItems(countryType).Where("Title = \"" + CountryName + "2\"").First().Id;

                string[] itemIds = new string[] { countryItem1Id.ToString(), countryItem2Id.ToString() };

                var pageId = ServerOperations.Pages().CreatePage(PageName);

                var countriesWidget = this.CreateMvcWidget(ResolveTypeCountry, WidgetNameCountries, itemIds);
                var controls        = new List <System.Web.UI.Control>();
                controls.Add(countriesWidget);

                PageContentGenerator.AddControlsToPage(pageId, controls);

                var locationsService     = SystemManager.GetContentLocationService();
                var dynamicItemLocations = locationsService.GetItemLocations(countryType, dynamicModuleManager.Provider.Name, countryItem1Id);

                expectedLocationsCount = 1;

                Assert.AreEqual(expectedLocationsCount, dynamicItemLocations.Count(), "Unexpected locations count");

                dynamicItemLocations = locationsService.GetItemLocations(countryType, dynamicModuleManager.Provider.Name, countryItem2Id);
                Assert.AreEqual(expectedLocationsCount, dynamicItemLocations.Count(), "Unexpected locations count");
            }
            finally
            {
                ServerOperations.Pages().DeleteAllPages();

                for (int i = 1; i <= 3; i++)
                {
                    ServerOperationsFeather.DynamicModuleBooking().DeleteCountry(CountryName + i.ToString(CultureInfo.InvariantCulture));
                }
            }
        }
示例#6
0
        private IQueryable<DynamicContent> GetBugsByProject(Guid projectId)
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();

            var bugs = dynamicModuleManager.GetDataItems(this.bugType).Where(d => d.SystemParentId == projectId && d.Status == ContentLifecycleStatus.Live);

            return bugs;
        }
示例#7
0
        private static IQueryable <DynamicContent> RetrieveDataThroughFiltering(Type type)
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();

            var myFilteredCollection = dynamicModuleManager.GetDataItems(type);

            return(myFilteredCollection);
        }
        public static IQueryable <DynamicContent> GetAllContentByType(String contentType, Boolean justLive = true)
        {
            //Just use an empty string for the provider.
            var providerName = String.Empty;

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type resourceType = TypeResolutionService.ResolveType(contentType);

            // Get all live items
            if (justLive)
            {
                return(dynamicModuleManager.GetDataItems(resourceType)
                       .Where(d => d.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live));
            }

            return(dynamicModuleManager.GetDataItems(resourceType));
        }
示例#9
0
        public IQueryable <DynamicContent> RetrieveCollectionOfTorrents(DynamicModuleManager dynamicModuleManager, Type torrentType)
        {
            var myCollection = dynamicModuleManager
                               .GetDataItems(torrentType)
                               .Where(t => t.Status == ContentLifecycleStatus.Live && t.Visible == true);

            return(myCollection);
        }
示例#10
0
        /// <summary>
        /// Converts the Guid[] type to the DynamicContent objects
        /// ** Sitefinitysteve.com Extension **
        /// </summary>
        public static IQueryable <DynamicContent> GetDynamicContentItems(this Guid[] contentLinks, string type)
        {
            DynamicModuleManager manager = DynamicModuleManager.GetManager();
            var contentType = TypeResolutionService.ResolveType(type);

            var items = manager.GetDataItems(contentType).Where(x => contentLinks.Contains(x.Id));

            return(items);
        }
示例#11
0
        private IQueryable <DynamicContent> GetProjects()
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type projectType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BugTracking.Project");

            var myCollection = dynamicModuleManager.GetDataItems(projectType).Where(p => p.Status == ContentLifecycleStatus.Live);

            return(myCollection);
        }
        private IQueryable <DynamicContent> RetrieveCollectionOfParallaxItems()
        {
            var providerName = "OpenAccessProvider";
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type parallaxitemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Carousel.Slide");

            var myCollection = dynamicModuleManager.GetDataItems(parallaxitemType).Where(p => p.Status == ContentLifecycleStatus.Live);

            return(myCollection);
        }
示例#13
0
        /// <summary>
        /// Gets content from the dynamic module manager by type and optionally applies a filter.
        /// </summary>
        /// <param name="contentType">String representation of the content type.</param>
        /// <param name="status">Status of the content you want returned. Null returns content in all statuses.</param>
        /// <param name="filter">Optional filter to apply to result set.</param>
        /// <returns></returns>
        public IResult <IQueryable <DynamicContent> > GetContentByType(
            string contentType,
            ContentLifecycleStatus?status = null,
            Expression <Func <DynamicContent, bool> > filter = null
            ) => Do <IQueryable <DynamicContent> > .Try((r) =>
        {
            if (string.IsNullOrWhiteSpace(contentType))
            {
                r.AddErrorAndLog(
                    _logger,
                    ERROR_CONTENT_TYPE_NULL_OR_EMPTY,
                    $"Content type passed into method {nameof(GetContentByType)} is null or empty."
                    );
                return(null);
            }

            var providerName = DefaultProviderName;

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);

            if (dynamicModuleManager == null)
            {
                r.AddErrorAndLog(
                    _logger,
                    ERROR_FAILED_TO_GET_DYNAMIC_MODULE_MANAGER,
                    $"Attempt to get dynamic module manager with provider name {providerName} in method {nameof(GetContentByType)} returned null."
                    );
                return(null);
            }

            Type dynamicContentType = TypeResolutionService.ResolveType(contentType);

            if (dynamicContentType == null)
            {
                r.AddErrorAndLog(
                    _logger,
                    ERROR_COULD_NOT_RESOLVE_TYPE,
                    $"Attempt to resolve dynamic type with name of {contentType} in method {nameof(GetContentByType)} returned null."
                    );
                return(null);
            }

            var dynamicContent = dynamicModuleManager
                                 .GetDataItems(dynamicContentType)
                                 .Where(e => status.HasValue ? e.Status == status : true);

            if (filter != null)
            {
                dynamicContent = dynamicContent.Where(filter);
            }

            return(dynamicContent);
        })
        .Result;
        /// <summary>
        /// Gets dynamic content items by type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static IQueryable <DynamicContent> GetDataItemsByType(string type)
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type resolvedType = TypeResolutionService.ResolveType(type);

            // Fetch a collection of "live" and "visible" items.
            var myCollection = dynamicModuleManager.GetDataItems(resolvedType)
                               .Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true);

            return(myCollection);
        }
示例#15
0
        public IQueryable <DynamicContent> GetAuthors()
        {
            var providerName = String.Empty;
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type authorType = TypeResolutionService.ResolveType(ItemType);

            // This is how we get the collection of Author items
            var myCollection = dynamicModuleManager.GetDataItems(authorType).Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);

            // At this point myCollection contains the items from type authorType
            return(myCollection);
        }
        public IQueryable <DynamicContent> RetrieveCollectionOfLiveData(string typeName, string providerName = null, bool reinitializeManager = false)
        {
            InitializeManager(providerName, reinitializeManager);
            Type type = TypeResolutionService.ResolveType(typeName);

            if (type == null)
            {
                throw new ArgumentNullException("type does not exists");
            }

            var data = manager.GetDataItems(type).Where(d => d.Status == ContentLifecycleStatus.Live && d.Visible == true);

            return(data);
        }
示例#17
0
        public void DynamicWidgets_HierarchicalWidgetsOnPage_DisplayCitiesFromSelectedCountries()
        {
            try
            {
                var providerName = FeatherWidgets.TestUtilities.CommonOperations.DynamicModulesOperations.ProviderName;
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
                Type countryType = TypeResolutionService.ResolveType(ResolveTypeCountry);

                var countryItem  = dynamicModuleManager.GetDataItems(countryType).Where("Status = Master AND Title = \"Country2\"").First();
                var countryItem2 = dynamicModuleManager.GetDataItems(countryType).Where("Status = Master AND Title = \"Country3\"").First();

                string[] parentIds = new string[] { countryItem.Id.ToString(), countryItem2.Id.ToString() };

                var citiesWidget = this.CreateMvcWidget(ResolveTypeCity, WidgetNameCities, ParentFilterMode.Selected, ResolveTypeCountry, parentIds);

                var controls = new List <System.Web.UI.Control>();
                controls.Add(citiesWidget);

                PageContentGenerator.AddControlsToPage(this.pageId, controls);

                string url             = UrlPath.ResolveAbsoluteUrl("~/" + PageName);
                string responseContent = PageInvoker.ExecuteWebRequest(url);

                for (int i = 1; i <= 3; i++)
                {
                    string suff = i.ToString(CultureInfo.InvariantCulture);

                    Assert.IsTrue(responseContent.Contains("Country2City" + suff), "The dynamic item with this title was NOT found Country2City" + suff);
                    Assert.IsFalse(responseContent.Contains("Country1City" + suff), "The dynamic item with this title was found Country1City" + suff);
                    Assert.IsTrue(responseContent.Contains("Country3City" + suff), "The dynamic item with this title was NOT found Country3City" + suff);
                }
            }
            finally
            {
                ServerOperations.Pages().DeleteAllPages();
            }
        }
        /// <summary>
        /// This is the default Action.
        /// </summary>
        public ActionResult Index()
        {
            var model = new WebinarModelList();


            var providerName = String.Empty;

            // Set a transaction name
            var transactionName = "someTransactionName";

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName);
            Type webinarType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Webinars.Webinar");

            // trying out the join
            var contentLinksManager = ContentLinksManager.GetManager();
            var links = contentLinksManager.GetContentLinks()
                        .Where(cl => cl.ParentItemType == typeof(WebinarModel).FullName &&
                               cl.ComponentPropertyName == "RelatedEvent");

            var webinars      = dynamicModuleManager.GetDataItems(webinarType);
            var eventsManager = EventsManager.GetManager();
            var events        = eventsManager.GetEvents();
            var relatedData   = events
                                .Join(links, (bp) => bp.OriginalContentId, (cl) => cl.ChildItemId, (bp, cl) => new {
                bp,
                cl
            })
                                .Join(webinars, (bpcl) => bpcl.cl.ParentItemId, (n) => n.OriginalContentId, (bpcl, n) => new {
                n,
                bpcl.bp
            }).Select(x => new WebinarModel()
            {
                Title = x.n.GetString("Title"), description = x.n.GetString("Description"), EventId = x.bp.Id.ToString()
            }).ToList();



            //passing back the collection (before performance optimizations)
            //List<WebinarModel> myCollection = dynamicModuleManager.GetDataItems(webinarType).Select(x => new WebinarModel()
            //{
            //    Title = x.GetValue("Title").ToString(),
            //    description = x.GetValue("Description").ToString(),
            //    StartTime = Convert.ToDateTime(x.GetValue("StartTime")),
            //    EndTime = Convert.ToDateTime(x.GetValue("EndTime")),
            //    EventId = EventsManager.GetManager().GetEvents().Where(e => e.Title == x.GetValue("Title").ToString()).Select(y => y.Id).ToString()
            //}).ToList();

            return(View("Default", relatedData));
        }
示例#19
0
        public List <DynamicContent> RetrieveCollectionOfPressArticles(string providerName)
        {
            if (ServerOperations.MultiSite().CheckIsMultisiteMode() && providerName == null)
            {
                providerName = "dynamicContentProvider";
            }

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle");

            // This is how we get the collection of Press Article items
            var myCollection = dynamicModuleManager.GetDataItems(pressArticleType).ToList();

            //// At this point myCollection contains the items from type pressArticleType
            return(myCollection);
        }
        public IQueryable <DynamicContent> RetrieveCollectionOfDestinos()
        {
            // Set the provider name for the DynamicModuleManager here. All available providers are listed in
            // Administration -> Settings -> Advanced -> DynamicModules -> Providers
            var providerName = String.Empty;

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type destinoType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Viagens.Destino");

            // This is how we get the collection of Destino items
            var myCollection = dynamicModuleManager.GetDataItems(destinoType)
                               .Where(d => d.Status == ContentLifecycleStatus.Live && d.Visible);

            // At this point myCollection contains the items from type destinoType
            return(myCollection);
        }
示例#21
0
        private void MigrateMedia(string transactionName)
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(parentItemProviderName, transactionName);

            var parentItems   = dynamicModuleManager.GetDataItems(parentItemType);
            var allItemsCount = parentItems.Count();
            var currentIndex  = 1;
            var sliceIterator = parentItems.SliceQuery(1000);

            // this manager will serve only for checking if child items exist, it should work with childItemProvider
            var childItemsManager = ManagerBase.GetMappedManagerInTransaction(childItemType, childItemProviderName, transactionName);

            var managerType         = ManagerBase.GetMappedManagerType(typeof(ContentLink));
            var contentLinksManager = ManagerBase.GetManagerInTransaction(managerType, null, transactionName) as ContentLinksManager;
            var appName             = contentLinksManager.Provider.ApplicationName;

            var librariesManager = LibrariesManager.GetManager(childItemProviderName);

            using (new ElevatedModeRegion(librariesManager))
            {
                foreach (var slicedQuery in sliceIterator)
                {
                    var currentQuery = slicedQuery;
                    foreach (var parentItem in currentQuery)
                    {
                        // get selected items for current parent item
                        var mediaContentLinks = parentItem.GetValue <ContentLink[]>(dynamicSelectorFieldName).ToArray();
                        foreach (var contentLink in mediaContentLinks)
                        {
                            ILifecycleDataItem currentItem = librariesManager.GetItemOrDefault(childItemType, contentLink.ChildItemId) as ILifecycleDataItem;
                            if (currentItem != null)
                            {
                                var masterContentItem = librariesManager.Lifecycle.GetMaster(currentItem);

                                this.AddRelationToItem(childItemsManager, contentLinksManager, appName, parentItem, masterContentItem.Id, contentLink.Ordinal, currentIndex, allItemsCount);
                            }
                        }
                        currentIndex++;
                    }

                    TransactionManager.FlushTransaction(transactionName);
                }
            }
            currentIndex = 1;
        }
        /// <summary>
        /// Publishes the specified data item.
        /// </summary>
        /// <param name="manager">The manager to publish with.</param>
        /// <param name="dataItem">The data item.</param>
        /// <param name="parentItem">(Optional) The parent of the data item to publish and save.</param>
        /// <returns>
        /// true if it succeeds, false if it fails.
        /// </returns>
        public static bool PublishAndSave(this DynamicModuleManager manager, DynamicContent dataItem, DynamicModel parentItem = null)
        {
            //CODE TAKEN FROM DEFAULT CODE REFERENCE OF MODULE BUILDER
            try
            {
                //UPDATE PUBLICATION DATE
                dataItem.PublicationDate = DateTime.UtcNow;

                //HANDLE NEW ITEM IF APPLICABLE
                if (dataItem.OriginalContentId == Guid.Empty)
                {
                    // Set item parent if applicable
                    if (parentItem != null)
                    {
                        var parentMaster = manager.GetDataItems(TypeResolutionService.ResolveType(parentItem.MappedType))
                                           .First(i => i.UrlName == parentItem.Slug && i.Status == ContentLifecycleStatus.Master);

                        dataItem.SetParent(parentMaster.Id, parentItem.MappedType);
                    }

                    //You need to set appropriate workflow status
                    dataItem.SetWorkflowStatus(manager.Provider.ApplicationName, "Published");

                    // We can now call the following to publish the item
                    manager.Lifecycle.Publish(dataItem);
                }
                else //HANDLE UPDATES ON EXISTING ITEM
                {
                    // Now we need to check in, so the changes apply
                    var master = manager.Lifecycle.CheckIn(dataItem);

                    // We can now call the following to publish the item
                    manager.Lifecycle.Publish(master);
                }

                // You need to call SaveChanges() in order for the items to be actually persisted to data store
                manager.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                //TODO: LOG ERROR
                return(false);
            }
        }
示例#23
0
        /// <summary>
        /// Delete a country item by title.
        /// </summary>
        /// <param name="countryName">The title of the item.</param>
        public void DeleteCountry(string countryName)
        {
            var providerName = string.Empty;

            if (ServerOperations.MultiSite().CheckIsMultisiteMode())
            {
                providerName = "dynamicContentProvider";
            }

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);

            Type           countryType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Booking.Country");
            DynamicContent countryItem = dynamicModuleManager.GetDataItems(countryType).Where("Title = \"" + countryName + "\"").First();

            dynamicModuleManager.DeleteDataItem(countryItem);

            dynamicModuleManager.SaveChanges();
        }
        /// <summary>
        /// This is the default Action.
        /// </summary>
        public ActionResult Index()
        {
            var model = new AuthorsWidgetModel();

            //GET AUTHORS
            var providerName = String.Empty;
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type authorType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Authors.Author");

            // This is how we get the collection of Author items
            var myCollection = dynamicModuleManager.GetDataItems(authorType).Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).Take(4);

            // At this point myCollection contains the items from type authorType
            model.AvatarEnabled = this.EnableAvatar;
            model.Authors       = myCollection.Select(i => AuthorViewModel.GetAuthorViewModel(i)).ToList();

            return(View("Default", model));
        }
        // Demonstrates how Destino content items can be retrieved through filtering
        public DynamicContent RetrieveDestinoThroughFiltering(string destinoUrl)
        {
            // Set the provider name for the DynamicModuleManager here. All available providers are listed in
            // Administration -> Settings -> Advanced -> DynamicModules -> Providers
            var providerName = String.Empty;

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type destinoType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Viagens.Destino");

            // This is how we get the destino items through filtering
            var myFilteredCollection = dynamicModuleManager.GetDataItems(destinoType)
                                       .SingleOrDefault(d => d.UrlName == destinoUrl && d.Status == ContentLifecycleStatus.Live && d.Visible);

            // At this point myFilteredCollection contains the items that match the lambda expression passed to the Where extension method
            // If you want only the first matching element you can freely get it by ".First()" extension method like this:
            // var myFirstFilteredItem = myFilteredCollection.First();
            return(myFilteredCollection);
        }
        /// <summary>
        /// Gets a item by type
        /// </summary>
        /// <param name="url">The url</param>
        /// <returns></returns>
        public object GetDataItemByUrlName(string url, List <Type> AllowedContentTypes)
        {
            url = System.Net.WebUtility.UrlDecode(url);

            object o = null;


            #region SF Content
            //Default SF content

            NewsManager newsManager = NewsManager.GetManager();
            List <Telerik.Sitefinity.News.Model.NewsItem> items =
                newsManager.GetNewsItems().Where(i => i.Status == ContentLifecycleStatus.Live).ToList();

            o = items.FirstOrDefault(q => q.UrlName == url);
            if (o != null)
            {
                return(o);
            }

            #endregion


            #region Dynamic content

            foreach (Type cType in AllowedContentTypes)
            {
                try
                {
                    o = dynamicModuleManager.GetDataItems(cType).FirstOrDefault(q => q.UrlName == url);
                    if (o != null)
                    {
                        return(o);
                    }
                }
                catch { }
            }


            #endregion


            return(null);
        }
示例#27
0
        private void MigrateGuidArray(string transactionName)
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(parentItemProviderName, transactionName);

            var parentItems   = dynamicModuleManager.GetDataItems(parentItemType);
            var allItemsCount = parentItems.Count();
            var currentIndex  = 1;
            var sliceIterator = parentItems.SliceQuery(1000);

            // this manager will serve only for checking if child items exist, it should work with childItemProvider
            var childItemsManager = ManagerBase.GetMappedManagerInTransaction(childItemType, childItemProviderName, transactionName);

            var managerType         = ManagerBase.GetMappedManagerType(typeof(ContentLink));
            var contentLinksManager = ManagerBase.GetManagerInTransaction(managerType, null, transactionName) as ContentLinksManager;
            var appName             = contentLinksManager.Provider.ApplicationName;

            Guid[] childItemIds;
            float  childItemOrdinal;

            foreach (var slicedQuery in sliceIterator)
            {
                var currentQuery = slicedQuery;
                foreach (var parentItem in currentQuery)
                {
                    childItemOrdinal = 0;
                    // get selected items for current parent item
                    childItemIds = parentItem.GetValue <Guid[]>(dynamicSelectorFieldName);
                    if (childItemIds != null)
                    {
                        foreach (var id in childItemIds)
                        {
                            this.AddRelationToItem(childItemsManager, contentLinksManager, appName, parentItem, id, childItemOrdinal, currentIndex, allItemsCount);
                            childItemOrdinal++;
                        }
                    }
                    currentIndex++;
                }

                TransactionManager.FlushTransaction(transactionName);
            }
            currentIndex = 1;
        }
        public List <DynamicContent> RetrieveCollectionOfAllFields()
        {
            // Set the provider name for the DynamicModuleManager here. All available providers are listed in
            // Administration -> Settings -> Advanced -> DynamicModules -> Providers
            var providerName = string.Empty;

            if (ServerOperations.MultiSite().CheckIsMultisiteMode())
            {
                providerName = "dynamicContentProvider";
            }

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
            Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.AllTypesModule.Alltypes");

            // This is how we get the collection of Press Article items
            var myCollection = dynamicModuleManager.GetDataItems(pressArticleType).ToList();

            //// At this point myCollection contains the items from type pressArticleType
            return(myCollection);
        }
示例#29
0
        // Demonstrates how a collection of Projects can be retrieved
        public IQueryable <DynamicContent> RetrieveCollectionOfProjects()
        {
            // 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
            var transactionName = "someTransactionName";

            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName, transactionName);
            Type projectsType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BugTracking.Projects");

            CreateProjectsItem(dynamicModuleManager, projectsType, transactionName);

            // This is how we get the collection of Project items
            var myCollection = dynamicModuleManager.GetDataItems(projectsType)
                               .Where(p => p.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && p.Visible == true);

            // At this point myCollection contains the items from type projectsType
            return(myCollection);
        }
示例#30
0
        public static List <DynamicContent> GetRelatedDynamicContentItemsByHierarchicalTaxonomy(TrackedList <Guid> detailsPageItemTaxonIds, Guid detailPageItemId, string fieldName, string dynamicContentType)
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type contentType = TypeResolutionService.ResolveType(dynamicContentType);
            var  allItems    = dynamicModuleManager.GetDataItems(contentType).Where(h => h.Status == ContentLifecycleStatus.Live && h.Visible && h.ApprovalWorkflowState == "Published").ToList();
            List <DynamicContent> relatedItems = new List <DynamicContent>();

            foreach (var item in allItems)
            {
                var articleTaxonIds = item.GetValue <TrackedList <Guid> >(fieldName);
                if (articleTaxonIds.Any(x => detailsPageItemTaxonIds.Contains(x)))
                {
                    // Skip the current loaded item in the details page
                    if (item.Id != detailPageItemId)
                    {
                        relatedItems.Add(item);
                    }
                }
            }

            return(relatedItems);
        }
        public override void ExecuteTask()
        {
            //If no url is provided, die
            if (webVidConfig.FeedUri.IsNullOrWhitespace())
                return;
            #region Execute Task
            {
                Type syncedVideoType;
                var providerName = "OpenAccessProvider";
                dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
                syncedVideoType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.SyncedVideos.SyncedVideo");
                List<google.Video> videos;
                DateTime lastRan;
                CallVideoService callService = new CallVideoService(webVidConfig.FeedUri);

                DateTime.TryParse(webVidConfig.LastRuntime, out lastRan);

                videos = callService.GetVideos().ToList();

                foreach (google.Video vid in videos)
                {
                    var myVideo = dynamicModuleManager.GetDataItems(syncedVideoType).Where(i => i.GetValue<string>("YouTubeVidId") == vid.VideoId && i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).FirstOrDefault();
                    // if lastRan is set and (vid.YouTubeEntry.Published.Ticks > lastRan.Ticks || vid.YouTubeEntry.Updated.Ticks > lastRan.Ticks)
                    if (webVidConfig.LastRuntime.IsNullOrWhitespace() || vid.YouTubeEntry.Published.Ticks > lastRan.Ticks || vid.YouTubeEntry.Updated.Ticks > lastRan.Ticks)
                        callService.createUpdateVideo(myVideo, vid);
                }
            }
            #endregion
            #region Rescheduling task
            {
                //Update Configuration Time
                ConfigManager manager = ConfigManager.GetManager();
                manager.Provider.SuppressSecurityChecks = true;
                WebVideoSyncConfig config = manager.GetSection<WebVideoSyncConfig>();
                config.LastRuntime = DateTime.UtcNow.ToString();
                manager.SaveSection(config);
                manager.Provider.SuppressSecurityChecks = false;

                //Reschedule Task
                SchedulingManager schedulingManager = SchedulingManager.GetManager();
                ScheduledVideoSync newTask = new ScheduledVideoSync();
                schedulingManager.AddTask(newTask);
                schedulingManager.SaveChanges();
            }
            #endregion
        }