Quick fix: Add .gitattributes and normalize line endings

- followed steps from https://stackoverflow.com/a/1511273
- mostly affected the Custom senders and their tests
This commit is contained in:
Doug Bunting 2017-11-09 08:04:46 -08:00
Родитель 5f62336e30
Коммит be8571953a
24 изменённых файлов: 2471 добавлений и 2467 удалений

4
.gitattributes поставляемый Normal file
Просмотреть файл

@ -0,0 +1,4 @@
* text=auto
*.cs diff=csharp
*.sh eol=lf
*.sln eol=crlf

Просмотреть файл

@ -1,299 +1,299 @@
// 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.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Description;
using Microsoft.AspNet.WebHooks.Filters;
using Microsoft.AspNet.WebHooks.Properties;
using Microsoft.AspNet.WebHooks.Routes;
namespace Microsoft.AspNet.WebHooks.Controllers
{
/// <summary>
/// The <see cref="WebHookRegistrationsController"/> allows the caller to create, modify, and manage WebHooks
/// through a REST-style interface.
/// </summary>
[Authorize]
[RoutePrefix("api/webhooks/registrations")]
public class WebHookRegistrationsController : ApiController
{
private IWebHookRegistrationsManager _registrationsManager;
/// <summary>
/// Gets all registered WebHooks for a given user.
/// </summary>
/// <returns>A collection containing the registered <see cref="WebHook"/> instances for a given user.</returns>
[Route("")]
public async Task<IEnumerable<WebHook>> Get()
{
try
{
IEnumerable<WebHook> webHooks = await _registrationsManager.GetWebHooksAsync(User, RemovePrivateFilters);
return webHooks;
}
catch (Exception ex)
{
Configuration.DependencyResolver.GetLogger().Error(ex.Message, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message, ex);
throw new HttpResponseException(error);
}
}
/// <summary>
/// Looks up a registered WebHook with the given <paramref name="id"/> for a given user.
/// </summary>
/// <returns>The registered <see cref="WebHook"/> instance for a given user.</returns>
[Route("{id}", Name = WebHookRouteNames.RegistrationLookupAction)]
[HttpGet]
[ResponseType(typeof(WebHook))]
public async Task<IHttpActionResult> Lookup(string id)
{
try
{
WebHook webHook = await _registrationsManager.LookupWebHookAsync(User, id, RemovePrivateFilters);
if (webHook != null)
{
return Ok(webHook);
}
return NotFound();
}
catch (Exception ex)
{
Configuration.DependencyResolver.GetLogger().Error(ex.Message, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message, ex);
throw new HttpResponseException(error);
}
}
/// <summary>
/// Registers a new WebHook for a given user.
/// </summary>
/// <param name="webHook">The <see cref="WebHook"/> to create.</param>
[Route("")]
[ValidateModel]
[ResponseType(typeof(WebHook))]
public async Task<IHttpActionResult> Post(WebHook webHook)
{
if (webHook == null)
{
return BadRequest();
}
try
{
// Validate the provided WebHook ID (or force one to be created on server side)
IWebHookIdValidator idValidator = Configuration.DependencyResolver.GetIdValidator();
await idValidator.ValidateIdAsync(Request, webHook);
// Validate other parts of WebHook
await _registrationsManager.VerifySecretAsync(webHook);
await _registrationsManager.VerifyFiltersAsync(webHook);
await _registrationsManager.VerifyAddressAsync(webHook);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Info(msg);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg, ex);
return ResponseMessage(error);
}
try
{
// Add WebHook for this user.
StoreResult result = await _registrationsManager.AddWebHookAsync(User, webHook, AddPrivateFilters);
if (result == StoreResult.Success)
{
return CreatedAtRoute(WebHookRouteNames.RegistrationLookupAction, new { id = webHook.Id }, webHook);
}
return CreateHttpResult(result);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <summary>
/// Updates an existing WebHook registration.
/// </summary>
/// <param name="id">The WebHook ID.</param>
/// <param name="webHook">The new <see cref="WebHook"/> to use.</param>
[Route("{id}")]
[ValidateModel]
public async Task<IHttpActionResult> Put(string id, WebHook webHook)
{
if (webHook == null)
{
return BadRequest();
}
if (!string.Equals(id, webHook.Id, StringComparison.OrdinalIgnoreCase))
{
return BadRequest();
}
try
{
// Validate parts of WebHook
await _registrationsManager.VerifySecretAsync(webHook);
await _registrationsManager.VerifyFiltersAsync(webHook);
await _registrationsManager.VerifyAddressAsync(webHook);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Info(msg);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg, ex);
return ResponseMessage(error);
}
try
{
// Update WebHook for this user
StoreResult result = await _registrationsManager.UpdateWebHookAsync(User, webHook, AddPrivateFilters);
return CreateHttpResult(result);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_UpdateFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <summary>
/// Deletes an existing WebHook registration.
/// </summary>
/// <param name="id">The WebHook ID.</param>
[Route("{id}")]
public async Task<IHttpActionResult> Delete(string id)
{
try
{
StoreResult result = await _registrationsManager.DeleteWebHookAsync(User, id);
return CreateHttpResult(result);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_DeleteFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <summary>
/// Deletes all existing WebHook registrations.
/// </summary>
[Route("")]
public async Task<IHttpActionResult> DeleteAll()
{
try
{
await _registrationsManager.DeleteAllWebHooksAsync(User);
return Ok();
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_DeleteAllFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <inheritdoc />
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
_registrationsManager = Configuration.DependencyResolver.GetRegistrationsManager();
}
/// <summary>
/// Removes all private (server side) filters from the given <paramref name="webHook"/>.
/// </summary>
protected virtual Task RemovePrivateFilters(string user, WebHook webHook)
{
if (webHook == null)
{
throw new ArgumentNullException(nameof(webHook));
}
var filters = webHook.Filters.Where(f => f.StartsWith(WebHookRegistrar.PrivateFilterPrefix, StringComparison.OrdinalIgnoreCase)).ToArray();
foreach (string filter in filters)
{
webHook.Filters.Remove(filter);
}
return Task.FromResult(true);
}
/// <summary>
/// Executes all <see cref="IWebHookRegistrar"/> instances for server side manipulation, inspection, or
/// rejection of registrations. This can for example be used to add server side only filters that
/// are not governed by <see cref="IWebHookFilterManager"/>.
/// </summary>
protected virtual async Task AddPrivateFilters(string user, WebHook webHook)
{
IEnumerable<IWebHookRegistrar> registrars = Configuration.DependencyResolver.GetRegistrars();
foreach (IWebHookRegistrar registrar in registrars)
{
try
{
await registrar.RegisterAsync(Request, webHook);
}
catch (HttpResponseException rex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrarStatusCode, registrar.GetType().Name, typeof(IWebHookRegistrar).Name, rex.Response.StatusCode);
Configuration.DependencyResolver.GetLogger().Info(msg);
throw;
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrarException, registrar.GetType().Name, typeof(IWebHookRegistrar).Name, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg);
throw new HttpResponseException(response);
}
}
}
/// <summary>
/// Creates an <see cref="IHttpActionResult"/> based on the provided <paramref name="result"/>.
/// </summary>
/// <param name="result">The result to use when creating the <see cref="IHttpActionResult"/>.</param>
/// <returns>An initialized <see cref="IHttpActionResult"/>.</returns>
private IHttpActionResult CreateHttpResult(StoreResult result)
{
switch (result)
{
case StoreResult.Success:
return Ok();
case StoreResult.Conflict:
return Conflict();
case StoreResult.NotFound:
return NotFound();
case StoreResult.OperationError:
return BadRequest();
default:
return InternalServerError();
}
}
}
}
// 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.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Description;
using Microsoft.AspNet.WebHooks.Filters;
using Microsoft.AspNet.WebHooks.Properties;
using Microsoft.AspNet.WebHooks.Routes;
namespace Microsoft.AspNet.WebHooks.Controllers
{
/// <summary>
/// The <see cref="WebHookRegistrationsController"/> allows the caller to create, modify, and manage WebHooks
/// through a REST-style interface.
/// </summary>
[Authorize]
[RoutePrefix("api/webhooks/registrations")]
public class WebHookRegistrationsController : ApiController
{
private IWebHookRegistrationsManager _registrationsManager;
/// <summary>
/// Gets all registered WebHooks for a given user.
/// </summary>
/// <returns>A collection containing the registered <see cref="WebHook"/> instances for a given user.</returns>
[Route("")]
public async Task<IEnumerable<WebHook>> Get()
{
try
{
IEnumerable<WebHook> webHooks = await _registrationsManager.GetWebHooksAsync(User, RemovePrivateFilters);
return webHooks;
}
catch (Exception ex)
{
Configuration.DependencyResolver.GetLogger().Error(ex.Message, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message, ex);
throw new HttpResponseException(error);
}
}
/// <summary>
/// Looks up a registered WebHook with the given <paramref name="id"/> for a given user.
/// </summary>
/// <returns>The registered <see cref="WebHook"/> instance for a given user.</returns>
[Route("{id}", Name = WebHookRouteNames.RegistrationLookupAction)]
[HttpGet]
[ResponseType(typeof(WebHook))]
public async Task<IHttpActionResult> Lookup(string id)
{
try
{
WebHook webHook = await _registrationsManager.LookupWebHookAsync(User, id, RemovePrivateFilters);
if (webHook != null)
{
return Ok(webHook);
}
return NotFound();
}
catch (Exception ex)
{
Configuration.DependencyResolver.GetLogger().Error(ex.Message, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message, ex);
throw new HttpResponseException(error);
}
}
/// <summary>
/// Registers a new WebHook for a given user.
/// </summary>
/// <param name="webHook">The <see cref="WebHook"/> to create.</param>
[Route("")]
[ValidateModel]
[ResponseType(typeof(WebHook))]
public async Task<IHttpActionResult> Post(WebHook webHook)
{
if (webHook == null)
{
return BadRequest();
}
try
{
// Validate the provided WebHook ID (or force one to be created on server side)
IWebHookIdValidator idValidator = Configuration.DependencyResolver.GetIdValidator();
await idValidator.ValidateIdAsync(Request, webHook);
// Validate other parts of WebHook
await _registrationsManager.VerifySecretAsync(webHook);
await _registrationsManager.VerifyFiltersAsync(webHook);
await _registrationsManager.VerifyAddressAsync(webHook);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Info(msg);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg, ex);
return ResponseMessage(error);
}
try
{
// Add WebHook for this user.
StoreResult result = await _registrationsManager.AddWebHookAsync(User, webHook, AddPrivateFilters);
if (result == StoreResult.Success)
{
return CreatedAtRoute(WebHookRouteNames.RegistrationLookupAction, new { id = webHook.Id }, webHook);
}
return CreateHttpResult(result);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <summary>
/// Updates an existing WebHook registration.
/// </summary>
/// <param name="id">The WebHook ID.</param>
/// <param name="webHook">The new <see cref="WebHook"/> to use.</param>
[Route("{id}")]
[ValidateModel]
public async Task<IHttpActionResult> Put(string id, WebHook webHook)
{
if (webHook == null)
{
return BadRequest();
}
if (!string.Equals(id, webHook.Id, StringComparison.OrdinalIgnoreCase))
{
return BadRequest();
}
try
{
// Validate parts of WebHook
await _registrationsManager.VerifySecretAsync(webHook);
await _registrationsManager.VerifyFiltersAsync(webHook);
await _registrationsManager.VerifyAddressAsync(webHook);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrationFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Info(msg);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg, ex);
return ResponseMessage(error);
}
try
{
// Update WebHook for this user
StoreResult result = await _registrationsManager.UpdateWebHookAsync(User, webHook, AddPrivateFilters);
return CreateHttpResult(result);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_UpdateFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <summary>
/// Deletes an existing WebHook registration.
/// </summary>
/// <param name="id">The WebHook ID.</param>
[Route("{id}")]
public async Task<IHttpActionResult> Delete(string id)
{
try
{
StoreResult result = await _registrationsManager.DeleteWebHookAsync(User, id);
return CreateHttpResult(result);
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_DeleteFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <summary>
/// Deletes all existing WebHook registrations.
/// </summary>
[Route("")]
public async Task<IHttpActionResult> DeleteAll()
{
try
{
await _registrationsManager.DeleteAllWebHooksAsync(User);
return Ok();
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_DeleteAllFailure, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage error = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, msg, ex);
return ResponseMessage(error);
}
}
/// <inheritdoc />
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
_registrationsManager = Configuration.DependencyResolver.GetRegistrationsManager();
}
/// <summary>
/// Removes all private (server side) filters from the given <paramref name="webHook"/>.
/// </summary>
protected virtual Task RemovePrivateFilters(string user, WebHook webHook)
{
if (webHook == null)
{
throw new ArgumentNullException(nameof(webHook));
}
var filters = webHook.Filters.Where(f => f.StartsWith(WebHookRegistrar.PrivateFilterPrefix, StringComparison.OrdinalIgnoreCase)).ToArray();
foreach (string filter in filters)
{
webHook.Filters.Remove(filter);
}
return Task.FromResult(true);
}
/// <summary>
/// Executes all <see cref="IWebHookRegistrar"/> instances for server side manipulation, inspection, or
/// rejection of registrations. This can for example be used to add server side only filters that
/// are not governed by <see cref="IWebHookFilterManager"/>.
/// </summary>
protected virtual async Task AddPrivateFilters(string user, WebHook webHook)
{
IEnumerable<IWebHookRegistrar> registrars = Configuration.DependencyResolver.GetRegistrars();
foreach (IWebHookRegistrar registrar in registrars)
{
try
{
await registrar.RegisterAsync(Request, webHook);
}
catch (HttpResponseException rex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrarStatusCode, registrar.GetType().Name, typeof(IWebHookRegistrar).Name, rex.Response.StatusCode);
Configuration.DependencyResolver.GetLogger().Info(msg);
throw;
}
catch (Exception ex)
{
string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_RegistrarException, registrar.GetType().Name, typeof(IWebHookRegistrar).Name, ex.Message);
Configuration.DependencyResolver.GetLogger().Error(msg, ex);
HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg);
throw new HttpResponseException(response);
}
}
}
/// <summary>
/// Creates an <see cref="IHttpActionResult"/> based on the provided <paramref name="result"/>.
/// </summary>
/// <param name="result">The result to use when creating the <see cref="IHttpActionResult"/>.</param>
/// <returns>An initialized <see cref="IHttpActionResult"/>.</returns>
private IHttpActionResult CreateHttpResult(StoreResult result)
{
switch (result)
{
case StoreResult.Success:
return Ok();
case StoreResult.Conflict:
return Conflict();
case StoreResult.NotFound:
return NotFound();
case StoreResult.OperationError:
return BadRequest();
default:
return InternalServerError();
}
}
}
}

Просмотреть файл

@ -1,46 +1,46 @@
// 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.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Http.Dependencies;
using Microsoft.AspNet.WebHooks.Services;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Extension methods for <see cref="IDependencyScope"/> facilitating getting the services used by custom WebHooks APIs.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class DependencyScopeExtensions
{
/// <summary>
/// Gets an <see cref="IWebHookIdValidator"/> implementation registered with the Dependency Injection engine
/// or a default implementation if none are registered.
/// </summary>
/// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
/// <returns>The registered <see cref="IWebHookIdValidator"/> instance or a default implementation if none are registered.</returns>
public static IWebHookIdValidator GetIdValidator(this IDependencyScope services)
{
IWebHookIdValidator validator = services.GetService<IWebHookIdValidator>();
return validator ?? CustomApiServices.GetIdValidator();
}
/// <summary>
/// Gets the set of <see cref="IWebHookRegistrar"/> instances registered with the Dependency Injection engine
/// or an empty collection if none are registered.
/// </summary>
/// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
/// <returns>An <see cref="IEnumerable{T}"/> containing the registered instances.</returns>
public static IEnumerable<IWebHookRegistrar> GetRegistrars(this IDependencyScope services)
{
IEnumerable<IWebHookRegistrar> registrar = services.GetServices<IWebHookRegistrar>();
if (registrar == null || !registrar.Any())
{
registrar = CustomApiServices.GetRegistrars();
}
return registrar;
}
}
}
// 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.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Http.Dependencies;
using Microsoft.AspNet.WebHooks.Services;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Extension methods for <see cref="IDependencyScope"/> facilitating getting the services used by custom WebHooks APIs.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class DependencyScopeExtensions
{
/// <summary>
/// Gets an <see cref="IWebHookIdValidator"/> implementation registered with the Dependency Injection engine
/// or a default implementation if none are registered.
/// </summary>
/// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
/// <returns>The registered <see cref="IWebHookIdValidator"/> instance or a default implementation if none are registered.</returns>
public static IWebHookIdValidator GetIdValidator(this IDependencyScope services)
{
IWebHookIdValidator validator = services.GetService<IWebHookIdValidator>();
return validator ?? CustomApiServices.GetIdValidator();
}
/// <summary>
/// Gets the set of <see cref="IWebHookRegistrar"/> instances registered with the Dependency Injection engine
/// or an empty collection if none are registered.
/// </summary>
/// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
/// <returns>An <see cref="IEnumerable{T}"/> containing the registered instances.</returns>
public static IEnumerable<IWebHookRegistrar> GetRegistrars(this IDependencyScope services)
{
IEnumerable<IWebHookRegistrar> registrar = services.GetServices<IWebHookRegistrar>();
if (registrar == null || !registrar.Any())
{
registrar = CustomApiServices.GetRegistrars();
}
return registrar;
}
}
}

