Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

init #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/NetPartyCli/.vs/NetPartyCli/v15/Server/sqlite3
13 changes: 13 additions & 0 deletions NetPartyCli/Database/PartyContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
namespace NetPartyCli.Database
{
public class PartyContext : DbContext
{
public PartyContext(DbContextOptions<PartyContext> options)
: base(options)
{ }

public DbSet<User> Users { get; set; }
public DbSet<Server> Servers { get; set; }
}
}
16 changes: 16 additions & 0 deletions NetPartyCli/Database/PartyContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using NetPartyCli.Database;

namespace NetPartyCli.Database
{
public class PartyContextFactory : IDesignTimeDbContextFactory<PartyContext>
{
public PartyContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<PartyContext>();
optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=PartyDB");
return new PartyContext(optionsBuilder.Options);
}
}
}
9 changes: 9 additions & 0 deletions NetPartyCli/Database/Server.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NetPartyCli.Database
{
public class Server
{
public int Id { get; set; }
public string Name { get; set; }
public int Distance { get; set; }
}
}
9 changes: 9 additions & 0 deletions NetPartyCli/Database/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NetPartyCli.Database
{
public class User
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
}
15 changes: 15 additions & 0 deletions NetPartyCli/Dto/ServerDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

namespace NetPartyCli.Dto
{
public class ServerDto
{
public ServerDto(string name, int distance)
{
Name = name;
Distance = distance;
}

public string Name { get; set; }
public int Distance { get; set; }
}
}
16 changes: 16 additions & 0 deletions NetPartyCli/Dto/UserDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace NetPartyCli.Dto
{
public class UserDto
{
public UserDto(string username, string password)
{
Username = username;
Password = password;
}

public string Username { get; set; }
public string Password { get; set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace NetPartyCli.Migrations.SqlServerMigrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ServerService",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true),
Distance = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Servers", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Username = table.Column<string>(nullable: true),
Password = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ServerService");

migrationBuilder.DropTable(
name: "Users");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NetPartyCli;
using NetPartyCli.Database;

namespace NetPartyCli.Migrations.SqlServerMigrations
{
[DbContext(typeof(PartyContext))]
partial class PartyContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

modelBuilder.Entity("NetPartyCli.Server", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<int>("Distance");

b.Property<string>("Name");

b.HasKey("Id");

b.ToTable("ServerService");
});

modelBuilder.Entity("NetPartyCli.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

b.Property<string>("Password");

b.Property<string>("Username");

b.HasKey("Id");

b.ToTable("Users");
});
#pragma warning restore 612, 618
}
}
}
21 changes: 21 additions & 0 deletions NetPartyCli/NetPartyCli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>7.1</LangVersion>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions NetPartyCli/NetPartyCli.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.28010.2046
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetPartyCli", "NetPartyCli.csproj", "{9C30AAD2-7944-4426-914B-B93EA9DBA736}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9C30AAD2-7944-4426-914B-B93EA9DBA736}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C30AAD2-7944-4426-914B-B93EA9DBA736}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C30AAD2-7944-4426-914B-B93EA9DBA736}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C30AAD2-7944-4426-914B-B93EA9DBA736}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8BD8AAF9-60A0-4E2F-8534-3E99E1DBD9B4}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions NetPartyCli/Presentation/Display.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using NetPartyCli.Dto;

namespace NetPartyCli.Presentation
{
public class Display
{
public void Show(IEnumerable<ServerDto> servers)
{
foreach (var server in servers)
{
Console.WriteLine($"Server name: {server.Name}, distance: {server.Distance}.");
}
}
}
}
12 changes: 12 additions & 0 deletions NetPartyCli/Presentation/ServerOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CommandLine;


namespace NetPartyCli.Presentation
{
[Verb("server_list", HelpText = "Fetches server list from API and saves data to persistent data store.")]
public class ServerOption
{
[Option('l', "local", Required = false, HelpText = "Fetches data from persistent data store.")]
public bool Local { get; set; }
}
}
14 changes: 14 additions & 0 deletions NetPartyCli/Presentation/UserOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using CommandLine;

namespace NetPartyCli.Presentation
{
[Verb("config", HelpText = "Stores username and password for API authorization in the persistent data store.")]
public class UserOption
{
[Option('u', "username", Required = false, HelpText = "API username.")]
public string Username { get; set; }

[Option('p', "password", Required = false, HelpText = "API password.")]
public string Password { get; set; }
}
}
Loading