Remove ASP.NET Core WebHooks code and infrastructure

- part of aspnet/WebHooks#228
- all deletions except removing content of root Directory.Build.* files
- leave WebHooks.sln because it's used in `GetDirectoryNameOfFileAbove(...)`
This commit is contained in:
Doug Bunting 2018-01-19 08:29:44 -08:00
Родитель f702a66575
Коммит f3d20f8c76
254 изменённых файлов: 3 добавлений и 17141 удалений

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

@ -1,61 +1,3 @@
<Project>
<!-- Imported only from .NET Core and .NET Standard projects. See conditions in lower-level Directory.Build.props files -->
<Import Project="version.props" />
<!-- Ensure changes to this file and version.props cause project rebuilds. -->
<PropertyGroup>
<RepositoryRoot Condition=" '$(RepositoryRoot)' == '' ">$([System.IO.Path]::GetFullPath( '$(MSBuildThisFileDirectory)' ))</RepositoryRoot>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<MSBuildAllProjects>$(MSBuildAllProjects);$(RepositoryRoot)version.props</MSBuildAllProjects>
</PropertyGroup>
<!-- Common package options. -->
<PropertyGroup>
<Authors>Microsoft</Authors>
<Company>Microsoft Corporation.</Company>
<Copyright>Copyright © Microsoft Corporation</Copyright>
<IncludeSource>true</IncludeSource>
<IncludeSymbols>true</IncludeSymbols>
<!-- Work around https://github.com/NuGet/Home/issues/4726 -->
<IncludeSymbols Condition=" '$(NuspecFile)' != '' ">false</IncludeSymbols>
<LangVersion>7.1</LangVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<NoPackageAnalysis>true</NoPackageAnalysis>
<PackageIconUrl>https://go.microsoft.com/fwlink/?LinkID=288859</PackageIconUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/aspnet/Home/2.0.0/LICENSE.txt</PackageLicenseUrl>
<PackageProjectUrl>https://asp.net</PackageProjectUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>
<!-- Default $(AssemblyRevision) when manually building an individual project. -->
<PropertyGroup>
<_TwoDigitYear>$([MSBuild]::Subtract($([System.DateTime]::UtcNow.Year), 2000))</_TwoDigitYear>
<_ThreeDigitDayOfYear>$([System.DateTime]::UtcNow.DayOfYear.ToString().PadLeft(3, '0'))</_ThreeDigitDayOfYear>
<AssemblyRevision Condition=" '$(AssemblyRevision)' == '' ">$(_TwoDigitYear)$(_ThreeDigitDayOfYear)</AssemblyRevision>
</PropertyGroup>
<!-- Additional specifics of this repository. -->
<PropertyGroup>
<Product>Microsoft ASP.NET Core WebHooks</Product>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/aspnet/WebHooks</RepositoryUrl>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyOriginatorKeyFile>$(RepositoryRoot)tools\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<SignAssembly>true</SignAssembly>
<!-- Must delay-sign the assemblies because 35MSSharedLib1024.snk contains no private key. -->
<DelaySign>true</DelaySign>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>BuildNumber</_Parameter1>
<_Parameter2>$(BuildNumber)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
<Project>
<!-- Stop MsBuild searching parent directories for this file. -->
</Project>

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

@ -1,28 +1,3 @@
<Project>
<!-- Will also stop MsBuild searching parent directories for this file. -->
<!-- $(Configuration) is not defined until after Directory.Build.props runs. -->
<PropertyGroup Condition="$(_ImportParentFile)">
<!-- Update $(PackageOutputPath) only if it has a default value. Users can override this e.g. on command line. -->
<PackageOutputPath Condition=" '$(PackageOutputPath)' == '$(BaseOutputPath)$(Configuration)\' ">
$(RepositoryRoot)bin\$(Configuration)\
</PackageOutputPath>
<PackageOutputPath Condition=" '$(PackageOutputPath)' == '$(BaseOutputPath)$(PlatformName)\$(Configuration)\' ">
$(RepositoryRoot)bin\$(PlatformName)\$(Configuration)\
</PackageOutputPath>
</PropertyGroup>
<!-- Default items are added after Directory.Build.props runs, causing invalid duplicate entries. -->
<ItemGroup Condition="$(_ImportParentFile) AND Exists( '$(MSBuildProjectDirectory)\Properties\Resources.resx' )">
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<!-- Stop MsBuild searching parent directories for this file. -->
</Project>

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

@ -1,5 +0,0 @@
{
"sdk": {
"version": "2.0.0"
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.AzureAlert\Microsoft.AspNetCore.WebHooks.Receivers.AzureAlert.csproj" />
</ItemGroup>
</Project>

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

@ -1,48 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
namespace AzureAlertCoreReceiver.Controllers
{
public class AzureAlertController : ControllerBase
{
[AzureAlertWebHook(Id = "It")]
public IActionResult AzureAlertForIt(string @event, AzureAlertNotification data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Get the notification status
var status = data.Status;
// Get the notification name
var name = data.Context.Name;
// Get the name of the metric that caused the event
var author = data.Context.Condition.MetricName;
return Ok();
}
[AzureAlertWebHook]
public IActionResult AzureAlert(string id, string @event, AzureAlertNotification data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Get the notification status
var status = data.Status;
// Get the notification name
var name = data.Context.Name;
// Get the name of the metric that caused the event
var author = data.Context.Condition.MetricName;
return Ok();
}
}
}

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace AzureAlertCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace AzureAlertCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddAzureAlertWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.BitBucket\Microsoft.AspNetCore.WebHooks.Receivers.BitBucket.csproj" />
</ItemGroup>
</Project>

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

@ -1,82 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace BitbucketCoreReceiver.Controllers
{
public class BitbucketController : ControllerBase
{
private readonly ILogger _logger;
public BitbucketController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<BitbucketController>();
}
[BitbucketWebHook(Id = "It")]
public IActionResult BitbucketForIt(string @event, string webHookId, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
0,
"{ControllerName} received '{EventName}' for '{Id}' and '{WebHookId}'.",
nameof(BitbucketController),
@event,
"It",
webHookId);
return Ok();
}
[BitbucketWebHook(EventName = "repo:push")]
public IActionResult BitbucketForPush(string id, string webHookId, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Extract information about the repository
var repository = data["repository"].ToObject<BitbucketRepository>();
// Information about the user causing the event
var actor = data["actor"].ToObject<BitbucketUser>();
// Information about the specific changes
foreach (var change in data["push"]["changes"])
{
// The previous commit
var oldTarget = change["old"]["target"].ToObject<BitbucketTarget>();
// The new commit
var newTarget = change["new"]["target"].ToObject<BitbucketTarget>();
}
return Ok();
}
[BitbucketWebHook]
public IActionResult Bitbucket(string id, string @event, string webHookId, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
1,
"{ControllerName} received '{EventName}' for '{Id}' and '{WebHookId}'.",
nameof(BitbucketController),
@event,
id,
webHookId);
return Ok();
}
}
}

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace BitbucketCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace BitbucketCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddBitbucketWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"BitbucketCoreReceiver": "Information",
"Default": "Warning",
"Microsoft": "Information"
}
}
}
}

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

@ -1,25 +0,0 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace BitbucketStronglyTypedCoreReceiver
{
/// <summary>
/// Contains information sent about an individual change in a Bitbucket <c>repo:push</c> notification. Ignores
/// information such as links found at this level in the notification as well as a few <see cref="bool"/>
/// properties.
/// </summary>
public class BitbucketChange
{
[JsonProperty("old")]
public BitbucketState Old { get; set; }
[JsonProperty("new")]
public BitbucketState New { get; set; }
[JsonProperty("commits", Required = Required.Always)]
public IList<BitbucketCommit> Commits { get; } = new List<BitbucketCommit>();
[JsonProperty("truncated", Required = Required.Always)]
public bool AreCommitsTruncated { get; set; }
}
}

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

@ -1,24 +0,0 @@
using Microsoft.AspNetCore.WebHooks;
using Newtonsoft.Json;
namespace BitbucketStronglyTypedCoreReceiver
{
/// <summary>
/// Contains information sent about an individual commit in a Bitbucket <c>repo:push</c> notification. Ignores
/// information such as links found at this level in the notification.
/// </summary>
public class BitbucketCommit
{
[JsonProperty("author", Required = Required.Always)]
public BitbucketUser Author { get; set; }
[JsonProperty("message", Required = Required.Always)]
public string Message { get; set; }
[JsonProperty("hash", Required = Required.Always)]
public string Sha1Hash { get; set; }
[JsonProperty("type", Required = Required.Always)]
public string Type { get; set; }
}
}

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

