Skip to content

Commit

Permalink
Update all examples from template changes
Browse files Browse the repository at this point in the history
- Add appsettings.json copying
- Update Cloud Event to CloudEvent
  • Loading branch information
jskeet committed May 24, 2021
1 parent 6832a52 commit 9ddddca
Show file tree
Hide file tree
Showing 27 changed files with 52 additions and 38 deletions.
9 changes: 0 additions & 9 deletions docs/examples.md
Expand Up @@ -378,15 +378,6 @@ by the `ASPNETCORE_ENVIRONMENT` and `DOTNET_ENVIRONMENT` environment variables.
> environment variables on a user level, to avoid accidentally attempting to run against the production
> configuration.
> **Note on AppSettings files**
>
> Currently, `appsettings.json` files are not copied by default when the project is published using `dotnet publish`.
> This means that although the function meay run as expected locally, when it is deployed the settings files would be
> absent. This can be fixed by explicitly including them in the project file, [as shown in this
> example](../examples/Google.Cloud.Functions.Examples.Configuration/Google.Cloud.Functions.Examples.Configuration.csproj).
> We hope to do this implicitly in a future release. See [issue
> 201](https://github.com/GoogleCloudPlatform/functions-framework-dotnet/issues/201) for more information.
Sample deployment:

```sh
Expand Down
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<PackageReference Include="Steeltoe.Extensions.Configuration.RandomValueBase" Version="2.4.4" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Expand Up @@ -7,5 +7,6 @@
<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<PackageReference Include="CloudNative.CloudEvents.NewtonsoftJson" Version="2.0.0-beta.3" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Expand Up @@ -29,11 +29,11 @@ open System.Threading.Tasks
type Function() =
interface ICloudEventFunction<StorageObjectData> with
/// <summary>
/// Logic for your function goes here. Note that a Cloud Event function just consumes an event;
/// Logic for your function goes here. Note that a CloudEvent function just consumes an event;
/// it doesn't provide any response.
/// </summary>
/// <param name="cloudEvent">The Cloud Event your function should consume.</param>
/// <param name="data">The deserialized data within the Cloud Event.</param>
/// <param name="cloudEvent">The CloudEvent your function should consume.</param>
/// <param name="data">The deserialized data within the CloudEvent.</param>
/// <param name="cancellationToken">A cancellation token that is notified if the request is aborted.</param>
/// <returns>A task representing the asynchronous operation.</returns>
member this.HandleAsync(cloudEvent, data, cancellationToken) =
Expand All @@ -42,7 +42,7 @@ type Function() =
printfn " Bucket: %s" data.Bucket
printfn " Size: %i" data.Size
printfn " Content type: %s" data.ContentType
printfn "Cloud event information:"
printfn "CloudEvent information:"
printfn " ID: %s" cloudEvent.Id
printfn " Source: %O" cloudEvent.Source
printfn " Type: %s" cloudEvent.Type
Expand Down
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<Compile Include="Function.fs" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Function.fs" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Expand Up @@ -20,14 +20,14 @@ open System.Threading.Tasks
type Function() =
interface ICloudEventFunction with
/// <summary>
/// Logic for your function goes here. Note that a Cloud Event function just consumes an event;
/// Logic for your function goes here. Note that a CloudEvent function just consumes an event;
/// it doesn't provide any response.
/// </summary>
/// <param name="cloudEvent">The Cloud Event your function should consume.</param>
/// <param name="cloudEvent">The CloudEvent your function should consume.</param>
/// <param name="cancellationToken">A cancellation token that is notified if the request is aborted.</param>
/// <returns>A task representing the asynchronous operation.</returns>
member this.HandleAsync(cloudEvent, cancellationToken) =
printfn "Cloud event information:"
printfn "CloudEvent information:"
printfn "ID: %s" cloudEvent.Id
printfn "Source: %A" cloudEvent.Source
printfn "Type: %s" cloudEvent.Type
Expand Down
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Function.fs" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
Expand Up @@ -6,5 +6,6 @@

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Expand Up @@ -31,11 +31,11 @@ namespace Google.Cloud.Functions.Examples.SimpleEventFunction
public class Function : ICloudEventFunction<StorageObjectData>
{
/// <summary>
/// Logic for your function goes here. Note that a Cloud Event function just consumes an event;
/// Logic for your function goes here. Note that a CloudEvent function just consumes an event;
/// it doesn't provide any response.
/// </summary>
/// <param name="cloudEvent">The Cloud Event your function should consume.</param>
/// <param name="data">The deserialized data within the Cloud Event.</param>
/// <param name="cloudEvent">The CloudEvent your function should consume.</param>
/// <param name="data">The deserialized data within the CloudEvent.</param>
/// <param name="cancellationToken">A cancellation token that is notified if the request is aborted.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public Task HandleAsync(CloudEvent cloudEvent, StorageObjectData data, CancellationToken cancellationToken)
Expand All @@ -45,7 +45,7 @@ public Task HandleAsync(CloudEvent cloudEvent, StorageObjectData data, Cancellat
Console.WriteLine($" Bucket: {data.Bucket}");
Console.WriteLine($" Size: {data.Size}");
Console.WriteLine($" Content type: {data.ContentType}");
Console.WriteLine("Cloud event information:");
Console.WriteLine("CloudEvent information:");
Console.WriteLine($" ID: {cloudEvent.Id}");
Console.WriteLine($" Source: {cloudEvent.Source}");
Console.WriteLine($" Type: {cloudEvent.Type}");
Expand Down
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand All @@ -7,5 +7,6 @@
<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<PackageReference Include="Google.Events.Protobuf" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Expand Up @@ -26,12 +26,12 @@ public class Function : ICloudEventFunction
/// Logic for your function goes here. Note that a CloudEvent function just consumes an event;
/// it doesn't provide any response.
/// </summary>
/// <param name="cloudEvent">The Cloud Event your function should consume.</param>
/// <param name="cloudEvent">The CloudEvent your function should consume.</param>
/// <param name="cancellationToken">A cancellation token that is notified if the request is aborted.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public Task HandleAsync(CloudEvent cloudEvent, CancellationToken cancellationToken)
{
Console.WriteLine("Cloud event information:");
Console.WriteLine("CloudEvent information:");
Console.WriteLine($"ID: {cloudEvent.Id}");
Console.WriteLine($"Source: {cloudEvent.Source}");
Console.WriteLine($"Type: {cloudEvent.Type}");
Expand Down
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Expand Up @@ -9,5 +9,6 @@
<PackageReference Include="Google.Cloud.Storage.V1" Version="3.2.0" />
<PackageReference Include="Google.Cloud.Vision.V1" Version="2.0.0" />
<PackageReference Include="Google.Events.Protobuf" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Expand Up @@ -8,5 +8,6 @@
<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<PackageReference Include="NodaTime" Version="3.0.0" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Expand Up @@ -28,11 +28,11 @@ Public Class CloudFunction
Implements ICloudEventFunction(Of StorageObjectData)

''' <summary>
''' Logic for your function goes here. Note that a Cloud Event function just consumes an event;
''' Logic for your function goes here. Note that a CloudEvent function just consumes an event;
''' it doesn't provide any response.
''' </summary>
''' <param name="cloudEvent">The Cloud Event your function should consume.</param>
''' <param name="data">The deserialized data within the Cloud Event.</param>
''' <param name="cloudEvent">The CloudEvent your function should consume.</param>
''' <param name="data">The deserialized data within the CloudEvent.</param>
''' <param name="cancellationToken">A cancellation token that is notified if the request is aborted.</param>
''' <returns>A task representing the asynchronous operation.</returns>
Public Function HandleAsync(cloudEvent As CloudEvent, data As StorageObjectData, cancellationToken As CancellationToken) As Task _
Expand All @@ -42,7 +42,7 @@ Public Class CloudFunction
Console.WriteLine($" Bucket: {data.Bucket}")
Console.WriteLine($" Size: {data.Size}")
Console.WriteLine($" Content type: {data.ContentType}")
Console.WriteLine("Cloud event information:")
Console.WriteLine("CloudEvent information:")
Console.WriteLine($" ID: {cloudEvent.Id}")
Console.WriteLine($" Source: {cloudEvent.Source}")
Console.WriteLine($" Type: {cloudEvent.Type}")
Expand Down
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Google.Cloud.Functions.Examples.VbEventFunction</RootNamespace>
Expand All @@ -8,5 +8,6 @@
<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<PackageReference Include="Google.Events.Protobuf" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Google.Cloud.Functions.Examples.VbHttpFunction</RootNamespace>
Expand All @@ -7,5 +7,6 @@

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
Expand Up @@ -20,15 +20,15 @@ Public Class CloudFunction
Implements ICloudEventFunction

''' <summary>
''' Logic for your function goes here. Note that a Cloud Event function just consumes an event;
''' Logic for your function goes here. Note that a CloudEvent function just consumes an event;
''' it doesn't provide any response.
''' </summary>
''' <param name="cloudEvent">The Cloud Event your function should consume.</param>
''' <param name="cloudEvent">The CloudEvent your function should consume.</param>
''' <param name="cancellationToken">A cancellation token that is notified if the request is aborted.</param>
''' <returns>A task representing the asynchronous operation.</returns>
Public Function HandleAsync(cloudEvent As CloudEvent, cancellationToken As CancellationToken) As Task _
Implements ICloudEventFunction.HandleAsync
Console.WriteLine("Cloud event information:")
Console.WriteLine("CloudEvent information:")
Console.WriteLine($"ID: {cloudEvent.Id}")
Console.WriteLine($"Source: {cloudEvent.Source}")
Console.WriteLine($"Type: {cloudEvent.Type}")
Expand Down
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Google.Cloud.Functions.Examples.VbUntypedEventFunction</RootNamespace>
Expand All @@ -7,5 +7,6 @@

<ItemGroup>
<PackageReference Include="Google.Cloud.Functions.Hosting" Version="1.0.0-beta04" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
6 changes: 5 additions & 1 deletion install-local-templates.sh
Expand Up @@ -13,6 +13,10 @@ NUGET_SOURCE=$PWD/src/Google.Cloud.Functions.Templates/bin/Release/

# Come out of the functions-framework-dotnet directory to use the default SDK,
# which is what VS uses.
$(cd .. && dotnet new -i Google.Cloud.Functions.Templates::$VERSION --nuget-source=$NUGET_SOURCE)
(cd .. && dotnet new -i Google.Cloud.Functions.Templates::$VERSION --nuget-source=$NUGET_SOURCE)

# Also install within functions-framework-dotnet directory so that it will
# be installed for use in examples/generate.sh
dotnet new -i Google.Cloud.Functions.Templates::$VERSION --nuget-source=$NUGET_SOURCE

echo "Installed local templates as version $VERSION"
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<Compile Include="Function.fs" />
<None Include="appsettings*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 9ddddca

Please sign in to comment.