Skip to content
Permalink
Browse files

Moved plugins into a separate project. Some refactors to the Registry…

… tests.
  • Loading branch information...
Chris S
Chris S committed Dec 3, 2015
1 parent 1109661 commit cbf0ee5af5393cf9378d105e17c5cbf7cda96b0a
Showing with 2,100 additions and 1,880 deletions.
  1. +14 −0 Roadkill.sln
  2. +21 −8 src/Roadkill.Core/DependencyResolution/LocatorStartup.cs
  3. +0 −24 src/Roadkill.Core/DependencyResolution/StructureMap/RoadkillRegistry.cs
  4. +5 −2 src/Roadkill.Core/DependencyResolution/StructureMap/StructureMapServiceLocator.cs
  5. +0 −1 src/Roadkill.Core/Plugins/IPluginFactory.cs
  6. +0 −6 src/Roadkill.Core/Plugins/PluginFactory.cs
  7. +65 −65 src/Roadkill.Core/Plugins/{SpecialPages → }/SpecialPagePlugin.cs
  8. +432 −432 src/Roadkill.Core/Plugins/{Text → }/TextPlugin.cs
  9. +2 −14 src/Roadkill.Core/Roadkill.Core.csproj
  10. +4 −15 src/Roadkill.Core/Startup.cs
  11. +0 −1 src/Roadkill.Core/Text/CustomTokenParser.cs
  12. +0 −8 src/Roadkill.Core/Text/MarkupConverter.cs
  13. +37 −0 src/Roadkill.Plugins/Properties/AssemblyInfo.cs
  14. +108 −0 src/Roadkill.Plugins/Roadkill.Plugins.csproj
  15. +56 −57 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/SpecialPages/BuiltIn/RandomPage.cs
  16. +150 −0 src/Roadkill.Plugins/TestUserService.cs
  17. +49 −57 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ClickableImages.cs
  18. +49 −57 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ExternalLinksInNewWindow.cs
  19. +93 −100 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/Jumbotron.cs
  20. +71 −79 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/MathJax.cs
  21. +47 −55 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ResizeImages.cs
  22. +143 −150 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/SyntaxHighlighter.cs
  23. +64 −66 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ToC/Item.cs
  24. +89 −92 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ToC/StringTemplate.cs
  25. +106 −109 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ToC/TocParser.cs
  26. +52 −57 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ToC/TocPlugin.cs
  27. +112 −114 src/{Roadkill.Core/Plugins → Roadkill.Plugins}/Text/BuiltIn/ToC/Tree.cs
  28. +8 −0 src/Roadkill.Plugins/packages.config
  29. +5 −1 src/Roadkill.Tests/Roadkill.Tests.csproj
  30. +8 −6 src/Roadkill.Tests/Setup/IocHelper.cs
  31. +301 −294 src/Roadkill.Tests/Unit/DI/{DependencyManagerTests.cs → RoadkillRegistryTests.cs}
  32. +1 −2 src/Roadkill.Tests/Unit/Plugins/JumbotronTests.cs
  33. +1 −2 src/Roadkill.Tests/Unit/Plugins/MathJaxTests.cs
  34. +1 −1 src/Roadkill.Tests/Unit/Plugins/RandomPageTests.cs
  35. +1 −2 src/Roadkill.Tests/Unit/Plugins/SyntaxHighlighterTests.cs
  36. +1 −1 src/Roadkill.Tests/Unit/Plugins/TocParserTests.cs
  37. +0 −2 src/Roadkill.Tests/Unit/StubsAndMocks/PluginFactoryMock.cs
  38. BIN src/Roadkill.Web/App_Data/roadkill152.sdf
  39. +4 −0 src/Roadkill.Web/Roadkill.Web.csproj
@@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Roadkill.Tests", "src\Roadk
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Roadkill.Web", "src\Roadkill.Web\Roadkill.Web.csproj", "{CD29D34E-4F1A-4D43-B150-08BA76EC9DA3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Roadkill.Plugins", "src\Roadkill.Plugins\Roadkill.Plugins.csproj", "{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -62,6 +64,18 @@ Global
{CD29D34E-4F1A-4D43-B150-08BA76EC9DA3}.Release|x64.Build.0 = Release|x64
{CD29D34E-4F1A-4D43-B150-08BA76EC9DA3}.Release|x86.ActiveCfg = Release|x86
{CD29D34E-4F1A-4D43-B150-08BA76EC9DA3}.Release|x86.Build.0 = Release|x86
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Debug|x64.ActiveCfg = Debug|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Debug|x64.Build.0 = Debug|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Debug|x86.ActiveCfg = Debug|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Debug|x86.Build.0 = Debug|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Release|Any CPU.Build.0 = Release|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Release|x64.ActiveCfg = Release|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Release|x64.Build.0 = Release|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Release|x86.ActiveCfg = Release|Any CPU
{EA201E5C-1FEF-4955-9CE8-F801D05E68CB}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1,3 +1,4 @@
using System;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
@@ -8,21 +9,23 @@
using Roadkill.Core.DependencyResolution;
using Roadkill.Core.DependencyResolution.MVC;
using Roadkill.Core.DependencyResolution.StructureMap;
using Roadkill.Core.Logging;
using Roadkill.Core.Mvc.ViewModels;
using Roadkill.Core.Services;
using StructureMap;

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(LocatorStartup), "StartMVC")]
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(LocatorStartup), "StartWebApi")]
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(LocatorStartup), "AfterInitialization")]
[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(LocatorStartup), "End")]