@ -1,16 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace BitbucketStronglyTypedCoreReceiver
{
/// <summary>
/// Contains information sent about the push in a Bitbucket WebHook <c>repo:push</c> notification.
/// </summary>
public class BitbucketPush
{
[JsonProperty("changes", Required = Required.Always)]
[MinLength(1)]
public IList<BitbucketChange> Changes { get; } = new List<BitbucketChange>();
}
}

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

@ -1,20 +0,0 @@
using Microsoft.AspNetCore.WebHooks;
using Newtonsoft.Json;
namespace BitbucketStronglyTypedCoreReceiver
{
/// <summary>
/// Contains information sent in a Bitbucket WebHook <c>repo:push</c> notification.
/// </summary>
public class BitbucketPushNotification
{
[JsonProperty("actor", Required = Required.Always)]
public BitbucketUser Actor { get; set; }
[JsonProperty("repository", Required = Required.Always)]
public BitbucketRepository Repository { get; set; }
[JsonProperty("push", Required = Required.Always)]
public BitbucketPush Push { get; set; }
}
}

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

@ -1,21 +0,0 @@
using Microsoft.AspNetCore.WebHooks;
using Newtonsoft.Json;
namespace BitbucketStronglyTypedCoreReceiver
{
/// <summary>
/// Contains information sent about the <c>old</c> or <c>new</c> state of an individual change in a Bitbucket
/// <c>repo:push</c> notification. Ignores information such as links found at this level in the notification.
/// </summary>
public class BitbucketState
{
[JsonProperty("type", Required = Required.Always)]
public string Type { get; set; }
[JsonProperty("name", Required = Required.Always)]
public string Name { get; set; }
[JsonProperty("target", Required = Required.Always)]
public BitbucketTarget Target { get; set; }
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.BitBucket\Microsoft.AspNetCore.WebHooks.Receivers.BitBucket.csproj" />
</ItemGroup>
</Project>

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

@ -1,82 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace BitbucketStronglyTypedCoreReceiver.Controllers
{
public class BitbucketController : ControllerBase
{
private readonly ILogger _logger;
public BitbucketController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<BitbucketController>();
}
[BitbucketWebHook(Id = "It")]
public IActionResult BitbucketForIt(string @event, string webHookId, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
0,
"{ControllerName} received '{EventName}' for '{Id}' and '{WebHookId}'.",
nameof(BitbucketController),
@event,
"It",
webHookId);
return Ok();
}
[BitbucketWebHook(EventName = "repo:push")]
public IActionResult BitbucketForPush(string id, string webHookId, BitbucketPushNotification data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Extract information about the repository
var repository = data.Repository;
// Information about the user causing the event
var actor = data.Actor;
// Information about the specific changes
foreach (var change in data.Push.Changes)
{
// The previous commit
var oldTarget = change.Old.Target;
// The new commit
var newTarget = change.New.Target;
}
return Ok();
}
[BitbucketWebHook]
public IActionResult Bitbucket(string id, string @event, string webHookId, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
1,
"{ControllerName} received '{EventName}' for '{Id}' and '{WebHookId}'.",
nameof(BitbucketController),
@event,
id,
webHookId);
return Ok();
}
}
}

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace BitbucketStronglyTypedCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace BitbucketStronglyTypedCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddBitbucketWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"BitbucketStronglyTypedCoreReceiver": "Information",
"Default": "Warning",
"Microsoft": "Information"
}
}
}
}

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

@ -1,12 +0,0 @@
<Project>
<PropertyGroup>
<_ImportParentFile>false</_ImportParentFile>
<_ImportParentFile Condition="$(MSBuildProjectName.EndsWith( 'CoreReceiver' ))">true</_ImportParentFile>
</PropertyGroup>
<Import Project="..\Directory.Build.props" Condition="$(_ImportParentFile)" />
<PropertyGroup Condition="$(_ImportParentFile)">
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>

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

@ -1,31 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Newtonsoft.Json.Linq;
namespace DropboxCoreReceiver.Controllers
{
public class DropboxController : ControllerBase
{
[DropboxWebHook(Id = "It")]
public IActionResult DropboxForIt(JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
[DropboxWebHook]
public IActionResult Dropbox(string id, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.Dropbox\Microsoft.AspNetCore.WebHooks.Receivers.Dropbox.csproj" />
</ItemGroup>
</Project>

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace DropboxCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace DropboxCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddDropboxWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,53 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace DynamicsCRMCoreReceiver.Controllers
{
public class DynamicsCRMController : ControllerBase
{
private readonly ILogger _logger;
public DynamicsCRMController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<DynamicsCRMController>();
}
[DynamicsCRMWebHook(Id = "It")]
public IActionResult DynamicsCRMForIt(string @event, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
0,
"{ControllerName} received '{MessageName}' for '{Id}'.",
nameof(DynamicsCRMController),
@event,
"It");
return Ok();
}
[DynamicsCRMWebHook]
public IActionResult DynamicsCRM(string id, string @event, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
1,
"{ControllerName} received '{MessageName}' for '{Id}'.",
nameof(DynamicsCRMController),
@event,
id);
return Ok();
}
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.DynamicsCRM\Microsoft.AspNetCore.WebHooks.Receivers.DynamicsCRM.csproj" />
</ItemGroup>
</Project>

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace DynamicsCRMCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace DynamicsCRMCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddDynamicsCRMWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"DynamicsCRMCoreReceiver": "Information",
"Default": "Warning",
"Microsoft": "Information"
}
}
}
}

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

