Skip to content

Commit

Permalink
Changed to use linq-es5 react package so it could be built withn NPM.…
Browse files Browse the repository at this point in the history
… Web interface now taking Env params for the db location as well as listen port. Docker build file working.
  • Loading branch information
TWhidden committed Sep 26, 2018
1 parent 7591f69 commit 02c004d
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 99 deletions.
7 changes: 6 additions & 1 deletion HolidayShow.Data.Core/EfHolidayContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ public class EfHolidayContext : DbContext

public EfHolidayContext()
{
_connectionString = "Server=10.64.128.100,1401;Database=HolidayShow_Dev;User Id=dev;Password=dev123;Trusted_Connection=False;";
//_connectionString = "Server=10.64.128.100,1401;Database=HolidayShow_Dev;User Id=dev;Password=dev123;Trusted_Connection=False;";
}

public EfHolidayContext(string cs)
{
_connectionString = cs;
}

public EfHolidayContext(DbContextOptions<EfHolidayContext> options) : base(options)
{

}

public void UpdateDatabase()
{
//this.Database.ExecuteSqlCommand(Resources.HolidayShow);
Expand Down
122 changes: 65 additions & 57 deletions HolidayShowWeb/ClientApp/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion HolidayShowWeb/ClientApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@material-ui/core": "^1.5.1",
"@material-ui/icons": "^2.0.3",
"linq-es2015": "^2.4.33",
"linq-es5": "^1.11.14",
"proptypes": "^1.1.0",
"react": "^16.4.2",
"react-beautiful-dnd": "^9.0.2",
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowWeb/ClientApp/src/components/DeviceEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import FormControl from '@material-ui/core/FormControl';
import Select from '@material-ui/core/Select';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import * as Enumerable from "linq-es2015";
import * as Enumerable from "linq-es5";

const styles = theme => ({
formControl: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Switch from '@material-ui/core/Switch';
import BusyContent from './controls/BusyContent';
import Button from '@material-ui/core/Button';
import FindReplace from '@material-ui/icons/FindReplace'
import * as Enumerable from "linq-es2015";
import * as Enumerable from "linq-es5";
import ErrorContent from './controls/ErrorContent';

const styles = theme => ({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl';
import TextField from '@material-ui/core/TextField';
import * as Enumerable from "linq-es2015";
import * as Enumerable from "linq-es5";
import IconButton from '@material-ui/core/IconButton';
import DeleteIcon from '@material-ui/icons/Delete';
import AddIcon from '@material-ui/icons/Add';
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowWeb/ClientApp/src/components/EffectsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl';
import TextField from '@material-ui/core/TextField';
import * as Enumerable from "linq-es2015";
import * as Enumerable from "linq-es5";
import IconButton from '@material-ui/core/IconButton';
import DeleteIcon from '@material-ui/icons/Delete';
import AddIcon from '@material-ui/icons/Add';
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowWeb/ClientApp/src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import BusyContent from './controls/BusyContent';
import ErrorContent from './controls/ErrorContent';
import * as Enumerable from "linq-es2015";
import * as Enumerable from "linq-es5";

const styles = theme => ({
button: {
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowWeb/ClientApp/src/components/SetsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl';
import TextField from '@material-ui/core/TextField';
import * as Enumerable from "linq-es2015";
import * as Enumerable from "linq-es5";
import IconButton from '@material-ui/core/IconButton';
import DeleteIcon from '@material-ui/icons/Delete';
import AddIcon from '@material-ui/icons/Add';
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowWeb/ClientApp/src/components/SettingsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import BusyContent from './controls/BusyContent';
import ErrorContent from './controls/ErrorContent';
import * as Enumerable from "linq-es2015";
import * as Enumerable from "linq-es5";

const delayMs = "SetDelayMs";
const audioTimeOffAt = "AudioTimeOffAt";
Expand Down
26 changes: 12 additions & 14 deletions HolidayShowWeb/Controllers/DeviceIoPortsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,52 +110,50 @@ public async Task<IActionResult> PutDeviceIoPortIdentify([FromRoute] int id)

try
{
using (var dc = new EfHolidayContext())
{

var ioPort = await dc.DeviceIoPorts.Where(x => x.DeviceIoPortId == id).FirstOrDefaultAsync();

var ioPort = await _context.DeviceIoPorts.Where(x => x.DeviceIoPortId == id).FirstOrDefaultAsync();
if (ioPort == null) return BadRequest(ModelState);

var existingSetting = await dc.Settings.Where(x => x.SettingName == SettingKeys.DetectDevicePin)
var existingSetting = await _context.Settings.Where(x => x.SettingName == SettingKeys.DetectDevicePin)
.FirstOrDefaultAsync();
if (existingSetting == null)
{
existingSetting = new Settings()
{
SettingName = SettingKeys.DetectDevicePin
};
dc.Settings.Add(existingSetting);
_context.Settings.Add(existingSetting);
}

existingSetting.ValueString = $"{ioPort.DeviceId}:{ioPort.CommandPin}";
await dc.SaveChangesAsync();
await _context.SaveChangesAsync();

var option = await dc.Settings.Where(x => x.SettingName == SettingKeys.SetPlaybackOption)
var option = await _context.Settings.Where(x => x.SettingName == SettingKeys.SetPlaybackOption)
.FirstOrDefaultAsync();
if (option == null)
{
option = new Settings {SettingName = SettingKeys.SetPlaybackOption};
dc.Settings.Add(option);
_context.Settings.Add(option);
}

option.ValueDouble = (double) SetPlaybackOptionEnum.DevicePinDetect;
await dc.SaveChangesAsync();
await _context.SaveChangesAsync();

var setting = await dc.Settings.Where(x => x.SettingName == SettingKeys.Refresh).FirstOrDefaultAsync();
var setting = await _context.Settings.Where(x => x.SettingName == SettingKeys.Refresh).FirstOrDefaultAsync();

if (setting == null)
{
setting = new Settings
{
SettingName = SettingKeys.Refresh,
};
dc.Settings.Add(setting);
_context.Settings.Add(setting);
}

setting.ValueString = "None";

await dc.SaveChangesAsync();
}
await _context.SaveChangesAsync();

}
catch (DbUpdateConcurrencyException)
{
Expand Down
7 changes: 2 additions & 5 deletions HolidayShowWeb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app

#Default Container Port 5555 will be used.
ARG DEFAULTPORT=5555
#Default Container Port 5001 will be used.
ARG DEFAULTPORT=5001

EXPOSE $DEFAULTPORT

Expand All @@ -15,8 +15,6 @@ ENV PORT=$DEFAULTPORT
ENV TZ=America/Los_Angeles
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

ENV ASPNETCORE_URLS http://+:80

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src

Expand All @@ -42,7 +40,6 @@ FROM base AS final
WORKDIR /app
COPY --from=publish /app .

EXPOSE 80
ENTRYPOINT ["dotnet", "HolidayShowWeb.dll"]


17 changes: 13 additions & 4 deletions HolidayShowWeb/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;

namespace HolidayShowWeb
{
Expand All @@ -12,10 +11,20 @@ public static void Main(string[] args)
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
// get the environment var
var portStr = System.Environment.GetEnvironmentVariable("PORT");
if (!int.TryParse(portStr, out var port))
{
port = 5001;
}

return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls($"http://*:5001");
.UseUrls($"http://*:{port}");
}


}
}
18 changes: 17 additions & 1 deletion HolidayShowWeb/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using HolidayShow.Data;
using HolidayShowWeb.Resovlers;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -31,8 +32,23 @@ public void ConfigureServices(IServiceCollection services)
configuration.RootPath = "ClientApp/build";
});

var server = System.Environment.GetEnvironmentVariable("DBSERVER");
var database = System.Environment.GetEnvironmentVariable("DBNAME");
var username = System.Environment.GetEnvironmentVariable("DBUSER");
var password = System.Environment.GetEnvironmentVariable("DBPASS");

var connectionString = Configuration.GetConnectionString("EfHolidayContext");
if (!string.IsNullOrWhiteSpace(server))
{
connectionString = $"Server={server};Database={database};User Id={username};Password={password};";
}
else
{
throw new Exception("Environment Variables Not Set! Set for DB Connection Information!");
}

services.AddDbContext<EfHolidayContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("EfHolidayContext")));
options.UseSqlServer(connectionString));

services.AddMvc().AddJsonOptions(options => {
//options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
Expand Down
2 changes: 1 addition & 1 deletion HolidayShowWeb/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"EfHolidayContext": "Server=10.64.128.100,1401;Database=HolidayShow_Dev;User Id=dev;Password=dev123;Trusted_Connection=False;"
"EfHolidayContext": ""
},
"Logging": {
"LogLevel": {
Expand Down
22 changes: 14 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
version: '3.4'

services:
HolidayShowClient:
image: holidayshowclient
build:
context: .
dockerfile: HolidayShowClient.Core/Dockerfile
# HolidayShowClient:
# image: holidayshowclient
# build:
# context: .
# dockerfile: HolidayShowClient.Core/Dockerfile


HolidayShowServer:
image: holidayshowserver
#HolidayShowServer:
# image: holidayshowserver
# build:
# context: .
# dockerfile: HolidayShowServer.Core/Dockerfile

HolidayShowEdit:
image: holidayshowedit
build:
context: .
dockerfile: HolidayShowServer.Core/Dockerfile
dockerfile: HolidayShowWeb/Dockerfile

0 comments on commit 02c004d

Please sign in to comment.