From c8b83456c1fe6ca6fa814b384b3162f5adccdd57 Mon Sep 17 00:00:00 2001 From: Malloc of Kuzkycyziklistan Date: Fri, 2 Jun 2017 16:02:48 -0500 Subject: [PATCH] probably going to switch away from sqlite e --- server/App.config | 16 +++++++++-- server/CircleScape.csproj | 18 +++++++------ server/DAL/Item.cs | 22 ++++++++++++++++ server/DAL/ItemDefinition.cs | 22 ++++++++++++++++ server/DAL/ScapeDb.cs | 51 +++++++++++++++++++++++++++++------- server/DAL/Session.cs | 21 +++++++-------- server/DAL/User.cs | 32 +++++++--------------- server/Entrypoint.cs | 2 +- server/packages.config | 4 ++- 9 files changed, 133 insertions(+), 55 deletions(-) create mode 100644 server/DAL/Item.cs create mode 100644 server/DAL/ItemDefinition.cs diff --git a/server/App.config b/server/App.config index b553131..6d745b8 100644 --- a/server/App.config +++ b/server/App.config @@ -14,9 +14,9 @@ - - + + @@ -30,4 +30,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/server/CircleScape.csproj b/server/CircleScape.csproj index 1b200d2..4453134 100644 --- a/server/CircleScape.csproj +++ b/server/CircleScape.csproj @@ -44,15 +44,13 @@ - packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll - True + packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll - packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll - True + packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll - - ..\..\..\..\..\..\Program Files (x86)\System.Data.SQLite\2015\bin\SQLite.Designer.dll + + packages\log4net.2.0.5\lib\net45-full\log4net.dll @@ -65,6 +63,9 @@ packages\System.Data.SQLite.EF6.1.0.105.0\lib\net46\System.Data.SQLite.EF6.dll True + + packages\System.Data.SQLite.EF6.Migrations.1.0.104\lib\System.Data.SQLite.EF6.Migrations.dll + packages\System.Data.SQLite.Linq.1.0.105.0\lib\net46\System.Data.SQLite.Linq.dll True @@ -80,6 +81,8 @@ + + @@ -137,8 +140,7 @@ - COPY "$(ProjectDir)scape.db" "$(TargetDir)" -XCOPY "$(ProjectDir)Assets" "$(TargetDir)" /Y + XCOPY "$(ProjectDir)Assets" "$(TargetDir)" /Y diff --git a/server/DAL/Item.cs b/server/DAL/Item.cs new file mode 100644 index 0000000..b5d0fe7 --- /dev/null +++ b/server/DAL/Item.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CircleScape.DAL { + public class Item { + public long Id { get; set; } + + [Index("ItemItemDefinitionId")] + public long DefinitionId { get; set; } + public virtual ItemDefinition Definition { get; set; } + + [Index("ItemUserId")] + public long UserId { get; set; } + public virtual User User { get; set; } + + public long Quantity { get; set; } + } +} diff --git a/server/DAL/ItemDefinition.cs b/server/DAL/ItemDefinition.cs new file mode 100644 index 0000000..fbd0e66 --- /dev/null +++ b/server/DAL/ItemDefinition.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Data.Entity.Spatial; + +namespace CircleScape.DAL { + public partial class ItemDefinition { + public long Id { get; set; } + + [Required] + public string Name { get; set; } + + [Required] + public string Sheet { get; set; } + public long Offset { get; set; } + + public bool Stackable { get; set; } = false; + + public virtual ICollection Items { get; set; } + } +} diff --git a/server/DAL/ScapeDb.cs b/server/DAL/ScapeDb.cs index fa679ea..857abca 100644 --- a/server/DAL/ScapeDb.cs +++ b/server/DAL/ScapeDb.cs @@ -1,22 +1,55 @@ -namespace CircleScape.DAL { - using System; - using System.Data.Entity; - using System.ComponentModel.DataAnnotations.Schema; - using System.Linq; +using System; +using System.Data.Entity; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Data.Entity.Migrations; +using System.Data.SQLite.EF6.Migrations; + +namespace CircleScape.DAL { + public partial class ScapeDb : DbContext { + static ScapeDb() { + Database.SetInitializer( + new MigrateDatabaseToLatestVersion(true) + ); + } + + public ScapeDb() : base("name=Database") { - public partial class Database : DbContext { - public Database() - : base("name=Database") { } public virtual DbSet Sessions { get; set; } public virtual DbSet Users { get; set; } + public virtual DbSet Items { get; set; } + public virtual DbSet ItemDefinitions { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity() .HasMany(e => e.Sessions) .WithRequired(e => e.User) - .WillCascadeOnDelete(false); + .HasForeignKey(e => e.UserId) + .WillCascadeOnDelete(true); + + modelBuilder.Entity() + .HasMany(e => e.Items) + .WithRequired(e => e.User) + .HasForeignKey(e => e.UserId) + .WillCascadeOnDelete(true); + + modelBuilder.Entity() + .HasMany(e => e.Items) + .WithRequired(e => e.Definition) + .HasForeignKey(e => e.DefinitionId) + .WillCascadeOnDelete(true); + } + } + + internal sealed class ScapeDbMigrationConfig + : DbMigrationsConfiguration + { + public ScapeDbMigrationConfig() { + AutomaticMigrationsEnabled = true; + AutomaticMigrationDataLossAllowed = true; + SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator()); } } } diff --git a/server/DAL/Session.cs b/server/DAL/Session.cs index 2caf8b4..1758665 100644 --- a/server/DAL/Session.cs +++ b/server/DAL/Session.cs @@ -1,21 +1,18 @@ -namespace CircleScape.DAL -{ - using System; - using System.Collections.Generic; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - using System.Data.Entity.Spatial; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Data.Entity.Spatial; - public partial class Session - { +namespace CircleScape.DAL { + public partial class Session { public long Id { get; set; } + [Index("SessionUserId")] public long UserId { get; set; } + public virtual User User { get; set; } [Required] - [StringLength(2147483647)] public string IpAddress { get; set; } - - public virtual User User { get; set; } } } diff --git a/server/DAL/User.cs b/server/DAL/User.cs index 94498ce..d29bac4 100644 --- a/server/DAL/User.cs +++ b/server/DAL/User.cs @@ -1,27 +1,17 @@ -namespace CircleScape.DAL -{ - using System; - using System.Collections.Generic; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - using System.Data.Entity.Spatial; - - public partial class User - { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] - public User() - { - Sessions = new HashSet(); - } +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Data.Entity.Spatial; +namespace CircleScape.DAL { + public partial class User { public long Id { get; set; } [Required] - [StringLength(2147483647)] public string Username { get; set; } [Required] - [StringLength(2147483647)] public string Password { get; set; } public long? Joined { get; set; } @@ -29,13 +19,11 @@ namespace CircleScape.DAL public long? LastLogin { get; set; } [Required] - [StringLength(2147483647)] public string JoinedIp { get; set; } - - [StringLength(2147483647)] + public string LastIp { get; set; } - - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection Sessions { get; set; } + public virtual ICollection Items { get; set; } } } diff --git a/server/Entrypoint.cs b/server/Entrypoint.cs index 1c6eed6..9f3171d 100644 --- a/server/Entrypoint.cs +++ b/server/Entrypoint.cs @@ -11,7 +11,7 @@ using Square; namespace CircleScape { class Entrypoint { static void Main(string[] args) { - var db = new Database(); + var db = new ScapeDb(); var users = db.Users.ToList(); var server = new Kneesocks.Server(6770, PoolManager.Pending); diff --git a/server/packages.config b/server/packages.config index d28215b..450a5e4 100644 --- a/server/packages.config +++ b/server/packages.config @@ -1,10 +1,12 @@  - + + + \ No newline at end of file