@ -1,64 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Newtonsoft.Json.Linq;
namespace GitHubCoreReceiver.Controllers
{
public class GitHubController : ControllerBase
{
[GitHubWebHook(EventName = "push", Id = "It")]
public IActionResult HandlerForItsPushes(string[] events, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
[GitHubWebHook(Id = "It")]
public IActionResult HandlerForIt(string[] events, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
[GitHubWebHook(EventName = "push")]
public IActionResult HandlerForPush(string id, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
[GitHubWebHook]
public IActionResult GitHubHandler(string id, string @event, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
[GeneralWebHook]
public IActionResult FallbackHandler(string receiverName, string id, string eventName, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.GitHub\Microsoft.AspNetCore.WebHooks.Receivers.GitHub.csproj" />
</ItemGroup>
</Project>

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace GitHubCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace GitHubCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddGitHubWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,42 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
namespace KuduCoreReceiver.Controllers
{
public class KuduController : ControllerBase
{
[KuduWebHook(Id = "It")]
public IActionResult KuduForIt(string @event, KuduNotification data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Get the notification message
var message = data.Message;
// Get the notification author
var author = data.Author;
return Ok();
}
[KuduWebHook]
public IActionResult Kudu(string id, string @event, KuduNotification data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Get the notification message
var message = data.Message;
// Get the notification author
var author = data.Author;
return Ok();
}
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.Kudu\Microsoft.AspNetCore.WebHooks.Receivers.Kudu.csproj" />
</ItemGroup>
</Project>

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace KuduCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace KuduCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddKuduWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,31 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
namespace MailChimpCoreReceiver.Controllers
{
public class MailChimpController : ControllerBase
{
[MailChimpWebHook(Id = "It")]
public IActionResult MailChimpForIt(string @event, IFormCollection data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
[MailChimpWebHook]
public IActionResult MailChimp(string id, string @event, IFormCollection data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.MailChimp\Microsoft.AspNetCore.WebHooks.Receivers.MailChimp.csproj" />
</ItemGroup>
</Project>

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace MailChimpCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace MailChimpCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddMailChimpWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,164 +0,0 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace PusherCoreReceiver.Controllers
{
public class PusherController : ControllerBase
{
private readonly ILogger _logger;
public PusherController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<PusherController>();
}
[PusherWebHook(Id = "It")]
public IActionResult PusherForIt(string[] eventNames, PusherNotifications data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Get the notification creation timestamp.
var createdAtUnix = data.CreatedAt;
var createdAt = DateTimeOffset.FromUnixTimeMilliseconds(createdAtUnix);
_logger.LogInformation(
0,
"{ControllerName} received {Count} notifications and {EventCount} events created at '{CreatedAt}'.",
nameof(PusherController),
data.Events.Count,
eventNames.Length,
createdAt.ToString("o"));
for (var i = 0; i < eventNames.Length; i++)
{
_logger.LogInformation(
1,
"Event {Index} was '{EventName}'.",
i,
eventNames[i]);
}
// Get details of the individual notifications.
var index = 0;
foreach (var @event in data.Events)
{
if (@event.TryGetValue(PusherConstants.EventNamePropertyName, out var eventName))
{
if (@event.TryGetValue(PusherConstants.ChannelNamePropertyName, out var channelName))
{
_logger.LogInformation(
2,
"Event {EventNumber} has {Count} properties, including name '{EventName}' and channel " +
"'{ChannelName}'.",
index,
@event.Count,
eventName,
channelName);
}
else
{
_logger.LogInformation(
3,
"Event {EventNumber} has {Count} properties, including name '{EventName}'.",
index,
@event.Count,
eventName);
}
}
else
{
_logger.LogError(
4,
"Event {EventNumber} has {Count} properties but does not contain a {PropertyName} property.",
index,
@event.Count,
PusherConstants.EventNamePropertyName);
}
index++;
}
return Ok();
}
[PusherWebHook]
public IActionResult Pusher(string id, string[] eventNames, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Get the notification creation timestamp.
var createdAtUnix = data.Value<long>(PusherConstants.EventRequestCreatedAtPropertyName);
var createdAt = DateTimeOffset.FromUnixTimeMilliseconds(createdAtUnix);
var events = data.Value<JArray>(PusherConstants.EventRequestPropertyContainerName);
_logger.LogInformation(
5,
"{ControllerName} / '{Id}' received {Count} notifications and {EventCount} events created at " +
"'{CreatedAt}'.",
nameof(PusherController),
id,
events.Count,
eventNames.Length,
createdAt.ToString("o"));
for (var i = 0; i < eventNames.Length; i++)
{
_logger.LogInformation(
6,
"Event {Index} was '{EventName}'.",
i,
eventNames[i]);
}
// Get details of the individual notifications.
var eventEnumerable = events.Values<JObject>();
var index = 0;
foreach (var @event in eventEnumerable)
{
var eventName = @event.Value<string>(PusherConstants.EventNamePropertyName);
if (!string.IsNullOrEmpty(eventName))
{
var channelName = @event.Value<string>(PusherConstants.EventNamePropertyName);
if (!string.IsNullOrEmpty(channelName))
{
_logger.LogInformation(
7,
"Event {EventNumber} has {Count} properties, including name '{EventName}' and channel " +
"'{ChannelName}'.",
index,
@event.Count,
eventName,
channelName);
}
else
{
_logger.LogInformation(
8,
"Event {EventNumber} has {Count} properties, including name '{EventName}'.",
index,
@event.Count,
eventName);
}
}
else
{
_logger.LogError(
9,
"Event {EventNumber} has {Count} properties but does not contain a {PropertyName} property.",
index,
@event.Count,
PusherConstants.EventNamePropertyName);
}
index++;
}
return Ok();
}
}
}

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace PusherCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.Pusher\Microsoft.AspNetCore.WebHooks.Receivers.Pusher.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="wwwroot\index.html" />
<Content Update="wwwroot\index.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

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

@ -1,32 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace PusherCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddPusherWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app
.UseDefaultFiles()
.UseStaticFiles()
.UseMvc();
}
}
}

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

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"PusherCoreReceiver": "Information",
"Default": "Warning",
"Microsoft": "Information"
}
}
}
}

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

@ -1,25 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Microsoft ASP.NET Core Pusher WebHooks receiver sample</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Microsoft ASP.NET Core Pusher WebHooks receiver sample</h1>
<p>
This sample illustrates how to wire up a Pusher WebHooks receiver. A sample WebHook URI is:
<code>https://{host}/api/webhooks/incoming/pusher/{id}</code>
</p>
<p>
Set <code>WebHooks:Pusher:SecretKey:{id}:{application key}</code> configuration values to the corresponding
secret keys. That is, match the Pusher application key / secret key pairs and optionally use IDs to
differentiate between multiple WebHooks.
</p>
<p>
Please see <a href="https://pusher.com/docs/webhooks">Pusher WebHooks</a> for more information.
</p>
</body>
</html>

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

@ -1,74 +0,0 @@
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Microsoft.Extensions.Logging;
namespace SalesforceCoreReceiver.Controllers
{
public class SalesforceController : ControllerBase
{
private readonly ILogger _logger;
private readonly ISalesforceResultCreator _resultCreator;
public SalesforceController(ILoggerFactory loggerFactory, ISalesforceResultCreator resultCreator)
{
_logger = loggerFactory.CreateLogger<SalesforceController>();
_resultCreator = resultCreator;
}
[SalesforceWebHook(Id = "It")]
public async Task<IActionResult> SalesforceForIt(string @event, XElement data)
{
if (!ModelState.IsValid)
{
return await _resultCreator.GetFailedResultAsync("Model binding failed.");
}
return await _resultCreator.GetSuccessResultAsync();
}
[SalesforceWebHook]
public async Task<IActionResult> Salesforce(string id, string @event, SalesforceNotifications data)
{
if (!ModelState.IsValid)
{
return await _resultCreator.GetFailedResultAsync("Model binding failed.");
}
_logger.LogInformation(
0,
"{ControllerName} / '{ReceiverId}' received {Count} notifications with ActionId '{ActionId}' (event " +
"'{EventName}').",
nameof(SalesforceController),
id,
data.Notifications.Count(),
data.ActionId,
@event);
_logger.LogInformation(
1,
"Data contains OrganizationId '{OrganizationId}' and SessionId '{SessionId}'.",
data.OrganizationId,
data.SessionId);
_logger.LogInformation(
2,
"Contained URLs include EnterpriseUrl '{EnterpriseUrl}' and PartnerUrl '{PartnerUrl}'.",
data.EnterpriseUrl,
data.PartnerUrl);
var index = 0;
foreach (var notification in data.Notifications)
{
_logger.LogInformation(
3,
"Notification #{Number} contained {Count} values.",
index,
notification.Count);
index++;
}
return await _resultCreator.GetSuccessResultAsync();
}
}
}

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace SalesforceCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.Salesforce\Microsoft.AspNetCore.WebHooks.Receivers.Salesforce.csproj" />
</ItemGroup>
</Project>

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace SalesforceCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddSalesforceWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"SalesforceCoreReceiver": "Information",
"Default": "Warning",
"Microsoft": "Information"
}
}
}
}

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

@ -1,163 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Microsoft.Extensions.Logging;
namespace SlackCoreReceiver.Controllers
{
public class SlackController : ControllerBase
{
private readonly ILogger _logger;
public SlackController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<SlackController>();
}
[SlackWebHook(Id = "command")]
public IActionResult SlackForCommand(string @event, string subtext, IFormCollection data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
0,
"{ControllerName} / '{ReceiverId}' received {Count} properties with event '{EventName}').",
nameof(SlackController),
"command",
data.Count,
@event);
string channel = data[SlackConstants.ChannelRequestFieldName];
string command = data[SlackConstants.CommandRequestFieldName];
string trigger = data[SlackConstants.TriggerRequestFieldName];
_logger.LogInformation(
1,
"Data contains channel '{ChannelName}', command '{Command}', and trigger '{Trigger}'.",
channel,
command,
trigger);
string text = data[SlackConstants.TextRequestFieldName];
_logger.LogInformation(
2,
"Data contains text '{Text}' and subtext '{Subtext}'.",
text,
subtext);
var slashCommand = SlackCommand.ParseActionWithValue(command);
// Ignore an error parsing the remainder of the command except to keep that action value together.
var actionValue = slashCommand.Value;
var actionValueName = "value";
var (parameters, error) = SlackCommand.ParseParameters(slashCommand.Value);
if (error == null)
{
actionValue = SlackCommand.GetNormalizedParameterString(parameters);
actionValueName = "parameters";
}
// Create the response.
var reply = $"Received slash command '{command}' with action '{slashCommand.Key}' and {actionValueName} " +
$"'{actionValue}'.";
// Slash responses can be augmented with attachments containing data, images, and more.
var attachment = new SlackAttachment("Attachment Text", "Fallback description")
{
Color = "#439FE0",
Pretext = "Hello from ASP.NET WebHooks!",
Title = "Attachment title",
};
// Slash attachments can contain tabular data as well
attachment.Fields.Add(new SlackField("Field1", "1234"));
attachment.Fields.Add(new SlackField("Field2", "5678"));
return new JsonResult(new SlackSlashResponse(reply, attachment));
}
[SlackWebHook(Id = "trigger")]
public IActionResult SlackForTrigger(string @event, string subtext, IFormCollection data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
3,
"{ControllerName} / '{ReceiverId}' received {Count} properties with event '{EventName}').",
nameof(SlackController),
"trigger",
data.Count,
@event);
var channel = data[SlackConstants.ChannelRequestFieldName];
var command = data[SlackConstants.CommandRequestFieldName];
var trigger = data[SlackConstants.TriggerRequestFieldName];
_logger.LogInformation(
4,
"Data contains channel '{ChannelName}', command '{Command}', and trigger '{Trigger}'.",
channel,
command,
trigger);
var text = data[SlackConstants.TextRequestFieldName];
_logger.LogInformation(
5,
"Data contains text '{Text}' and subtext '{Subtext}'.",
text,
subtext);
// Create the response.
var triggerCommand = SlackCommand.ParseActionWithValue(subtext);
// Information can be returned using a SlackResponse.
var reply = string.Format(
"Received trigger '{0}' with action '{1}' and value '{2}'",
trigger,
triggerCommand.Key,
triggerCommand.Value);
return new JsonResult(new SlackResponse(reply));
}
[SlackWebHook]
public IActionResult Slack(string id, string @event, string subtext, IFormCollection data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
6,
"{ControllerName} / '{ReceiverId}' received {Count} properties with event '{EventName}').",
nameof(SlackController),
id,
data.Count,
@event);
var channel = data[SlackConstants.ChannelRequestFieldName];
var command = data[SlackConstants.CommandRequestFieldName];
var trigger = data[SlackConstants.TriggerRequestFieldName];
_logger.LogInformation(
7,
"Data contains channel '{ChannelName}', command '{Command}', and trigger '{Trigger}'.",
channel,
command,
trigger);
var text = data[SlackConstants.TextRequestFieldName];
_logger.LogInformation(
8,
"Data contains text '{Text}' and subtext '{Subtext}'.",
text,
subtext);
return Ok();
}
}
}

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace SlackCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.Slack\Microsoft.AspNetCore.WebHooks.Receivers.Slack.csproj" />
</ItemGroup>
</Project>

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

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace SlackCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddSlackWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}

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

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"SlackCoreReceiver": "Information",
"Default": "Warning",
"Microsoft": "Information"
}
}
}
}

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

