Skip to content

Commit

Permalink
Updated to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
madebygps committed Nov 19, 2023
1 parent 7a8beaa commit eecf1de
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 54 deletions.
10 changes: 7 additions & 3 deletions .devcontainer/api/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": ".NET API",
"name": ".NET Azure Functions API",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
Expand All @@ -18,7 +18,7 @@
"workspaceFolder": "/workspace/api",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},


// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
Expand All @@ -41,7 +41,7 @@
},

// Uncomment the next line to run commands after the container is created.
"postCreateCommand": "chmod +x /workspace/api/setup.sh; /workspace/api/setup.sh"
"postCreateCommand": "chmod +x ./setup.sh; ./setup.sh"


// Configure tool-specific properties.
Expand All @@ -50,3 +50,7 @@
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}




7 changes: 7 additions & 0 deletions api/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"azureFunctions.deploySubpath": "bin/Release/net8.0/publish",
"azureFunctions.projectLanguage": "C#",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.preDeployTask": "publish (functions)"
}
74 changes: 65 additions & 9 deletions api/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,69 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "func: host start",
"type": "func",
"command": "host start",
"problemMatcher": "$func-watch",
"isBackground": true,

}
{
"label": "clean (functions)",
"command": "dotnet",
"args": [
"clean",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"problemMatcher": "$msCompile"
},
{
"label": "build (functions)",
"command": "dotnet",
"args": [
"build",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"dependsOn": "clean (functions)",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$msCompile"
},
{
"label": "clean release (functions)",
"command": "dotnet",
"args": [
"clean",
"--configuration",
"Release",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"problemMatcher": "$msCompile"
},
{
"label": "publish (functions)",
"command": "dotnet",
"args": [
"publish",
"--configuration",
"Release",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"type": "process",
"dependsOn": "clean release (functions)",
"problemMatcher": "$msCompile"
},
{
"type": "func",
"dependsOn": "build (functions)",
"options": {
"cwd": "${workspaceFolder}/bin/Debug/net8.0"
},
"command": "host start",
"isBackground": true,
"problemMatcher": "$func-dotnet-watch"
}
]
}
}
22 changes: 13 additions & 9 deletions api/Counter.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using System.Text.Json.Serialization;

namespace Api.Function;

public class Counter
namespace Api.Function
{

[JsonPropertyName("id")]
public string? Id {get; set;}

[JsonPropertyName("count")]
public int Count {get;set;}
public class Counter
{
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonPropertyName("count")]
public int Count { get; set; }
public Counter(string id)
{
Id = id ?? throw new ArgumentNullException(nameof(id));
}
}
}
14 changes: 7 additions & 7 deletions api/GetVisitorCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ public class GetVisitorCounter
{
private readonly ILogger _logger;

public GetVisitorCounter(ILoggerFactory loggerFactory)
public GetVisitorCounter(ILogger<GetVisitorCounter> logger)
{
_logger = loggerFactory.CreateLogger<GetVisitorCounter>();
_logger = logger;
}

[Function("GetVisitorCounter")]
public MyOutputType Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
public async Task<UpdatedCounter> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[CosmosDBInput("CloudResume","Counter", Connection = "CosmosDbConnectionString", Id = "index",
PartitionKey = "index")] Counter counter)
{

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "application/json; charset=utf-8");
string jsonString = JsonSerializer.Serialize(counter);
response.WriteString(jsonString);
counter.Count =+ counter.Count+1;
return new MyOutputType()
await response.WriteStringAsync(jsonString);
counter.Count += 1;
return new UpdatedCounter()
{
UpdatedCounter = counter,
NewCounter = counter,
HttpResponse = response
};
}
Expand Down
5 changes: 2 additions & 3 deletions api/CounterOutputType.cs → api/UpdatedCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@


