Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Updating to preview 5 #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions FunctionApp/Function1/Function1.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
using System.Collections.Generic;
using System.Net;
using System.Reflection.PortableExecutable;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required for something?

using System.Text.Json;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Extensions.Storage;
using Microsoft.Azure.Functions.Worker.Http;
Comment on lines +6 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this just be Microsoft.Azure.Functions.Worker and Microsoft.Azure.Functions.Worker.Http?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for all below!


namespace FunctionApp
{
public static class Function1
{

[FunctionName("Function1")]
public static HttpResponseData Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, [Blob("test-samples/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob,
[Queue("functionstesting2", Connection = "AzureWebJobsStorage")] OutputBinding<Book> book)
[Function("Function1")]
public static Result Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
[BlobInput("test-samples/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob)
{
var bookVal = (Book)JsonSerializer.Deserialize(myBlob, typeof(Book));
book.SetValue(bookVal);
var response = new HttpResponseData(HttpStatusCode.OK);
var headers = new Dictionary<string, string>();
headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
headers.Add("Content", "Content - Type: text / html; charset = utf - 8");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
response.Headers.Add("Content", "Content - Type: text / html; charset = utf - 8");

response.Headers = headers;
response.Body = "Book Sent to Queue!";
response.WriteString("Book Sent to Queue!");

return response;
return new Result { Response = response, Book = bookVal };
}

public class Book
Expand All @@ -34,5 +35,13 @@ public class Book
public string id { get; set; }
}

public class Result
{
[QueueOutput("books", Connection = "AzureWebJobsStorage")]
public Book Book { get; set; }

public HttpResponseData Response { get; set; }
}

}
}
8 changes: 5 additions & 3 deletions FunctionApp/Function2/Function2.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.Storage;

namespace FunctionApp
{
public static class Function2
{
[FunctionName("Function2")]
[Function("Function2")]
public static Book Run([QueueTrigger("functionstesting2", Connection = "AzureWebJobsStorage")] Book myQueueItem,
[Blob("test-samples/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob)
[BlobInput("test-samples/sample1.txt", Connection = "AzureWebJobsStorage")] string myBlob)
{
Console.WriteLine(myBlob);

return myQueueItem;
}
}
Expand Down
26 changes: 16 additions & 10 deletions FunctionApp/Function3/Function3.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Extensions.Storage;
using Microsoft.Azure.Functions.Worker.Http;

namespace FunctionApp
{
public static class Function3
{

[FunctionName("Function3")]
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
[Queue("functionstesting2", Connection = "AzureWebJobsStorage")] OutputBinding<string> name)
[Function("Function3")]
public static Result Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req)
{
var response = new HttpResponseData(HttpStatusCode.OK);
response.Body = "Success!!";
var response = req.CreateResponse(HttpStatusCode.OK);
response.WriteString("Success!!");

name.SetValue("some name");
return new Result { Response = response, Name = "Azure Functions" };
}

public class Result
{
[QueueOutput("myQueue", Connection = "AzureWebJobsStorage")]
public string Name { get; set; }

return response;
public HttpResponseData Response { get; set; }
}
}

Expand Down
23 changes: 11 additions & 12 deletions FunctionApp/Function4/Function4.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
using System.Collections.Generic;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Pipeline;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace FunctionApp
{
public static class Function4
{

[FunctionName("Function4")]
[Function("Function4")]
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
FunctionExecutionContext executionContext)
FunctionContext executionContext)
{
var logger = executionContext.Logger;
var logger = executionContext.GetLogger(nameof(Function4));
logger.LogInformation("message logged");
var response = new HttpResponseData(HttpStatusCode.OK);
var headers = new Dictionary<string, string>();
headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
headers.Add("Content", "Content - Type: text / html; charset = utf - 8");
var response = req.CreateResponse(HttpStatusCode.OK);

response.Headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
response.Headers.Add("Content", "Content - Type: text / html; charset = utf - 8");

response.Headers = headers;
response.Body = "Welcome to .NET 5!!";
response.WriteString("Welcome to .NET 5!!");

return response;
}
Expand Down
31 changes: 13 additions & 18 deletions FunctionApp/Function5/Function5.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net;
using System.Text;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
using Microsoft.Azure.Functions.Worker.Extensions.Http;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Azure.Functions.Worker.Pipeline;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Converters;

Expand All @@ -21,11 +18,11 @@ public Function5(IHttpResponderService responderService)
_responderService = responderService;
}

[FunctionName(nameof(Function5))]
[Function(nameof(Function5))]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req,
FunctionExecutionContext executionContext)
FunctionContext executionContext)
{
var logger = executionContext.Logger;
var logger = executionContext.GetLogger<Function5>();
logger.LogInformation("message logged");

return _responderService.ProcessRequest(req);
Expand All @@ -46,12 +43,11 @@ public DefaultHttpResponderService()

public HttpResponseData ProcessRequest(HttpRequestData httpRequest)
{
var response = new HttpResponseData(HttpStatusCode.OK);
var headers = new Dictionary<string, string>();
headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
headers.Add("Content", "Content - Type: text / html; charset = utf - 8");
var response = httpRequest.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Date", "Mon, 18 Jul 2016 16:06:00 GMT");
response.Headers.Add("Content", "Content - Type: text / html; charset = utf - 8");

response.Headers = headers;
response.Cookies.Append("dotnetworker", "delicious cookie");

var responseBuilder = new StringBuilder();

Expand All @@ -61,7 +57,7 @@ public HttpResponseData ProcessRequest(HttpRequestData httpRequest)
responseBuilder.AppendLine($"Headers:");
foreach (var item in httpRequest.Headers)
{
responseBuilder.AppendLine($"\t{item.Key} = {item.Value}");
responseBuilder.AppendLine($"\t{item.Key} = {string.Join(",", item.Value)}");
}

responseBuilder.AppendLine($"Identities:");
Expand All @@ -73,11 +69,10 @@ public HttpResponseData ProcessRequest(HttpRequestData httpRequest)
foreach (var claim in item.Claims)
{
responseBuilder.AppendLine($"\t\tType: {claim.Type}, Value: {claim.Value}");

}
}

response.Body = responseBuilder.ToString();
response.WriteString(responseBuilder.ToString());
return response;
}
}
Expand Down
9 changes: 4 additions & 5 deletions FunctionApp/FunctionApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
</Target>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.12" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.0-preview4" OutputItemType="Analyzer" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sdk probably needs to be here

<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.0.0-preview4" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.0.0-preview5" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12-preview1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4-preview1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
</ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions FunctionApp/Middleware/SampleMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Microsoft.Azure.Functions.Worker.Pipeline;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Pipeline;
using System.Threading.Tasks;

namespace FunctionApp
{
public class SampleMiddleware
{
public Task Invoke(FunctionExecutionContext context, FunctionExecutionDelegate next)
public Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
{
context.Items.Add("Greeting", "Hello from our middleware");
return next(context);
Expand Down