@ -1,72 +0,0 @@
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
namespace StripeCoreReceiver.Controllers
{
public class StripeController : ControllerBase
{
private readonly ILogger _logger;
public StripeController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<StripeController>();
}
[StripeWebHook(Id = "It")]
public IActionResult StripeForIt(string @event, string notificationId, JObject data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
return Ok();
}
[StripeWebHook]
public IActionResult Stripe(string id, string @event, string notificationId, StripeEvent data)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation(
0,
"{ControllerName} / '{ReceiverId}' received a '{EventType}' notification (event '{EventName}').",
nameof(StripeController),
id,
data.EventType,
@event);
_logger.LogInformation(
1,
"Data created at '{Created}' and contains Notification ID '{Id}' / '{NotificationId}', Live mode " +
"'{DetailsLiveMode}', and Request ID '{RequestId}'.",
data.Created,
data.Id,
notificationId,
data.LiveMode,
data.Request);
var details = data.Data.Object;
var created = DateTimeOffset.FromUnixTimeMilliseconds(
details.Value<long>(StripeConstants.CreatedPropertyName));
_logger.LogInformation(
2,
"Event detail created at '{DetailsCreated}' and contains {PropertyCount} properties, including " +
"Account '{Account}', Id '{DetailsId}', Live mode '{DetailsLiveMode}', and Name '{Name}'.",
created,
details.Count,
details.Value<string>("account"),
details.Value<string>("id"),
details.Value<string>(StripeConstants.LiveModePropertyName),
details.Value<string>("name"));
return Ok();
}
}
}

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

@ -1,18 +0,0 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace StripeCoreReceiver
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

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

@ -1,24 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace StripeCoreReceiver
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvcCore()
.AddStripeWebHooks();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc();
}
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.WebHooks.Receivers.Stripe\Microsoft.AspNetCore.WebHooks.Receivers.Stripe.csproj" />
</ItemGroup>
</Project>

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

@ -1,15 +0,0 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"StripeCoreReceiver": "Information",
"Default": "Warning",
"Microsoft": "Information"
}
}
}
}

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

@ -1,22 +0,0 @@
<Project>
<PropertyGroup>
<_ImportParentFile>false</_ImportParentFile>
<_ImportParentFile Condition="$(MSBuildProjectName.StartsWith( 'Microsoft.AspNetCore.' ))">true</_ImportParentFile>
</PropertyGroup>
<Import Project="..\Directory.Build.props" Condition="$(_ImportParentFile)" />
<PropertyGroup Condition="$(_ImportParentFile)">
<DefineConstants>$(DefineConstants);ASPNETWEBHOOKS</DefineConstants>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>Microsoft.AspNetCore.WebHooks</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup Condition="$(_ImportParentFile)">
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>Serviceable</_Parameter1>
<_Parameter2>True</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Project>

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

@ -1,73 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Provides information about the condition under which the WebHook notification was sent from Azure Alert Service.
/// </summary>
public class AzureAlertCondition
{
/// <summary>
/// Gets or sets the name of the metric that defines what the rule monitors.
/// </summary>
[JsonProperty("metricName")]
public string MetricName { get; set; }
/// <summary>
/// Gets or sets the units allowed in the metric, e.g. 'Bytes' and 'Percent'.
/// See '<c>https://msdn.microsoft.com/en-us/library/microsoft.azure.insights.models.unit.aspx</c>'
/// for details.
/// </summary>
[JsonProperty("metricUnit")]
public string MetricUnit { get; set; }
/// <summary>
/// Gets or sets the actual value of the metric that caused the event.
/// </summary>
[JsonProperty("metricValue")]
public string MetricValue { get; set; }
/// <summary>
/// Gets or sets the threshold value that activates the event.
/// </summary>
[JsonProperty("threshold")]
public string Threshold { get; set; }
/// <summary>
/// Gets or sets the period of time that is used to monitor alert activity based on
/// the threshold. The value is between 5 minutes and 1 day.
/// </summary>
[JsonProperty("windowSize")]
public string WindowSize { get; set; }
/// <summary>
/// Gets or sets how the data is collection, e.g. 'Average' and 'Last'.
/// See '<c>https://msdn.microsoft.com/en-us/library/microsoft.azure.insights.models.aggregationtype.aspx</c>' for details.
/// </summary>
[JsonProperty("timeAggregation")]
public string TimeAggregation { get; set; }
/// <summary>
/// Gets or sets the operator used to compare the data and the threshold.
/// </summary>
[JsonProperty("operator")]
public string Operator { get; set; }
/// <summary>
/// Gets or sets details of an Availability (Web Test) failure.
/// </summary>
/// <remarks>Set in Availability (Web Test) alerts but not Metric alerts.</remarks>
[JsonProperty("failureDetails")]
public string FailureDetails { get; set; }
/// <summary>
/// Gets or sets the name of an Availability (Web Test) alert.
/// </summary>
/// <remarks>Set in Availability (Web Test) alerts but not Metric alerts.</remarks>
[JsonProperty("webTestName")]
public string WebTestName { get; set; }
}
}

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

@ -1,22 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Well-known names used in Azure Alert receivers and handlers.
/// </summary>
public static class AzureAlertConstants
{
/// <summary>
/// Gets the JSON path of the property in an Azure Alert WebHook request body containing the Azure Alert event
/// name. Matches the Application Insights rule name.
/// </summary>
public static string EventBodyPropertyPath => "$['context']['name']";
/// <summary>
/// Gets the name of the Azure Alert WebHook receiver.
/// </summary>
public static string ReceiverName => "azurealert";
}
}

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

@ -1,94 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Provides context information for a WebHook notification sent from Azure Alert Service.
/// </summary>
public class AzureAlertContext
{
/// <summary>
/// Gets or sets the unique ID for this alert.
/// </summary>
[JsonProperty("id", Required = Required.Always)]
public string Id { get; set; }
/// <summary>
/// Gets or sets the name of the alert.
/// </summary>
[JsonProperty("name", Required = Required.Always)]
public string Name { get; set; }
/// <summary>
/// Gets or sets the description of the alert.
/// </summary>
[JsonProperty("description", Required = Required.Always)]
public string Description { get; set; }
/// <summary>
/// Gets or sets the condition type, e.g. '<c>Metric</c>' or '<c>Event</c>'.
/// </summary>
[JsonProperty("conditionType", Required = Required.Always)]
public string ConditionType { get; set; }
/// <summary>
/// Gets or sets the Azure subscription ID.
/// </summary>
[JsonProperty("subscriptionId", Required = Required.Always)]
public string SubscriptionId { get; set; }
/// <summary>
/// Gets or sets the time at which the alert was triggered. The alert is triggered as soon as
/// the metric is read from the diagnostics storage.
/// </summary>
[JsonProperty("timestamp", Required = Required.Always)]
public DateTime Timestamp { get; set; }
/// <summary>
/// Gets or sets information about the condition causing the event.
/// </summary>
[JsonProperty("condition", Required = Required.Always)]
public AzureAlertCondition Condition { get; set; }
/// <summary>
/// Gets or sets the resource group name of the impacted resource causing the alert.
/// </summary>
[JsonProperty("resourceGroupName", Required = Required.Always)]
public string ResourceGroupName { get; set; }
/// <summary>
/// Gets or sets the name of the resource causing the alert.
/// </summary>
[JsonProperty("resourceName", Required = Required.Always)]
public string ResourceName { get; set; }
/// <summary>
/// Gets or sets the type of the impacted resource.
/// </summary>
[JsonProperty("resourceType", Required = Required.Always)]
public string ResourceType { get; set; }
/// <summary>
/// Gets or sets the ID of the resource.
/// </summary>
[JsonProperty("resourceId", Required = Required.Always)]
public string ResourceId { get; set; }
/// <summary>
/// Gets or sets the geographic location of the resource.
/// </summary>
/// <remarks>Set in Metric alerts but not Availability (Web Test) alerts.</remarks>
[JsonProperty("resourceRegion")]
public string ResourceRegion { get; set; }
/// <summary>
/// Gets or sets a direct link to the resource summary page on the Azure portal.
/// </summary>
[JsonProperty("portalLink", Required = Required.Always)]
public string PortalLink { get; set; }
}
}

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

