Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/[Pp]ackages

*.user

/.idea
[Oo]bj
[Bb]in
/AssemblyVersion.cs
Expand Down
37 changes: 37 additions & 0 deletions GraphLabs.Dal.Ef/Extensions/LabModeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using GraphLabs.DomainModel;

namespace GraphLabs.Dal.Ef.Extensions
{
public static class LabModeExtensions
{
/// <summary> Значение -> строка </summary>
public static string ValueToString(this LabExecutionMode mode)
{
switch (mode)
{
case LabExecutionMode.IntroductoryMode:
return "Контрольный";
case LabExecutionMode.TestMode:
return "Ознакомительный";
default:
throw new Exception("something missing here");
}
}

public static LabExecutionMode? GetValueByString(string value)
{
if (value == null)
return null;
switch (value)
{
case "Контрольный":
return LabExecutionMode.TestMode;
case "Ознакомительный":
return LabExecutionMode.IntroductoryMode;
default:
return null;
}
}
}
}
4 changes: 2 additions & 2 deletions GraphLabs.DomainModel/GraphLabs.DomainModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
13 changes: 13 additions & 0 deletions GraphLabs.Site.Core/Filters/AbstractFilterableModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Linq.Expressions;

namespace GraphLabs.Site.Core.Filters
{
public abstract class AbstractFilterableModel<T>
{
public static Expression<Func<T, bool>> CreateFilter(FilterParams<T> filterParams)
{
return t => true;
}
}
}
19 changes: 19 additions & 0 deletions GraphLabs.Site.Core/Filters/BoundedFilterAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace GraphLabs.Site.Core.Filters
{
[System.AttributeUsage(System.AttributeTargets.Property)]
public class BoundedFilterAttribute : Attribute, IFilterAttribute
{
private String _name;
private Object[] _limiters;

public BoundedFilterAttribute(string name, Object[] limiters)
{
_name = name;
_limiters = limiters;
}
}
}
17 changes: 17 additions & 0 deletions GraphLabs.Site.Core/Filters/DynamicBoundFilterAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace GraphLabs.Site.Core.Filters
{
[System.AttributeUsage(System.AttributeTargets.Property)]
public class DynamicBoundFilterAttribute : Attribute, IFilterAttribute
{
private String _name;
private Type _typeOfProvider;

public DynamicBoundFilterAttribute(string name, Type typeOfProvider)
{
_name = name;
_typeOfProvider = typeOfProvider;
}
}
}
93 changes: 93 additions & 0 deletions GraphLabs.Site.Core/Filters/FilterParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Globalization;
using System.Reflection;

namespace GraphLabs.Site.Core.Filters
{
public class FilterParams<T>
{
private readonly NameValueCollection _filterParams;
private Dictionary<string, object> cache = new Dictionary<string, object>();

public FilterParams(NameValueCollection filterParams)
{
_filterParams = filterParams;
}

private string GetParam(string name)
{
string value = _filterParams.Get(name);
if (value == "") value = null;
return value;
}

public string GetStringParam(string name)
{
return GetParam(name);
}

public DateTime? GetDateTimeParam(string name)
{
var val = GetParam(name);
if (val == null)
return null;
return DateTime.ParseExact(val, "yyyy-MM-ddTHH:mm", CultureInfo.InvariantCulture);
}

public object GetBoundedParam(string name)
{
var index = GetIntParam(name);
if (index == null)
{
return null;
}

var propertyInfo = typeof(T).GetProperty(name);
if (propertyInfo == null) return null;
foreach (var customAttributeData in propertyInfo.CustomAttributes)
{
if (customAttributeData.AttributeType == typeof(BoundedFilterAttribute))
{
return ((ReadOnlyCollection<CustomAttributeTypedArgument>) customAttributeData
.ConstructorArguments[1].Value)[index.Value].Value;
} else if (customAttributeData.AttributeType == typeof(DynamicBoundFilterAttribute))
{
if (cache.ContainsKey(name))
{
return cache[name];
}
var key = GetParam(name + "ver");
var values = (object[]) GraphLabsValuesHolder.getAndRemove(key);
var result = values[index.Value];
cache[name] = result;
return result;
}
}

return null;
}

public int? GetIntParam(string name)
{
try
{
string s = GetParam(name);
return s == null ? (int?) null : Int32.Parse(s);
}
catch (FormatException)
{
return null;
}
}


public bool? GetBoolParam(string name)
{
string s = GetParam(name);
return s == null ? (bool?) null : Boolean.Parse(s);
}
}
}
41 changes: 41 additions & 0 deletions GraphLabs.Site.Core/Filters/GraphLabsValuesHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Concurrent;

