Skip to content

Commit

Permalink
merging dev to master (#26)
Browse files Browse the repository at this point in the history
* Upgraded SimpleInjector dependency to 4.x, removed dependency on SimpleInjector.Extensions.LifetimeScoping.
Replaced usages of removed two-argument IConstructorResolutionBehavior.GetConstructor method with single argument one.
Replaced usages of LifetimeScoping with ThreadScopedLifestyle.

* Changed the name of the sample decorator class to indicate it now uses ThreadScopedLifestyle

* Pr/19 fixed (#21)

* Added Renamed

This is used for RenamedFileSystemEvent

* Inherited from RenamedEventArgs

Added oldName argument

* Added CreateRenamedFileSystemEvent

added null parameter for compatibility to other functions

* Added WhenFileSystemRenamed

modified code for use of fileSystemWatcher.Renamed

* Rename file test

Added test for rename and modified other to check FileSystemRenamed

* Added option to remove FileSystemWatcher duplicated events

* Updated all Nuget packages

* upgrading packages

* bump dependencies

* upgrade versions

* upgrade versions

* Update README.md

* fix runner

* update to build master
  • Loading branch information
tynor88 committed May 25, 2017
1 parent abd5efa commit 25dbec5
Show file tree
Hide file tree
Showing 57 changed files with 2,452 additions and 320 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ References

Copyright & License
=======================
Copyright 2014-2016 tynor88
Copyright 2014-2017 tynor88

Licensed under the [MIT License](https://github.com/tynor88/Topshelf.SimpleInjector/blob/master/LICENSE)
6 changes: 3 additions & 3 deletions Samples/Topshelf.FileSystemWatcher.Sample/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>
</configuration>
104 changes: 89 additions & 15 deletions Samples/Topshelf.FileSystemWatcher.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,114 @@ namespace Topshelf.FileSystemWatcher.Sample
internal class Program
{
private static readonly string _testDir = Directory.GetCurrentDirectory() + @"\test\";
private static readonly bool _includeSubDirectories = true;
private static readonly bool _excludeDuplicateEvents = true;

private static void Main(string[] args)
{
HostFactory.Run(config =>
{
config.UseTestHost();
config.Service<Program>(s =>
{
s.ConstructUsing(() => new Program());
s.WhenStarted((service, host) =>
s.BeforeStartingService((hostStart) =>
{
if (!Directory.Exists(_testDir))
Directory.CreateDirectory(_testDir);
using (FileStream fs = File.Create(_testDir + "testfile.ext"))
{
}
return true;
});
s.WhenStarted((service, host) => true);
s.WhenStopped((service, host) => true);
s.WhenFileSystemCreated(configurator =>
configurator.AddDirectory(dir =>
{
dir.Path = _testDir;
dir.CreateDir = true;
dir.NotifyFilters = NotifyFilters.FileName;
}), FileSystemCreated);
s.WhenFileSystemCreated(ConfigureDirectoryWorkCreated, FileSystemCreated);
s.WhenFileSystemChanged(ConfigureDirectoryWorkChanged, FileSystemCreated);
s.WhenFileSystemRenamed(ConfigureDirectoryWorkRenamedFile, FileSystemRenamedFile);
s.WhenFileSystemRenamed(ConfigureDirectoryWorkRenamedDirectory, FileSystemRenamedDirectory);
s.WhenFileSystemDeleted(ConfigureDirectoryWorkDeleted, FileSystemCreated);
});
});
Console.ReadKey();
}

private static void ConfigureDirectoryWorkCreated(FileSystemWatcherConfigurator obj)
{
obj.AddDirectory(dir =>
{
dir.Path = _testDir;
dir.IncludeSubDirectories = _includeSubDirectories;
dir.NotifyFilters = NotifyFilters.DirectoryName | NotifyFilters.FileName;
dir.ExcludeDuplicateEvents = _excludeDuplicateEvents;
});
}
private static void ConfigureDirectoryWorkChanged(FileSystemWatcherConfigurator obj)
{
obj.AddDirectory(dir =>
{
dir.Path = _testDir;
dir.IncludeSubDirectories = _includeSubDirectories;
dir.NotifyFilters = NotifyFilters.LastWrite;
dir.ExcludeDuplicateEvents = _excludeDuplicateEvents;
});
}
private static void ConfigureDirectoryWorkRenamedFile(FileSystemWatcherConfigurator obj)
{
obj.AddDirectory(dir =>
{
dir.Path = _testDir;
dir.IncludeSubDirectories = _includeSubDirectories;
dir.NotifyFilters = NotifyFilters.FileName;
dir.ExcludeDuplicateEvents = _excludeDuplicateEvents;
});
}
private static void ConfigureDirectoryWorkRenamedDirectory(FileSystemWatcherConfigurator obj)
{
obj.AddDirectory(dir =>
{
dir.Path = _testDir;
dir.IncludeSubDirectories = _includeSubDirectories;
dir.NotifyFilters = NotifyFilters.DirectoryName;
dir.ExcludeDuplicateEvents = _excludeDuplicateEvents;
});
}
private static void ConfigureDirectoryWorkDeleted(FileSystemWatcherConfigurator obj)
{
obj.AddDirectory(dir =>
{
dir.Path = _testDir;
dir.IncludeSubDirectories = _includeSubDirectories;
dir.NotifyFilters = NotifyFilters.DirectoryName | NotifyFilters.FileName;
dir.ExcludeDuplicateEvents = _excludeDuplicateEvents;
});
}

private static void FileSystemCreated(TopshelfFileSystemEventArgs topshelfFileSystemEventArgs)
{
Console.WriteLine("New file created! ChangeType = {0} FullPath = {1} Name = {2} FileSystemEventType {3}", topshelfFileSystemEventArgs.ChangeType, topshelfFileSystemEventArgs.FullPath, topshelfFileSystemEventArgs.Name, topshelfFileSystemEventArgs.FileSystemEventType);
Console.WriteLine("*********************");
Console.WriteLine("ChangeType = {0}", topshelfFileSystemEventArgs.ChangeType);
Console.WriteLine("FullPath = {0}", topshelfFileSystemEventArgs.FullPath);
Console.WriteLine("Name = {0}", topshelfFileSystemEventArgs.Name);
Console.WriteLine("FileSystemEventType {0}", topshelfFileSystemEventArgs.FileSystemEventType);
Console.WriteLine("*********************");
}

private static void FileSystemRenamedFile(TopshelfFileSystemEventArgs topshelfFileSystemEventArgs)
{
Console.WriteLine("*********************");
Console.WriteLine("Rename File");
Console.WriteLine("ChangeType = {0}", topshelfFileSystemEventArgs.ChangeType);
Console.WriteLine("FullPath = {0}", topshelfFileSystemEventArgs.FullPath);
Console.WriteLine("Name = {0}", topshelfFileSystemEventArgs.Name);
Console.WriteLine("FileSystemEventType {0}", topshelfFileSystemEventArgs.FileSystemEventType);
Console.WriteLine("*********************");
}

private static void FileSystemRenamedDirectory(TopshelfFileSystemEventArgs topshelfFileSystemEventArgs)
{
Console.WriteLine("*********************");
Console.WriteLine("Rename Dir");
Console.WriteLine("ChangeType = {0}", topshelfFileSystemEventArgs.ChangeType);
Console.WriteLine("FullPath = {0}", topshelfFileSystemEventArgs.FullPath);
Console.WriteLine("Name = {0}", topshelfFileSystemEventArgs.Name);
Console.WriteLine("FileSystemEventType {0}", topshelfFileSystemEventArgs.FileSystemEventType);
Console.WriteLine("*********************");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Topshelf.FileSystemWatcher.Sample</RootNamespace>
<AssemblyName>Topshelf.FileSystemWatcher.Sample</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -40,8 +41,8 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Topshelf, Version=3.3.154.0, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b, processorArchitecture=MSIL">
<HintPath>..\..\packages\Topshelf.3.3.1\lib\net40-full\Topshelf.dll</HintPath>
<Reference Include="Topshelf, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b, processorArchitecture=MSIL">
<HintPath>..\..\packages\Topshelf.4.0.3\lib\net452\Topshelf.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand All @@ -67,5 +68,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
2 changes: 1 addition & 1 deletion Samples/Topshelf.FileSystemWatcher.Sample/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Topshelf" version="3.3.1" targetFramework="net45" />
<package id="Topshelf" version="4.0.3" targetFramework="net452" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reflection;
using Quartz;
using SimpleInjector;
using SimpleInjector.Lifestyles;

namespace Topshelf.SimpleInjector.Quartz.Decorators.Sample
{
Expand All @@ -13,7 +14,7 @@ private static void Main(string[] args)
{
_container.Register<IDependencyInjected, DependencyInjected>();
_container.RegisterDecorator(typeof(IJob), typeof(LoggingDecorator));
_container.RegisterDecorator(typeof(IJob), typeof(LifetimeScopeDecoratorFuncTFactory));
_container.RegisterDecorator(typeof(IJob), typeof(ThreadScopedDecoratorFuncTFactory));

HostFactory.Run(config =>
{
Expand Down Expand Up @@ -94,22 +95,22 @@ public void Execute(IJobExecutionContext context)
}
}

public class LifetimeScopeDecoratorFuncTFactory : IJob
public class ThreadScopedDecoratorFuncTFactory : IJob
{
private readonly Func<IJob> _decorateeFactory;
private readonly Container _container;

public LifetimeScopeDecoratorFuncTFactory(Func<IJob> decorateeFactory, Container container)
public ThreadScopedDecoratorFuncTFactory(Func<IJob> decorateeFactory, Container container)
{
_decorateeFactory = decorateeFactory;
_container = container;
}

public void Execute(IJobExecutionContext context)
{
using (_container.BeginLifetimeScope())
using (ThreadScopedLifestyle.BeginScope(_container))
{
Console.WriteLine("See, i am decorating the Job: " + typeof(JobWithInjectedDependenciesDecorated).Name + " with a Lifetime Scope!");
Console.WriteLine("See, i am decorating the Job: " + typeof(JobWithInjectedDependenciesDecorated).Name + " with a Thread Scope!");
var job = _decorateeFactory.Invoke();
job.Execute(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Topshelf.SimpleInjector.Quartz.Decorators.Sample</RootNamespace>
<AssemblyName>Topshelf.SimpleInjector.Quartz.Decorators.Sample</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -41,16 +42,11 @@
<HintPath>..\..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Quartz, Version=2.3.3.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<HintPath>..\..\packages\Quartz.2.3.3\lib\net40\Quartz.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SimpleInjector, Version=3.1.2.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\..\packages\SimpleInjector.3.1.2\lib\net45\SimpleInjector.dll</HintPath>
<Private>True</Private>
<Reference Include="Quartz, Version=2.5.0.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<HintPath>..\..\packages\Quartz.2.5.0\lib\net40\Quartz.dll</HintPath>
</Reference>
<Reference Include="SimpleInjector.Extensions.LifetimeScoping, Version=3.1.2.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\..\packages\SimpleInjector.Extensions.LifetimeScoping.3.1.2\lib\net40-client\SimpleInjector.Extensions.LifetimeScoping.dll</HintPath>
<Reference Include="SimpleInjector, Version=4.0.7.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\..\packages\SimpleInjector.4.0.7\lib\net45\SimpleInjector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -60,9 +56,8 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Topshelf, Version=3.3.154.0, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b, processorArchitecture=MSIL">
<HintPath>..\..\packages\Topshelf.3.3.1\lib\net40-full\Topshelf.dll</HintPath>
<Private>True</Private>
<Reference Include="Topshelf, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b, processorArchitecture=MSIL">
<HintPath>..\..\packages\Topshelf.4.0.3\lib\net452\Topshelf.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -71,6 +66,9 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="job_scheduling_data_2_0.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
Expand All @@ -93,5 +91,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Topshelf" publicKeyToken="b800c4cfcdeea87b" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.154.0" newVersion="3.3.154.0" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="SimpleInjector" publicKeyToken="984cb50dea722e99" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.2.0" newVersion="3.1.2.0" />
<bindingRedirect oldVersion="0.0.0.0-4.0.7.0" newVersion="4.0.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /></startup></configuration>

0 comments on commit 25dbec5

Please sign in to comment.