@ -1,38 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Contains information sent in a WebHook notification from Azure Alert Service.
/// </summary>
public class AzureAlertNotification
{
private readonly IDictionary<string, object> _properties = new Dictionary<string, object>();
/// <summary>
/// Gets or sets the kind of alert. Azure automatically sends activated and resolved alerts for the condition sets.
/// Examples of values include '<c>Activated</c>' and '<c>Resolved</c>'.
/// </summary>
[JsonProperty("status", Required = Required.Always)]
public string Status { get; set; }
/// <summary>
/// Gets or sets context information for this alert.
/// </summary>
[JsonProperty("context", Required = Required.Always)]
public AzureAlertContext Context { get; set; }
/// <summary>
/// Gets a collection of additional properties for this alert.
/// </summary>
[JsonProperty("properties")]
public IDictionary<string, object> Properties
{
get { return _properties; }
}
}
}

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

@ -1,51 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// <para>
/// An <see cref="System.Attribute"/> indicating the associated action is an Azure Alert WebHook endpoint.
/// Specifies the optional <see cref="WebHookAttribute.Id"/>. Also adds a
/// <see cref="Filters.WebHookReceiverExistsFilter"/> for the action.
/// </para>
/// <para>
/// The signature of the action should be:
/// <code>
/// Task{IActionResult} ActionName(string id, string @event, TData data)
/// </code>
/// or include the subset of parameters required. <c>TData</c> must be compatible with expected requests e.g.
/// <see cref="Newtonsoft.Json.Linq.JObject"/> or <see cref="AzureAlertNotification"/>.
/// </para>
/// <para>
/// An example Azure Alert WebHook URI is
/// '<c>https://{host}/api/webhooks/incoming/azurealert/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
/// See
/// <see href="https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts"/>
/// for additional details about Azure Alert WebHook requests.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// If the application enables CORS in general (see the <c>Microsoft.AspNetCore.Cors</c> package), apply
/// <c>DisableCorsAttribute</c> to this action. If the application depends on the
/// <c>Microsoft.AspNetCore.Mvc.ViewFeatures</c> package, apply <c>IgnoreAntiforgeryTokenAttribute</c> to this
/// action.
/// </para>
/// <para>
/// <see cref="AzureAlertWebHookAttribute"/> should be used at most once per <see cref="WebHookAttribute.Id"/> in a
/// WebHook application.
/// </para>
/// </remarks>
public class AzureAlertWebHookAttribute : WebHookAttribute
{
/// <summary>
/// Instantiates a new <see cref="AzureAlertWebHookAttribute"/> indicating the associated action is an Azure
/// Alert WebHook endpoint.
/// </summary>
public AzureAlertWebHookAttribute()
: base(AzureAlertConstants.ReceiverName)
{
}
}
}

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

@ -1,44 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for setting up Azure Alert WebHooks in an <see cref="IMvcBuilder" />.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class AzureAlertMvcBuilderExtensions
{
/// <summary>
/// <para>
/// Add Azure Alert WebHook configuration and services to the specified <paramref name="builder"/>. See
/// <see href="https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts"/>
/// for additional details about Azure Alert WebHook requests.
/// </para>
/// <para>
/// The '<c>WebHooks:AzureAlert:SecretKey:default</c>' configuration value contains the secret key for Azure
/// Alert WebHook URIs of the form '<c>https://{host}/api/webhooks/incoming/azurealert?code={secret key}</c>'.
/// '<c>WebHooks:AzureAlert:SecretKey:{id}</c>' configuration values contain secret keys for
/// Azure Alert WebHook URIs of the form
/// '<c>https://{host}/api/webhooks/incoming/azurealert/{id}?code={secret key}</c>'.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder" /> to configure.</param>
/// <returns>The <paramref name="builder"/>.</returns>
public static IMvcBuilder AddAzureAlertWebHooks(this IMvcBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
AzureAlertServiceCollectionSetup.AddAzureAlertServices(builder.Services);
return builder.AddWebHooks();
}
}
}

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

@ -1,46 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for setting up Azure Alert WebHooks in an <see cref="IMvcCoreBuilder" />.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class AzureAlertMvcCoreBuilderExtensions
{
/// <summary>
/// <para>
/// Add Azure Alert WebHook configuration and services to the specified <paramref name="builder"/>. See
/// <see href="https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts"/>
/// for additional details about Azure Alert WebHook requests.
/// </para>
/// <para>
/// The '<c>WebHooks:AzureAlert:SecretKey:default</c>' configuration value contains the secret key for Azure
/// Alert WebHook URIs of the form '<c>https://{host}/api/webhooks/incoming/azurealert?code={secret key}</c>'.
/// '<c>WebHooks:AzureAlert:SecretKey:{id}</c>' configuration values contain secret keys for
/// Azure Alert WebHook URIs of the form
/// '<c>https://{host}/api/webhooks/incoming/azurealert/{id}?code={secret key}</c>'.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder" /> to configure.</param>
/// <returns>The <paramref name="builder"/>.</returns>
public static IMvcCoreBuilder AddAzureAlertWebHooks(this IMvcCoreBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
AzureAlertServiceCollectionSetup.AddAzureAlertServices(builder.Services);
return builder
.AddJsonFormatters()
.AddWebHooks();
}
}
}

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

@ -1,30 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Metadata;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.AspNetCore.WebHooks.Internal
{
/// <summary>
/// Methods to add services for the Azure Alert receiver.
/// </summary>
public static class AzureAlertServiceCollectionSetup
{
/// <summary>
/// Add services for the Azure Alert receiver.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to update.</param>
public static void AddAzureAlertServices(IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.TryAddEnumerable(ServiceDescriptor.Singleton<IWebHookMetadata, AzureAlertMetadata>());
}
}
}

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

@ -1,36 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks.Metadata
{
/// <summary>
/// An <see cref="IWebHookMetadata"/> service containing metadata about the Azure Alert receiver.
/// </summary>
public class AzureAlertMetadata :
WebHookMetadata,
IWebHookBodyTypeMetadataService,
IWebHookEventFromBodyMetadata,
IWebHookVerifyCodeMetadata
{
/// <summary>
/// Instantiates a new <see cref="AzureAlertMetadata"/> instance.
/// </summary>
public AzureAlertMetadata()
: base(AzureAlertConstants.ReceiverName)
{
}
// IWebHookBodyTypeMetadataService...
/// <inheritdoc />
public WebHookBodyType BodyType => WebHookBodyType.Json;
// IWebHookEventFromBodyMetadata...
/// <inheritdoc />
public bool AllowMissing => false;
/// <inheritdoc />
public string BodyPropertyPath => AzureAlertConstants.EventBodyPropertyPath;
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<Description>ASP.NET Core Azure Alert WebHooks infrastructure. Contains the AzureAlertWebHookAttribute class and AddAzureAlertWebHooks method.</Description>
<PackageTags>aspnetcore;webhook;receiver;azurealert</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.0.0" />
<ProjectReference Include="..\Microsoft.AspNetCore.WebHooks.Receivers\Microsoft.AspNetCore.WebHooks.Receivers.csproj" />
</ItemGroup>
</Project>

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

@ -1,25 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Contains information about a Bitbucket author.
/// </summary>
public class BitbucketAuthor
{
/// <summary>
/// Gets or sets the Bitbucket user information for this author.
/// </summary>
[JsonProperty("user")]
public BitbucketUser User { get; set; }
/// <summary>
/// Gets or sets the raw author in the form of a name and email alias.
/// </summary>
[JsonProperty("raw")]
public string Raw { get; set; }
}
}

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

@ -1,37 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Well-known names used in Bitbucket receivers and handlers.
/// </summary>
public static class BitbucketConstants
{
/// <summary>
/// Gets the name of the header containing the Bitbucket event name e.g. <c>repo:push</c> or
/// <c>issue:created</c>.
/// </summary>
public static string EventHeaderName => "X-Event-Key";
/// <summary>
/// Gets the name of the Bitbucket WebHook receiver.
/// </summary>
public static string ReceiverName => "bitbucket";
/// <summary>
/// Gets the name of the header containing the Bitbucket WebHook UUID.
/// </summary>
public static string WebHookIdHeaderName => "X-Hook-UUID";
/// <summary>
/// Gets the name of one parameter bound to the <see cref="WebHookIdHeaderName"/> header.
/// </summary>
public static string WebHookIdParameterName1 => "webHookid";
/// <summary>
/// Gets the name of another parameter bound to the <see cref="WebHookIdHeaderName"/> header.
/// </summary>
public static string WebHookIdParameterName2 => "webHook_id";
}
}

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

