Merge branch '6.2.0-pubcontent' into 7.0.0-pubcontent
Conflicts: src/Umbraco.Core/Cache/CacheProviderBase.cs src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs src/Umbraco.Core/Cache/NullCacheProvider.cs src/Umbraco.Core/Cache/StaticCacheProvider.cs src/Umbraco.Core/Configuration/UmbracoSettings.cs src/Umbraco.Core/CoreBootManager.cs src/Umbraco.Core/Dynamics/PropertyResult.cs src/Umbraco.Core/Models/IPublishedContentProperty.cs src/Umbraco.Core/Models/PublishedItemType.cs src/Umbraco.Core/PropertyEditors/IPropertyEditorValueConverter.cs src/Umbraco.Core/PropertyEditors/PropertyEditorValueConvertersResolver.cs src/Umbraco.Core/PropertyEditors/PropertyValueConvertersResolver.cs src/Umbraco.Core/PublishedContentExtensions.cs src/Umbraco.Core/PublishedContentHelper.cs src/Umbraco.Core/Umbraco.Core.csproj src/Umbraco.Tests/CodeFirst/StronglyTypedMapperTest.cs src/Umbraco.Tests/LibraryTests.cs src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs src/Umbraco.Web/ExamineExtensions.cs src/Umbraco.Web/Models/DynamicPublishedContent.cs src/Umbraco.Web/Models/XmlPublishedContent.cs src/Umbraco.Web/Models/XmlPublishedContentProperty.cs src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs src/Umbraco.Web/PublishedContentExtensions.cs src/Umbraco.Web/Templates/TemplateUtilities.cs src/Umbraco.Web/Umbraco.Web.csproj src/Umbraco.Web/WebBootManager.cs src/Umbraco.Web/umbraco.presentation/macro.cs src/umbraco.MacroEngines/RazorDynamicNode/PropertyResult.cs src/umbraco.MacroEngines/RazorDynamicNode/PublishedContentExtensions.cs
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
namespace Umbraco.Web.Dynamics
|
||||
{
|
||||
internal static class ExtensionMethods
|
||||
{
|
||||
|
||||
|
||||
public static DynamicPublishedContentList Random(this DynamicPublishedContentList all, int min, int max)
|
||||
public static DynamicPublishedContentList Random(this DynamicPublishedContentList source, int min, int max)
|
||||
{
|
||||
//get a random number generator
|
||||
Random r = new Random();
|
||||
//choose the number of elements to be returned between Min and Max
|
||||
int Number = r.Next(min, max);
|
||||
//Call the other method
|
||||
return Random(all, Number);
|
||||
}
|
||||
public static DynamicPublishedContentList Random(this DynamicPublishedContentList all, int max)
|
||||
{
|
||||
//Randomly order the items in the set by a Guid, Take the correct number, and return this wrapped in a new DynamicNodeList
|
||||
return new DynamicPublishedContentList(all.Items.OrderBy(x => Guid.NewGuid()).Take(max));
|
||||
return Random(source, new Random().Next(min, max));
|
||||
}
|
||||
|
||||
public static DynamicPublishedContent Random(this DynamicPublishedContentList all)
|
||||
public static DynamicPublishedContentList Random(this DynamicPublishedContentList source, int max)
|
||||
{
|
||||
return all.Items.OrderBy(x => Guid.NewGuid()).First();
|
||||
return new DynamicPublishedContentList(source.OrderByRandom().Take(max));
|
||||
}
|
||||
|
||||
public static DynamicPublishedContent Random(this DynamicPublishedContentList source)
|
||||
{
|
||||
return new DynamicPublishedContent(source.OrderByRandom().First());
|
||||
}
|
||||
|
||||
private static IEnumerable<IPublishedContent> OrderByRandom(this DynamicPublishedContentList source)
|
||||
{
|
||||
return source.Items.OrderBy(x => Guid.NewGuid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user