Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from imranmomin/develop
Browse files Browse the repository at this point in the history
Add support for .net standard
  • Loading branch information
imranmomin authored Mar 28, 2018
2 parents 870dc30 + ee0e0ed commit ddab224
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 400 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,5 @@ paket-files/
# JetBrains Rider
.idea/
*.sln.iml

/test
2 changes: 1 addition & 1 deletion Hangfire.AzureDocumentDB/CountersAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void Execute(CancellationToken cancellationToken)
Task<StoredProcedureResponse<bool>> procedureTask = storage.Client.ExecuteStoredProcedureAsync<bool>(spDeleteDocumentIfExistsUri, deleteCountersr);
procedureTask.Wait(cancellationToken);
}
}, cancellationToken);
}, cancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);

continueTask.Wait(cancellationToken);
}
Expand Down
27 changes: 15 additions & 12 deletions Hangfire.AzureDocumentDB/DocumentDbStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private DocumentDbStorage(DocumentDbStorageOptions options)

ConnectionPolicy connectionPolicy = ConnectionPolicy.Default;
connectionPolicy.RequestTimeout = options.RequestTimeout;
Client = new DocumentClient(options.Endpoint, options.AuthSecret, connectionPolicy, serializerSettings: settings);
Client = new DocumentClient(options.Endpoint, options.AuthSecret, settings, connectionPolicy);
Task task = Client.OpenAsync();
Task continueTask = task.ContinueWith(t => Initialize(), TaskContinuationOptions.OnlyOnRanToCompletion);
continueTask.Wait();
Expand Down Expand Up @@ -131,25 +131,25 @@ private void Initialize()

// create database
logger.Info($"Creating database : {Options.DatabaseName}");
Task databaseTask = Client.CreateDatabaseIfNotExistsAsync(new Database { Id = Options.DatabaseName });
Task<ResourceResponse<Database>> databaseTask = Client.CreateDatabaseIfNotExistsAsync(new Database { Id = Options.DatabaseName });

// create document collection
Task collectionTask = databaseTask.ContinueWith(t =>
Task<ResourceResponse<DocumentCollection>> collectionTask = databaseTask.ContinueWith(t =>
{
logger.Info($"Creating document collection : {Options.CollectionName}");
Uri databaseUri = UriFactory.CreateDatabaseUri(Options.DatabaseName);
return Client.CreateDocumentCollectionIfNotExistsAsync(databaseUri, new DocumentCollection { Id = Options.CollectionName });
}, TaskContinuationOptions.OnlyOnRanToCompletion);
logger.Info($"Creating document collection : {t.Result.Resource.Id}");
Uri databaseUri = UriFactory.CreateDatabaseUri(t.Result.Resource.Id);
return Client.CreateDocumentCollectionIfNotExistsAsync(databaseUri, new DocumentCollection { Id = Options.CollectionName });
}, TaskContinuationOptions.OnlyOnRanToCompletion).Unwrap();

// create stored procedures
Task continueTask = collectionTask.ContinueWith(t =>
{
CollectionUri = UriFactory.CreateDocumentCollectionUri(Options.DatabaseName, Options.CollectionName);
CollectionUri = UriFactory.CreateDocumentCollectionUri(Options.DatabaseName, t.Result.Resource.Id);
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
string[] storedProcedureFiles = assembly.GetManifestResourceNames().Where(n => n.EndsWith(".js")).ToArray();
foreach (string storedProcedureFile in storedProcedureFiles)
{
logger.Info($"Creating database : {storedProcedureFile}");
logger.Info($"Creating storedprocedure : {storedProcedureFile}");
Stream stream = assembly.GetManifestResourceStream(storedProcedureFile);
using (MemoryStream memoryStream = new MemoryStream())
{
Expand All @@ -161,14 +161,17 @@ private void Initialize()
.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries)
.Last()
};
Client.UpsertStoredProcedureAsync(CollectionUri, sp);
Client.UpsertStoredProcedureAsync(CollectionUri, sp).Wait();
}
stream?.Close();
}
}, TaskContinuationOptions.OnlyOnRanToCompletion);

// wait for 10 seconds, before timeout;
continueTask.Wait(10000);
continueTask.Wait();
if (continueTask.IsFaulted || continueTask.IsCanceled)
{
throw new ApplicationException("Unable to create the stored procedures", databaseTask.Exception);
}
}

