Skip to content

Commit c655d76

Browse files
Merge pull request #20 from xavierjefferson/2020DNC
2020 dnc
2 parents 506372a + c36ee81 commit c655d76

30 files changed

+384
-594
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="hangfire.core" Version="1.7.17" />
10+
<PackageReference Include="serilog" Version="2.10.0" />
11+
<PackageReference Include="serilog.sinks.console" Version="3.1.1" />
12+
<PackageReference Include="snork.fluentnhibernatetools" Version="1.2.1014" />
13+
<PackageReference Include="system.data.sqlite" Version="1.0.113.6" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\Hangfire.FluentNHibernateStorage\Hangfire.FluentNHibernateStorage.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Data.SQLite;
3+
using System.IO;
4+
using Hangfire.FluentNHibernateStorage;
5+
using Serilog;
6+
using Serilog.Events;
7+
using Snork.FluentNHibernateTools;
8+
9+
namespace Hangfire.FluentNHibernate.ConsoleApplication
10+
{
11+
internal class Program
12+
{
13+
public static void HelloWorld(DateTime whenQueued, TimeSpan interval)
14+
{
15+
Log.Logger.Information(null, "Hello world at {2} intervals. Enqueued={0}, Now={1}", whenQueued,
16+
DateTime.Now,
17+
interval);
18+
}
19+
20+
private static void Main(string[] args)
21+
{
22+
Log.Logger = new LoggerConfiguration()
23+
.WriteTo.Console(LogEventLevel.Debug)
24+
.CreateLogger();
25+
26+
var database = new FileInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".sqlite"));
27+
Log.Information((Exception) null, "Using file {0}", database.FullName);
28+
if (!database.Exists)
29+
{
30+
Log.Information((Exception) null, "File {0} doesn't exist, creating", database.FullName);
31+
SQLiteConnection.CreateFile(database.FullName);
32+
}
33+
else
34+
{
35+
Log.Information((Exception) null, "File {0} exists", database.FullName);
36+
}
37+
38+
Console.WriteLine("Hello World!");
39+
Log.Information((Exception) null, "Starting server");
40+
41+
try
42+
{
43+
GlobalConfiguration.Configuration.UseFluentNHibernateJobStorage(
44+
string.Format("Data Source={0};Version=3;", database.FullName),
45+
ProviderTypeEnum.SQLite, new FluentNHibernateStorageOptions(){QueuePollInterval = new TimeSpan(0,0,5)});
46+
47+
using (var server = new BackgroundJobServer())
48+
{
49+
RecurringJob.AddOrUpdate("h2",() => HelloWorld(DateTime.Now, TimeSpan.FromMinutes(2)), "*/2 * * * *");
50+
RecurringJob.AddOrUpdate("h5",() => HelloWorld(DateTime.Now, TimeSpan.FromMinutes(5)), "*/5 * * * *");
51+
RecurringJob.AddOrUpdate("h1",() => HelloWorld(DateTime.Now, TimeSpan.FromMinutes(1)), "* * * * *");
52+
RecurringJob.AddOrUpdate("h7",() => HelloWorld(DateTime.Now, TimeSpan.FromMinutes(7)), "*/7 * * * *");
53+
RecurringJob.AddOrUpdate("h7", () => HelloWorld(DateTime.Now, TimeSpan.FromSeconds(30)), "*/30 * * * * *");
54+
Console.WriteLine("Hangfire Server started. Press any key to exit...");
55+
Console.ReadKey();
56+
}
57+
}
58+
catch (Exception ex)
59+
{
60+
Log.Error(ex, "Couldn't start server");
61+
}
62+
database.Delete();
63+
}
64+
}
65+
}

