-
Notifications
You must be signed in to change notification settings - Fork 205
/
Program.cs
86 lines (77 loc) · 3.19 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SendGrid.Helpers.Mail;
using WebJobsSandbox;
namespace ExtensionsSample
{
public static class Program
{
public static async Task Main(string[] args)
{
string filesTestPath = @"c:\temp\files";
// Add or remove types from this list to choose which functions will
// be indexed by the JobHost.
// To run some of the other samples included, add their types to this list
var typeLocator = new SamplesTypeLocator(
typeof(FileSamples),
typeof(TimerSamples));
var builder = new HostBuilder()
.UseEnvironment("Development")
.ConfigureWebJobs(webJobsBuilder =>
{
webJobsBuilder
.AddAzureStorageCoreServices()
.AddAzureStorage()
.AddFiles(o =>
{
o.RootPath = filesTestPath;
})
.AddTimers()
.AddMobileApps()
.AddTwilioSms()
.AddCosmosDB()
.AddSendGrid(o =>
{
o.ToAddress = new EmailAddress("admin@webjobssamples.com", "WebJobs Extensions Samples");
o.FromAddress = new EmailAddress("samples@webjobssamples.com", "WebJobs Extensions Samples");
});
})
.ConfigureLogging(b =>
{
b.SetMinimumLevel(LogLevel.Debug);
b.AddConsole();
})
.ConfigureServices(s =>
{
s.AddSingleton<ITypeLocator>(typeLocator);
})
.UseConsoleLifetime();
EnsureSampleDirectoriesExist(filesTestPath);
var host = builder.Build();
using (host)
{
// Some direct invocations to demonstrate various binding scenarios
var jobHost = (JobHost)host.Services.GetService<IJobHost>();
await jobHost.CallAsync(typeof(FileSamples).GetMethod("ReadWrite"));
await host.RunAsync();
}
}
private static void EnsureSampleDirectoriesExist(string rootFilesPath)
{
// Ensure all the directories referenced by the file sample bindings
// exist
Directory.CreateDirectory(rootFilesPath);
Directory.CreateDirectory(Path.Combine(rootFilesPath, "import"));
Directory.CreateDirectory(Path.Combine(rootFilesPath, "cache"));
Directory.CreateDirectory(Path.Combine(rootFilesPath, "convert"));
Directory.CreateDirectory(Path.Combine(rootFilesPath, "converted"));
File.WriteAllText(Path.Combine(rootFilesPath, "input.txt"), "WebJobs SDK Extensions!");
}
}
}