Skip to content

Commit

Permalink
Integrated pull request from rposener for SQL storage provider for We…
Browse files Browse the repository at this point in the history
…bHook registrations!
  • Loading branch information
rposener authored and Henrik Frystyk Nielsen committed Oct 31, 2015
1 parent 73f0c0d commit 7464765
Show file tree
Hide file tree
Showing 27 changed files with 1,597 additions and 0 deletions.
1 change: 1 addition & 0 deletions CustomDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Word>salesforce</Word>
<Word>kudu</Word>
<Word>trello</Word>
<Word>ver</Word>
<Word>你好</Word>
</Recognized>
<Deprecated/>
Expand Down
1 change: 1 addition & 0 deletions Settings.StyleCop
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Value>\.generated\.cs$</Value>
<Value>\.g\.i\.cs$</Value>
<Value>TemporaryGeneratedFile_.*\.cs$</Value>
<Value>\.Designer\.cs$</Value>
</CollectionProperty>
</ParserSettings>
</Parser>
Expand Down
18 changes: 18 additions & 0 deletions WebHooks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureReceivers", "samples\A
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InstagramReceiver", "samples\InstagramReceiver\InstagramReceiver.csproj", "{3F9F62DD-C365-4FEC-A10E-5314D111EBF5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.WebHooks.Custom.SqlStorage", "src\Microsoft.AspNet.WebHooks.Custom.SqlStorage\Microsoft.AspNet.WebHooks.Custom.SqlStorage.csproj", "{EAC99E25-F698-41B2-8671-740D642781AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.WebHooks.Custom.SqlStorage.Test", "test\Microsoft.AspNet.WebHooks.Custom.SqlStorage.Test\Microsoft.AspNet.WebHooks.Custom.SqlStorage.Test.csproj", "{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CodeAnalysis|Any CPU = CodeAnalysis|Any CPU
Expand Down Expand Up @@ -379,6 +383,18 @@ Global
{3F9F62DD-C365-4FEC-A10E-5314D111EBF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F9F62DD-C365-4FEC-A10E-5314D111EBF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F9F62DD-C365-4FEC-A10E-5314D111EBF5}.Release|Any CPU.Build.0 = Release|Any CPU
{EAC99E25-F698-41B2-8671-740D642781AB}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
{EAC99E25-F698-41B2-8671-740D642781AB}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
{EAC99E25-F698-41B2-8671-740D642781AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EAC99E25-F698-41B2-8671-740D642781AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAC99E25-F698-41B2-8671-740D642781AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EAC99E25-F698-41B2-8671-740D642781AB}.Release|Any CPU.Build.0 = Release|Any CPU
{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F}.CodeAnalysis|Any CPU.ActiveCfg = CodeAnalysis|Any CPU
{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F}.CodeAnalysis|Any CPU.Build.0 = CodeAnalysis|Any CPU
{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -428,6 +444,8 @@ Global
{D6287838-8329-4349-90F1-D9CBF49EDCEA} = {9575CB90-BC4B-43BB-8AEA-82C53FDA4187}
{5DFA6EF9-2417-47AF-B8BB-424E420D9464} = {E957C8D9-B4A0-488B-838F-BAB4DE080A76}
{3F9F62DD-C365-4FEC-A10E-5314D111EBF5} = {E957C8D9-B4A0-488B-838F-BAB4DE080A76}
{EAC99E25-F698-41B2-8671-740D642781AB} = {929F44D0-A040-4DC3-A22F-4C5829C05D44}
{CCE7ADB5-7335-4F7D-A34D-0B7CA1D3141F} = {9575CB90-BC4B-43BB-8AEA-82C53FDA4187}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8;packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45
Expand Down
25 changes: 25 additions & 0 deletions src/Microsoft.AspNet.WebHooks.Custom.SqlStorage/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.ComponentModel;
using System.Data.Entity;
using Microsoft.AspNet.DataProtection;
using Microsoft.AspNet.WebHooks;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Services;
using Microsoft.AspNet.WebHooks.Storage;
using Microsoft.Framework.DependencyInjection;

namespace System.Web.Http
{
/// <summary>
/// Extension methods for <see cref="HttpConfiguration"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class HttpConfigurationExtensions
{
private const string ApplicationName = "Microsoft.AspNet.WebHooks";
private const string Purpose = "WebHookPersistence";
private const string DataProtectionKeysFolderName = "DataProtection-Keys";

/// <summary>
/// Configures a Microsoft SQL Server Storage implementation of <see cref="IWebHookStore"/>
/// which provides a persistent store for registered WebHooks used by the custom WebHooks module.
/// </summary>
/// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config)
{
if (config == null)
{
throw new ArgumentNullException("config");
}

WebHooksConfig.Initialize(config);

ILogger logger = config.DependencyResolver.GetLogger();
SettingsDictionary settings = config.DependencyResolver.GetSettings();

// We explicitly set the DB initializer to null to avoid that an existing DB is initialized wrongly.
Database.SetInitializer<WebHookContext>(null);

IDataProtectionProvider provider = GetDataProtectionProvider();
IDataProtector protector = provider.CreateProtector(Purpose);

IWebHookStore store = new SqlWebHookStore(settings, protector, logger);
CustomServices.SetStore(store);
}

/// <summary>
/// This follows the same initialization that is provided when <see cref="IDataProtectionProvider"/>
/// is initialized within ASP.NET 5.0 Dependency Injection.
/// </summary>
/// <returns>A fully initialized <see cref="IDataProtectionProvider"/>.</returns>
internal static IDataProtectionProvider GetDataProtectionProvider()
{
ServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddDataProtection();
IServiceProvider services = serviceCollection.BuildServiceProvider();
return services.GetDataProtectionProvider();
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),WebHooks.sln))\tools\WebHooks.settings.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EAC99E25-F698-41B2-8671-740D642781AB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AspNet.WebHooks</RootNamespace>
<AssemblyName>Microsoft.AspNet.WebHooks.Custom.SqlStorage</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<RunCodeAnalysis>$(CodeAnalysis)</RunCodeAnalysis>
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
<CodeAnalysisRuleSet>..\..\FxCop.ruleset</CodeAnalysisRuleSet>
<DefineConstants>$(DefineConstants);ASPNETWEBHOOKS</DefineConstants>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNet.Cryptography.Internal, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.Cryptography.Internal.1.0.0-beta6\lib\net451\Microsoft.AspNet.Cryptography.Internal.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNet.DataProtection, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.DataProtection.1.0.0-beta6\lib\net451\Microsoft.AspNet.DataProtection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNet.DataProtection.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.DataProtection.Abstractions.1.0.0-beta6\lib\net451\Microsoft.AspNet.DataProtection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Framework.Configuration, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Framework.Configuration.1.0.0-beta6\lib\net45\Microsoft.Framework.Configuration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Framework.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Framework.Configuration.Abstractions.1.0.0-beta6\lib\net45\Microsoft.Framework.Configuration.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Framework.Configuration.Binder, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Framework.Configuration.Binder.1.0.0-beta6\lib\net45\Microsoft.Framework.Configuration.Binder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Framework.DependencyInjection, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Framework.DependencyInjection.1.0.0-beta5\lib\net45\Microsoft.Framework.DependencyInjection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Framework.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Framework.DependencyInjection.Abstractions.1.0.0-beta6\lib\net45\Microsoft.Framework.DependencyInjection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Framework.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Framework.Logging.Abstractions.1.0.0-beta6\lib\net45\Microsoft.Framework.Logging.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Framework.OptionsModel, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Framework.OptionsModel.1.0.0-beta6\lib\net45\Microsoft.Framework.OptionsModel.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.2\lib\net45\System.Web.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<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="..\Common\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Migrations\201510210452218_WebHooksInitialDb.cs" />
<Compile Include="Migrations\201510210452218_WebHooksInitialDb.Designer.cs">
<DependentUpon>201510210452218_WebHooksInitialDb.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\SqlStorageResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>SqlStorageResources.resx</DependentUpon>
</Compile>
<Compile Include="Storage\Registration.cs" />
<Compile Include="Storage\WebHookContext.cs" />
<Compile Include="Extensions\HttpConfigurationExtensions.cs" />
<Compile Include="WebHooks\SqlWebHookStore.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Migrations\201510210452218_WebHooksInitialDb.resx">
<DependentUpon>201510210452218_WebHooksInitialDb.cs</DependentUpon>
<ExcludeFromStyleCop>True</ExcludeFromStyleCop>
</EmbeddedResource>
<EmbeddedResource Include="Properties\SqlStorageResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>SqlStorageResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="Microsoft.AspNet.WebHooks.Custom.SqlStorage.nuspec" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNet.WebHooks.Common\Microsoft.AspNet.WebHooks.Common.csproj">
<Project>{f7dd0935-6320-4efc-9464-d5a2d2b8c2f7}</Project>
<Name>Microsoft.AspNet.WebHooks.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.AspNet.WebHooks.Custom\Microsoft.AspNet.WebHooks.Custom.csproj">
<Project>{d4d210c6-3283-4d1d-806e-8717d8f51179}</Project>
<Name>Microsoft.AspNet.WebHooks.Custom</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\..\CustomDictionary.xml">
<Link>CustomDictionary.xml</Link>
</CodeAnalysisDictionary>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.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('..\..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.4.7.49.1\build\StyleCop.MSBuild.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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$symversion$</version>
<title>Microsoft ASP.NET Custom WebHooks SQL Module</title>
<authors>Microsoft</authors>
<owners>Microsoft, aspnet</owners>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_ENU.htm</licenseUrl>
<projectUrl>http://www.asp.net/</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>
This package provides support for persisting your custom WebHooks registrations in a SQL database.
</description>
<releaseNotes></releaseNotes>
<copyright>&#169; Microsoft Corporation. All rights reserved</copyright>
<tags>Microsoft AspNet WebApi AspNetWebApi WebHooks</tags>
</metadata>
</package>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7464765

Please sign in to comment.