Skip to content

Commit

Permalink
aspnetboilerplate#41: Created initial background job classes and Hang…
Browse files Browse the repository at this point in the history
…Fire adapter.
  • Loading branch information
hikalkan committed Jan 20, 2016
1 parent e9f046b commit f58741b
Show file tree
Hide file tree
Showing 31 changed files with 902 additions and 15 deletions.
1 change: 1 addition & 0 deletions nupkg/pack_abp.bat
@@ -1,5 +1,6 @@
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp\Abp.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.AutoMapper\Abp.AutoMapper.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.HangFire\Abp.HangFire.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.EntityFramework\Abp.EntityFramework.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.FluentMigrator\Abp.FluentMigrator.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.MemoryDb\Abp.MemoryDb.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
Expand Down
104 changes: 104 additions & 0 deletions src/Abp.HangFire/Abp.HangFire.csproj
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{58A5158C-C78B-4451-BFD8-FFC31D48D713}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Abp</RootNamespace>
<AssemblyName>Abp.HangFire</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Castle.Facilities.Logging, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.LoggingFacility.3.3.0\lib\net45\Castle.Facilities.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Castle.Windsor, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Hangfire.Core, Version=1.5.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hangfire.Core.1.5.3\lib\net45\Hangfire.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Hangfire\AbpHangfireModule.cs" />
<Compile Include="Hangfire\Configuration\AbpHangfireConfiguration.cs" />
<Compile Include="Hangfire\Configuration\AbpHangfireModuleConfigurationExtensions.cs" />
<Compile Include="Hangfire\Configuration\HangfireGlobalConfigurationExtensions.cs" />
<Compile Include="Hangfire\HangfireBackgroundJobManager.cs" />
<Compile Include="Hangfire\Configuration\IAbpHangfireConfiguration.cs" />
<Compile Include="Hangfire\WindsorJobActivator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="Abp.HangFire.nuspec" />
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Abp\Abp.csproj">
<Project>{2C221D3B-5F54-4C5B-8082-318636415132}</Project>
<Name>Abp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
14 changes: 14 additions & 0 deletions src/Abp.HangFire/Abp.HangFire.nuspec
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>Abp.HangFire</id>
<version>$version$</version>
<title>Abp.HangFire</title>
<authors>Halil İbrahim Kalkan</authors>
<owners>Halil İbrahim Kalkan</owners>
<description>HangFire integration package for ASP.NET Boilerplate.</description>
<projectUrl>http://www.aspnetboilerplate.com</projectUrl>
<iconUrl>http://www.aspnetboilerplate.com/images/abp_nupkg.png</iconUrl>
<tags>asp.net boilerplate mvc application web framework domain driven design dependency injection hangfire</tags>
</metadata>
</package>
33 changes: 33 additions & 0 deletions src/Abp.HangFire/Hangfire/AbpHangfireModule.cs
@@ -0,0 +1,33 @@
using System.Reflection;
using Abp.Hangfire.Configuration;
using Abp.Modules;
using Abp.Threading.BackgroundWorkers;
using Hangfire;

namespace Abp.Hangfire
{
[DependsOn(typeof(AbpKernelModule))]
public class AbpHangfireModule : AbpModule
{
public override void PreInitialize()
{
IocManager.Register<IAbpHangfireConfiguration, AbpHangfireConfiguration>();

GlobalConfiguration.Configuration
.UseWindsorJobActivator(IocManager);
//.UseSqlServerStorage("Default", options); // Here you can put any Connection String
}

public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
}

public override void PostInitialize()
{
IocManager.Resolve<IBackgroundWorkerManager>().Add(
IocManager.Resolve<HangfireBackgroundJobManager>()
);
}
}
}
@@ -0,0 +1,9 @@
using Hangfire;

namespace Abp.Hangfire.Configuration
{
public class AbpHangfireConfiguration : IAbpHangfireConfiguration
{
public BackgroundJobServer Server { get; set; }
}
}
@@ -0,0 +1,15 @@
using Abp.Configuration.Startup;

namespace Abp.Hangfire.Configuration
{
public static class AbpHangfireConfigurationExtensions
{
/// <summary>
/// Used to configure ABP NHibernate module.
/// </summary>
public static IAbpHangfireConfiguration AbpNHibernate(this IModuleConfigurations configurations)
{
return configurations.AbpConfiguration.GetOrCreate("Modules.Abp.Hangfire", () => configurations.AbpConfiguration.IocManager.Resolve<IAbpHangfireConfiguration>());
}
}
}
@@ -0,0 +1,27 @@
using System;
using Abp.Dependency;
using Hangfire;
using Hangfire.Annotations;

