mirror of
https://github.com/dockersamples/example-voting-app.git
synced 2026-05-20 16:33:03 +00:00
remove dupe dotnet voting and result apps (#277)
This commit is contained in:
18
result/.vscode/launch.json
vendored
18
result/.vscode/launch.json
vendored
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Attach",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"port": 5858,
|
||||
"address": "localhost",
|
||||
"restart": true,
|
||||
"sourceMaps": false,
|
||||
"outDir": null,
|
||||
"localRoot": "${workspaceRoot}",
|
||||
"remoteRoot": "/app",
|
||||
"timeout": 10000
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
FROM microsoft/dotnet:2.1-sdk-nanoserver-sac2016 as builder
|
||||
|
||||
WORKDIR /Result
|
||||
COPY Result/Result.csproj .
|
||||
RUN dotnet restore
|
||||
|
||||
COPY /Result .
|
||||
RUN dotnet publish -c Release -o /out Result.csproj
|
||||
|
||||
# app image
|
||||
FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016
|
||||
|
||||
WORKDIR /app
|
||||
ENTRYPOINT ["dotnet", "Result.dll"]
|
||||
|
||||
COPY --from=builder /out .
|
||||
@@ -1,16 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as builder
|
||||
|
||||
WORKDIR /Result
|
||||
COPY Result/Result.csproj .
|
||||
RUN dotnet restore
|
||||
|
||||
COPY /Result .
|
||||
RUN dotnet publish -c Release -o /out Result.csproj
|
||||
|
||||
# app image
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
|
||||
|
||||
WORKDIR /app
|
||||
ENTRYPOINT ["dotnet", "Result.dll"]
|
||||
|
||||
COPY --from=builder /out .
|
||||
@@ -1,9 +0,0 @@
|
||||
using Result.Models;
|
||||
|
||||
namespace Result.Data
|
||||
{
|
||||
public interface IResultData
|
||||
{
|
||||
ResultsModel GetResults();
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using System.Linq;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Result.Models;
|
||||
|
||||
namespace Result.Data
|
||||
{
|
||||
public class MySqlResultData : IResultData
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public MySqlResultData(IConfiguration config, ILogger<MySqlResultData> logger)
|
||||
{
|
||||
_connectionString = config.GetConnectionString("ResultData");
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public ResultsModel GetResults()
|
||||
{
|
||||
var model = new ResultsModel();
|
||||
using (var connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
var results = connection.Query("SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote ORDER BY vote");
|
||||
if (results.Any(x => x.vote == "a"))
|
||||
{
|
||||
model.OptionA = (int) results.First(x => x.vote == "a").count;
|
||||
}
|
||||
if (results.Any(x => x.vote == "b"))
|
||||
{
|
||||
model.OptionB = (int) results.First(x => x.vote == "b").count;
|
||||
}
|
||||
model.VoteCount = model.OptionA + model.OptionB;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Result.Hubs
|
||||
{
|
||||
public class ResultsHub : Hub
|
||||
{
|
||||
//no public methods, only used for push from PublishRTesultsTimer
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Result.Models
|
||||
{
|
||||
public class ResultsModel
|
||||
{
|
||||
public int OptionA { get; set; }
|
||||
|
||||
public int OptionB { get; set; }
|
||||
|
||||
public int VoteCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
@page
|
||||
@model Result.Pages.IndexModel
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>@Model.OptionA vs @Model.OptionB -- Result</title>
|
||||
<base href="/index.html">
|
||||
<meta name="viewport" content="width=device-width, initial-scale = 1.0">
|
||||
<meta name="keywords" content="docker-compose, docker, stack">
|
||||
<meta name="author" content="Docker">
|
||||
<link rel='stylesheet' href='~/css/site.css' />
|
||||
</head>
|
||||
<body>
|
||||
<div id="background-stats">
|
||||
<div id="background-stats-1">
|
||||
</div>
|
||||
<!--
|
||||
-->
|
||||
<div id="background-stats-2">
|
||||
</div>
|
||||
</div>
|
||||
<div id="content-container">
|
||||
<div id="content-container-center">
|
||||
<div id="choice">
|
||||
<div class="choice resulta">
|
||||
<div class="label">@Model.OptionA</div>
|
||||
<div class="stat" id="optionA">50%</div>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<div class="choice resultb">
|
||||
<div class="label">@Model.OptionB</div>
|
||||
<div class="stat" id="optionB">50%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="result">
|
||||
<span id="totalVotes">No votes yet</span>
|
||||
</div>
|
||||
<script src="~/lib/signalr/dist/browser/signalr.min.js"></script>
|
||||
<script src="~/js/results.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Result.Pages
|
||||
{
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private string _optionA;
|
||||
private string _optionB;
|
||||
protected readonly IConfiguration _configuration;
|
||||
|
||||
public string OptionA { get; private set; }
|
||||
public string OptionB { get; private set; }
|
||||
|
||||
public IndexModel(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_optionA = _configuration.GetValue<string>("Voting:OptionA");
|
||||
_optionB = _configuration.GetValue<string>("Voting:OptionB");
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
OptionA = _optionA;
|
||||
OptionB = _optionB;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
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 Result
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:56785",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Result": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="1.50.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.12" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,52 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Result.Data;
|
||||
using Result.Hubs;
|
||||
using Result.Timers;
|
||||
|
||||
namespace Result
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
||||
services.AddSignalR();
|
||||
|
||||
services.AddTransient<IResultData, MySqlResultData>()
|
||||
.AddSingleton<PublishResultsTimer>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseSignalR(routes =>
|
||||
{
|
||||
routes.MapHub<ResultsHub>("/resultsHub");
|
||||
});
|
||||
app.UseMvc();
|
||||
|
||||
var timer = app.ApplicationServices.GetService<PublishResultsTimer>();
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using System.Timers;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Result.Data;
|
||||
using Result.Hubs;
|
||||
|
||||
namespace Result.Timers
|
||||
{
|
||||
public class PublishResultsTimer
|
||||
{
|
||||
private readonly IHubContext<ResultsHub> _hubContext;
|
||||
private readonly IResultData _resultData;
|
||||
private readonly Timer _timer;
|
||||
|
||||
public PublishResultsTimer(IHubContext<ResultsHub> hubContext, IResultData resultData, IConfiguration configuration)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_resultData = resultData;
|
||||
var publishMilliseconds = configuration.GetValue<int>("ResultsTimer:PublishMilliseconds");
|
||||
_timer = new Timer(publishMilliseconds)
|
||||
{
|
||||
Enabled = false
|
||||
};
|
||||
_timer.Elapsed += PublishResults;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (!_timer.Enabled)
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void PublishResults(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
var model = _resultData.GetResults();
|
||||
_hubContext.Clients.All.SendAsync("UpdateResults", model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"Voting": {
|
||||
"OptionA": "Cats",
|
||||
"OptionB": "Dogs"
|
||||
},
|
||||
"ResultsTimer": {
|
||||
"PublishMilliseconds": 2500
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"ResultData": "Server=mysql;Port=4000;Database=votes;User=root;SslMode=None"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"defaultProvider": "unpkg",
|
||||
"libraries": [
|
||||
{
|
||||
"library": "@aspnet/signalr@1.0.3",
|
||||
"destination": "wwwroot/lib/signalr/",
|
||||
"files": [
|
||||
"dist/browser/signalr.js",
|
||||
"dist/browser/signalr.min.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
@import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600);
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
font-family: 'Open Sans';
|
||||
}
|
||||
|
||||
body {
|
||||
opacity: 0;
|
||||
transition: all 1s linear;
|
||||
}
|
||||
|
||||
.divider {
|
||||
height: 150px;
|
||||
width: 2px;
|
||||
background-color: #C0C9CE;
|
||||
position: relative;
|
||||
top: 50%;
|
||||
float: left;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
#background-stats-1 {
|
||||
background-color: #2196f3;
|
||||
}
|
||||
|
||||
#background-stats-2 {
|
||||
background-color: #00cbca;
|
||||
}
|
||||
|
||||
#content-container {
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
display: table;
|
||||
padding: 10px;
|
||||
max-width: 940px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#content-container-center {
|
||||
display: table-cell;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
#result {
|
||||
z-index: 3;
|
||||
position: absolute;
|
||||
bottom: 40px;
|
||||
right: 20px;
|
||||
color: #fff;
|
||||
opacity: 0.5;
|
||||
font-size: 45px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
#choice {
|
||||
transition: all 300ms linear;
|
||||
line-height: 1.3em;
|
||||
background: #fff;
|
||||
box-shadow: 10px 0 0 #fff, -10px 0 0 #fff;
|
||||
vertical-align: middle;
|
||||
font-size: 40px;
|
||||
font-weight: 600;
|
||||
width: 450px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
#choice a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#choice a:hover, #choice a:focus {
|
||||
outline: 0;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#choice .choice {
|
||||
width: 49%;
|
||||
position: relative;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
text-align: left;
|
||||
padding-left: 50px;
|
||||
}
|
||||
|
||||
#choice .choice .label {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
#choice .choice.resultb {
|
||||
color: #00cbca;
|
||||
float: right;
|
||||
}
|
||||
|
||||
#choice .choice.resulta {
|
||||
color: #2196f3;
|
||||
float: left;
|
||||
}
|
||||
|
||||
#background-stats {
|
||||
z-index: 1;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
#background-stats div {
|
||||
transition: width 400ms ease-in-out;
|
||||
display: inline-block;
|
||||
margin-bottom: -4px;
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
body{padding-top:50px;padding-bottom:20px}.body-content{padding-left:15px;padding-right:15px}.carousel-caption p{font-size:20px;line-height:1.4}.carousel-inner .item img[src$=".svg"]{width:100%}#qrCode{margin:15px}@media screen and (max-width:767px){.carousel-caption{display:none}}
|
||||
@@ -1,41 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var connection = new signalR.HubConnectionBuilder().withUrl("/resultsHub").build();
|
||||
|
||||
connection.on("UpdateResults", function (results) {
|
||||
document.body.style.opacity=1;
|
||||
|
||||
var a = parseInt(results.optionA || 0);
|
||||
var b = parseInt(results.optionB || 0);
|
||||
var percentages = getPercentages(a, b);
|
||||
|
||||
document.getElementById("optionA").innerText = percentages.a + "%";
|
||||
document.getElementById("optionB").innerText = percentages.b + "%";
|
||||
var totalVotes = 'No votes yet';
|
||||
if (results.voteCount > 0) {
|
||||
totalVotes = results.voteCount + (results.voteCount > 1 ? " votes" : " vote");
|
||||
}
|
||||
document.getElementById("totalVotes").innerText = totalVotes;
|
||||
|
||||
var bg1 = document.getElementById('background-stats-1');
|
||||
var bg2 = document.getElementById('background-stats-2');
|
||||
bg1.style.width = (percentages.a-0.2) + "%";
|
||||
bg2.style.width = (percentages.b-0.2) + "%";
|
||||
});
|
||||
|
||||
connection.start().catch(function (err) {
|
||||
return console.error(err.toString());
|
||||
});
|
||||
|
||||
function getPercentages(a, b) {
|
||||
var result = {};
|
||||
|
||||
if (a + b > 0) {
|
||||
result.a = Math.round(a / (a + b) * 100);
|
||||
result.b = 100 - result.a;
|
||||
} else {
|
||||
result.a = result.b = 50;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user