This commit is contained in:
ShunXian Cai 2017-07-25 15:26:26 -07:00
Родитель ce347464be
Коммит 1776a63422
23 изменённых файлов: 142 добавлений и 84 удалений

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

@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventGridBinding", "EventGridBinding\EventGridBinding.csproj", "{828D7696-5D52-4AEB-8973-4382E9760094}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D0455F87-5E51-4AFD-ACF1-2F50A352F3D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventGridExtension", "EventGridExtension\EventGridExtension.csproj", "{D04DD2A7-EE6B-44C2-B615-DC380D8D2569}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventGridExtension", "src\EventGridExtension\EventGridExtension.csproj", "{D04DD2A7-EE6B-44C2-B615-DC380D8D2569}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B40A0AB6-1971-4DE9-954A-DD92AF1694CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventGridBinding", "test\EventGridBinding\EventGridBinding.csproj", "{828D7696-5D52-4AEB-8973-4382E9760094}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -13,16 +17,20 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{828D7696-5D52-4AEB-8973-4382E9760094}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{828D7696-5D52-4AEB-8973-4382E9760094}.Debug|Any CPU.Build.0 = Debug|Any CPU
{828D7696-5D52-4AEB-8973-4382E9760094}.Release|Any CPU.ActiveCfg = Release|Any CPU
{828D7696-5D52-4AEB-8973-4382E9760094}.Release|Any CPU.Build.0 = Release|Any CPU
{D04DD2A7-EE6B-44C2-B615-DC380D8D2569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D04DD2A7-EE6B-44C2-B615-DC380D8D2569}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D04DD2A7-EE6B-44C2-B615-DC380D8D2569}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D04DD2A7-EE6B-44C2-B615-DC380D8D2569}.Release|Any CPU.Build.0 = Release|Any CPU
{828D7696-5D52-4AEB-8973-4382E9760094}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{828D7696-5D52-4AEB-8973-4382E9760094}.Debug|Any CPU.Build.0 = Debug|Any CPU
{828D7696-5D52-4AEB-8973-4382E9760094}.Release|Any CPU.ActiveCfg = Release|Any CPU
{828D7696-5D52-4AEB-8973-4382E9760094}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D04DD2A7-EE6B-44C2-B615-DC380D8D2569} = {D0455F87-5E51-4AFD-ACF1-2F50A352F3D5}
{828D7696-5D52-4AEB-8973-4382E9760094} = {B40A0AB6-1971-4DE9-954A-DD92AF1694CC}
EndGlobalSection
EndGlobal

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

@ -33,15 +33,6 @@
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.WebJobs, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.Core.2.1.0-beta1\lib\net45\Microsoft.Azure.WebJobs.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.WebJobs.Extensions, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.Extensions.2.1.0-beta1\lib\net45\Microsoft.Azure.WebJobs.Extensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.WebJobs.Host, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.2.1.0-beta1\lib\net45\Microsoft.Azure.WebJobs.Host.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Edm, Version=5.6.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
@ -145,10 +136,25 @@
<Compile Include="EventGridJobHostConfigurationExtensions.cs" />
<Compile Include="EventGridTriggerAttribute.cs" />
<Compile Include="EventGridTriggerAttributeBindingProvider.cs" />
<Compile Include="TestListener.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="D:\azure-webjobs-sdk-extensions\src\WebJobs.Extensions\WebJobs.Extensions.csproj">
<Project>{E6F59990-F3A1-469F-A9D8-6D529121D385}</Project>
<Name>WebJobs.Extensions</Name>
</ProjectReference>
<ProjectReference Include="D:\azure-webjobs-sdk\src\Microsoft.Azure.WebJobs.Host\WebJobs.Host.csproj">
<Project>{0E095CB2-3030-49FF-966C-785F1A55F0C1}</Project>
<Name>WebJobs.Host</Name>
</ProjectReference>
<ProjectReference Include="D:\azure-webjobs-sdk\src\Microsoft.Azure.WebJobs\WebJobs.csproj">
<Project>{E3F2B2C8-6B8D-4D6A-A3AE-98366C9F3B49}</Project>
<Name>WebJobs</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

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

@ -0,0 +1,3 @@
WebJobs D:/azure-webjobs-sdk/src/Microsoft.Azure.WebJobs/WebJobs.csproj ../packages/Microsoft.Azure.WebJobs.Core.2.1.0-beta1/lib/net45/Microsoft.Azure.WebJobs.dll
WebJobs.Host D:/azure-webjobs-sdk/src/Microsoft.Azure.WebJobs.Host/WebJobs.Host.csproj ../packages/Microsoft.Azure.WebJobs.2.1.0-beta1/lib/net45/Microsoft.Azure.WebJobs.Host.dll
WebJobs.Extensions D:/azure-webjobs-sdk-extensions/src/WebJobs.Extensions/WebJobs.Extensions.csproj ../packages/Microsoft.Azure.WebJobs.Extensions.2.1.0-beta1/lib/net45/Microsoft.Azure.WebJobs.Extensions.dll

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

@ -14,6 +14,13 @@ namespace Microsoft.Azure.WebJobs
public class EventGridExtensionConfig : IExtensionConfigProvider,
IAsyncConverter<HttpRequestMessage, HttpResponseMessage>
{
private bool _isTest = false;
public bool IsTest
{
get { return _isTest; }
set { _isTest = value; }
}
public void Initialize(ExtensionConfigContext context)
{
if (context == null)

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

@ -16,7 +16,7 @@ namespace Microsoft.Azure.WebJobs
// Register our extension configuration provider
// done by the function runtime
config.RegisterExtensionConfigProvider(new EventGridExtensionConfig());
config.RegisterExtensionConfigProvider(new EventGridExtensionConfig() { IsTest = true });
}
}
}

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