Просмотреть файл

@ -1,109 +1,109 @@
<?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>{F0EE25B8-D851-40DA-AB2A-E0BACE9C1E5D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AspNet.WebHooks</RootNamespace>
<AssemblyName>Microsoft.AspNet.WebHooks.Custom.Api</AssemblyName>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<RunCodeAnalysis>$(CodeAnalysis)</RunCodeAnalysis>
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
<CodeAnalysisRuleSet>..\..\FxCop.ruleset</CodeAnalysisRuleSet>
<DefineConstants>$(DefineConstants);ASPNETWEBHOOKS</DefineConstants>
<SignAssembly>true</SignAssembly>
<NuGetPackageImportStamp>baf64cbe</NuGetPackageImportStamp>
</PropertyGroup>
<ItemGroup>
<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.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="Controllers\WebHookFiltersController.cs" />
<Compile Include="Controllers\WebHookRegistrationsController.cs" />
<Compile Include="Extensions\DependencyScopeExtensions.cs" />
<Compile Include="Extensions\HttpConfigurationExtensions.cs" />
<Compile Include="Filters\ValidateModelAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\CustomApiResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CustomApiResources.resx</DependentUpon>
</Compile>
<Compile Include="Routes\WebHookRouteNames.cs" />
<Compile Include="Services\CustomApiServices.cs" />
<Compile Include="WebHooks\DefaultWebHookIdValidator.cs" />
<Compile Include="WebHooks\IWebHookIdValidator.cs" />
<Compile Include="WebHooks\WebHookRegistrar.cs" />
<Compile Include="WebHooks\IWebHookRegistrar.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\CustomApiResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CustomApiResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="Microsoft.AspNet.WebHooks.Custom.Api.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.5.0.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\packages\StyleCop.MSBuild.5.0.0\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.5.0.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.5.0.0\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>
-->
<?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>{F0EE25B8-D851-40DA-AB2A-E0BACE9C1E5D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AspNet.WebHooks</RootNamespace>
<AssemblyName>Microsoft.AspNet.WebHooks.Custom.Api</AssemblyName>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<RunCodeAnalysis>$(CodeAnalysis)</RunCodeAnalysis>
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
<CodeAnalysisRuleSet>..\..\FxCop.ruleset</CodeAnalysisRuleSet>
<DefineConstants>$(DefineConstants);ASPNETWEBHOOKS</DefineConstants>
<SignAssembly>true</SignAssembly>
<NuGetPackageImportStamp>baf64cbe</NuGetPackageImportStamp>
</PropertyGroup>
<ItemGroup>
<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.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="Controllers\WebHookFiltersController.cs" />
<Compile Include="Controllers\WebHookRegistrationsController.cs" />
<Compile Include="Extensions\DependencyScopeExtensions.cs" />
<Compile Include="Extensions\HttpConfigurationExtensions.cs" />
<Compile Include="Filters\ValidateModelAttribute.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\CustomApiResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CustomApiResources.resx</DependentUpon>
</Compile>
<Compile Include="Routes\WebHookRouteNames.cs" />
<Compile Include="Services\CustomApiServices.cs" />
<Compile Include="WebHooks\DefaultWebHookIdValidator.cs" />
<Compile Include="WebHooks\IWebHookIdValidator.cs" />
<Compile Include="WebHooks\WebHookRegistrar.cs" />
<Compile Include="WebHooks\IWebHookRegistrar.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\CustomApiResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CustomApiResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="Microsoft.AspNet.WebHooks.Custom.Api.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.5.0.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\packages\StyleCop.MSBuild.5.0.0\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.5.0.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.5.0.0\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>

Просмотреть файл

@ -1,126 +1,126 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.AspNet.WebHooks.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class CustomApiResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal CustomApiResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.WebHooks.Properties.CustomApiResources", typeof(CustomApiResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to The WebHook test launcher is not enabled. To enable the test launcher for testing purposes, please set the &apos;{0}&apos; application setting to &apos;{1}&apos;. The test launcher should not be enabled in production environments..
/// </summary>
internal static string LaunchController_NotEnabled {
get {
return ResourceManager.GetString("LaunchController_NotEnabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not delete WebHooks due to error: {0}.
/// </summary>
internal static string RegistrationController_DeleteAllFailure {
get {
return ResourceManager.GetString("RegistrationController_DeleteAllFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not delete WebHook due to error: {0}.
/// </summary>
internal static string RegistrationController_DeleteFailure {
get {
return ResourceManager.GetString("RegistrationController_DeleteFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &apos;{0}&apos; implementation of &apos;{1}&apos; caused an exception: {2}.
/// </summary>
internal static string RegistrationController_RegistrarException {
get {
return ResourceManager.GetString("RegistrationController_RegistrarException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &apos;{0}&apos; implementation of &apos;{1}&apos; resulted in an HTTP response with status code {2}.
/// </summary>
internal static string RegistrationController_RegistrarStatusCode {
get {
return ResourceManager.GetString("RegistrationController_RegistrarStatusCode", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not register WebHook due to error: {0}.
/// </summary>
internal static string RegistrationController_RegistrationFailure {
get {
return ResourceManager.GetString("RegistrationController_RegistrationFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not update WebHook due to error: {0}.
/// </summary>
internal static string RegistrationController_UpdateFailure {
get {
return ResourceManager.GetString("RegistrationController_UpdateFailure", resourceCulture);
}
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.AspNet.WebHooks.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class CustomApiResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal CustomApiResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.WebHooks.Properties.CustomApiResources", typeof(CustomApiResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to The WebHook test launcher is not enabled. To enable the test launcher for testing purposes, please set the &apos;{0}&apos; application setting to &apos;{1}&apos;. The test launcher should not be enabled in production environments..
/// </summary>
internal static string LaunchController_NotEnabled {
get {
return ResourceManager.GetString("LaunchController_NotEnabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not delete WebHooks due to error: {0}.
/// </summary>
internal static string RegistrationController_DeleteAllFailure {
get {
return ResourceManager.GetString("RegistrationController_DeleteAllFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not delete WebHook due to error: {0}.
/// </summary>
internal static string RegistrationController_DeleteFailure {
get {
return ResourceManager.GetString("RegistrationController_DeleteFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &apos;{0}&apos; implementation of &apos;{1}&apos; caused an exception: {2}.
/// </summary>
internal static string RegistrationController_RegistrarException {
get {
return ResourceManager.GetString("RegistrationController_RegistrarException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &apos;{0}&apos; implementation of &apos;{1}&apos; resulted in an HTTP response with status code {2}.
/// </summary>
internal static string RegistrationController_RegistrarStatusCode {
get {
return ResourceManager.GetString("RegistrationController_RegistrarStatusCode", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not register WebHook due to error: {0}.
/// </summary>
internal static string RegistrationController_RegistrationFailure {
get {
return ResourceManager.GetString("RegistrationController_RegistrationFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Could not update WebHook due to error: {0}.
/// </summary>
internal static string RegistrationController_UpdateFailure {
get {
return ResourceManager.GetString("RegistrationController_UpdateFailure", resourceCulture);
}
}
}
}

Просмотреть файл

@ -1,141 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="LaunchController_NotEnabled" xml:space="preserve">
<value>The WebHook test launcher is not enabled. To enable the test launcher for testing purposes, please set the '{0}' application setting to '{1}'. The test launcher should not be enabled in production environments.</value>
</data>
<data name="RegistrationController_DeleteAllFailure" xml:space="preserve">
<value>Could not delete WebHooks due to error: {0}</value>
</data>
<data name="RegistrationController_DeleteFailure" xml:space="preserve">
<value>Could not delete WebHook due to error: {0}</value>
</data>
<data name="RegistrationController_RegistrarException" xml:space="preserve">
<value>The '{0}' implementation of '{1}' caused an exception: {2}</value>
</data>
<data name="RegistrationController_RegistrarStatusCode" xml:space="preserve">
<value>The '{0}' implementation of '{1}' resulted in an HTTP response with status code {2}</value>
</data>
<data name="RegistrationController_RegistrationFailure" xml:space="preserve">
<value>Could not register WebHook due to error: {0}</value>
</data>
<data name="RegistrationController_UpdateFailure" xml:space="preserve">
<value>Could not update WebHook due to error: {0}</value>
</data>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="LaunchController_NotEnabled" xml:space="preserve">
<value>The WebHook test launcher is not enabled. To enable the test launcher for testing purposes, please set the '{0}' application setting to '{1}'. The test launcher should not be enabled in production environments.</value>
</data>
<data name="RegistrationController_DeleteAllFailure" xml:space="preserve">
<value>Could not delete WebHooks due to error: {0}</value>
</data>
<data name="RegistrationController_DeleteFailure" xml:space="preserve">
<value>Could not delete WebHook due to error: {0}</value>
</data>
<data name="RegistrationController_RegistrarException" xml:space="preserve">
<value>The '{0}' implementation of '{1}' caused an exception: {2}</value>
</data>
<data name="RegistrationController_RegistrarStatusCode" xml:space="preserve">
<value>The '{0}' implementation of '{1}' resulted in an HTTP response with status code {2}</value>
</data>
<data name="RegistrationController_RegistrationFailure" xml:space="preserve">
<value>Could not register WebHook due to error: {0}</value>
</data>
<data name="RegistrationController_UpdateFailure" xml:space="preserve">
<value>Could not update WebHook due to error: {0}</value>
</data>
</root>

Просмотреть файл

@ -1,79 +1,79 @@
// 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.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Utilities;
namespace Microsoft.AspNet.WebHooks.Services
{
/// <summary>
/// Provides singleton instances of custom WebHook API services used by this module.
/// If alternative implementations are provided by a Dependency Injection engine then
/// those instances are used instead.
/// </summary>
public static class CustomApiServices
{
private static IWebHookIdValidator _idValidator;
private static IEnumerable<IWebHookRegistrar> _registrars;
/// <summary>
/// Gets a default <see cref="IWebHookIdValidator"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookIdValidator"/> instance.</returns>
public static IWebHookIdValidator GetIdValidator()
{
if (_idValidator != null)
{
return _idValidator;
}
IWebHookIdValidator instance = new DefaultWebHookIdValidator();
Interlocked.CompareExchange(ref _idValidator, instance, null);
return _idValidator;
}
/// <summary>
/// Sets a default <see cref="IWebHookIdValidator"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <param name="instance">The <see cref="IWebHookIdValidator"/> to use. If <c>null</c> then a default implementation is used.</param>
public static void SetIdValidator(IWebHookIdValidator instance)
{
_idValidator = instance;
}
/// <summary>
/// Gets the set of <see cref="IWebHookRegistrar"/> instances discovered by a default
/// discovery mechanism which is used if none are registered with the Dependency Injection engine.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> containing the discovered instances.</returns>
public static IEnumerable<IWebHookRegistrar> GetRegistrars()
{
if (_registrars != null)
{
return _registrars;
}
IAssembliesResolver assembliesResolver = WebHooksConfig.Config.Services.GetAssembliesResolver();
ICollection<Assembly> assemblies = assembliesResolver.GetAssemblies();
IEnumerable<IWebHookRegistrar> instances = TypeUtilities.GetInstances<IWebHookRegistrar>(assemblies, t => TypeUtilities.IsType<IWebHookRegistrar>(t));
Interlocked.CompareExchange(ref _registrars, instances, null);
return _registrars;
}
/// <summary>
/// For testing purposes
/// </summary>
internal static void Reset()
{
_registrars = null;
_idValidator = null;
}
}
}
// 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.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Utilities;
namespace Microsoft.AspNet.WebHooks.Services
{
/// <summary>
/// Provides singleton instances of custom WebHook API services used by this module.
/// If alternative implementations are provided by a Dependency Injection engine then
/// those instances are used instead.
/// </summary>
public static class CustomApiServices
{
private static IWebHookIdValidator _idValidator;
private static IEnumerable<IWebHookRegistrar> _registrars;
/// <summary>
/// Gets a default <see cref="IWebHookIdValidator"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookIdValidator"/> instance.</returns>
public static IWebHookIdValidator GetIdValidator()
{
if (_idValidator != null)
{
return _idValidator;
}
IWebHookIdValidator instance = new DefaultWebHookIdValidator();
Interlocked.CompareExchange(ref _idValidator, instance, null);
return _idValidator;
}
/// <summary>
/// Sets a default <see cref="IWebHookIdValidator"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <param name="instance">The <see cref="IWebHookIdValidator"/> to use. If <c>null</c> then a default implementation is used.</param>
public static void SetIdValidator(IWebHookIdValidator instance)
{
_idValidator = instance;
}
/// <summary>
/// Gets the set of <see cref="IWebHookRegistrar"/> instances discovered by a default
/// discovery mechanism which is used if none are registered with the Dependency Injection engine.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> containing the discovered instances.</returns>
public static IEnumerable<IWebHookRegistrar> GetRegistrars()
{
if (_registrars != null)
{
return _registrars;
}
IAssembliesResolver assembliesResolver = WebHooksConfig.Config.Services.GetAssembliesResolver();
ICollection<Assembly> assemblies = assembliesResolver.GetAssemblies();
IEnumerable<IWebHookRegistrar> instances = TypeUtilities.GetInstances<IWebHookRegistrar>(assemblies, t => TypeUtilities.IsType<IWebHookRegistrar>(t));
Interlocked.CompareExchange(ref _registrars, instances, null);
return _registrars;
}
/// <summary>
/// For testing purposes
/// </summary>
internal static void Reset()
{
_registrars = null;
_idValidator = null;
}
}
}

Просмотреть файл

@ -1,31 +1,31 @@
// 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.Net.Http;
using System.Threading.Tasks;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides an abstraction for manipulating the registration flow of WebHooks as it goes through the
/// <see cref="Controllers.WebHookRegistrationsController"/> class. The <see cref="IWebHookRegistrar"/> allows
/// an implementation to change, modify, or reject WebHook registrations as they are created or updated.
/// This can for example be used to add filters to registrations enabling broadcast notifications
/// or specific group notifications.
/// </summary>
public interface IWebHookRegistrar
{
/// <summary>
/// This method is called as part of creating or updating a <see cref="WebHook"/> registration.
/// If an <see cref="Exception"/> is thrown, then the operation is rejected. As registrations
/// can be edited by the user, any filters added here must either be listed by an
/// <see cref="IWebHookFilterManager"/> implementation, or prefixed by
/// <see cref="WebHookRegistrar.PrivateFilterPrefix"/> in order to remain hidden from the user.
/// Failure to do so will lead to WebHook registration updates being rejected due to unknown filters.
/// </summary>
/// <param name="request">The current <see cref="HttpRequestMessage"/>.</param>
/// <param name="webHook">The incoming <see cref="WebHook"/> to inspect, manipulate, or reject.</param>
Task RegisterAsync(HttpRequestMessage request, WebHook webHook);
}
}
// 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.Net.Http;
using System.Threading.Tasks;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides an abstraction for manipulating the registration flow of WebHooks as it goes through the
/// <see cref="Controllers.WebHookRegistrationsController"/> class. The <see cref="IWebHookRegistrar"/> allows
/// an implementation to change, modify, or reject WebHook registrations as they are created or updated.
/// This can for example be used to add filters to registrations enabling broadcast notifications
/// or specific group notifications.
/// </summary>
public interface IWebHookRegistrar
{
/// <summary>
/// This method is called as part of creating or updating a <see cref="WebHook"/> registration.
/// If an <see cref="Exception"/> is thrown, then the operation is rejected. As registrations
/// can be edited by the user, any filters added here must either be listed by an
/// <see cref="IWebHookFilterManager"/> implementation, or prefixed by
/// <see cref="WebHookRegistrar.PrivateFilterPrefix"/> in order to remain hidden from the user.
/// Failure to do so will lead to WebHook registration updates being rejected due to unknown filters.
/// </summary>
/// <param name="request">The current <see cref="HttpRequestMessage"/>.</param>
/// <param name="webHook">The incoming <see cref="WebHook"/> to inspect, manipulate, or reject.</param>
Task RegisterAsync(HttpRequestMessage request, WebHook webHook);
}
}

Просмотреть файл

@ -1,37 +1,37 @@
// 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.Net.Http;
using System.Threading.Tasks;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides an abstract base class implementation of <see cref="IWebHookRegistrar"/>. An <see cref="IWebHookRegistrar"/>
/// implementation can be used to change, modify, or reject WebHook registrations as they are created or updated
/// through the <see cref="Controllers.WebHookRegistrationsController"/>. This can for example be used to add
/// filters to WebHook registrations enabling broadcast notifications or specific group notifications.
/// </summary>
public abstract class WebHookRegistrar : IWebHookRegistrar
{
private const string Prefix = "MS_Private_";
/// <summary>
/// Gets a prefix indicating that a WebHook registration filter is private to the server implementation
/// and should not be made visible to the user. As WebHook registrations can be added or edited by the user,
/// all registration filters must either be listed by an <see cref="IWebHookFilterManager"/> implementation,
/// or prefixed by <see cref="WebHookRegistrar.PrivateFilterPrefix"/> in order to remain hidden from the user.
/// Failure to do so will lead to WebHook registration updates being rejected due to unknown filters.
/// </summary>
public static string PrivateFilterPrefix
{
get
{
return Prefix;
}
}
/// <inheritdoc />
public abstract Task RegisterAsync(HttpRequestMessage request, WebHook webHook);
}
}
// 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.Net.Http;
using System.Threading.Tasks;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides an abstract base class implementation of <see cref="IWebHookRegistrar"/>. An <see cref="IWebHookRegistrar"/>
/// implementation can be used to change, modify, or reject WebHook registrations as they are created or updated
/// through the <see cref="Controllers.WebHookRegistrationsController"/>. This can for example be used to add
/// filters to WebHook registrations enabling broadcast notifications or specific group notifications.
/// </summary>
public abstract class WebHookRegistrar : IWebHookRegistrar
{
private const string Prefix = "MS_Private_";
/// <summary>
/// Gets a prefix indicating that a WebHook registration filter is private to the server implementation
/// and should not be made visible to the user. As WebHook registrations can be added or edited by the user,
/// all registration filters must either be listed by an <see cref="IWebHookFilterManager"/> implementation,
/// or prefixed by <see cref="WebHookRegistrar.PrivateFilterPrefix"/> in order to remain hidden from the user.
/// Failure to do so will lead to WebHook registration updates being rejected due to unknown filters.
/// </summary>
public static string PrivateFilterPrefix
{
get
{
return Prefix;
}
}
/// <inheritdoc />
public abstract Task RegisterAsync(HttpRequestMessage request, WebHook webHook);
}
}

Просмотреть файл

@ -276,9 +276,9 @@ namespace Microsoft.AspNet.WebHooks
deleteMessages.Add(message);
}
}
}
// Loop through the responses to see which messages should be deleted from the queue based on the response statuses.
}
// Loop through the responses to see which messages should be deleted from the queue based on the response statuses.
foreach (HttpResponseMessage response in responses)
{
WebHookWorkItem workItem = response.RequestMessage.Properties.GetValueOrDefault<WebHookWorkItem>(WorkItemKey);

Просмотреть файл

@ -1,25 +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>
<?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>

Просмотреть файл

@ -1,66 +1,66 @@
// 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.WebHooks;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Services;
using Microsoft.AspNetCore.DataProtection;
namespace System.Web.Http
{
/// <summary>
/// Extension methods for <see cref="HttpConfiguration"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class HttpConfigurationExtensions
{
/// <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.
/// Using this initializer, the data will be encrypted using <see cref="IDataProtector"/>.
/// </summary>
/// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config)
{
InitializeCustomWebHooksSqlStorage(config, encryptData: true);
}
/// <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>
/// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param>
public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config, bool encryptData)
{
if (config == null)
{
throw new ArgumentNullException(nameof(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<WebHookStoreContext>(null);
IWebHookStore store;
if (encryptData)
{
IDataProtector protector = DataSecurity.GetDataProtector();
store = new SqlWebHookStore(settings, protector, logger);
}
else
{
store = new SqlWebHookStore(settings, logger);
}
CustomServices.SetStore(store);
}
}
}
// 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.WebHooks;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Services;
using Microsoft.AspNetCore.DataProtection;
namespace System.Web.Http
{
/// <summary>
/// Extension methods for <see cref="HttpConfiguration"/>.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class HttpConfigurationExtensions
{
/// <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.
/// Using this initializer, the data will be encrypted using <see cref="IDataProtector"/>.
/// </summary>
/// <param name="config">The current <see cref="HttpConfiguration"/>config.</param>
public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config)
{
InitializeCustomWebHooksSqlStorage(config, encryptData: true);
}
/// <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>
/// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param>
public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config, bool encryptData)
{
if (config == null)
{
throw new ArgumentNullException(nameof(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<WebHookStoreContext>(null);
IWebHookStore store;
if (encryptData)
{
IDataProtector protector = DataSecurity.GetDataProtector();
store = new SqlWebHookStore(settings, protector, logger);
}
else
{
store = new SqlWebHookStore(settings, logger);
}
CustomServices.SetStore(store);
}
}
}

Просмотреть файл

@ -1,187 +1,187 @@
<?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>true</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.AspNetCore.Cryptography.Internal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Cryptography.Internal.1.0.0\lib\net451\Microsoft.AspNetCore.Cryptography.Internal.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.DataProtection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.DataProtection.1.0.0\lib\net451\Microsoft.AspNetCore.DataProtection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.DataProtection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.DataProtection.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.DataProtection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Hosting.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.Hosting.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Hosting.Server.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Http.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Http.Features.1.0.0\lib\net451\Microsoft.AspNetCore.Http.Features.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.1.0.0\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.FileProviders.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.FileProviders.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Options, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Options.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Options.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.PlatformAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.PlatformAbstractions.1.0.0\lib\net451\Microsoft.Extensions.PlatformAbstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Primitives.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.Composition" />
<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.Text.Encodings.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Text.Encodings.Web.4.0.0\lib\netstandard1.0\System.Text.Encodings.Web.dll</HintPath>
<Private>True</Private>
</Reference>
<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="..\Common\DataSecurity.cs">
<Link>Common\DataSecurity.cs</Link>
</Compile>
<Compile Include="Extensions\HttpConfigurationExtensions.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\IRegistration.cs" />
<Compile Include="Storage\Registration.cs" />
<Compile Include="WebHooks\DbWebHookStore.cs" />
<Compile Include="WebHooks\WebHookStoreContext.cs" />
<Compile Include="WebHooks\SqlWebHookStore.cs" />
</ItemGroup>
<ItemGroup>
<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>
<None Include="Readme.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\packages\StyleCop.MSBuild.5.0.0\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.5.0.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.5.0.0\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>
-->
<?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>true</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.AspNetCore.Cryptography.Internal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Cryptography.Internal.1.0.0\lib\net451\Microsoft.AspNetCore.Cryptography.Internal.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.DataProtection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.DataProtection.1.0.0\lib\net451\Microsoft.AspNetCore.DataProtection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.DataProtection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.DataProtection.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.DataProtection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Hosting.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.Hosting.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Hosting.Server.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Http.Abstractions.1.0.0\lib\net451\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNetCore.Http.Features.1.0.0\lib\net451\Microsoft.AspNetCore.Http.Features.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.1.0.0\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.FileProviders.Abstractions.1.0.0\lib\netstandard1.0\Microsoft.Extensions.FileProviders.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.1.0.0\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Options, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Options.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Options.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.PlatformAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.PlatformAbstractions.1.0.0\lib\net451\Microsoft.Extensions.PlatformAbstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.1.0.0\lib\netstandard1.0\Microsoft.Extensions.Primitives.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.Composition" />
<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.Text.Encodings.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Text.Encodings.Web.4.0.0\lib\netstandard1.0\System.Text.Encodings.Web.dll</HintPath>
<Private>True</Private>
</Reference>
<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="..\Common\DataSecurity.cs">
<Link>Common\DataSecurity.cs</Link>
</Compile>
<Compile Include="Extensions\HttpConfigurationExtensions.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\IRegistration.cs" />
<Compile Include="Storage\Registration.cs" />
<Compile Include="WebHooks\DbWebHookStore.cs" />
<Compile Include="WebHooks\WebHookStoreContext.cs" />
<Compile Include="WebHooks\SqlWebHookStore.cs" />
</ItemGroup>
<ItemGroup>
<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>
<None Include="Readme.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\packages\StyleCop.MSBuild.5.0.0\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.5.0.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.5.0.0\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>

Просмотреть файл

@ -1,6 +1,6 @@
// 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.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNet.WebHooks.Custom.SqlStorage.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
// 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.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNet.WebHooks.Custom.SqlStorage.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]

Просмотреть файл

@ -1,39 +1,39 @@
// 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.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.AspNet.WebHooks.Storage
{
/// <summary>
/// Defines the WebHook registration data model for rows stored in Microsoft SQL.
/// </summary>
[Table("WebHooks")]
public class Registration : IRegistration
{
/// <inheritdoc />
[Key]
[StringLength(256)]
[Column(Order = 0)]
public string User { get; set; }
/// <inheritdoc />
[Key]
[StringLength(64)]
[Column(Order = 1)]
public string Id { get; set; }
/// <inheritdoc />
[Required]
public string ProtectedData { get; set; }
/// <summary>
/// Gets or sets a unique row version.
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This is the pattern for row version.")]
[Timestamp]
public byte[] RowVer { get; set; }
}
}
// 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.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.AspNet.WebHooks.Storage
{
/// <summary>
/// Defines the WebHook registration data model for rows stored in Microsoft SQL.
/// </summary>
[Table("WebHooks")]
public class Registration : IRegistration
{
/// <inheritdoc />
[Key]
[StringLength(256)]
[Column(Order = 0)]
public string User { get; set; }
/// <inheritdoc />
[Key]
[StringLength(64)]
[Column(Order = 1)]
public string Id { get; set; }
/// <inheritdoc />
[Required]
public string ProtectedData { get; set; }
/// <summary>
/// Gets or sets a unique row version.
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "This is the pattern for row version.")]
[Timestamp]
public byte[] RowVer { get; set; }
}
}

Просмотреть файл

@ -1,100 +1,100 @@
// 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.Globalization;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Properties;
using Microsoft.AspNet.WebHooks.Services;
using Microsoft.AspNet.WebHooks.Storage;
using Microsoft.AspNetCore.DataProtection;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides an implementation of <see cref="IWebHookStore"/> storing registered WebHooks in Microsoft SQL Server.
/// </summary>
[CLSCompliant(false)]
public class SqlWebHookStore : DbWebHookStore<WebHookStoreContext, Registration>
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlWebHookStore"/> class with the given <paramref name="settings"/>
/// and <paramref name="logger"/>.
/// Using this constructor, the data will not be encrypted while persisted to the database.
/// </summary>
public SqlWebHookStore(SettingsDictionary settings, ILogger logger)
: base(logger)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
CheckSqlStorageConnectionString(settings);
}
/// <summary>
/// Initializes a new instance of the <see cref="SqlWebHookStore"/> class with the given <paramref name="settings"/>,
/// <paramref name="protector"/>, and <paramref name="logger"/>.
/// Using this constructor, the data will be encrypted using the provided <paramref name="protector"/>.
/// </summary>
public SqlWebHookStore(SettingsDictionary settings, IDataProtector protector, ILogger logger)
: base(protector, logger)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
CheckSqlStorageConnectionString(settings);
}
/// <summary>
/// Provides a static method for creating a standalone <see cref="SqlWebHookStore"/> instance which will
/// encrypt the data to be stored using <see cref="IDataProtector"/>.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> instance to use.</param>
/// <returns>An initialized <see cref="SqlWebHookStore"/> instance.</returns>
public static IWebHookStore CreateStore(ILogger logger)
{
return CreateStore(logger, encryptData: true);
}
/// <summary>
/// Provides a static method for creating a standalone <see cref="SqlWebHookStore"/> instance.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> instance to use.</param>
/// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param>
/// <returns>An initialized <see cref="SqlWebHookStore"/> instance.</returns>
public static IWebHookStore CreateStore(ILogger logger, bool encryptData)
{
SettingsDictionary settings = CommonServices.GetSettings();
IWebHookStore store;
if (encryptData)
{
IDataProtector protector = DataSecurity.GetDataProtector();
store = new SqlWebHookStore(settings, protector, logger);
}
else
{
store = new SqlWebHookStore(settings, logger);
}
return store;
}
internal static string CheckSqlStorageConnectionString(SettingsDictionary settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
ConnectionSettings connection;
if (!settings.Connections.TryGetValue(WebHookStoreContext.ConnectionStringName, out connection) || connection == null || string.IsNullOrEmpty(connection.ConnectionString))
{
string msg = string.Format(CultureInfo.CurrentCulture, SqlStorageResources.SqlStore_NoConnectionString, WebHookStoreContext.ConnectionStringName);
throw new InvalidOperationException(msg);
}
return connection.ConnectionString;
}
}
}
// 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.Globalization;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Properties;
using Microsoft.AspNet.WebHooks.Services;
using Microsoft.AspNet.WebHooks.Storage;
using Microsoft.AspNetCore.DataProtection;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides an implementation of <see cref="IWebHookStore"/> storing registered WebHooks in Microsoft SQL Server.
/// </summary>
[CLSCompliant(false)]
public class SqlWebHookStore : DbWebHookStore<WebHookStoreContext, Registration>
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlWebHookStore"/> class with the given <paramref name="settings"/>
/// and <paramref name="logger"/>.
/// Using this constructor, the data will not be encrypted while persisted to the database.
/// </summary>
public SqlWebHookStore(SettingsDictionary settings, ILogger logger)
: base(logger)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
CheckSqlStorageConnectionString(settings);
}
/// <summary>
/// Initializes a new instance of the <see cref="SqlWebHookStore"/> class with the given <paramref name="settings"/>,
/// <paramref name="protector"/>, and <paramref name="logger"/>.
/// Using this constructor, the data will be encrypted using the provided <paramref name="protector"/>.
/// </summary>
public SqlWebHookStore(SettingsDictionary settings, IDataProtector protector, ILogger logger)
: base(protector, logger)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
CheckSqlStorageConnectionString(settings);
}
/// <summary>
/// Provides a static method for creating a standalone <see cref="SqlWebHookStore"/> instance which will
/// encrypt the data to be stored using <see cref="IDataProtector"/>.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> instance to use.</param>
/// <returns>An initialized <see cref="SqlWebHookStore"/> instance.</returns>
public static IWebHookStore CreateStore(ILogger logger)
{
return CreateStore(logger, encryptData: true);
}
/// <summary>
/// Provides a static method for creating a standalone <see cref="SqlWebHookStore"/> instance.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/> instance to use.</param>
/// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param>
/// <returns>An initialized <see cref="SqlWebHookStore"/> instance.</returns>
public static IWebHookStore CreateStore(ILogger logger, bool encryptData)
{
SettingsDictionary settings = CommonServices.GetSettings();
IWebHookStore store;
if (encryptData)
{
IDataProtector protector = DataSecurity.GetDataProtector();
store = new SqlWebHookStore(settings, protector, logger);
}
else
{
store = new SqlWebHookStore(settings, logger);
}
return store;
}
internal static string CheckSqlStorageConnectionString(SettingsDictionary settings)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
ConnectionSettings connection;
if (!settings.Connections.TryGetValue(WebHookStoreContext.ConnectionStringName, out connection) || connection == null || string.IsNullOrEmpty(connection.ConnectionString))
{
string msg = string.Format(CultureInfo.CurrentCulture, SqlStorageResources.SqlStore_NoConnectionString, WebHookStoreContext.ConnectionStringName);
throw new InvalidOperationException(msg);
}
return connection.ConnectionString;
}
}
}

Просмотреть файл

@ -1,39 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.1" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Cryptography.Internal" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.DataProtection" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.DataProtection.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Hosting.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Hosting.Server.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Http.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Http.Features" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.FileProviders.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Options" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.PlatformAbstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Primitives" version="1.0.0" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net451" />
<package id="System.Collections" version="4.0.11" targetFramework="net451" />
<package id="System.Collections.Concurrent" version="4.0.12" targetFramework="net451" />
<package id="System.ComponentModel" version="4.0.1" targetFramework="net451" />
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net451" />
<package id="System.Globalization" version="4.0.11" targetFramework="net451" />
<package id="System.IO" version="4.1.0" targetFramework="net451" />
<package id="System.Linq" version="4.1.0" targetFramework="net451" />
<package id="System.Linq.Expressions" version="4.1.0" targetFramework="net451" />
<package id="System.Reflection" version="4.1.0" targetFramework="net451" />
<package id="System.Resources.ResourceManager" version="4.0.1" targetFramework="net451" />
<package id="System.Runtime" version="4.1.0" targetFramework="net451" />
<package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net451" />
<package id="System.Runtime.InteropServices" version="4.1.0" targetFramework="net451" />
<package id="System.Text.Encodings.Web" version="4.0.0" targetFramework="net451" />
<package id="System.Threading" version="4.0.11" targetFramework="net451" />
<package id="System.Threading.Tasks" version="4.0.11" targetFramework="net451" />
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.1" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net451" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Cryptography.Internal" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.DataProtection" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.DataProtection.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Hosting.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Hosting.Server.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Http.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.AspNetCore.Http.Features" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.FileProviders.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Options" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.PlatformAbstractions" version="1.0.0" targetFramework="net451" />
<package id="Microsoft.Extensions.Primitives" version="1.0.0" targetFramework="net451" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net451" />
<package id="System.Collections" version="4.0.11" targetFramework="net451" />
<package id="System.Collections.Concurrent" version="4.0.12" targetFramework="net451" />
<package id="System.ComponentModel" version="4.0.1" targetFramework="net451" />
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net451" />
<package id="System.Globalization" version="4.0.11" targetFramework="net451" />
<package id="System.IO" version="4.1.0" targetFramework="net451" />
<package id="System.Linq" version="4.1.0" targetFramework="net451" />
<package id="System.Linq.Expressions" version="4.1.0" targetFramework="net451" />
<package id="System.Reflection" version="4.1.0" targetFramework="net451" />
<package id="System.Resources.ResourceManager" version="4.0.1" targetFramework="net451" />
<package id="System.Runtime" version="4.1.0" targetFramework="net451" />
<package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net451" />
<package id="System.Runtime.InteropServices" version="4.1.0" targetFramework="net451" />
<package id="System.Text.Encodings.Web" version="4.0.0" targetFramework="net451" />
<package id="System.Threading" version="4.0.11" targetFramework="net451" />
<package id="System.Threading.Tasks" version="4.0.11" targetFramework="net451" />
</packages>

Просмотреть файл

@ -1,158 +1,158 @@
// 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.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Utilities;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides singleton instances of WebHook receiver services.
/// If alternative implementations are provided by a Dependency Injection engine then
/// those instances are used instead.
/// </summary>
public static class ReceiverServices
{
private static IWebHookReceiverManager _receiverManager;
private static IWebHookReceiverConfig _receiverConfig;
private static IWebHookHandlerSorter _handlerSorter;
private static IEnumerable<IWebHookReceiver> _receivers;
private static IEnumerable<IWebHookHandler> _handlers;
/// <summary>
/// Gets a default <see cref="IWebHookReceiverManager"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookReceiverManager"/> instance.</returns>
public static IWebHookReceiverManager GetReceiverManager(IEnumerable<IWebHookReceiver> receivers, ILogger logger)
{
if (_receiverManager != null)
{
return _receiverManager;
}
if (receivers == null)
{
throw new ArgumentNullException(nameof(receivers));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
IWebHookReceiverManager instance = new WebHookReceiverManager(receivers, logger);
Interlocked.CompareExchange(ref _receiverManager, instance, null);
return _receiverManager;
}
/// <summary>
/// Gets a default <see cref="IWebHookReceiverConfig"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookReceiverConfig"/> instance.</returns>
public static IWebHookReceiverConfig GetReceiverConfig(SettingsDictionary settings, ILogger logger)
{
if (_receiverConfig != null)
{
return _receiverConfig;
}
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
IWebHookReceiverConfig instance = new WebHookReceiverConfig(settings, logger);
Interlocked.CompareExchange(ref _receiverConfig, instance, null);
return _receiverConfig;
}
/// <summary>
/// Sets a default <see cref="IWebHookReceiverConfig"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <param name="instance">The <see cref="IWebHookReceiverConfig"/> to use. If <c>null</c> then a default implementation is used.</param>
public static void SetReceiverConfig(IWebHookReceiverConfig instance)
{
_receiverConfig = instance;
}
/// <summary>
/// Gets a default <see cref="IWebHookHandlerSorter"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookHandlerSorter"/> instance.</returns>
public static IWebHookHandlerSorter GetHandlerSorter()
{
if (_handlerSorter != null)
{
return _handlerSorter;
}
IWebHookHandlerSorter instance = new WebHookHandlerSorter();
Interlocked.CompareExchange(ref _handlerSorter, instance, null);
return _handlerSorter;
}
/// <summary>
/// Gets the set of <see cref="IWebHookReceiver"/> instances discovered by a default
/// discovery mechanism which is used if none are registered with the Dependency Injection engine.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> containing the discovered instances.</returns>
public static IEnumerable<IWebHookReceiver> GetReceivers()
{
if (_receivers != null)
{
return _receivers;
}
IAssembliesResolver assembliesResolver = WebHooksConfig.Config.Services.GetAssembliesResolver();
ICollection<Assembly> assemblies = assembliesResolver.GetAssemblies();
IEnumerable<IWebHookReceiver> instances = TypeUtilities.GetInstances<IWebHookReceiver>(assemblies, t => TypeUtilities.IsType<IWebHookReceiver>(t));
Interlocked.CompareExchange(ref _receivers, instances, null);
return _receivers;
}
/// <summary>
/// Gets the set of <see cref="IWebHookHandler"/> instances discovered by a default
/// discovery mechanism which is used if none are registered with the Dependency Injection engine.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> containing the discovered instances.</returns>
public static IEnumerable<IWebHookHandler> GetHandlers()
{
if (_handlers != null)
{
return _handlers;
}
IAssembliesResolver assembliesResolver = WebHooksConfig.Config.Services.GetAssembliesResolver();
ICollection<Assembly> assemblies = assembliesResolver.GetAssemblies();
IEnumerable<IWebHookHandler> instances = TypeUtilities.GetInstances<IWebHookHandler>(assemblies, t => TypeUtilities.IsType<IWebHookHandler>(t));
Interlocked.CompareExchange(ref _handlers, instances, null);
return _handlers;
}
/// <summary>
/// Resets all values for testing purposes.
/// </summary>
internal static void Reset()
{
_receiverManager = null;
_receiverConfig = null;
_handlerSorter = null;
_receivers = null;
_handlers = null;
}
}
}
// 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.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Utilities;
namespace Microsoft.AspNet.WebHooks
{
/// <summary>
/// Provides singleton instances of WebHook receiver services.
/// If alternative implementations are provided by a Dependency Injection engine then
/// those instances are used instead.
/// </summary>
public static class ReceiverServices
{
private static IWebHookReceiverManager _receiverManager;
private static IWebHookReceiverConfig _receiverConfig;
private static IWebHookHandlerSorter _handlerSorter;
private static IEnumerable<IWebHookReceiver> _receivers;
private static IEnumerable<IWebHookHandler> _handlers;
/// <summary>
/// Gets a default <see cref="IWebHookReceiverManager"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookReceiverManager"/> instance.</returns>
public static IWebHookReceiverManager GetReceiverManager(IEnumerable<IWebHookReceiver> receivers, ILogger logger)
{
if (_receiverManager != null)
{
return _receiverManager;
}
if (receivers == null)
{
throw new ArgumentNullException(nameof(receivers));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
IWebHookReceiverManager instance = new WebHookReceiverManager(receivers, logger);
Interlocked.CompareExchange(ref _receiverManager, instance, null);
return _receiverManager;
}
/// <summary>
/// Gets a default <see cref="IWebHookReceiverConfig"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookReceiverConfig"/> instance.</returns>
public static IWebHookReceiverConfig GetReceiverConfig(SettingsDictionary settings, ILogger logger)
{
if (_receiverConfig != null)
{
return _receiverConfig;
}
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
IWebHookReceiverConfig instance = new WebHookReceiverConfig(settings, logger);
Interlocked.CompareExchange(ref _receiverConfig, instance, null);
return _receiverConfig;
}
/// <summary>
/// Sets a default <see cref="IWebHookReceiverConfig"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <param name="instance">The <see cref="IWebHookReceiverConfig"/> to use. If <c>null</c> then a default implementation is used.</param>
public static void SetReceiverConfig(IWebHookReceiverConfig instance)
{
_receiverConfig = instance;
}
/// <summary>
/// Gets a default <see cref="IWebHookHandlerSorter"/> implementation which is used if none are registered with the
/// Dependency Injection engine.
/// </summary>
/// <returns>A default <see cref="IWebHookHandlerSorter"/> instance.</returns>
public static IWebHookHandlerSorter GetHandlerSorter()
{
if (_handlerSorter != null)
{
return _handlerSorter;
}
IWebHookHandlerSorter instance = new WebHookHandlerSorter();
Interlocked.CompareExchange(ref _handlerSorter, instance, null);
return _handlerSorter;
}
/// <summary>
/// Gets the set of <see cref="IWebHookReceiver"/> instances discovered by a default
/// discovery mechanism which is used if none are registered with the Dependency Injection engine.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> containing the discovered instances.</returns>
public static IEnumerable<IWebHookReceiver> GetReceivers()
{
if (_receivers != null)
{
return _receivers;
}
IAssembliesResolver assembliesResolver = WebHooksConfig.Config.Services.GetAssembliesResolver();
ICollection<Assembly> assemblies = assembliesResolver.GetAssemblies();
IEnumerable<IWebHookReceiver> instances = TypeUtilities.GetInstances<IWebHookReceiver>(assemblies, t => TypeUtilities.IsType<IWebHookReceiver>(t));
Interlocked.CompareExchange(ref _receivers, instances, null);
return _receivers;
}
/// <summary>
/// Gets the set of <see cref="IWebHookHandler"/> instances discovered by a default
/// discovery mechanism which is used if none are registered with the Dependency Injection engine.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> containing the discovered instances.</returns>
public static IEnumerable<IWebHookHandler> GetHandlers()
{
if (_handlers != null)
{
return _handlers;
}
IAssembliesResolver assembliesResolver = WebHooksConfig.Config.Services.GetAssembliesResolver();
ICollection<Assembly> assemblies = assembliesResolver.GetAssemblies();
IEnumerable<IWebHookHandler> instances = TypeUtilities.GetInstances<IWebHookHandler>(assemblies, t => TypeUtilities.IsType<IWebHookHandler>(t));
Interlocked.CompareExchange(ref _handlers, instances, null);
return _handlers;
}
/// <summary>
/// Resets all values for testing purposes.
/// </summary>
internal static void Reset()
{
_receiverManager = null;
_receiverConfig = null;
_handlerSorter = null;
_receivers = null;
_handlers = null;
}
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,115 +1,115 @@
// 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.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Dependencies;
using Microsoft.AspNet.WebHooks.Services;
using Moq;
using Xunit;
namespace Microsoft.AspNet.WebHooks
{
[Collection("ConfigCollection")]
public class DependencyScopeExtensionsTests
{
private readonly Mock<IDependencyScope> _resolverMock;
private readonly HttpConfiguration _config;
public DependencyScopeExtensionsTests()
{
_resolverMock = new Mock<IDependencyScope>();
_config = new HttpConfiguration();
CustomApiServices.Reset();
}
[Fact]
public void GetIdValidator_ReturnsDependencyInstance_IfRegistered()
{
// Arrange
Mock<IWebHookIdValidator> instanceMock = new Mock<IWebHookIdValidator>();
_resolverMock.Setup(r => r.GetService(typeof(IWebHookIdValidator)))
.Returns(instanceMock.Object)
.Verifiable();
// Act
IWebHookIdValidator actual = _resolverMock.Object.GetIdValidator();
// Assert
Assert.Same(instanceMock.Object, actual);
instanceMock.Verify();
}
[Fact]
public void GetIdValidator_ReturnsDefaultInstance_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IWebHookIdValidator actual = _resolverMock.Object.GetIdValidator();
// Assert
Assert.IsType<DefaultWebHookIdValidator>(actual);
}
[Fact]
public void GetIdValidator_ReturnsSameInstance_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IWebHookIdValidator actual1 = _resolverMock.Object.GetIdValidator();
IWebHookIdValidator actual2 = _resolverMock.Object.GetIdValidator();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetRegistrars_ReturnsDependencyInstances_IfRegistered()
{
// Arrange
Mock<IWebHookRegistrar> instanceMock = new Mock<IWebHookRegistrar>();
List<IWebHookRegistrar> instances = new List<IWebHookRegistrar> { instanceMock.Object };
_resolverMock.Setup(r => r.GetServices(typeof(IWebHookRegistrar)))
.Returns(instances)
.Verifiable();
// Act
IEnumerable<IWebHookRegistrar> actual = _resolverMock.Object.GetRegistrars();
// Assert
Assert.Same(instances, actual);
instanceMock.Verify();
}
[Fact]
public void GetRegistrars_ReturnsDefaultInstances_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IEnumerable<IWebHookRegistrar> actual = _resolverMock.Object.GetRegistrars();
// Assert
Assert.Empty(actual);
}
[Fact]
public void GetRegistrars_ReturnsSameInstances_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IEnumerable<IWebHookRegistrar> actual1 = _resolverMock.Object.GetRegistrars();
IEnumerable<IWebHookRegistrar> actual2 = _resolverMock.Object.GetRegistrars();
// Assert
Assert.Same(actual1, actual2);
}
}
}
// 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.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Dependencies;
using Microsoft.AspNet.WebHooks.Services;
using Moq;
using Xunit;
namespace Microsoft.AspNet.WebHooks
{
[Collection("ConfigCollection")]
public class DependencyScopeExtensionsTests
{
private readonly Mock<IDependencyScope> _resolverMock;
private readonly HttpConfiguration _config;
public DependencyScopeExtensionsTests()
{
_resolverMock = new Mock<IDependencyScope>();
_config = new HttpConfiguration();
CustomApiServices.Reset();
}
[Fact]
public void GetIdValidator_ReturnsDependencyInstance_IfRegistered()
{
// Arrange
Mock<IWebHookIdValidator> instanceMock = new Mock<IWebHookIdValidator>();
_resolverMock.Setup(r => r.GetService(typeof(IWebHookIdValidator)))
.Returns(instanceMock.Object)
.Verifiable();
// Act
IWebHookIdValidator actual = _resolverMock.Object.GetIdValidator();
// Assert
Assert.Same(instanceMock.Object, actual);
instanceMock.Verify();
}
[Fact]
public void GetIdValidator_ReturnsDefaultInstance_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IWebHookIdValidator actual = _resolverMock.Object.GetIdValidator();
// Assert
Assert.IsType<DefaultWebHookIdValidator>(actual);
}
[Fact]
public void GetIdValidator_ReturnsSameInstance_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IWebHookIdValidator actual1 = _resolverMock.Object.GetIdValidator();
IWebHookIdValidator actual2 = _resolverMock.Object.GetIdValidator();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetRegistrars_ReturnsDependencyInstances_IfRegistered()
{
// Arrange
Mock<IWebHookRegistrar> instanceMock = new Mock<IWebHookRegistrar>();
List<IWebHookRegistrar> instances = new List<IWebHookRegistrar> { instanceMock.Object };
_resolverMock.Setup(r => r.GetServices(typeof(IWebHookRegistrar)))
.Returns(instances)
.Verifiable();
// Act
IEnumerable<IWebHookRegistrar> actual = _resolverMock.Object.GetRegistrars();
// Assert
Assert.Same(instances, actual);
instanceMock.Verify();
}
[Fact]
public void GetRegistrars_ReturnsDefaultInstances_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IEnumerable<IWebHookRegistrar> actual = _resolverMock.Object.GetRegistrars();
// Assert
Assert.Empty(actual);
}
[Fact]
public void GetRegistrars_ReturnsSameInstances_IfNoneRegistered()
{
// Arrange
_config.InitializeCustomWebHooks();
// Act
IEnumerable<IWebHookRegistrar> actual1 = _resolverMock.Object.GetRegistrars();
IEnumerable<IWebHookRegistrar> actual2 = _resolverMock.Object.GetRegistrars();
// Assert
Assert.Same(actual1, actual2);
}
}
}

Просмотреть файл

@ -1,116 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),WebHooks.sln))\tools\WebHooks.settings.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C20671F3-181F-45D7-A62C-5DE1DE610FE9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AspNet.WebHooks</RootNamespace>
<AssemblyName>Microsoft.AspNet.WebHooks.Custom.Api.Test</AssemblyName>
<OutputPath>..\..\bin\Test\$(Configuration)\</OutputPath>
<RunCodeAnalysis>$(CodeAnalysis)</RunCodeAnalysis>
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
<CodeAnalysisRuleSet>..\..\FxCopTest.ruleset</CodeAnalysisRuleSet>
<DefineConstants>$(DefineConstants);ASPNETWEBHOOKS</DefineConstants>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.2.1502.911, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\packages\Moq.4.2.1502.0911\lib\net40\Moq.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.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.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" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\WebHookFiltersControllerTests.cs" />
<Compile Include="Controllers\WebHookRegistrationsControllerTests.cs" />
<Compile Include="Extensions\DependencyScopeExtensionsTests.cs" />
<Compile Include="Filters\ValidateModelAttributeTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\CustomApiServicesTests.cs" />
<Compile Include="WebHooks\DefaultWebHookIdValidatorTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Src\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="..\..\Src\Microsoft.AspNet.WebHooks.Custom.Api\Microsoft.AspNet.WebHooks.Custom.Api.csproj">
<Project>{f0ee25b8-d851-40da-ab2a-e0bace9c1e5d}</Project>
<Name>Microsoft.AspNet.WebHooks.Custom.Api</Name>
</ProjectReference>
<ProjectReference Include="..\..\Src\Microsoft.AspNet.WebHooks.Custom\Microsoft.AspNet.WebHooks.Custom.csproj">
<Project>{d4d210c6-3283-4d1d-806e-8717d8f51179}</Project>
<Name>Microsoft.AspNet.WebHooks.Custom</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.TestUtilities\Microsoft.TestUtilities.csproj">
<Project>{608b1d09-e4de-4dba-8dbf-7758003988f0}</Project>
<Name>Microsoft.TestUtilities</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\..\CustomDictionary.xml">
<Link>CustomDictionary.xml</Link>
</CodeAnalysisDictionary>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</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. 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\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
<Error Condition="!Exists('..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.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>
-->
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),WebHooks.sln))\tools\WebHooks.settings.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C20671F3-181F-45D7-A62C-5DE1DE610FE9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AspNet.WebHooks</RootNamespace>
<AssemblyName>Microsoft.AspNet.WebHooks.Custom.Api.Test</AssemblyName>
<OutputPath>..\..\bin\Test\$(Configuration)\</OutputPath>
<RunCodeAnalysis>$(CodeAnalysis)</RunCodeAnalysis>
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
<CodeAnalysisRuleSet>..\..\FxCopTest.ruleset</CodeAnalysisRuleSet>
<DefineConstants>$(DefineConstants);ASPNETWEBHOOKS</DefineConstants>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=4.2.1502.911, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\packages\Moq.4.2.1502.0911\lib\net40\Moq.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.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.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" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\WebHookFiltersControllerTests.cs" />
<Compile Include="Controllers\WebHookRegistrationsControllerTests.cs" />
<Compile Include="Extensions\DependencyScopeExtensionsTests.cs" />
<Compile Include="Filters\ValidateModelAttributeTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\CustomApiServicesTests.cs" />
<Compile Include="WebHooks\DefaultWebHookIdValidatorTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Src\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="..\..\Src\Microsoft.AspNet.WebHooks.Custom.Api\Microsoft.AspNet.WebHooks.Custom.Api.csproj">
<Project>{f0ee25b8-d851-40da-ab2a-e0bace9c1e5d}</Project>
<Name>Microsoft.AspNet.WebHooks.Custom.Api</Name>
</ProjectReference>
<ProjectReference Include="..\..\Src\Microsoft.AspNet.WebHooks.Custom\Microsoft.AspNet.WebHooks.Custom.csproj">
<Project>{d4d210c6-3283-4d1d-806e-8717d8f51179}</Project>
<Name>Microsoft.AspNet.WebHooks.Custom</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.TestUtilities\Microsoft.TestUtilities.csproj">
<Project>{608b1d09-e4de-4dba-8dbf-7758003988f0}</Project>
<Name>Microsoft.TestUtilities</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\..\CustomDictionary.xml">
<Link>CustomDictionary.xml</Link>
</CodeAnalysisDictionary>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</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. 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\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
<Error Condition="!Exists('..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<Import Project="..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\packages\StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.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>
-->
</Project>

Просмотреть файл

@ -1,57 +1,57 @@
// 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.Collections.Generic;
using System.Web.Http;
using Microsoft.AspNet.WebHooks.Config;
using Moq;
using Xunit;
namespace Microsoft.AspNet.WebHooks.Services
{
[Collection("ConfigCollection")]
public class CustomApiServicesTests
{
public CustomApiServicesTests()
{
HttpConfiguration config = new HttpConfiguration();
WebHooksConfig.Initialize(config);
}
[Fact]
public void GetIdValidator_ReturnsSingleInstance()
{
// Act
IWebHookIdValidator actual1 = CustomApiServices.GetIdValidator();
IWebHookIdValidator actual2 = CustomApiServices.GetIdValidator();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void SetIdValidator_GetIdValidator_Roundtrips()
{
// Arrange
Mock<IWebHookIdValidator> idValidatorMock = new Mock<IWebHookIdValidator>();
// Act
CustomApiServices.SetIdValidator(idValidatorMock.Object);
IWebHookIdValidator actual = CustomApiServices.GetIdValidator();
// Assert
Assert.Same(idValidatorMock.Object, actual);
}
[Fact]
public void GetFilterProviders_ReturnsSingletonInstance()
{
// Act
IEnumerable<IWebHookRegistrar> actual1 = CustomApiServices.GetRegistrars();
IEnumerable<IWebHookRegistrar> actual2 = CustomApiServices.GetRegistrars();
// Assert
Assert.Same(actual1, actual2);
}
}
}
// 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.Collections.Generic;
using System.Web.Http;
using Microsoft.AspNet.WebHooks.Config;
using Moq;
using Xunit;
namespace Microsoft.AspNet.WebHooks.Services
{
[Collection("ConfigCollection")]
public class CustomApiServicesTests
{
public CustomApiServicesTests()
{
HttpConfiguration config = new HttpConfiguration();
WebHooksConfig.Initialize(config);
}
[Fact]
public void GetIdValidator_ReturnsSingleInstance()
{
// Act
IWebHookIdValidator actual1 = CustomApiServices.GetIdValidator();
IWebHookIdValidator actual2 = CustomApiServices.GetIdValidator();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void SetIdValidator_GetIdValidator_Roundtrips()
{
// Arrange
Mock<IWebHookIdValidator> idValidatorMock = new Mock<IWebHookIdValidator>();
// Act
CustomApiServices.SetIdValidator(idValidatorMock.Object);
IWebHookIdValidator actual = CustomApiServices.GetIdValidator();
// Assert
Assert.Same(idValidatorMock.Object, actual);
}
[Fact]
public void GetFilterProviders_ReturnsSingletonInstance()
{
// Act
IEnumerable<IWebHookRegistrar> actual1 = CustomApiServices.GetRegistrars();
IEnumerable<IWebHookRegistrar> actual2 = CustomApiServices.GetRegistrars();
// Assert
Assert.Same(actual1, actual2);
}
}
}

Просмотреть файл

@ -1,84 +1,84 @@
// 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.Configuration;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Web.Http;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Services;
using Moq;
using Xunit;
using EF = Microsoft.AspNet.WebHooks.Migrations;
namespace Microsoft.AspNet.WebHooks
{
[Collection("StoreCollection")]
public class SqlWebHookStoreTests : WebHookStoreTest
{
public SqlWebHookStoreTests()
: base(CreateStore())
{
}
public static TheoryData<ConnectionSettings> ConnectionSettingsData
{
get
{
return new TheoryData<ConnectionSettings>
{
null,
new ConnectionSettings(WebHookStoreContext.ConnectionStringName, string.Empty),
};
}
}
[Fact]
public void CreateStore_Succeeds()
{
// Arrange
ILogger logger = new Mock<ILogger>().Object;
// Act
IWebHookStore actual = SqlWebHookStore.CreateStore(logger);
// Assert
Assert.IsType<SqlWebHookStore>(actual);
}
[Theory]
[MemberData(nameof(ConnectionSettingsData))]
public void CheckSqlStorageConnectionString_Throws_IfNullOrEmptyConnectionString(ConnectionSettings connectionSettings)
{
// Arrange
SettingsDictionary settings = new SettingsDictionary();
settings.Connections.Add(WebHookStoreContext.ConnectionStringName, connectionSettings);
// Act
InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => SqlWebHookStore.CheckSqlStorageConnectionString(settings));
// Assert
Assert.Equal("Please provide a SQL connection string with name 'MS_SqlStoreConnectionString' in the configuration string section of the 'Web.Config' file.", ex.Message);
}
private static IWebHookStore CreateStore()
{
// Delete any existing DB
string connectionString = ConfigurationManager.ConnectionStrings[WebHookStoreContext.ConnectionStringName].ConnectionString;
Database.Delete(connectionString);
// Initialize DB using code first migration
var dbConfig = new EF.Configuration();
var migrator = new DbMigrator(dbConfig);
migrator.Update();
HttpConfiguration config = new HttpConfiguration();
config.InitializeCustomWebHooksSqlStorage();
IWebHookStore store = CustomServices.GetStore();
Assert.IsType<SqlWebHookStore>(store);
return store;
}
}
}
// 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.Configuration;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Web.Http;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Microsoft.AspNet.WebHooks.Services;
using Moq;
using Xunit;
using EF = Microsoft.AspNet.WebHooks.Migrations;
namespace Microsoft.AspNet.WebHooks
{
[Collection("StoreCollection")]
public class SqlWebHookStoreTests : WebHookStoreTest
{
public SqlWebHookStoreTests()
: base(CreateStore())
{
}
public static TheoryData<ConnectionSettings> ConnectionSettingsData
{
get
{
return new TheoryData<ConnectionSettings>
{
null,
new ConnectionSettings(WebHookStoreContext.ConnectionStringName, string.Empty),
};
}
}
[Fact]
public void CreateStore_Succeeds()
{
// Arrange
ILogger logger = new Mock<ILogger>().Object;
// Act
IWebHookStore actual = SqlWebHookStore.CreateStore(logger);
// Assert
Assert.IsType<SqlWebHookStore>(actual);
}
[Theory]
[MemberData(nameof(ConnectionSettingsData))]
public void CheckSqlStorageConnectionString_Throws_IfNullOrEmptyConnectionString(ConnectionSettings connectionSettings)
{
// Arrange
SettingsDictionary settings = new SettingsDictionary();
settings.Connections.Add(WebHookStoreContext.ConnectionStringName, connectionSettings);
// Act
InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => SqlWebHookStore.CheckSqlStorageConnectionString(settings));
// Assert
Assert.Equal("Please provide a SQL connection string with name 'MS_SqlStoreConnectionString' in the configuration string section of the 'Web.Config' file.", ex.Message);
}
private static IWebHookStore CreateStore()
{
// Delete any existing DB
string connectionString = ConfigurationManager.ConnectionStrings[WebHookStoreContext.ConnectionStringName].ConnectionString;
Database.Delete(connectionString);
// Initialize DB using code first migration
var dbConfig = new EF.Configuration();
var migrator = new DbMigrator(dbConfig);
migrator.Update();
HttpConfiguration config = new HttpConfiguration();
config.InitializeCustomWebHooksSqlStorage();
IWebHookStore store = CustomServices.GetStore();
Assert.IsType<SqlWebHookStore>(store);
return store;
}
}
}

Просмотреть файл

@ -1,102 +1,102 @@
// 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.Collections.Generic;
using System.Web.Http;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Moq;
using Xunit;
namespace Microsoft.AspNet.WebHooks.Services
{
[Collection("ConfigCollection")]
public class ReceiverServicesTests
{
public ReceiverServicesTests()
{
HttpConfiguration config = new HttpConfiguration();
WebHooksConfig.Initialize(config);
ReceiverServices.Reset();
}
[Fact]
public void GetReceiverManager_ReturnsSingleInstance()
{
// Arrange
ILogger logger = CommonServices.GetLogger();
List<IWebHookReceiver> receivers = new List<IWebHookReceiver>();
// Act
IWebHookReceiverManager actual1 = ReceiverServices.GetReceiverManager(receivers, logger);
IWebHookReceiverManager actual2 = ReceiverServices.GetReceiverManager(receivers, logger);
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetReceiverConfig_ReturnsSingleInstance()
{
// Arrange
SettingsDictionary settings = CommonServices.GetSettings();
ILogger logger = CommonServices.GetLogger();
// Act
IWebHookReceiverConfig actual1 = ReceiverServices.GetReceiverConfig(settings, logger);
IWebHookReceiverConfig actual2 = ReceiverServices.GetReceiverConfig(settings, logger);
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void SetReceiverConfig_GetReceiverConfig_Roundtrips()
{
// Arrange
SettingsDictionary settings = CommonServices.GetSettings();
ILogger logger = CommonServices.GetLogger();
Mock<IWebHookReceiverConfig> configMock = new Mock<IWebHookReceiverConfig>();
// Act
ReceiverServices.SetReceiverConfig(configMock.Object);
IWebHookReceiverConfig actual = ReceiverServices.GetReceiverConfig(settings, logger);
// Assert
Assert.Same(configMock.Object, actual);
}
[Fact]
public void GetHandlerSorter_ReturnsSingletonInstance()
{
// Act
IWebHookHandlerSorter actual1 = ReceiverServices.GetHandlerSorter();
IWebHookHandlerSorter actual2 = ReceiverServices.GetHandlerSorter();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetReceivers_ReturnsSingletonInstance()
{
// Act
IEnumerable<IWebHookReceiver> actual1 = ReceiverServices.GetReceivers();
IEnumerable<IWebHookReceiver> actual2 = ReceiverServices.GetReceivers();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetHandlers_ReturnsSingleInstance()
{
// Act
IEnumerable<IWebHookHandler> actual1 = ReceiverServices.GetHandlers();
IEnumerable<IWebHookHandler> actual2 = ReceiverServices.GetHandlers();
// Assert
Assert.Same(actual1, actual2);
}
}
}
// 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.Collections.Generic;
using System.Web.Http;
using Microsoft.AspNet.WebHooks.Config;
using Microsoft.AspNet.WebHooks.Diagnostics;
using Moq;
using Xunit;
namespace Microsoft.AspNet.WebHooks.Services
{
[Collection("ConfigCollection")]
public class ReceiverServicesTests
{
public ReceiverServicesTests()
{
HttpConfiguration config = new HttpConfiguration();
WebHooksConfig.Initialize(config);
ReceiverServices.Reset();
}
[Fact]
public void GetReceiverManager_ReturnsSingleInstance()
{
// Arrange
ILogger logger = CommonServices.GetLogger();
List<IWebHookReceiver> receivers = new List<IWebHookReceiver>();
// Act
IWebHookReceiverManager actual1 = ReceiverServices.GetReceiverManager(receivers, logger);
IWebHookReceiverManager actual2 = ReceiverServices.GetReceiverManager(receivers, logger);
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetReceiverConfig_ReturnsSingleInstance()
{
// Arrange
SettingsDictionary settings = CommonServices.GetSettings();
ILogger logger = CommonServices.GetLogger();
// Act
IWebHookReceiverConfig actual1 = ReceiverServices.GetReceiverConfig(settings, logger);
IWebHookReceiverConfig actual2 = ReceiverServices.GetReceiverConfig(settings, logger);
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void SetReceiverConfig_GetReceiverConfig_Roundtrips()
{
// Arrange
SettingsDictionary settings = CommonServices.GetSettings();
ILogger logger = CommonServices.GetLogger();
Mock<IWebHookReceiverConfig> configMock = new Mock<IWebHookReceiverConfig>();
// Act
ReceiverServices.SetReceiverConfig(configMock.Object);
IWebHookReceiverConfig actual = ReceiverServices.GetReceiverConfig(settings, logger);
// Assert
Assert.Same(configMock.Object, actual);
}
[Fact]
public void GetHandlerSorter_ReturnsSingletonInstance()
{
// Act
IWebHookHandlerSorter actual1 = ReceiverServices.GetHandlerSorter();
IWebHookHandlerSorter actual2 = ReceiverServices.GetHandlerSorter();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetReceivers_ReturnsSingletonInstance()
{
// Act
IEnumerable<IWebHookReceiver> actual1 = ReceiverServices.GetReceivers();
IEnumerable<IWebHookReceiver> actual2 = ReceiverServices.GetReceivers();
// Assert
Assert.Same(actual1, actual2);
}
[Fact]
public void GetHandlers_ReturnsSingleInstance()
{
// Act
IEnumerable<IWebHookHandler> actual1 = ReceiverServices.GetHandlers();
IEnumerable<IWebHookHandler> actual2 = ReceiverServices.GetHandlers();
// Assert
Assert.Same(actual1, actual2);
}
}
}