Hangfire.FluentNHibernate.SampleApplication/App.config

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
32
<configuration>
43
<configSections>
54
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" requirePermission="false" />
6-
<sectionGroup name="userSettings"
7-
type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
8-
<section name="Hangfire.FluentNHibernate.SampleApplication.Properties.Settings"
9-
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
10-
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
5+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
6+
<section name="Hangfire.FluentNHibernate.SampleApplication.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
117
</sectionGroup>
128
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
13-
<section name="entityFramework"
14-
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
15-
requirePermission="false" />
16-
<section name="oracle.manageddataaccess.client"
17-
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
9+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
10+
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
1811
</configSections>
1912
<startup>
20-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
13+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
2114
</startup>
2215
<log4net>
2316
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
@@ -70,34 +63,22 @@
7063
<system.data>
7164
<DbProviderFactories>
7265
<remove invariant="MySql.Data.MySqlClient" />
73-
<add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient"
74-
name="MySQL Data Provider"
75-
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
66+
<add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
7667
<remove invariant="System.Data.SQLite.EF6" />
77-
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6"
78-
description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
79-
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
68+
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
8069
<remove invariant="System.Data.SQLite" />
81-
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
82-
description=".NET Framework Data Provider for SQLite"
83-
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
70+
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
8471
<remove invariant="Oracle.ManagedDataAccess.Client" />
85-
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client"
86-
description="Oracle Data Provider for .NET, Managed Driver"
87-
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
72+
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
8873
<remove invariant="FirebirdSql.Data.FirebirdClient" />
89-
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient"
90-
description=".NET Framework Data Provider for Firebird"
91-
type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
74+
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
9275
</DbProviderFactories>
9376
</system.data>
9477
<entityFramework>
9578
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
9679
<providers>
97-
<provider invariantName="System.Data.SqlClient"
98-
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
99-
<provider invariantName="System.Data.SQLite.EF6"
100-
type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
80+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
81+
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
10182
</providers>
10283
</entityFramework>
10384
<runtime>
@@ -111,14 +92,25 @@
11192
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
11293
<bindingRedirect oldVersion="0.0.0.0-4.122.1.0" newVersion="4.122.1.0" />
11394
</dependentAssembly>
95+
<dependentAssembly>
96+
<assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
97+
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
98+
</dependentAssembly>
99+
<dependentAssembly>
100+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
101+
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
102+
</dependentAssembly>
103+
<dependentAssembly>
104+
<assemblyIdentity name="System.Configuration.ConfigurationManager" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
105+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
106+
</dependentAssembly>
114107
</assemblyBinding>
115108
</runtime>
116109
<oracle.manageddataaccess.client>
117110
<version number="*">
118111
<dataSources>
119-
<dataSource alias="SampleDataSource"
120-
descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
112+
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
121113
</dataSources>
122114
</version>
123115
</oracle.manageddataaccess.client>
124-
</configuration>
116+
</configuration>

Hangfire.FluentNHibernate.SampleApplication/Form1.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,10 @@ private ProviderTypeEnum ProviderType
6161
}
6262
}
6363

64-
public static void HelloWorld()
64+
public static void HelloWorld(DateTime whenQueued, int interval)
6565
{
66-
loggerNew.Info("Hello world at 2 min intervals");
67-
}
68-
69-
public static void HelloWorld5()
70-
{
71-
loggerNew.Info("Hello world at 5 min intervals");
66+
loggerNew.InfoFormat("Hello world at {2} min intervals. Enqueued={0}, Now={1}", whenQueued, DateTime.Now,
67+
interval);
7268
}
7369

7470
public static void Display(string x)
@@ -182,8 +178,10 @@ private void StartButton_Click(object sender, EventArgs e)
182178
storage.GetBackgroundProcesses());
183179

184180
/*ADD DUMMY CRON JOBS FOR DEMONSTRATION PURPOSES*/
185-
RecurringJob.AddOrUpdate(() => HelloWorld(), Cron.MinuteInterval(2));
186-
RecurringJob.AddOrUpdate(() => HelloWorld5(), Cron.MinuteInterval(5));
181+
RecurringJob.AddOrUpdate("h2", () => HelloWorld(DateTime.Now, 2), "*/2 * * * *");
182+
RecurringJob.AddOrUpdate("h5", () => HelloWorld(DateTime.Now, 5), "*/5 * * * *");
183+
RecurringJob.AddOrUpdate("h1", () => HelloWorld(DateTime.Now, 1), "* * * * *");
184+
RecurringJob.AddOrUpdate("h7", () => HelloWorld(DateTime.Now, 7), "*/7 * * * *");
187185
loggerNew.Info("Background server started");
188186
State = StateEnum.Started;
189187
}

0 commit comments

Comments
 (0)