namespace GraphLabs.Site.Core.Filters
{
public class GraphLabsValuesHolder
{
private static readonly Random r = new Random();
private static readonly ConcurrentDictionary<string, object> _container =
new ConcurrentDictionary<string, object>();

//return accesssor string to type
public static string registerValue(object value)
{
while (true)
{
var key = r.Next().ToString();
if (!_container.ContainsKey(key))
{
lock (_container)
{
if (!_container.ContainsKey(key))
{
_container[key] = value;
return key;
}
}
}
}

}

//gets and remove value
public static object getAndRemove(string key)
{
var o = _container[key];
_container.TryRemove(key, out o);
return o;
}
}
}
5 changes: 5 additions & 0 deletions GraphLabs.Site.Core/Filters/IFilterAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace GraphLabs.Site.Core.Filters
{
public interface IFilterAttribute
{}
}
9 changes: 9 additions & 0 deletions GraphLabs.Site.Core/Filters/IFilterValuesProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace GraphLabs.Site.Core.Filters
{
public interface IFilterValuesProvider
{
Object[] getValues();
}
}
15 changes: 15 additions & 0 deletions GraphLabs.Site.Core/Filters/IFilterable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Linq.Expressions;
using GraphLabs.DomainModel.Infrastructure;
using GraphLabs.Site.Models.Infrastructure;

namespace GraphLabs.Site.Core.Filters
{
public interface IFilterable<TEntity, TModel>
where TEntity : AbstractEntity
where TModel : AbstractFilterableModel<TEntity>
{
IListModel<TModel> Filter(Expression<Func<TEntity, bool>> filter);
}

}
15 changes: 15 additions & 0 deletions GraphLabs.Site.Core/Filters/StringFilterAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace GraphLabs.Site.Core.Filters
{
[System.AttributeUsage(System.AttributeTargets.Property)]
public class StringFilterAttribute : Attribute, IFilterAttribute
{
private string _name;

public StringFilterAttribute(string name)
{
_name = name;
}
}
}
11 changes: 10 additions & 1 deletion GraphLabs.Site.Core/GraphLabs.Site.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@
<Compile Include="..\AssemblyVersion.cs">
<Link>Properties\AssemblyVersion.cs</Link>
</Compile>
<Compile Include="Filters\BoundedFilterAttribute.cs" />
<Compile Include="Filters\DynamicBoundFilterAttribute.cs" />
<Compile Include="Filters\FilterParams.cs" />
<Compile Include="Filters\AbstractFilterableModel.cs" />
<Compile Include="Filters\IFilterAttribute.cs" />
<Compile Include="Filters\IFilterable.cs" />
<Compile Include="Filters\IFilterValuesProvider.cs" />
<Compile Include="Filters\StringFilterAttribute.cs" />
<Compile Include="Filters\GraphLabsValuesHolder.cs" />
<Compile Include="GraphLabsException.cs" />
<Compile Include="IChangesTracker.cs" />
<Compile Include="OperationContext\IOperationContext.cs" />
Expand All @@ -145,7 +154,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>cd "$(SolutionDir)"
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
powershell "&amp; ""$(SolutionDir)\generateVersionInfo.ps1"""</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
1 change: 1 addition & 0 deletions GraphLabs.Site.Models/GraphLabs.Site.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<Compile Include="AvailableLab\DemoLabListModel.cs" />
<Compile Include="AvailableLab\DemoLabModelLoader.cs" />
<Compile Include="AvailableLab\TestingLabModel.cs" />
<Compile Include="Groups\NameFilterProvider.cs" />
<Compile Include="Infrastructure\EntityRemover.cs" />
<Compile Include="Infrastructure\AbstractModelSaver.cs" />
<Compile Include="Infrastructure\AbstractModelLoader.cs" />
Expand Down
15 changes: 13 additions & 2 deletions GraphLabs.Site.Models/Groups/GroupListModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using System.Linq;
using System;
using System.Linq;
using System.Linq.Expressions;
using GraphLabs.DomainModel;
using GraphLabs.Site.Core.Filters;
using GraphLabs.Site.Models.Infrastructure;

namespace GraphLabs.Site.Models.Groups
{
/// <summary> Модель списка групп </summary>
public sealed class GroupListModel : ListModelBase<GroupModel>
public sealed class GroupListModel : ListModelBase<GroupModel>, IFilterable<Group, GroupModel>
{
private readonly IEntityQuery _query;
private readonly IEntityBasedModelLoader<GroupModel, Group> _modelLoader;
private Expression<Func<Group, bool>> _filter = (group => true);

/// <summary> Модель списка групп </summary>
public GroupListModel(IEntityQuery query, IEntityBasedModelLoader<GroupModel, Group> modelLoader)
Expand All @@ -21,9 +25,16 @@ public GroupListModel(IEntityQuery query, IEntityBasedModelLoader<GroupModel, Gr
protected override GroupModel[] LoadItems()
{
return _query.OfEntities<Group>()
.Where(_filter)
.ToArray()
.Select(_modelLoader.Load)
.ToArray();
}

public IListModel<GroupModel> Filter(Expression<Func<Group, bool>> filter)
{
_filter = filter;
return this;
}
}
}
Loading