namespace Abp.Hangfire.Configuration
{
public static class HangfireGlobalConfigurationExtensions
{
public static IGlobalConfiguration<WindsorJobActivator> UseWindsorJobActivator(
[NotNull] this IGlobalConfiguration configuration,
[NotNull] IIocResolver iocResolver)
{
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}

if (iocResolver == null)
{
throw new ArgumentNullException("iocResolver");
}

return configuration.UseActivator(new WindsorJobActivator(iocResolver));
}
}
}
@@ -0,0 +1,9 @@
using Hangfire;

namespace Abp.Hangfire.Configuration
{
public interface IAbpHangfireConfiguration
{
BackgroundJobServer Server { get; set; }
}
}
57 changes: 57 additions & 0 deletions src/Abp.HangFire/Hangfire/HangfireBackgroundJobManager.cs
@@ -0,0 +1,57 @@
using System;
using System.Threading.Tasks;
using Abp.BackgroundJobs;
using Abp.Dependency;
using Abp.Hangfire.Configuration;
using Abp.Threading.BackgroundWorkers;
using Castle.Core.Logging;
using Hangfire;

namespace Abp.Hangfire
{
public class HangfireBackgroundJobManager : BackgroundWorkerBase, IBackgroundJobManager, ISingletonDependency
{
public ILogger Logger { get; set; }

private readonly IAbpHangfireConfiguration _configuration;

public HangfireBackgroundJobManager(IAbpHangfireConfiguration configuration)
{
_configuration = configuration;

Logger = NullLogger.Instance;
}

public override void Start()
{
base.Start();

if (_configuration.Server == null)
{
_configuration.Server = new BackgroundJobServer();
}
}

public override void WaitToStop()
{
try
{
_configuration.Server.Dispose();
}
catch(Exception ex)
{
Logger.Warn(ex.ToString(), ex);
}

base.WaitToStop();
}

public Task EnqueueAsync<TJob>(object state, BackgroundJobPriority priority = BackgroundJobPriority.Normal,
TimeSpan? delay = null) where TJob : IBackgroundJob
{
BackgroundJob.Enqueue<TJob>(job => job.Execute(state));

return Task.FromResult(0);
}
}
}
34 changes: 34 additions & 0 deletions src/Abp.HangFire/Hangfire/WindsorJobActivator.cs
@@ -0,0 +1,34 @@
using System;
using Abp.Dependency;
using Hangfire;

namespace Abp.Hangfire
{
public class WindsorJobActivator : JobActivator
{
readonly IIocResolver _iocResolver;

/// <summary>
/// Initializes new instance of WindsorJobActivator with a Windsor Kernel
/// </summary>
public WindsorJobActivator(IIocResolver iocResolver)
{
if (iocResolver == null)
{
throw new ArgumentNullException("iocResolver");
}

_iocResolver = iocResolver;
}

/// <summary>
/// Activates a job of a given type using the Windsor Kernel
/// </summary>
/// <param name="jobType">Type of job to activate</param>
/// <returns></returns>
public override object ActivateJob(Type jobType)
{
return _iocResolver.Resolve(jobType);
}
}
}
37 changes: 37 additions & 0 deletions src/Abp.HangFire/Properties/AssemblyInfo.cs
@@ -0,0 +1,37 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Abp;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Abp.HangFire")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Abp.HangFire")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2a68b114-5b41-423d-b5c7-a53a1841c807")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion(AbpConsts.CurrentVersion)]
[assembly: AssemblyFileVersion(AbpConsts.CurrentVersion)]
11 changes: 11 additions & 0 deletions src/Abp.HangFire/app.config
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
9 changes: 9 additions & 0 deletions src/Abp.HangFire/packages.config
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Castle.LoggingFacility" version="3.3.0" targetFramework="net452" />
<package id="Castle.Windsor" version="3.3.0" targetFramework="net452" />
<package id="Hangfire.Core" version="1.5.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
<package id="Owin" version="1.0" targetFramework="net452" />
</packages>

0 comments on commit f58741b

Please sign in to comment.