Skip to content

Commit

Permalink
Added DotNetCoreAITester
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeltrao committed Jun 29, 2018
1 parent 8d40ef2 commit 7c3bc32
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 0 deletions.
25 changes: 25 additions & 0 deletions application-insights/DotNetCoreAITester/DotNetCoreAITester.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27825.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetCoreAITester", "DotNetCoreAITester\DotNetCoreAITester.csproj", "{ADF6B7F1-8620-42BA-B946-C696C7A63D94}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ADF6B7F1-8620-42BA-B946-C696C7A63D94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ADF6B7F1-8620-42BA-B946-C696C7A63D94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ADF6B7F1-8620-42BA-B946-C696C7A63D94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADF6B7F1-8620-42BA-B946-C696C7A63D94}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B5B65FA-6A3C-4740-9396-0ED66C8CCB3B}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider",
"Version": "8.13.10511.1",
"GettingStartedDocument": {
"Uri": "https://go.microsoft.com/fwlink/?LinkID=798432"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.AspNetCore.Mvc;

namespace DotNetCoreAITester.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{

static Random random = new Random();

// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}


[HttpGet]
[Route("metric")]
/// <summary>
/// Creates custom event
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public IActionResult Metric(string name = null, double? value = null)
{
name = name ?? "customMetric";
if (!value.HasValue)
value = random.NextDouble();

var telemetry = new TelemetryClient();
telemetry.TrackMetric(new MetricTelemetry(name, value.Value));

return Content($"Metric {name} created with value {value}");
}

[HttpGet]
[Route("event")]
/// <summary>
/// Creates custom event
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public IActionResult Event(string name = null)
{
name = name ?? "customEvent";
var telemetry = new TelemetryClient();
telemetry.TrackEvent(name);

return Content($"Event {name} created");
}


[HttpGet]
[Route("error")]
/// <summary>
/// Throws an error
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public IActionResult Error(string message = null)
{
message = message ?? "Bug in the system";

throw new Exception(message);
}

// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}

// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}

// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}

// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<ApplicationInsightsResourceId>/subscriptions/7a7761b9-7410-475e-a136-2ec8b8869af6/resourcegroups/default-weu/providers/microsoft.insights/components/fbrdefaultai</ApplicationInsightsResourceId>
<ApplicationInsightsAnnotationResourceId>/subscriptions/7a7761b9-7410-475e-a136-2ec8b8869af6/resourcegroups/default-weu/providers/microsoft.insights/components/fbrdefaultai</ApplicationInsightsAnnotationResourceId>
<UserSecretsId>11ef131f-98fd-4c78-bed1-15fa5843d69a</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace DotNetCoreAITester
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace DotNetCoreAITester
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ApplicationInsights": {
"InstrumentationKey": "<set-your-application-insights-key>"
}
}

0 comments on commit 7c3bc32

Please sign in to comment.