@ -0,0 +1,46 @@
using Microsoft.Azure.WebJobs.Host.Executors;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Azure.WebJobs
{
public class EventGridListener : Microsoft.Azure.WebJobs.Host.Listeners.IListener
{
public ITriggeredFunctionExecutor Executor { private set; get; }
private EventGridExtensionConfig _listenersStore;
private readonly string _functionName;
public EventGridListener(ITriggeredFunctionExecutor executor, EventGridExtensionConfig listenersStore, string functionName)
{
_listenersStore = listenersStore;
_functionName = functionName;
Executor = executor;
}
public Task StartAsync(CancellationToken cancellationToken)
{
_listenersStore.AddListener(_functionName, this);
return Task.FromResult(true);
}
public Task StopAsync(CancellationToken cancellationToken)
{
// calling order stop -> cancel -> dispose
return Task.FromResult(true);
}
public void Dispose()
{
// TODO unsubscribe
}
public void Cancel()
{
// TODO cancel any outstanding tasks initiated by this listener
}
}
}

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

@ -102,6 +102,11 @@ namespace Microsoft.Azure.WebJobs
public Task<IListener> CreateListenerAsync(ListenerFactoryContext context)
{
// listenersStore is of Type "EventGridExtensionConfig"
if (_listenersStore.IsTest)
{
return Task.FromResult<IListener>(new TestListener(context.Executor));
}
return Task.FromResult<IListener>(new EventGridListener(context.Executor, _listenersStore, _functionName));
}

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

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

@ -7,10 +7,55 @@ using System.Threading.Tasks;
namespace Microsoft.Azure.WebJobs
{
public class EventGridListener : Microsoft.Azure.WebJobs.Host.Listeners.IListener
public class TestListener : Microsoft.Azure.WebJobs.Host.Listeners.IListener
{
// this only works for anonymous blob access
private const string stringJson = @"[{
public ITriggeredFunctionExecutor Executor { private set; get; }
private System.Timers.Timer _timer;
public TestListener(ITriggeredFunctionExecutor executor)
{
Executor = executor;
// For this sample, we're using a timer to generate
// trigger events. You'll replace this with your event source.
_timer = new System.Timers.Timer(5 * 1000)
{
AutoReset = false
};
_timer.Elapsed += OnTimer;
}
public Task StartAsync(CancellationToken cancellationToken)
{
_timer.Start();
return Task.FromResult(true);
}
public Task StopAsync(CancellationToken cancellationToken)
{
_timer.Stop();
return Task.FromResult(true);
}
public void Dispose()
{
_timer.Dispose();
}
public void Cancel()
{
// TODO: cancel any outstanding tasks initiated by this listener
}
private void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
{
// invoke the function executor
// this is similar to code in ProcessAsync()
string stringJson = @"[{
'topic': '/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourcegroups/canaryeh/providers/Microsoft.EventHub/namespaces/canaryeh',
'subject': 'eventhubs/test',
'eventType': 'captureFileCreated',
@ -29,68 +74,6 @@ namespace Microsoft.Azure.WebJobs
},
'publishTime': '2017-07-14T23:10:29.5004788Z'
}]";
public ITriggeredFunctionExecutor Executor { private set; get; }
private System.Timers.Timer _timer;
private EventGridExtensionConfig _listenersStore;
private readonly string _functionName;
public EventGridListener(ITriggeredFunctionExecutor executor, EventGridExtensionConfig listenersStore, string functionName)
{
_listenersStore = listenersStore;
_functionName = functionName;
Executor = executor;
// For this sample, we're using a timer to generate
// trigger events. You'll replace this with your event source.
/*
_timer = new System.Timers.Timer(5 * 1000)
{
AutoReset = false
};
_timer.Elapsed += OnTimer;
*/
}
public Task StartAsync(CancellationToken cancellationToken)
{
if (_timer != null)
{
_timer.Start();
}
_listenersStore.AddListener(_functionName, this);
return Task.FromResult(true);
}
public Task StopAsync(CancellationToken cancellationToken)
{
if (_timer != null)
{
_timer.Stop();
}
// SHUN TODO: calling order stop -> cancel -> dispose
return Task.FromResult(true);
}
public void Dispose()
{
// SHUN TODO unsubscribe
if (_timer != null)
{
_timer.Dispose();
}
}
public void Cancel()
{
// TODO: cancel any outstanding tasks initiated by this listener
}
private void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
{
// invoke the function executor
List<EventGridEvent> events = JsonConvert.DeserializeObject<List<EventGridEvent>>(stringJson);
foreach (var param in events)
{

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

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

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

@ -144,7 +144,7 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventGridExtension\EventGridExtension.csproj">
<ProjectReference Include="..\..\src\EventGridExtension\EventGridExtension.csproj">
<Project>{d04dd2a7-ee6b-44c2-b615-dc380d8d2569}</Project>
<Name>EventGridExtension</Name>
</ProjectReference>

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

@ -11,9 +11,9 @@ namespace EventGridBinding
Console.WriteLine(value);
}
public static void testInputStream([EventGridTrigger("eventhubarchive")] Stream myBlob, string name)
public static void testInputStream([EventGridTrigger("eventhubarchive")] Stream myBlob, string blobTrigger)
{
Console.WriteLine($"file name {name}");
Console.WriteLine($"file name {blobTrigger}");
var reader = new StreamReader(myBlob);
string line = null;
while (!string.IsNullOrEmpty(line = reader.ReadLine()))

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

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