Skip to content

Commit

Permalink
Domain refactored (#41)
Browse files Browse the repository at this point in the history
* Domain refactored

* Added MySQL support for DbProvider
Cleaned up tests

* Temporary fix for user insertion, Timestamp is now created on the server for the time being.

* The TrainingSessionRepository now correctly fetches the species. The DbContext Local database set was not up to date after calling UpdateAsync. The current fix is to Detach the objects you want to make sure are the latest in the next fetch query.
  • Loading branch information
metalglove authored Aug 24, 2019
1 parent fcd6e56 commit 77930db
Show file tree
Hide file tree
Showing 76 changed files with 2,376 additions and 2,811 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ Follow these steps to get your development environment set up:
"Host": "{COMMON NAME OR FULLY QUALLIFIED DOMAIN NAME}"
},
"NeuralmDb": {
"ConnectionString": "Server={YOUR SERVER NAME\\MSSQLINSTANCE};Database=NeuralmDbContext;Trusted_Connection=True;MultipleActiveResultSets=true",
"UseLazyLoading": false
"ConnectionString": "{MSSQL/MYSQL CONNECTION STRING}",
"UseLazyLoading": true,
"DbProvider": "{MSSQL/MYSQL (OR LEAVE IT EMPTY FOR IN MEMORY PROVIDER)}"
}
}
```
NOTE: Keep `UseLazyLoading` on false for now!
ConnectionString examples:
```
MSSQL: "Server=(LocalDb)\\MSSQLLocalDB;Database=NeuralmDbContext;Trusted_Connection=True;MultipleActiveResultSets=true"
MYSQL: "Server=localhost;Database=NeuralmDbContext;User=root;Password=;"
```
3. Afterwards generate a self signed certificate using the script in powershell (Administrator mode!)
```powershell
New-SelfSignedCertificate -DnsName "{COMMON NAME OR FULLY QUALLIFIED DOMAIN NAME}" -CertStoreLocation "cert:\LocalMachine\My" -FriendlyName "NeuralmCert"
Expand All @@ -54,12 +59,13 @@ Follow these steps to get your development environment set up:
5. Once the build has run successfully, start the server to confirm that the database connection is successful either by hitting `F5` or go to `Debug > Start`. A console will launch and start initializing. Upon completion, the console will look like this:


![Screenshot](https://github.com/neuralm/Neuralm-Server/blob/master/docs/images/Successful%20installation.png?raw=true)
![Screenshot](https://github.com/neuralm/Neuralm-Server/blob/master/docs/images/Successful%20installation.png?raw=true)

## Running the tests

**NOTE:** For the tests each method will create its own database with a random GUID and delete itself after completion of the test. This is done so that the tests can run in parallel and do not have any dependencies. Because InMemoryDatabase is not *yet* a relational-database provider, some tests will use the repository instead of the service to make the tests work as intended.

Run the tests using this command:
```
dotnet test
```
## Deployment
## Contributing
Expand Down
24 changes: 0 additions & 24 deletions src/Neuralm.Application.Messages/Dtos/BrainDto.cs

This file was deleted.

12 changes: 6 additions & 6 deletions src/Neuralm.Application.Messages/Dtos/ConnectionGeneDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class ConnectionGeneDto
/// <inheritdoc cref="ConnectionGene.Id"/>
public Guid Id { get; set; }

/// <inheritdoc cref="ConnectionGene.BrainId"/>
public Guid BrainId { get; set; }
/// <inheritdoc cref="ConnectionGene.OrganismId"/>
public Guid OrganismId { get; set; }

/// <inheritdoc cref="ConnectionGene.InId"/>
public uint InId { get; set; }
/// <inheritdoc cref="ConnectionGene.InNodeIdentifier"/>
public uint InNodeIdentifier { get; set; }

/// <inheritdoc cref="ConnectionGene.OutId"/>
public uint OutId { get; set; }
/// <inheritdoc cref="ConnectionGene.OutNodeIdentifier"/>
public uint OutNodeIdentifier { get; set; }

/// <inheritdoc cref="ConnectionGene.InnovationNumber"/>
public uint InnovationNumber { get; set; }
Expand Down
14 changes: 3 additions & 11 deletions src/Neuralm.Application.Messages/Dtos/OrganismDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Neuralm.Domain.Entities.NEAT;

namespace Neuralm.Application.Messages.Dtos
Expand All @@ -11,17 +12,8 @@ public class OrganismDto
/// <inheritdoc cref="Organism.Id"/>
public Guid Id { get; set; }

/// <inheritdoc cref="Organism.SpeciesId"/>
public Guid SpeciesId { get; set; }

/// <inheritdoc cref="Organism.BrainId"/>
public Guid BrainId { get; set; }

/// <inheritdoc cref="Organism.TrainingRoomId"/>
public Guid TrainingRoomId { get; set; }

/// <inheritdoc cref="Organism.Brain"/>
public BrainDto Brain { get; set; }
/// <inheritdoc cref="Organism.ConnectionGenes"/>
public List<ConnectionGeneDto> ConnectionGenes { get; set; }

/// <inheritdoc cref="Organism.Score"/>
public double Score { get; set; }
Expand Down
9 changes: 0 additions & 9 deletions src/Neuralm.Application.Messages/Dtos/TrainingRoomDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,5 @@ public class TrainingRoomDto

/// <inheritdoc cref="TrainingRoom.TrainingRoomSettings"/>
public TrainingRoomSettingsDto TrainingRoomSettings { get; set; }

/// <inheritdoc cref="TrainingRoom.HighestScore"/>
public double HighestScore { get; set; }

/// <inheritdoc cref="TrainingRoom.LowestScore"/>
public double LowestScore { get; set; }

/// <inheritdoc cref="TrainingRoom.AverageScore"/>
public double AverageScore { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Neuralm.Application/Configurations/DbConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public class DbConfiguration
{
public string ConnectionString { get; set; }
public bool UseLazyLoading { get; set; }
public string DbProvider { get; set; }
}
}
5 changes: 4 additions & 1 deletion src/Neuralm.Application/Converters/DtoToEntityConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

Expand All @@ -18,6 +19,8 @@ public static class DtoToEntityConverter
/// <returns>Returns the converted dto as entity.</returns>
public static TEntity Convert<TEntity, TDto>(TDto dto) where TEntity : class, new()
{
if (dto == null)
throw new ArgumentNullException(nameof(dto));
TEntity entity = new TEntity();
IList<PropertyInfo> dtoProperties = new List<PropertyInfo>(typeof(TDto).GetProperties());
IList<PropertyInfo> entityProperties = new List<PropertyInfo>(typeof(TEntity).GetProperties());
Expand Down
11 changes: 10 additions & 1 deletion src/Neuralm.Application/Converters/EntityToDtoConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static class EntityToDtoConverter
/// <returns>Returns the converted entity as dto.</returns>
public static TDto Convert<TDto, TEntity>(TEntity entity) where TDto : class, new()
{
if (entity == null)
throw new ArgumentNullException(nameof(entity));
TDto dto = new TDto();
IList<PropertyInfo> joinedProperties =
typeof(TDto).GetProperties().Join(typeof(TEntity).GetProperties(),
Expand All @@ -46,7 +48,11 @@ public static class EntityToDtoConverter
}
foreach (object item in list)
{
Type actualType = ((IProxyTargetAccessor)item).DynProxyGetTarget().GetType().BaseType;
if (item == null)
continue;
Type actualType = item.GetType();
if (item is IProxyTargetAccessor accessor)
actualType = accessor.DynProxyGetTarget().GetType().BaseType;
genericListInstance.Add(Convert(dtoItemType, actualType, item));
}
property.SetValue(dto, genericListInstance);
Expand Down Expand Up @@ -126,6 +132,9 @@ private static bool GetValue(Type entityType, object entity, PropertyInfo proper
entityObject = entityType.GetProperty(property.Name).GetValue(entity, null);
}

if (entityObject == null)
return false;

object result = Convert(property.PropertyType, newEntityType, entityObject);
property.SetValue(dto, result);
return true;
Expand Down
Loading

0 comments on commit 77930db

Please sign in to comment.