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

Wrapped getter for DataService in DataObjectController. #65

Draft
wants to merge 1 commit into
base: develop-old
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ private HttpResponseMessage DeleteEntity(object key)
}
else
{
_dataService.UpdateObject(obj);
IDataService ds = GetDataService(obj.GetType());
ds.UpdateObject(obj);
}
}

Expand Down Expand Up @@ -465,7 +466,8 @@ private DataObject UpdateObject(EdmEntityObject edmEntity, object key)
}
else
{
_dataService.UpdateObjects(ref objsArrSmall);
IDataService ds = GetDataService(obj.GetType());
ds.UpdateObjects(ref objsArrSmall);
}

// При успешном обновлении вычищаем из файловой системы, файлы подлежащие удалению.
Expand Down Expand Up @@ -509,21 +511,25 @@ private DataObject ReturnDataObject(Type objType, object keyValue)
&& dataObjectFromCache.GetLoadedProperties().Length == 1
&& dataObjectFromCache.CheckLoadedProperty(x => x.__PrimaryKey))
{
_dataService.LoadObject(view, dataObjectFromCache);
IDataService ds = GetDataService(objType);
ds.LoadObject(view, dataObjectFromCache);
}

return dataObjectFromCache;
}

// Проверим существование объекта в базе.
LoadingCustomizationStruct lcs = LoadingCustomizationStruct.GetSimpleStruct(objType, view);
lcs.LimitFunction = FunctionBuilder.BuildEquals(keyValue);
DataObject[] dobjs = _dataService.LoadObjects(lcs, _dataObjectCache);
if (dobjs.Length == 1)
else
{
DataObject dataObject = dobjs[0];
_newDataObjects.Add(dataObject, false);
return dataObject;
// Проверим существование объекта в базе.
LoadingCustomizationStruct lcs = LoadingCustomizationStruct.GetSimpleStruct(objType, view);
lcs.LimitFunction = FunctionBuilder.BuildEquals(keyValue);
IDataService ds = GetDataService(objType);
DataObject[] dobjs = ds.LoadObjects(lcs, _dataObjectCache);
if (dobjs.Length == 1)
{
DataObject dataObject = dobjs[0];
_newDataObjects.Add(dataObject, false);
return dataObject;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
Expand Down Expand Up @@ -267,7 +266,8 @@ public int GetObjectsCount(Type type, ODataQueryOptions queryOptions)
lcs.LoadingTypes = new[] { type };
lcs.ReturnType = LcsReturnType.Objects;

return _dataService.GetObjectsCount(lcs);
IDataService ds = GetDataService(type);
return ds.GetObjectsCount(lcs);
}

internal HttpResponseMessage CreateExcel(NameValueCollection queryParams)
Expand Down Expand Up @@ -324,15 +324,10 @@ internal HttpResponseMessage CreateExcel(NameValueCollection queryParams)

par.DetailsInSeparateColumns = Convert.ToBoolean(queryParams.Get("detSeparateCols"));
par.DetailsInSeparateRows = Convert.ToBoolean(queryParams.Get("detSeparateRows"));
MemoryStream result;
if (_model.ODataExportService != null)
{
result = _model.ODataExportService.CreateExportStream(_dataService, par, _objs, queryParams);
}
else
{
result = _model.ExportService.CreateExportStream(_dataService, par, _objs);
}
IDataService ds = GetDataService(view.DefineClassType);
var result = _model.ODataExportService != null
? _model.ODataExportService.CreateExportStream(ds, par, _objs, queryParams)
: _model.ExportService.CreateExportStream(ds, par, _objs);

HttpResponseMessage msg = Request.CreateResponse(HttpStatusCode.OK);
RawOutputFormatter.PrepareHttpResponseMessage(ref msg, "application/ms-excel", _model, result.ToArray());
Expand Down Expand Up @@ -498,7 +493,8 @@ internal EdmEntityObject GetEdmObject(IEdmEntityType entityType, object obj, int
{
if (!DynamicView.ContainsPoperty(dynamicView.View, propPath))
{
_dataService.LoadObject(dynamicView.View, (DataObject)master, false, true, _dataObjectCache);
IDataService ds = GetDataService(master.GetType());
ds.LoadObject(dynamicView.View, (DataObject)master, false, true, _dataObjectCache);
}

edmObj = GetEdmObject(_model.GetEdmEntityType(master.GetType()), master, level, expandedItem, dynamicView);
Expand Down Expand Up @@ -988,7 +984,8 @@ public LoadingCustomizationStruct CreateLcs()
if (_dynamicView != null)
view = _dynamicView.View;
IEnumerable<View> resolvingViews;
view = DynamicView.GetViewWithPropertiesUsedInExpression(expr, type, view, _dataService, out resolvingViews);
IDataService ds = GetDataService(type);
view = DynamicView.GetViewWithPropertiesUsedInExpression(expr, type, view, ds, out resolvingViews);
if (_lcsLoadingTypes.Count == 0)
_lcsLoadingTypes = _model.GetDerivedTypes(type).ToList();

Expand Down Expand Up @@ -1018,6 +1015,16 @@ public LoadingCustomizationStruct CreateLcs()
return lcs;
}

/// <summary>
/// Получить сервис данных для обрабатываемого типа.
/// </summary>
/// <param name="type">Обрабатываемый тип данных.</param>
/// <returns>Инстанция сервис данных.</returns>
protected virtual IDataService GetDataService(Type type)
{
return _dataService;
}

/// <summary>
/// Инициализирует переменные класса значениями из запроса OData.
/// </summary>
Expand Down Expand Up @@ -1092,9 +1099,10 @@ private DataObject[] LoadObjects(LoadingCustomizationStruct lcs, out int count,
{
foreach (var propType in Information.GetAllTypesFromView(lcs.View))
{
if (!_dataService.SecurityManager.AccessObjectCheck(propType, tTypeAccess.Full, false))
IDataService ds = GetDataService(propType);
if (!ds.SecurityManager.AccessObjectCheck(propType, tTypeAccess.Full, false))
{
_dataService.SecurityManager.AccessObjectCheck(propType, tTypeAccess.Read, true);
ds.SecurityManager.AccessObjectCheck(propType, tTypeAccess.Read, true);
}
}

Expand All @@ -1105,13 +1113,14 @@ private DataObject[] LoadObjects(LoadingCustomizationStruct lcs, out int count,
doLoad = ExecuteCallbackBeforeGet(ref lcs);
if (doLoad)
{
IDataService ds = GetDataService(lcs.LoadingTypes.First());
if (!callGetObjectsCount)
{
dobjs = _dataService.LoadObjects(lcs, _dataObjectCache);
dobjs = ds.LoadObjects(lcs, _dataObjectCache);
}
else
{
count = _dataService.GetObjectsCount(lcs);
count = ds.GetObjectsCount(lcs);
}
}

Expand Down