@ -1,19 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Contains information about a link in Bitbucket.
/// </summary>
public class BitbucketLink
{
/// <summary>
/// Gets or sets the URI of the link.
/// </summary>
[JsonProperty("href")]
public string Reference { get; set; }
}
}

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

@ -1,38 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Contains information about a parent commit in Bitbucket.
/// </summary>
public class BitbucketParent
{
private readonly IDictionary<string, BitbucketLink> _links = new Dictionary<string, BitbucketLink>();
/// <summary>
/// Gets or sets the hash of the parent commit.
/// </summary>
[JsonProperty("hash")]
public string Hash { get; set; }
/// <summary>
/// The type of operation on the repository, e.g. 'commit'.
/// </summary>
[JsonProperty("type")]
public string Operation { get; set; }
/// <summary>
/// Gets the collection of <see cref="BitbucketLink"/> instances and their link relationships. The
/// key is the link relationship and the value is the actual link.
/// </summary>
[JsonProperty("links")]
public IDictionary<string, BitbucketLink> Links
{
get { return _links; }
}
}
}

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

@ -1,67 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Contains information about a Bitbucket repository.
/// </summary>
public class BitbucketRepository
{
private readonly IDictionary<string, BitbucketLink> _links = new Dictionary<string, BitbucketLink>();
/// <summary>
/// Gets or sets a unique ID for this repository.
/// </summary>
[JsonProperty("uuid")]
public string RepositoryId { get; set; }
/// <summary>
/// Gets or sets the full name of the repository, e.g. '<c>someuser/myrepo</c>'.
/// </summary>
[JsonProperty("full_name")]
public string FullName { get; set; }
/// <summary>
/// Gets or sets the name of the repository, e.g. '<c>myrepo</c>'.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets a value indicating with the repository is private or not.
/// </summary>
[JsonProperty("is_private")]
public bool IsPrivate { get; set; }
/// <summary>
/// Gets the collection of <see cref="BitbucketLink"/> instances and their link relationships. The
/// key is the link relationship and the value is the actual link.
/// </summary>
[JsonProperty("links")]
public IDictionary<string, BitbucketLink> Links
{
get { return _links; }
}
/// <summary>
/// Gets or sets the kind of this element, e.g. '<c>repository</c>'.
/// </summary>
[JsonProperty("type")]
public string ItemType { get; set; }
/// <summary>
/// Gets or sets the type of repository, e.g. '<c>hg</c>'.
/// </summary>
[JsonProperty("scm")]
public string RepositoryType { get; set; }
/// <summary>
/// Gets or sets the Bitbucket user information for owner of the repository.
/// </summary>
public BitbucketUser Owner { get; set; }
}
}

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

@ -1,68 +0,0 @@
// 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.Collections.ObjectModel;
using Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Contains details about the most recent operation to a Bitbucket repository after a push.
/// </summary>
public class BitbucketTarget
{
private readonly Collection<BitbucketParent> _parents = new Collection<BitbucketParent>();
private readonly IDictionary<string, BitbucketLink> _links = new Dictionary<string, BitbucketLink>();
/// <summary>
/// Gets or sets the email alias for this author.
/// </summary>
[JsonProperty("message")]
public string Message { get; set; }
/// <summary>
/// The type of operation on the repository, e.g. 'commit'.
/// </summary>
[JsonProperty("type")]
public string Operation { get; set; }
/// <summary>
/// Gets the collection of <see cref="BitbucketLink"/> instances and their link relationships. The
/// key is the link relationship and the value is the actual link.
/// </summary>
[JsonProperty("links")]
public IDictionary<string, BitbucketLink> Links
{
get { return _links; }
}
/// <summary>
/// Gets or sets the hash of the commit
/// </summary>
[JsonProperty("hash")]
public string Hash { get; set; }
/// <summary>
/// Gets the collection of <see cref="BitbucketParent"/> instances for this target.
/// </summary>
[JsonProperty("parents")]
public Collection<BitbucketParent> Parents
{
get { return _parents; }
}
/// <summary>
/// Gets or sets the <see cref="BitbucketAuthor"/> for this target.
/// </summary>
[JsonProperty("author")]
public BitbucketAuthor Author { get; set; }
/// <summary>
/// Gets or set the UTC time of this target.
/// </summary>
[JsonProperty("date")]
public DateTime Date { get; set; }
}
}

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

@ -1,50 +0,0 @@
// 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 Newtonsoft.Json;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Contains information about a user in Bitbucket.
/// </summary>
public class BitbucketUser
{
private readonly IDictionary<string, BitbucketLink> _links = new Dictionary<string, BitbucketLink>();
/// <summary>
/// Gets or sets a unique ID for this user.
/// </summary>
[JsonProperty("uuid")]
public string UserId { get; set; }
/// <summary>
/// Gets or sets the type of the user.
/// </summary>
[JsonProperty("type")]
public string UserType { get; set; }
/// <summary>
/// Gets or sets the the first and last name of the user.
/// </summary>
[JsonProperty("display_name")]
public string DisplayName { get; set; }
/// <summary>
/// Gets or sets the user name for this user.
/// </summary>
[JsonProperty("username")]
public string UserName { get; set; }
/// <summary>
/// Gets the collection of <see cref="BitbucketLink"/> instances and their link relationships. The
/// key is the link relationship and the value is the actual link.
/// </summary>
[JsonProperty("links")]
public IDictionary<string, BitbucketLink> Links
{
get { return _links; }
}
}
}

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

@ -1,77 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Metadata;
using Microsoft.AspNetCore.WebHooks.Properties;
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// <para>
/// An <see cref="Attribute"/> indicating the associated action is a Bitbucket WebHook endpoint.
/// Specifies the optional <see cref="WebHookAttribute.Id"/> and <see cref="EventName"/>. Also adds a
/// <see cref="Filters.WebHookReceiverExistsFilter"/> for the action.
/// </para>
/// <para>
/// The signature of the action should be:
/// <code>
/// Task{IActionResult} ActionName(string id, string @event, string webHookId, TData data)
/// </code>
/// or include the subset of parameters required. <c>TData</c> must be compatible with expected requests e.g.
/// <see cref="Newtonsoft.Json.Linq.JObject"/>.
/// </para>
/// <para>
/// An example Bitbucket WebHook URI is
/// '<c>https://{host}/api/webhooks/incoming/bitbucket/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8</c>'.
/// See <see href="https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html"/> for additional
/// details about Bitbucket WebHook requests.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// If the application enables CORS in general (see the <c>Microsoft.AspNetCore.Cors</c> package), apply
/// <c>DisableCorsAttribute</c> to this action. If the application depends on the
/// <c>Microsoft.AspNetCore.Mvc.ViewFeatures</c> package, apply <c>IgnoreAntiforgeryTokenAttribute</c> to this
/// action.
/// </para>
/// <para>
/// <see cref="BitbucketWebHookAttribute"/> should be used at most once per <see cref="WebHookAttribute.Id"/> and
/// <see cref="EventName"/> in a WebHook application.
/// </para>
/// </remarks>
public class BitbucketWebHookAttribute : WebHookAttribute, IWebHookEventSelectorMetadata
{
private string _eventName;
/// <summary>
/// Instantiates a new <see cref="BitbucketWebHookAttribute"/> indicating the associated action is a Bitbucket
/// WebHook endpoint.
/// </summary>
public BitbucketWebHookAttribute()
: base(BitbucketConstants.ReceiverName)
{
}
/// <summary>
/// Gets or sets the name of the event the associated controller action accepts.
/// </summary>
/// <value>Default value is <see langword="null"/>, indicating this action accepts all events.</value>
public string EventName
{
get
{
return _eventName;
}
set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException(Resources.General_ArgumentCannotBeNullOrEmpty, nameof(value));
}
_eventName = value;
}
}
}
}

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