namespace Roadkill.Core.DependencyResolution
{
// This class does the following:
// - Is called on app startup
// - Creates a new Container that uses DefaultRegistry, which does the real work.
// - Uses a new StructureMapServiceLocator for the service locator
// - Creates a new Container that uses RoadkillRegistry, which does the scanning + instance mapping.
// - Uses a new StructureMapServiceLocator as the service locator
// - Uses a StructureMapScopeModule HttpModule to create a new container per request
// - Does additional MVC/WebApi plumbing after application start in AfterInitialization

public static class LocatorStartup
{
@@ -43,15 +46,25 @@ internal static void StartMVCInternal(RoadkillRegistry registry, bool isWeb)
DynamicModuleUtility.RegisterModule(typeof(StructureMapHttpModule));
}

internal static void StartWebApi()
// Must be run **after** the app has started/initialized via WebActivor
public static void AfterInitialization()
{
// WebApi locator
GlobalConfiguration.Configuration.DependencyResolver = Locator;
// Setup the additional MVC DI stuff
var settings = Locator.GetInstance<ApplicationSettings>();
AfterInitializationInternal(Locator.Container, settings);

// Setup the repository
var repository = Locator.GetInstance<IRepository>();
repository.Startup(settings.DataStoreType, settings.ConnectionString, settings.UseObjectCache);

Log.ConfigureLogging(settings);
}

// Must be run **after** the app has started/initialized via WebActivor
public static void ConfigureAdditionalMVC(IContainer container, ApplicationSettings appSettings)
internal static void AfterInitializationInternal(IContainer container, ApplicationSettings appSettings)
{
// WebApi locator
GlobalConfiguration.Configuration.DependencyResolver = Locator;

// MVC attributes
var mvcProvider = new MvcAttributeProvider(container);
FilterProviders.Providers.Add(mvcProvider); // attributes
@@ -44,8 +44,6 @@ public RoadkillRegistry(ConfigReaderWriter configReader)
ConfigureUserService();
ConfigureFileService();
ConfigureSetterInjection();

Log.ConfigureLogging(_applicationSettings);
}

private void ScanTypes(IAssemblyScanner scanner)
@@ -158,28 +156,6 @@ private void ConfigureInstances(ConfigReaderWriter configReader)
#endif
}

public void RegisterCustomInstances(ApplicationSettings applicationSettings, IRepository repository, IUserContext context)
{
if (applicationSettings == null)
throw new IoCException("The ApplicationSettings parameter is null", null);

if (repository == null)
throw new IoCException("The IRepository parameter is null", null);

if (context == null)
throw new IoCException("The IRoadkillContext parameter is null", null);

if (applicationSettings.Installed && string.IsNullOrEmpty(applicationSettings.ConnectionString))
throw new DatabaseException("The configuration file's connection string is empty (and installed=true).", null);


For<ApplicationSettings>().HybridHttpOrThreadLocalScoped().Use(applicationSettings);
For<IRepository>().HybridHttpOrThreadLocalScoped().Use(repository);
For<IUserContext>().HybridHttpOrThreadLocalScoped().Use(context);

Log.ConfigureLogging(applicationSettings);
}

private void ConfigureSetterInjection()
{
Policies.SetAllProperties(x => x.OfType<ISetterInjected>());
@@ -34,6 +34,9 @@ public class StructureMapServiceLocator : ServiceLocatorImplBase, IDependencyRes
public IContainer Container { get; set; }
public bool IsWeb { get; set; }

[ThreadStatic]
private static IContainer _container;

public IContainer CurrentNestedContainer
{
get
@@ -44,7 +47,7 @@ public IContainer CurrentNestedContainer
}
else
{
return (IContainer) Thread.GetData(Thread.GetNamedDataSlot(NestedContainerKey));
return _container;
}
}
set
@@ -55,7 +58,7 @@ public IContainer CurrentNestedContainer
}
else
{
Thread.SetData(Thread.GetNamedDataSlot(NestedContainerKey), value);
_container = value;
}
}
}
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Roadkill.Core.Configuration;
using Roadkill.Core.Plugins.SpecialPages;

