Skip to content

Commit

Permalink
use dotnet core
Browse files Browse the repository at this point in the history
  • Loading branch information
PaluMacil committed Apr 25, 2018
1 parent 8ab35f8 commit 799d36b
Show file tree
Hide file tree
Showing 135 changed files with 26,132 additions and 539 deletions.
29 changes: 4 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
debug

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Logs
log.txt
*.csproj.user
/.vs
bin/
obj/
57 changes: 41 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": ["dev"],
"showLog": true
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/web/bin/Debug/netcoreapp2.0/web.dll",
"args": [],
"cwd": "${workspaceFolder}/web",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
,]
}
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/web/web.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
24 changes: 24 additions & 0 deletions Cli/Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>dwn</AssemblyName>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<UserSecretsId>aspnet-cli-6c5e2d8f-26d0-4767-9035-8b2aaac6f1b8</UserSecretsId>
<RootNamespace>Dwn.Cli</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\data\Data.csproj" />
</ItemGroup>

<ItemGroup>

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.2" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions Cli/Commands/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Microsoft.EntityFrameworkCore;
using Dwn.Data.Database;
using Dwn.Data.Models.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Identity;
using System.Linq;

namespace Dwn.Cli.Commands
{
public interface ICommand
{
void Execute();
}
}
86 changes: 86 additions & 0 deletions Cli/Commands/ListCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using Microsoft.EntityFrameworkCore;
using Dwn.Data.Database;
using Dwn.Data.Models.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Identity;
using System.Linq;
using System.Collections.Generic;

namespace Dwn.Cli.Commands
{
public class ListCommand : ICommand
{
private ApplicationDbContext Db;
private string PrimarySubject;
private string SecondarySubject;
private UserManager<ApplicationUser> UserManager;
private RoleManager<IdentityRole> RoleManager;
private static IEnumerable<string> ServiceNames;


public ListCommand(
ApplicationDbContext db,
string primarySubject,
string secondarySubject,
UserManager<ApplicationUser> userManager,
RoleManager<IdentityRole> roleManager,
IEnumerable<string> serviceNames)
{
Db = db;
PrimarySubject = primarySubject.ToLower();
SecondarySubject = secondarySubject.ToLower();
UserManager = userManager;
RoleManager = roleManager;
ServiceNames = serviceNames;
}

public void Execute()
{
switch (PrimarySubject)
{
case "users":
Users(SecondarySubject);
break;
case "roles":
Roles(SecondarySubject);
break;
case "injectable":
Injectable();
break;
}
}

private void Injectable()
{
foreach (var s in ServiceNames)
{
Console.WriteLine(s);
}
}

private void Users(string forRole)
{
IList<ApplicationUser> users;
if (forRole == null)
{
users = Db.Users.ToList();
}
else
{
users = UserManager.GetUsersInRoleAsync(forRole).Result;
}

foreach (var u in users)
{
Console.WriteLine(u.Email);
}
}

private void Roles(string forUser)
{

}
}
}
18 changes: 18 additions & 0 deletions Cli/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Dwn.Cli
{
public static class Helpers
{
public static T GetElementOrDefault<T>(this T[] array, int index)
{
if (index < array.Length)
{
return array[index];
}
return default(T);
}
}
}
65 changes: 65 additions & 0 deletions Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using Microsoft.EntityFrameworkCore;
using Dwn.Data.Database;
using Dwn.Data.Models.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Identity;
using System.Linq;
using Dwn.Cli.Commands;
using System.Collections.Generic;

namespace Dwn.Cli
{
class Program
{
private static IConfigurationRoot Configuration;
private static ServiceCollection Services;

static void Main(string[] args)
{
var provider = GetServiceProvider();

var db = provider.GetService<ApplicationDbContext>();
var userManager = provider.GetService<UserManager<ApplicationUser>>();
var roleManager = provider.GetService<RoleManager<IdentityRole>>();

if (args.Length == 1)
{
Console.WriteLine("Available commands: list");
return;
}
ICommand cmd;
switch (args[1])
{
case "list":
var serviceNames = Services.OrderBy(s => s.ServiceType.Name).Select(s => s.ServiceType.Name);
cmd = new ListCommand(db, args.GetElementOrDefault(2), args.GetElementOrDefault(3), userManager, roleManager, serviceNames);
break;
}
}

private static ServiceProvider GetServiceProvider()
{
// Get configuration from user secrets if in dev mode.
var builder = new ConfigurationBuilder();
string env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (env == "Development")
{
builder.AddUserSecrets<Program>();
} // TODO: else use env variables
Configuration = builder.Build();

var services = new ServiceCollection();
var conn = Configuration.GetConnectionString("Ry");
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(conn)
);
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();

Services = services;
return services.BuildServiceProvider();
}
}
}
15 changes: 15 additions & 0 deletions Cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Commandline Tool for dwn

```
cd cli
dotnet restore
dotnet user-secrets set "ConnectionStrings:Ry" "Server=127.0.0.1;Port=5432;Database=postgres;User Id=username;Password=mypw;"
```

```
dotnet publish -c Release -r win10-x64
```

```
$ENV:PATH="$ENV:PATH;$pwd\bin\Release\netcoreapp2.0\win10-x64\publish"
```
8 changes: 8 additions & 0 deletions Data/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Dwn.Data
{
public class Class1
{
}
}
11 changes: 11 additions & 0 deletions Data/Data.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RootNamespace>Dwn.Data</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.2" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Data/Database/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Dwn.Data.Models.Identity;

namespace Dwn.Data.Database
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{ }

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
}
Loading

0 comments on commit 799d36b

Please sign in to comment.