Skip to content

Commit 14982f4

Browse files
committed
Added a solution around projects for better VS2017 integration, added first test & frontend code
1 parent a09eadb commit 14982f4

14 files changed

+410
-13
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*.userosscache
55
*.sln.docstates
66

7+
.vs
8+
.vscode
9+
710
# User-specific files (MonoDevelop/Xamarin Studio)
811
*.userprefs
912

Create-Infrastructure.ps1

+19-13
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ Param(
55
[Parameter(Mandatory=$True)]
66
[string]
77
$EnvironmentTag,
8-
8+
99
[string]
10-
$ResourceGroupLocation = "North Europe"
10+
$ResourceGroupLocation = "North Europe",
11+
12+
[switch]
13+
$SkipCluster
1114
)
1215

1316
# stop the script on first error
@@ -36,21 +39,24 @@ if (-not $automationKeyVault) {
3639
throw "Automation key vault not found. Make sure you run the Create-Prerequisites.ps1 script first."
3740
}
3841

39-
$clusterManagerId = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalId).SecretValueText
40-
$clusterManagerKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalPassword).SecretValue
41-
$sshPublicKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName machineSshPublicKey).SecretValueText
42-
4342
$keyVaultName = "ca-devcache-$EnvironmentTag"
4443
Create-KeyVault -KeyVaultName $keyVaultName -ResourceGroupName $resourceGroupName -ResourceGroupLocation $ResourceGroupLocation
4544

4645
$eventHubTemplateParameters = New-Object -TypeName Hashtable
4746
$eventHubTemplateParameters["EnvironmentTag"] = $EnvironmentTag
4847

49-
$clusterTemplateParameters = New-Object -TypeName Hashtable
50-
$clusterTemplateParameters["EnvironmentTag"] = $EnvironmentTag
51-
$clusterTemplateParameters["ManagementPrincipalId"] = $clusterManagerId
52-
$clusterTemplateParameters["ManagementPrincipalKey"] = $clusterManagerKey
53-
$clusterTemplateParameters["SshPublicKey"] = $sshPublicKey
54-
5548
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $eventHubTemplateFile -TemplateParameters $eventHubTemplateParameters
56-
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $clusterTemplateFile -TemplateParameters $clusterTemplateParameters
49+
50+
if (-not $SkipCluster) {
51+
$clusterManagerId = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalId).SecretValueText
52+
$clusterManagerKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalPassword).SecretValue
53+
$sshPublicKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName machineSshPublicKey).SecretValueText
54+
55+
$clusterTemplateParameters = New-Object -TypeName Hashtable
56+
$clusterTemplateParameters["EnvironmentTag"] = $EnvironmentTag
57+
$clusterTemplateParameters["ManagementPrincipalId"] = $clusterManagerId
58+
$clusterTemplateParameters["ManagementPrincipalKey"] = $clusterManagerKey
59+
$clusterTemplateParameters["SshPublicKey"] = $sshPublicKey
60+
61+
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $clusterTemplateFile -TemplateParameters $clusterTemplateParameters
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace DeviceCache.Frontend.Controllers
5+
{
6+
[Route("api/[controller]")]
7+
public class DataController : Controller
8+
{
9+
[HttpGet]
10+
public IEnumerable<string> Get()
11+
{
12+
return new[] { "Works", "Works too!" };
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp1.1</TargetFramework>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
8+
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
9+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
10+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
11+
</ItemGroup>
12+
<ItemGroup>
13+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
14+
</ItemGroup>
15+
16+
</Project>

DeviceCache.Frontend/Program.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.IO;
2+
using Microsoft.AspNetCore.Hosting;
3+
4+
namespace DeviceCache.Frontend
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
var host = new WebHostBuilder()
11+
.UseKestrel()
12+
.UseContentRoot(Directory.GetCurrentDirectory())
13+
.UseIISIntegration()
14+
.UseStartup<Startup>()
15+
.UseApplicationInsights()
16+
.Build();
17+
18+
host.Run();
19+
}
20+
}
21+
}

DeviceCache.Frontend/Startup.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Logging;
6+
7+
namespace DeviceCache.Frontend
8+
{
9+
public class Startup
10+
{
11+
public Startup(IHostingEnvironment env)
12+
{
13+
var builder = new ConfigurationBuilder()
14+
.SetBasePath(env.ContentRootPath)
15+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
16+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
17+
.AddEnvironmentVariables();
18+
Configuration = builder.Build();
19+
}
20+
21+
public IConfigurationRoot Configuration { get; }
22+
23+
// This method gets called by the runtime. Use this method to add services to the container.
24+
public void ConfigureServices(IServiceCollection services)
25+
{
26+
// Add framework services.
27+
services.AddMvc();
28+
}
29+
30+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
31+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
32+
{
33+
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
34+
loggerFactory.AddDebug();
35+
36+
app.UseMvc();
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Debug",
6+
"System": "Information",
7+
"Microsoft": "Information"
8+
}
9+
}
10+
}