private static DocumentDbStorageOptions Transform(string url, string authSecret, string database, string collection, DocumentDbStorageOptions options)
Expand Down
164 changes: 34 additions & 130 deletions Hangfire.AzureDocumentDB/Hangfire.AzureDocumentDB.csproj
Original file line number Diff line number Diff line change
@@ -1,125 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E0AD3801-5504-49A7-80C6-8B4373DDE0E5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Hangfire.Azure.DocumentDb</RootNamespace>
<AssemblyName>Hangfire.Azure.DocumentDb</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<ProductName>Hangfire.AzureDocumentDB</ProductName>
<Title>Hangfire.AzureDocumentDB</Title>
<Company>Hangfire.AzureDocumentDB</Company>
<Authors>Imran Momin</Authors>
<PackageLicenseUrl>https://github.com/imranmomin/Hangfire.AzureDocumentDB/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/imranmomin/Hangfire.AzureDocumentDB</PackageProjectUrl>
<Copyright>Copyright 2018</Copyright>
<PackageTags>Hangfire Azure DocumentDB</PackageTags>
<Description>This package adds support to Microsoft Azure DocumentDB for Hangfire</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageVersion>1.0.1</PackageVersion>
<Version>2.0.0</Version>
<FileVersion>2.0.0.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Hangfire.Azure.DocumentDb.xml</DocumentationFile>
<RunCodeAnalysis>true</RunCodeAnalysis>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>NETCORE;NETSTANDARD;NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Hangfire.Azure.DocumentDb.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
<DefineConstants>NET461;NETFULL</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="Hangfire.Core, Version=1.6.14.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Hangfire.Core.1.6.14\lib\net45\Hangfire.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.15.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.15.0\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<PackageReference Include="Hangfire.Core" Version="1.6.17" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DocumentDbConnection.cs" />
<Compile Include="DocumentDbDistributedLock.cs" />
<Compile Include="DocumentDbRetryException.cs" />
<Compile Include="DocumentDbDistributedLockException.cs" />
<Compile Include="DocumentDbMonitoringApi.cs" />
<Compile Include="DocumentDbStorage.cs" />
<Compile Include="DocumentDbStorageExtensions.cs" />
<Compile Include="DocumentDbStorageOptions.cs" />
<Compile Include="DocumentDbWriteOnlyTransaction.cs" />
<Compile Include="CountersAggregator.cs" />
<Compile Include="Entities\Counter.cs" />
<Compile Include="Entities\DocumentBase.cs" />
<Compile Include="Entities\Hash.cs" />
<Compile Include="Entities\Job.cs" />
<Compile Include="Entities\List.cs" />
<Compile Include="Entities\Lock.cs" />
<Compile Include="Entities\Parameter.cs" />
<Compile Include="Entities\Queue.cs" />
<Compile Include="Entities\Server.cs" />
<Compile Include="Entities\Set.cs" />
<Compile Include="Entities\State.cs" />
<Compile Include="ExpirationManager.cs" />
<Compile Include="Helper\AzureDocumentDBHelper.cs" />
<Compile Include="Helper\TimeHelper.cs" />
<Compile Include="Json\DocumentContractResolver.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Queue\Entities\FetchedJob.cs" />
<Compile Include="Queue\Interface\IPersistentJobQueue.cs" />
<Compile Include="Queue\Interface\IPersistentJobQueueMonitoringApi.cs" />
<Compile Include="Queue\Interface\IPersistentJobQueueProvider.cs" />
<Compile Include="Queue\JobQueue.cs" />
<Compile Include="Queue\JobQueueMonitoringApi.cs" />
<Compile Include="Queue\JobQueueProvider.cs" />
<Compile Include="Queue\PersistentJobQueueProviderCollection.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="StoredProcedure\deleteDocumentIfExists.js" />
Expand All @@ -143,19 +53,13 @@
<EmbeddedResource Include="StoredProcedure\removeServer.js" />
<EmbeddedResource Include="StoredProcedure\setJobParameter.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use 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('..\packages\Microsoft.Azure.DocumentDB.1.15.0\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.15.0\build\Microsoft.Azure.DocumentDB.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.15.0\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.15.0\build\Microsoft.Azure.DocumentDB.targets')" />
<!-- 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>
-->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="1.9.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.Azure.DocumentDB" Version="1.21.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
35 changes: 0 additions & 35 deletions Hangfire.AzureDocumentDB/Properties/AssemblyInfo.cs

This file was deleted.

63 changes: 0 additions & 63 deletions Hangfire.AzureDocumentDB/Properties/Resources.Designer.cs

This file was deleted.

Loading

0 comments on commit ddab224

Please sign in to comment.