namespace Api.Function;
public class MyOutputType
public class UpdatedCounter
{


[CosmosDBOutput("CloudResume", "Counter", Connection = "CosmosDbConnectionString")]
public Counter? UpdatedCounter { get; set; }
public Counter? NewCounter { get; set; }
public HttpResponseData? HttpResponse { get; set; }
}
2 changes: 1 addition & 1 deletion api/api.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
12 changes: 6 additions & 6 deletions api/api.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api", "api.csproj", "{D2E898D9-ED4A-4E84-A720-FF2BF01F8EDB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api", "api.csproj", "{731F3A28-1EB9-45A0-8225-69E66457B2FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D2E898D9-ED4A-4E84-A720-FF2BF01F8EDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2E898D9-ED4A-4E84-A720-FF2BF01F8EDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2E898D9-ED4A-4E84-A720-FF2BF01F8EDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2E898D9-ED4A-4E84-A720-FF2BF01F8EDB}.Release|Any CPU.Build.0 = Release|Any CPU
{731F3A28-1EB9-45A0-8225-69E66457B2FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{731F3A28-1EB9-45A0-8225-69E66457B2FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{731F3A28-1EB9-45A0-8225-69E66457B2FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{731F3A28-1EB9-45A0-8225-69E66457B2FD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7A7C57C1-AC85-4302-95E1-BA15A3BEDFF4}
SolutionGuid = {16CCE356-7614-4677-B8D0-203832FFA5B4}
EndGlobalSection
EndGlobal
Binary file removed api/microsoft.gpg
Binary file not shown.
20 changes: 8 additions & 12 deletions api/setup.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/bin/bash
# set to 9 or 10
DEBIAN_VERSION=10

# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/$DEBIAN_VERSION/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list

# Move the GPG key to the appropriate directory
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

# Set up the stable repository
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -f 1)/prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list'

# Update the package lists for upgrades and new packages
sudo apt-get update

# Install the Azure Functions Core Tools
sudo apt-get install azure-functions-core-tools-4
31 changes: 31 additions & 0 deletions azure-resume.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "api", "api\api.csproj", "{82F065D8-4DCE-4A40-ACE8-571D047EA2F1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "tests", "tests\tests.csproj", "{21EEEFE3-450D-4898-AF27-992C80CE6FB2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{82F065D8-4DCE-4A40-ACE8-571D047EA2F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{82F065D8-4DCE-4A40-ACE8-571D047EA2F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82F065D8-4DCE-4A40-ACE8-571D047EA2F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82F065D8-4DCE-4A40-ACE8-571D047EA2F1}.Release|Any CPU.Build.0 = Release|Any CPU
{21EEEFE3-450D-4898-AF27-992C80CE6FB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21EEEFE3-450D-4898-AF27-992C80CE6FB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21EEEFE3-450D-4898-AF27-992C80CE6FB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21EEEFE3-450D-4898-AF27-992C80CE6FB2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EBA57613-07C6-4C47-B1C9-BF0D1DC3CF41}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
api:
image: mcr.microsoft.com/devcontainers/dotnet:1-7.0-bullseye
image: mcr.microsoft.com/devcontainers/dotnet:8.0-bookworm
volumes:
# Mount the root folder that contains .git
- .:/workspace:cached
Expand Down
6 changes: 3 additions & 3 deletions frontend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ window.addEventListener('DOMContentLoaded', (event) =>{
getVisitCount();
})

const functionApiUrl = 'https://getvisitorcounter.azurewebsites.net/api/GetVisitorCounter';
const localFunctionApi = 'http://localhost:7071/api/GetVisitorCounter';
const productionApiUrl = 'https://getvisitorcounter.azurewebsites.net/api/GetVisitorCounter';
const localApiUrl = 'http://localhost:7071/api/GetVisitorCounter';

const getVisitCount = () => {
let count = 30;
fetch(functionApiUrl).then(response => {
fetch(productionApiUrl).then(response => {
return response.json()
}).then(response =>{
console.log("Website called function API.");
Expand Down

0 comments on commit eecf1de

Please sign in to comment.