@ -1,43 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for setting up Bitbucket WebHooks in an <see cref="IMvcBuilder" />.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class BitbucketMvcBuilderExtensions
{
/// <summary>
/// <para>
/// Add Bitbucket WebHook configuration and services to the specified <paramref name="builder"/>. See
/// <see href="https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html"/> for additional
/// details about Bitbucket WebHook requests.
/// </para>
/// <para>
/// The '<c>WebHooks:Bitbucket:SecretKey:default</c>' configuration value contains the secret key for Bitbucket
/// WebHook URIs of the form '<c>https://{host}/api/webhooks/incoming/bitbucket?code={secret key}</c>'.
/// '<c>WebHooks:Bitbucket:SecretKey:{id}</c>' configuration values contain secret keys for Bitbucket WebHook
/// URIs of the form '<c>https://{host}/api/webhooks/incoming/bitbucket/{id}?code={secret key}</c>'.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder" /> to configure.</param>
/// <returns>The <paramref name="builder"/>.</returns>
public static IMvcBuilder AddBitbucketWebHooks(this IMvcBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
BitbucketServiceCollectionSetup.AddBitbucketServices(builder.Services);
return builder.AddWebHooks();
}
}
}

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

@ -1,45 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for setting up Bitbucket WebHooks in an <see cref="IMvcCoreBuilder" />.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class BitbucketMvcCoreBuilderExtensions
{
/// <summary>
/// <para>
/// Add Bitbucket WebHook configuration and services to the specified <paramref name="builder"/>. See
/// <see href="https://confluence.atlassian.com/bitbucket/manage-webhooks-735643732.html"/> for additional
/// details about Bitbucket WebHook requests.
/// </para>
/// <para>
/// The '<c>WebHooks:Bitbucket:SecretKey:default</c>' configuration value contains the secret key for Bitbucket
/// WebHook URIs of the form '<c>https://{host}/api/webhooks/incoming/bitbucket?code={secret key}</c>'.
/// '<c>WebHooks:Bitbucket:SecretKey:{id}</c>' configuration values contain secret keys for Bitbucket WebHook
/// URIs of the form '<c>https://{host}/api/webhooks/incoming/bitbucket/{id}?code={secret key}</c>'.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder" /> to configure.</param>
/// <returns>The <paramref name="builder"/>.</returns>
public static IMvcCoreBuilder AddBitbucketWebHooks(this IMvcCoreBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
BitbucketServiceCollectionSetup.AddBitbucketServices(builder.Services);
return builder
.AddJsonFormatters()
.AddWebHooks();
}
}
}

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

@ -1,30 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Metadata;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.AspNetCore.WebHooks.Internal
{
/// <summary>
/// Methods to add services for the Bitbucket receiver.
/// </summary>
public static class BitbucketServiceCollectionSetup
{
/// <summary>
/// Add services for the Bitbucket receiver.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to update.</param>
public static void AddBitbucketServices(IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.TryAddEnumerable(ServiceDescriptor.Singleton<IWebHookMetadata, BitbucketMetadata>());
}
}
}

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

@ -1,59 +0,0 @@
// 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;
namespace Microsoft.AspNetCore.WebHooks.Metadata
{
/// <summary>
/// An <see cref="IWebHookMetadata"/> service containing metadata about the Bitbucket receiver.
/// </summary>
public class BitbucketMetadata :
WebHookMetadata,
IWebHookBindingMetadata,
IWebHookBodyTypeMetadataService,
IWebHookEventMetadata,
IWebHookVerifyCodeMetadata
{
/// <summary>
/// Instantiates a new <see cref="BitbucketMetadata"/> instance.
/// </summary>
public BitbucketMetadata()
: base(BitbucketConstants.ReceiverName)
{
}
// IWebHookBindingMetadata...
/// <inheritdoc />
public IReadOnlyList<WebHookParameter> Parameters { get; } = new WebHookParameter[]
{
new WebHookParameter(
BitbucketConstants.WebHookIdParameterName1,
WebHookParameterType.Header,
BitbucketConstants.WebHookIdHeaderName,
isRequired: true),
new WebHookParameter(
BitbucketConstants.WebHookIdParameterName2,
WebHookParameterType.Header,
BitbucketConstants.WebHookIdHeaderName,
isRequired: true),
};
// IWebHookBodyTypeMetadataService...
/// <inheritdoc />
public WebHookBodyType BodyType => WebHookBodyType.Json;
// IWebHookEventMetadata...
/// <inheritdoc />
public string ConstantValue => null;
/// <inheritdoc />
public string HeaderName => BitbucketConstants.EventHeaderName;
/// <inheritdoc />
public string QueryParameterName => null;
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<Description>ASP.NET Core Bitbucket WebHooks infrastructure. Contains the BitbucketWebHookAttribute class and AddBitbucketWebHooks method.</Description>
<PackageTags>aspnetcore;webhook;receiver;bitbucket</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.0.0" />
<ProjectReference Include="..\Microsoft.AspNetCore.WebHooks.Receivers\Microsoft.AspNetCore.WebHooks.Receivers.csproj" />
</ItemGroup>
</Project>

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

@ -1,72 +0,0 @@
//------------------------------------------------------------------------------
// <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.AspNetCore.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", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <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.AspNetCore.WebHooks.Properties.Resources", typeof(Resources).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 Value cannot be null or empty..
/// </summary>
internal static string General_ArgumentCannotBeNullOrEmpty {
get {
return ResourceManager.GetString("General_ArgumentCannotBeNullOrEmpty", resourceCulture);
}
}
}
}

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

@ -1,123 +0,0 @@
<?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="General_ArgumentCannotBeNullOrEmpty" xml:space="preserve">
<value>Value cannot be null or empty.</value>
</data>
</root>

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

@ -1,44 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Well-known names and values used in Dropbox receivers and handlers.
/// </summary>
public static class DropboxConstants
{
/// <summary>
/// Gets the name of a query parameter containing a value to include in the response to an HTTP GET request.
/// </summary>
public static string ChallengeQueryParameterName => "challenge";
/// <summary>
/// Gets the only supported event name for this receiver. This value may be model bound but cannot be used in
/// action selection.
/// </summary>
public static string EventName => "change";
/// <summary>
/// Gets the name of the Dropbox WebHook receiver.
/// </summary>
public static string ReceiverName => "dropbox";
/// <summary>
/// Gets the minimum length of the secret key configured for this receiver. Used to confirm the secret key is
/// property configured before responding to an HTTP GET request.
/// </summary>
public static int SecretKeyMinLength => 15;
/// <summary>
/// Gets the maximum length of the secret key configured for this receiver. Used to confirm the secret key is
/// property configured before responding to an HTTP GET request.
/// </summary>
public static int SecretKeyMaxLength => 128;
/// <summary>
/// Gets the name of the HTTP header that contains the (hex-encoded) signature of the request.
/// </summary>
public static string SignatureHeaderName => "X-Dropbox-Signature";
}
}

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

@ -1,49 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// <para>
/// An <see cref="System.Attribute"/> indicating the associated action is a Dropbox WebHook endpoint. Specifies the
/// optional <see cref="WebHookAttribute.Id"/>. Also adds a <see cref="Filters.WebHookReceiverExistsFilter"/> for
/// the action.
/// </para>
/// <para>
/// The signature of the action should be:
/// <code>
/// Task{IActionResult} ActionName(string id, string @event, TData data)
/// </code>
/// or include the subset of parameters required. <c>@event</c> will always contain the value <c>"change"</c>.
/// <c>TData</c> must be compatible with expected requests e.g. <see cref="Newtonsoft.Json.Linq.JObject"/>.
/// </para>
/// <para>
/// An example Dropbox WebHook URI is '<c>https://{host}/api/webhooks/incoming/dropbox/{id}</c>'. See
/// <see href="https://www.dropbox.com/developers/webhooks/docs"/> for additional details about Dropbox WebHook
/// requests.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// If the application enables CORS in general (see the <c>Microsoft.AspNetCore.Cors</c> package), apply
/// <c>DisableCorsAttribute</c> to this action. If the application depends on the
/// <c>Microsoft.AspNetCore.Mvc.ViewFeatures</c> package, apply <c>IgnoreAntiforgeryTokenAttribute</c> to this
/// action.
/// </para>
/// <para>
/// <see cref="DropboxWebHookAttribute"/> should be used at most once per <see cref="WebHookAttribute.Id"/> in a
/// WebHook application.
/// </para>
/// </remarks>
public class DropboxWebHookAttribute : WebHookAttribute
{
/// <summary>
/// Instantiates a new <see cref="DropboxWebHookAttribute"/> indicating the associated action is a Dropbox
/// WebHook endpoint.
/// </summary>
public DropboxWebHookAttribute()
: base(DropboxConstants.ReceiverName)
{
}
}
}

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