namespace Roadkill.Core.Plugins
{
@@ -2,16 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Roadkill.Core.Configuration;
using Roadkill.Core.Database;
using Roadkill.Core.DependencyResolution;
using Roadkill.Core.DependencyResolution.StructureMap;
using Roadkill.Core.Logging;
using Roadkill.Core.Plugins.Text.BuiltIn;
using Roadkill.Core.Plugins.SpecialPages;
using StructureMap;

namespace Roadkill.Core.Plugins
{
@@ -1,65 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Roadkill.Core.Configuration;
using Roadkill.Core.DependencyResolution;
using Roadkill.Core.Mvc.Attributes;
using Roadkill.Core.Mvc.Controllers;
using Roadkill.Core.Security;
using Roadkill.Core.Services;
using StructureMap.Attributes;

namespace Roadkill.Core.Plugins
{
/// <summary>
/// Represents a plugin for a specific wiki Special:pluginname page, for example Special:Random.
/// </summary>
public abstract class SpecialPagePlugin : ISetterInjected
{
/// <summary>
/// Gets or sets the current Roadkill <see cref="ApplicationSettings"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public ApplicationSettings ApplicationSettings { get; set; }

/// <summary>
/// Gets or sets the current logged in user represnted by <see cref="IUserContext"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public IUserContext Context { get; set; }

/// <summary>
/// Gets or sets the current Roadkill <see cref="UserServiceBase"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public UserServiceBase UserService { get; set; }

/// <summary>
/// Gets or sets the current Roadkill <see cref="IPageService"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public IPageService PageService { get; set; }

/// <summary>
/// Gets the current Roadkill <see cref="SettingsService"/> that can be used to get the current <see cref="SiteSettings"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public SettingsService SettingsService { get; set; }

/// <summary>
/// The unique name of the special page, used in the url /Special:{name}
/// </summary>
public abstract string Name { get; }

/// <summary>
/// Returns an <see cref="System.Web.Mvc.ActionResult"/> for the special page. This can include a <see cref="ViewResult"/> that
/// points to a view in the /Plugin/PluginId folder.
/// </summary>
/// <param name="controller">The <see cref="SpecialPagesController"/> that the action belongs to.</param>
/// <returns></returns>
public abstract ActionResult GetResult(SpecialPagesController controller);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Roadkill.Core.Configuration;
using Roadkill.Core.DependencyResolution;
using Roadkill.Core.Mvc.Attributes;
using Roadkill.Core.Mvc.Controllers;
using Roadkill.Core.Security;
using Roadkill.Core.Services;
using StructureMap.Attributes;

namespace Roadkill.Core.Plugins
{
/// <summary>
/// Represents a plugin for a specific wiki Special:pluginname page, for example Special:Random.
/// </summary>
public abstract class SpecialPagePlugin : ISetterInjected
{
/// <summary>
/// Gets or sets the current Roadkill <see cref="ApplicationSettings"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public ApplicationSettings ApplicationSettings { get; set; }

/// <summary>
/// Gets or sets the current logged in user represnted by <see cref="IUserContext"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public IUserContext Context { get; set; }

/// <summary>
/// Gets or sets the current Roadkill <see cref="UserServiceBase"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public UserServiceBase UserService { get; set; }

/// <summary>
/// Gets or sets the current Roadkill <see cref="IPageService"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public IPageService PageService { get; set; }

/// <summary>
/// Gets the current Roadkill <see cref="SettingsService"/> that can be used to get the current <see cref="SiteSettings"/>. This property is automatically filled by Roadkill when the plugin is loaded.
/// </summary>
[SetterProperty]
public SettingsService SettingsService { get; set; }

/// <summary>
/// The unique name of the special page, used in the url /Special:{name}
/// </summary>
public abstract string Name { get; }

/// <summary>
/// Returns an <see cref="System.Web.Mvc.ActionResult"/> for the special page. This can include a <see cref="ViewResult"/> that
/// points to a view in the /Plugin/PluginId folder.
/// </summary>
/// <param name="controller">The <see cref="SpecialPagesController"/> that the action belongs to.</param>
/// <returns></returns>
public abstract ActionResult GetResult(SpecialPagesController controller);
}
}
Oops, something went wrong.

0 comments on commit cbf0ee5

Please sign in to comment.
You can’t perform that action at this time.