DeviceCache.Frontend/appsettings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<OutputPath>bin\$(Configuration)\</OutputPath>
7+
<DebugSymbols>false</DebugSymbols>
8+
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
9+
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
10+
<TargetRuntime>None</TargetRuntime>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">obj\</BaseIntermediateOutputPath>
12+
<BaseIntermediateOutputPath Condition=" !HasTrailingSlash('$(BaseIntermediateOutputPath)') ">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
13+
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
14+
<ProjectReferencesOutputPath Condition=" '$(ProjectReferencesOutputPath)' == '' ">$(IntermediateOutputPath)ProjectReferences</ProjectReferencesOutputPath>
15+
<ProjectReferencesOutputPath Condition=" !HasTrailingSlash('$(ProjectReferencesOutputPath)') ">$(ProjectReferencesOutputPath)\</ProjectReferencesOutputPath>
16+
<StageArtifacts Condition=" '$(StageArtifacts)' == '' ">true</StageArtifacts>
17+
</PropertyGroup>
18+
19+
<PropertyGroup>
20+
<DefineCommonItemSchemas>false</DefineCommonItemSchemas>
21+
<DefineCommonCapabilities>false</DefineCommonCapabilities>
22+
</PropertyGroup>
23+
24+
<ProjectExtensions>
25+
<ProjectCapabilities>
26+
<DeploymentProject />
27+
</ProjectCapabilities>
28+
</ProjectExtensions>
29+
30+
<ItemDefinitionGroup>
31+
<Content>
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</Content>
34+
<None>
35+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
36+
</None>
37+
<ProjectReference>
38+
<Private>false</Private>
39+
<Targets>Build</Targets>
40+
</ProjectReference>
41+
</ItemDefinitionGroup>
42+
43+
<Target Name="CreateManifestResourceNames" />
44+
45+
<PropertyGroup>
46+
<StageArtifactsDependsOn>
47+
_GetDeploymentProjectContent;
48+
_CalculateContentOutputRelativePaths;
49+
_GetReferencedProjectsOutput;
50+
_CalculateArtifactStagingDirectory;
51+
_CopyOutputToArtifactStagingDirectory;
52+
</StageArtifactsDependsOn>
53+
</PropertyGroup>
54+
55+
<Target Name="_CopyOutputToArtifactStagingDirectory">
56+
<Copy SourceFiles="@(DeploymentProjectContentOutput)" DestinationFiles="$(ArtifactStagingDirectory)\$(MSBuildProjectName)%(RelativePath)" />
57+
<Copy SourceFiles="@(BuildProjectReferencesOutput)" DestinationFiles="$(ArtifactStagingDirectory)\$(MSBuildProjectName)\%(ProjectName)\%(RecursiveDir)%(FileName)%(Extension)" />
58+
</Target>
59+
60+
<Target Name="_GetDeploymentProjectContent">
61+
<MSBuild Projects="$(MSBuildProjectFile)" Targets="ContentFilesProjectOutputGroup">
62+
<Output TaskParameter="TargetOutputs" ItemName="DeploymentProjectContentOutput" />
63+
</MSBuild>
64+
</Target>
65+
66+
<Target Name="_GetReferencedProjectsOutput">
67+
<PropertyGroup>
68+
<MsBuildProperties>Configuration=$(Configuration);Platform=$(Platform)</MsBuildProperties>
69+
</PropertyGroup>
70+
71+
<MSBuild Projects="@(ProjectReference)"
72+
BuildInParallel="$(BuildInParallel)"
73+
Properties="$(MsBuildProperties)"
74+
Targets="%(ProjectReference.Targets)" />
75+
76+
<ItemGroup>
77+
<BuildProjectReferencesOutput Include="%(ProjectReference.IncludeFilePath)">
78+
<ProjectName>$([System.IO.Path]::GetFileNameWithoutExtension('%(ProjectReference.Identity)'))</ProjectName>
79+
</BuildProjectReferencesOutput>
80+
</ItemGroup>
81+
</Target>
82+
83+
<Target Name="_CalculateArtifactStagingDirectory" Condition=" '$(ArtifactStagingDirectory)'=='' ">
84+
<PropertyGroup>
85+
<ArtifactStagingDirectory Condition=" '$(OutDir)'!='' ">$(OutDir)</ArtifactStagingDirectory>
86+
<ArtifactStagingDirectory Condition=" '$(ArtifactStagingDirectory)'=='' ">$(OutputPath)</ArtifactStagingDirectory>
87+
<ArtifactStagingDirectory Condition=" !HasTrailingSlash('$(ArtifactStagingDirectory)') ">$(ArtifactStagingDirectory)\</ArtifactStagingDirectory>
88+
<ArtifactStagingDirectory>$(ArtifactStagingDirectory)staging\</ArtifactStagingDirectory>
89+
<ArtifactStagingDirectory Condition=" '$(Build_StagingDirectory)'!='' AND '$(TF_Build)'=='True' ">$(Build_StagingDirectory)</ArtifactStagingDirectory>
90+
</PropertyGroup>
91+
</Target>
92+
93+
<!-- Appends each of the deployment project's content output files with metadata indicating its relative path from the deployment project's folder. -->
94+
<Target Name="_CalculateContentOutputRelativePaths"
95+
Outputs="%(DeploymentProjectContentOutput.Identity)">
96+
<PropertyGroup>
97+
<_OriginalIdentity>%(DeploymentProjectContentOutput.Identity)</_OriginalIdentity>
98+
<_RelativePath>$(_OriginalIdentity.Replace('$(MSBuildProjectDirectory)', ''))</_RelativePath>
99+
</PropertyGroup>
100+
101+
<ItemGroup>
102+
<DeploymentProjectContentOutput>
103+
<RelativePath>$(_RelativePath)</RelativePath>
104+
</DeploymentProjectContentOutput>
105+
</ItemGroup>
106+
</Target>
107+
108+
<Target Name="CoreCompile" />
109+
110+
<PropertyGroup>
111+
<StageArtifactsAfterTargets Condition=" '$(StageArtifacts)' == 'true' ">
112+
PrepareForRun
113+
</StageArtifactsAfterTargets>
114+
</PropertyGroup>
115+
116+
<Target Name="StageArtifacts" DependsOnTargets="$(StageArtifactsDependsOn)" AfterTargets="$(StageArtifactsAfterTargets)"/>
117+
118+
<!-- Custom target to clean up local deployment staging files -->
119+
<Target Name="DeleteBinObjFolders" BeforeTargets="Clean">
120+
<RemoveDir Directories="$(OutputPath)" />
121+
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
122+
</Target>
123+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|AnyCPU">
5+
<Configuration>Debug</Configuration>
6+
<Platform>AnyCPU</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|AnyCPU">
9+
<Configuration>Release</Configuration>
10+
<Platform>AnyCPU</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>495e95aa-552b-480d-aa47-5adc0e7da3ee</ProjectGuid>
15+
</PropertyGroup>
16+
<PropertyGroup>
17+
<TargetFrameworkIdentifier>Deployment</TargetFrameworkIdentifier>
18+
<TargetFrameworkVersion>1.0</TargetFrameworkVersion>
19+
<PrepareForBuildDependsOn>
20+
</PrepareForBuildDependsOn>
21+
</PropertyGroup>
22+
<Import Condition=" Exists('Deployment.targets') " Project="Deployment.targets" />
23+
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
24+
<!-- vertag<:>start tokens<:>maj.min -->
25+
<Import Condition=" Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Deployment\1.1\DeploymentProject.targets') " Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Deployment\1.1\DeploymentProject.targets" />
26+
<!-- vertag<:>end -->
27+
<ItemGroup>
28+
<None Include="AutomationSecrets.json" />
29+
<None Include="Cluster.json" />
30+
<None Include="Common-Functions.ps1" />
31+
<None Include="Deployment.targets">
32+
<Visible>False</Visible>
33+
</None>
34+
<None Include="EventHub.json" />
35+
</ItemGroup>
36+
<Target Name="GetReferenceAssemblyPaths" />
37+
</Project>

DeviceCache.Tests/AcceptanceTests.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using Microsoft.Extensions.Configuration;
3+
using Xunit;
4+
5+
namespace DeviceCache.Tests
6+
{
7+
public class AcceptanceTests
8+
{
9+
public AcceptanceTests()
10+
{
11+
var builder = new ConfigurationBuilder()
12+
.AddJsonFile("test-settings.json");
13+
14+
Configuration = builder.Build();
15+
}
16+
17+
public IConfigurationRoot Configuration { get; }
18+
19+
[Fact]
20+
public void ShouldReadCachedDataSentFromDevice()
21+
{
22+
// Arrange
23+
24+
// Act
25+
throw new NotImplementedException();
26+
27+
// Assert
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)