@ -1,43 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for setting up Dropbox WebHooks in an <see cref="IMvcBuilder" />.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class DropboxMvcBuilderExtensions
{
/// <summary>
/// <para>
/// Add Dropbox WebHook configuration and services to the specified <paramref name="builder"/>. See
/// <see href="https://www.dropbox.com/developers/webhooks/docs"/> for additional details about Dropbox WebHook
/// requests.
/// </para>
/// <para>
/// The '<c>WebHooks:Dropbox:SecretKey:default</c>' configuration value contains the secret key for Dropbox
/// WebHook URIs of the form '<c>https://{host}/api/webhooks/incoming/dropbox</c>'.
/// '<c>WebHooks:Dropbox:SecretKey:{id}</c>' configuration values contain secret keys for Dropbox WebHook URIs
/// of the form '<c>https://{host}/api/webhooks/incoming/dropbox/{id}</c>'.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder" /> to configure.</param>
/// <returns>The <paramref name="builder"/>.</returns>
public static IMvcBuilder AddDropboxWebHooks(this IMvcBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
DropboxServiceCollectionSetup.AddDropboxServices(builder.Services);
return builder.AddWebHooks();
}
}
}

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

@ -1,45 +0,0 @@
// 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 Microsoft.AspNetCore.WebHooks.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for setting up Dropbox WebHooks in an <see cref="IMvcCoreBuilder" />.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class DropboxMvcCoreBuilderExtensions
{
/// <summary>
/// <para>
/// Add Dropbox WebHook configuration and services to the specified <paramref name="builder"/>. See
/// <see href="https://www.dropbox.com/developers/webhooks/docs"/> for additional details about Dropbox WebHook
/// requests.
/// </para>
/// <para>
/// The '<c>WebHooks:Dropbox:SecretKey:default</c>' configuration value contains the secret key for Dropbox
/// WebHook URIs of the form '<c>https://{host}/api/webhooks/incoming/dropbox</c>'.
/// '<c>WebHooks:Dropbox:SecretKey:{id}</c>' configuration values contain secret keys for Dropbox WebHook URIs
/// of the form '<c>https://{host}/api/webhooks/incoming/dropbox/{id}</c>'.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder" /> to configure.</param>
/// <returns>The <paramref name="builder"/>.</returns>
public static IMvcCoreBuilder AddDropboxWebHooks(this IMvcCoreBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
DropboxServiceCollectionSetup.AddDropboxServices(builder.Services);
return builder
.AddJsonFormatters()
.AddWebHooks();
}
}
}

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

@ -1,119 +0,0 @@
// 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.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.WebHooks.Filters
{
/// <summary>
/// An <see cref="IAsyncResourceFilter"/> that verifies the Dropbox signature header. Confirms the header exists,
/// reads Body bytes, and compares the hashes.
/// </summary>
public class DropboxVerifySignatureFilter : WebHookVerifySignatureFilter, IAsyncResourceFilter
{
/// <summary>
/// Instantiates a new <see cref="DropboxVerifySignatureFilter"/> instance.
/// </summary>
/// <param name="configuration">
/// The <see cref="IConfiguration"/> used to initialize <see cref="WebHookSecurityFilter.Configuration"/>.
/// </param>
/// <param name="hostingEnvironment">
/// The <see cref="IHostingEnvironment" /> used to initialize
/// <see cref="WebHookSecurityFilter.HostingEnvironment"/>.
/// </param>
/// <param name="loggerFactory">
/// The <see cref="ILoggerFactory"/> used to initialize <see cref="WebHookSecurityFilter.Logger"/>.
/// </param>
public DropboxVerifySignatureFilter(
IConfiguration configuration,
IHostingEnvironment hostingEnvironment,
ILoggerFactory loggerFactory)
: base(configuration, hostingEnvironment, loggerFactory)
{
}
/// <inheritdoc />
public override string ReceiverName => DropboxConstants.ReceiverName;
/// <inheritdoc />
public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
var routeData = context.RouteData;
var request = context.HttpContext.Request;
if (routeData.TryGetWebHookReceiverName(out var receiverName) &&
IsApplicable(receiverName) &&
HttpMethods.IsPost(request.Method))
{
// 1. Confirm a secure connection.
var errorResult = EnsureSecureConnection(ReceiverName, context.HttpContext.Request);
if (errorResult != null)
{
context.Result = errorResult;
return;
}
// 2. Get the expected hash from the signature header.
var header = GetRequestHeader(request, DropboxConstants.SignatureHeaderName, out errorResult);
if (errorResult != null)
{
context.Result = errorResult;
return;
}
var expectedHash = GetDecodedHash(header, DropboxConstants.SignatureHeaderName, out errorResult);
if (errorResult != null)
{
context.Result = errorResult;
return;
}
// 3. Get the configured secret key.
var secretKey = GetSecretKey(
ReceiverName,
routeData,
DropboxConstants.SecretKeyMinLength,
DropboxConstants.SecretKeyMaxLength);
if (secretKey == null)
{
context.Result = new NotFoundResult();
return;
}
var secret = Encoding.UTF8.GetBytes(secretKey);
// 4. Get the actual hash of the request body.
var actualHash = await GetRequestBodyHash_SHA256(request, secret);
// 5. Verify that the actual hash matches the expected hash.
if (!SecretEqual(expectedHash, actualHash))
{
// Log about the issue and short-circuit remainder of the pipeline.
errorResult = CreateBadSignatureResult(receiverName, DropboxConstants.SignatureHeaderName);
context.Result = errorResult;
return;
}
}
await next();
}
}
}

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

@ -1,50 +0,0 @@
// 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 Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.WebHooks.Filters;
using Microsoft.AspNetCore.WebHooks.Metadata;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.WebHooks.Internal
{
/// <summary>
/// Methods to add services for the Dropbox receiver.
/// </summary>
public static class DropboxServiceCollectionSetup
{
/// <summary>
/// Add services for the Dropbox receiver.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to update.</param>
public static void AddDropboxServices(IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, MvcOptionsSetup>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IWebHookMetadata, DropboxMetadata>());
services.TryAddSingleton<DropboxVerifySignatureFilter>();
}
private class MvcOptionsSetup : IConfigureOptions<MvcOptions>
{
/// <inheritdoc />
public void Configure(MvcOptions options)
{
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
options.Filters.AddService<DropboxVerifySignatureFilter>(WebHookSecurityFilter.Order);
}
}
}
}

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

@ -1,50 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks.Metadata
{
/// <summary>
/// An <see cref="IWebHookMetadata"/> service containing metadata about the Dropbox receiver.
/// </summary>
public class DropboxMetadata :
WebHookMetadata,
IWebHookBodyTypeMetadataService,
IWebHookEventMetadata,
IWebHookGetRequestMetadata
{
/// <summary>
/// Instantiates a new <see cref="DropboxMetadata"/> instance.
/// </summary>
public DropboxMetadata()
: base(DropboxConstants.ReceiverName)
{
}
// IWebHookBodyTypeMetadataService...
/// <inheritdoc />
public WebHookBodyType BodyType => WebHookBodyType.Json;
// IWebHookEventMetadata...
/// <inheritdoc />
public string ConstantValue => DropboxConstants.EventName;
/// <inheritdoc />
public string HeaderName => null;
/// <inheritdoc />
public string QueryParameterName => null;
// IWebHookGetRequestMetadata...
/// <inheritdoc />
public string ChallengeQueryParameterName => DropboxConstants.ChallengeQueryParameterName;
/// <inheritdoc />
public int SecretKeyMinLength => DropboxConstants.SecretKeyMinLength;
/// <inheritdoc />
public int SecretKeyMaxLength => DropboxConstants.SecretKeyMaxLength;
}
}

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

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>$(Configurations);CodeAnalysis</Configurations>
<Description>ASP.NET Core Dropbox WebHooks infrastructure. Contains the DropboxWebHookAttribute class and AddDropboxWebHooks method.</Description>
<PackageTags>aspnetcore;webhook;receiver;dropbox</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.0.0" />
<ProjectReference Include="..\Microsoft.AspNetCore.WebHooks.Receivers\Microsoft.AspNetCore.WebHooks.Receivers.csproj" />
</ItemGroup>
</Project>

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

@ -1,22 +0,0 @@
// 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.
namespace Microsoft.AspNetCore.WebHooks
{
/// <summary>
/// Well-known names used in Dynamics CRM receivers and handlers.
/// </summary>
public static class DynamicsCRMConstants
{
/// <summary>
/// Gets the JSON path of the property in a Dynamics CRM WebHook request body containing the Dynamics CRM
/// event name.
/// </summary>
public static string EventBodyPropertyPath => "$.MessageName";
/// <summary>
/// Gets the name of the Dynamics CRM WebHook receiver.
/// </summary>
public static string ReceiverName => "dynamicscrm";
}
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше