Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Guard #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion AssemblyInfo.General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

[assembly: AssemblyCompany("Национальный Исследовательский Ядерный Университет МИФИ")]
[assembly: AssemblyProduct("GraphLabs")]
[assembly: AssemblyCopyright("Copyright © 2012-2016")]
[assembly: AssemblyCopyright("Copyright © 2012-2018")]
[assembly: AssemblyTrademark("")]
8 changes: 8 additions & 0 deletions Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

public class Class1
{
public Class1()
{
}
}
4 changes: 4 additions & 0 deletions GraphLabs.Dal.Ef/GraphLabs.Dal.Ef.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@
<Project>{3e515720-d0a1-4b01-a3e0-c82412b2d663}</Project>
<Name>GraphLabs.DomainModel</Name>
</ProjectReference>
<ProjectReference Include="..\GraphLabs.Guard\GraphLabs.Guard.csproj">
<Project>{d0a05aef-dc7e-4b2b-a82a-9a23eaa0af95}</Project>
<Name>GraphLabs.Guard</Name>
</ProjectReference>
<ProjectReference Include="..\GraphLabs.Site.Core\GraphLabs.Site.Core.csproj">
<Project>{d62cc3f4-3ea1-44ff-b9e2-492582788b3b}</Project>
<Name>GraphLabs.Site.Core</Name>
Expand Down
3 changes: 2 additions & 1 deletion GraphLabs.Dal.Ef/GraphLabsContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GraphLabs.DomainModel.Contexts;
using GraphLabs.DomainModel.Infrastructure;


namespace GraphLabs.Dal.Ef
{
class GraphLabsContextImpl : IGraphLabsContext, IEntityQuery, IEntityFactory
Expand Down Expand Up @@ -34,7 +35,7 @@ public GraphLabsContextImpl(GraphLabsContext ctx)

private Type GetEntityTypeFor(Type type)
{
Contract.Assert(typeof(AbstractEntity).IsAssignableFrom(type));
Guard.AreAssignedTypes(typeof(AbstractEntity), type);

var baseType = type.BaseType;
if (baseType == typeof(AbstractEntity))
Expand Down
2 changes: 1 addition & 1 deletion GraphLabs.Dal.Ef/Infrastructure/ChangesTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ChangesTracker : IChangesTracker
/// <summary> Менеджер изменений </summary>
public ChangesTracker(GraphLabsContext context)
{
Contract.Requires(context != null);
Guard.IsNotNull(nameof(context), context );

_context = context;
}
Expand Down
12 changes: 10 additions & 2 deletions GraphLabs.Dal.Ef/Infrastructure/EntityChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,25 @@ public EntityChange(DbEntityEntry entry)
/// <summary> Изменилось ли свойство? </summary>
public bool PropertyChanged(string propertyName)
{
Guard.IsNotNullOrWhiteSpace(propertyName);
return _entry.CurrentValues[propertyName] != _entry.OriginalValues[propertyName];
}

public IReadOnlyDictionary<string, object> OriginalValues
{
get { return _originalValues.Value; }

get
{
return _originalValues.Value;
}
}

public IReadOnlyDictionary<string, object> CurrentValues
{
get { return _currentValues.Value; }
get
{
return _currentValues.Value;
}
}
}
}
5 changes: 3 additions & 2 deletions GraphLabs.Dal.Ef/Infrastructure/EntitySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public TEntity Find(params object[] keyValues)
/// <exception cref="EntityNotFoundException">Не удалось найти сущность с заданным ключом</exception>
public TEntity Get(params object[] keyValues)
{
Guard.IsPositive(keyValues.Length, nameof(keyValues));
var entity = _ctx.Set<TEntity>().Find(keyValues);
if (entity == null)
throw new EntityNotFoundException(typeof(TEntity), keyValues);
Expand All @@ -42,7 +43,7 @@ public TDerivedEntity CreateNew<TDerivedEntity>() where TDerivedEntity : TEntity
var set = _ctx.Set<TEntity>();
var entity = set.Create<TDerivedEntity>();
set.Add(entity);

Guard.IsNotNull(entity);
return entity;
}

Expand All @@ -52,7 +53,7 @@ public TEntity CreateNew()
var set = _ctx.Set<TEntity>();
var entity = set.Create();
set.Add(entity);

Guard.IsNotNull(entity, "entity");
return entity;
}
}
Expand Down
2 changes: 2 additions & 0 deletions GraphLabs.Dal.Ef/IoC/DalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GraphLabs.Site.Core.OperationContext;
using GraphLabs.Site.Utils.IoC;
using Microsoft.Practices.Unity;
using GraphLabs;

namespace GraphLabs.Dal.Ef.IoC
{
Expand All @@ -17,6 +18,7 @@ public sealed class DalConfiguration : IUnityRegistry
/// <summary> Сконфигурировать </summary>
public void ConfigureContainer(IUnityContainer container)
{
Guard.IsNotNull(nameof(container), container);
// Сам EF-контекст
container.RegisterType<GraphLabsContext>(new HierarchicalLifetimeManager());

Expand Down
14 changes: 10 additions & 4 deletions GraphLabs.Dal.Ef/Repositories/CategoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ public CategoryRepository(GraphLabsContext context)
/// <summary> Получить категорию по id </summary>
public Category GetById(long id)
{
Guard.IsPositive(id, nameof(id) );
CheckNotDisposed();

return Context.Categories.Single(c => c.Id == id);
var result = Context.Categories.Single(c => c.Id == id);
Guard.IsNotNull(result);
return (result);
}

///<summary> Получить все категории </summary>
public Category[] GetAllCategories()
{
CheckNotDisposed();

return Context.Categories.ToArray();
var result = Context.Categories.ToArray();
Guard.IsNotNull(result);
return result;
}

///<summary> Сохранение категории </summary>
public void SaveCategory(Category category)
{
Guard.IsNotNull(nameof(category), category);
CheckNotDisposed();

Context.Categories.Add(category);
Expand All @@ -42,7 +47,8 @@ public void SaveCategory(Category category)
///<summary> Редактирование категории </summary>
public void EditCategory(Category category)
{
CheckNotDisposed();
Guard.IsNotNull(nameof(category), category);
CheckNotDisposed();

Context.Entry(category).State = EntityState.Modified;
Context.SaveChanges();
Expand Down
16 changes: 10 additions & 6 deletions GraphLabs.Dal.Ef/Repositories/GroupRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@ public GroupRepository(GraphLabsContext context)
public Group[] GetAllGroups()
{
CheckNotDisposed();

return Context.Groups.ToArray();
var result = Context.Groups.ToArray();
Guard.IsNotNull(result);
return result;
}

/// <summary> Получить группы, открытые для регистрации </summary>
public Group[] GetOpenGroups()
{
CheckNotDisposed();

return Context.Groups.Where(g => g.IsOpen).ToArray();
var result = Context.Groups.Where(g => g.IsOpen).ToArray();
Guard.IsNotNull(result);
return result;
}

/// <summary> Получить группу по id </summary>
public Group GetGroupById(long id)
{
Guard.IsPositive(id, "id");
CheckNotDisposed();

return Context.Groups.Where(g => g.Id == id).Single();
var result = Context.Groups.Where(g => g.Id == id).Single();
Guard.IsNotNull(result);
return result;
}
}
}
Loading