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

Resolve IEventHandlerContainer and IFunctionContainer using dependency injection. #51

Open
wants to merge 1 commit into
base: develop-old
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Web.Http;
using System.Web.OData;
using System.Web.OData.Extensions;
using System.Web.OData.Query;
using System.Web.OData.Routing;
using Expressions;

using ICSSoft.STORMNET;
using Microsoft.OData.Core;
using Microsoft.OData.Edm.Library;
using Microsoft.OData.Edm.Values;
using NewPlatform.Flexberry.ORM.ODataService.Formatter;

using NewPlatform.Flexberry.ORM.ODataService.Functions;
using NewPlatform.Flexberry.ORM.ODataService.Handlers;
using NewPlatform.Flexberry.ORM.ODataService.Model;
using NewPlatform.Flexberry.ORM.ODataService.Routing;

using Action = NewPlatform.Flexberry.ORM.ODataService.Functions.Action;

/// <summary>
Expand Down Expand Up @@ -107,7 +99,7 @@ private IHttpActionResult ExecuteAction(ODataActionParameters parameters)

if (result is DataObject)
{
var entityType = _model.GetEdmEntityType(result.GetType());
var entityType = Model.GetEdmEntityType(result.GetType());
return SetResult(GetEdmObject(entityType, result, 1, null));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public HttpResponseMessage Post([FromBody] EdmEntityObject edmEntity)
}

DataObject obj = UpdateObject(edmEntity, null);
ExecuteCallbackAfterCreate(obj);
Events.AfterCreate(this, obj);

edmEntity = GetEdmObject(_model.GetEdmEntityType(type), obj, 1, null, null);
edmEntity = GetEdmObject(Model.GetEdmEntityType(Type), obj, 1, null, null);
var responseForPreferMinimal = TestPreferMinimal();
if (responseForPreferMinimal != null)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public HttpResponseMessage Patch([FromODataUri] Guid key, [FromBody] EdmEntityOb
}

DataObject obj = UpdateObject(edmEntity, key);
ExecuteCallbackAfterUpdate(obj);
Events.AfterUpdate(this, obj);

var responseForPreferMinimal = TestPreferMinimal();
if (responseForPreferMinimal != null)
Expand All @@ -147,7 +147,7 @@ public HttpResponseMessage Patch([FromODataUri] Guid key, [FromBody] EdmEntityOb
return Request.CreateResponse(System.Net.HttpStatusCode.NoContent);
}

edmEntity = GetEdmObject(_model.GetEdmEntityType(type), obj, 1, null, null);
edmEntity = GetEdmObject(Model.GetEdmEntityType(Type), obj, 1, null, null);
var result = Request.CreateResponse(System.Net.HttpStatusCode.OK, edmEntity);
result.Headers.Add("Preference-Applied", "return=representation");
return result;
Expand Down Expand Up @@ -195,7 +195,7 @@ private HttpResponseMessage DeleteEntity(object key)

Init();

var obj = _dataObjectCache.CreateDataObject(type, key);
var obj = DataObjectCache.CreateDataObject(Type, key);

// Раз объект данных удаляется, то и все ассоциированные с ним файлы должны быть удалены.
// Запоминаем метаданные всех ассоциированных файлов, кроме файлов соответствующих файловым свойствам типа File
Expand All @@ -213,7 +213,7 @@ private HttpResponseMessage DeleteEntity(object key)
// В данный момент ReferentialConstraints не создаются в модели.
obj.SetStatus(ObjectStatus.Deleted);

if (ExecuteCallbackBeforeDelete(obj))
if (Events.BeforeDelete(this, obj))
{
if (Request.Properties.ContainsKey(DataObjectODataBatchHandler.DataObjectsToUpdatePropertyKey))
{
Expand All @@ -222,13 +222,13 @@ private HttpResponseMessage DeleteEntity(object key)
}
else
{
_dataService.UpdateObject(obj);
DataService.UpdateObject(obj);
}
}

// При успешном удалении вычищаем из файловой системы, файлы подлежащие удалению.
FileController.RemoveFileUploadDirectories(_removingFileDescriptions);
ExecuteCallbackAfterDelete(obj);
Events.AfterDelete(this, obj);

return Request.CreateResponse(System.Net.HttpStatusCode.NoContent);
}
Expand All @@ -249,7 +249,7 @@ private HttpResponseMessage InternalServerErrorMessage(Exception ex)
{
HttpStatusCode code = HttpStatusCode.InternalServerError;
Exception originalEx = ex;
ex = ExecuteCallbackAfterInternalServerError(ex, ref code);
ex = Events.AfterInternalServerError(this, ex, ref code);

if (ex == null)
{
Expand Down Expand Up @@ -433,15 +433,15 @@ private DataObject UpdateObject(EdmEntityObject edmEntity, object key)
{
if (_newDataObjects[objs[i]])
{
if (!ExecuteCallbackBeforeCreate(objs[i]))
if (!Events.BeforeCreate(this, objs[i]))
{
objs.RemoveAt(i);
i++;
}
}
else
{
if (!ExecuteCallbackBeforeUpdate(objs[i]))
if (!Events.BeforeUpdate(this, objs[i]))
{
objs.RemoveAt(i);
i++;
Expand All @@ -466,7 +466,7 @@ private DataObject UpdateObject(EdmEntityObject edmEntity, object key)
}
else
{
_dataService.UpdateObjects(ref objsArrSmall);
DataService.UpdateObjects(ref objsArrSmall);
}

// При успешном обновлении вычищаем из файловой системы, файлы подлежащие удалению.
Expand Down Expand Up @@ -495,7 +495,7 @@ private DataObject ReturnDataObject(Type objType, object keyValue)

if (keyValue != null)
{
DataObject dataObjectFromCache = _dataObjectCache.GetLivingDataObject(objType, keyValue);
DataObject dataObjectFromCache = DataObjectCache.GetLivingDataObject(objType, keyValue);

if (dataObjectFromCache != null)
{
Expand All @@ -507,13 +507,13 @@ private DataObject ReturnDataObject(Type objType, object keyValue)
return dataObjectFromCache;
}

var view = _model.GetDataObjectDefaultView(objType);
var view = Model.GetDataObjectDefaultView(objType);

// Проверим существование объекта в базе.
var ldef = SQLWhereLanguageDef.LanguageDef;
LoadingCustomizationStruct lcs = LoadingCustomizationStruct.GetSimpleStruct(objType, view);
lcs.LimitFunction = ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.GuidType, SQLWhereLanguageDef.StormMainObjectKey), keyValue);
DataObject[] dobjs = _dataService.LoadObjects(lcs, _dataObjectCache);
DataObject[] dobjs = DataService.LoadObjects(lcs, DataObjectCache);
if (dobjs.Length == 1)
{
DataObject dataObject = dobjs[0];
Expand All @@ -527,12 +527,12 @@ private DataObject ReturnDataObject(Type objType, object keyValue)

if (keyValue != null)
{
obj = _dataObjectCache.CreateDataObject(objType, keyValue);
obj = DataObjectCache.CreateDataObject(objType, keyValue);
}
else
{
obj = (DataObject)Activator.CreateInstance(objType);
_dataObjectCache.AddDataObject(obj);
DataObjectCache.AddDataObject(obj);
}

_newDataObjects.Add(obj, true);
Expand All @@ -555,13 +555,13 @@ private DataObject GetDataObjectByEdmEntity(EdmEntityObject edmEntity, object ke
}

IEdmEntityType entityType = (IEdmEntityType)edmEntity.ActualEdmType;
Type objType = _model.GetDataObjectType(_model.GetEdmEntitySet(entityType).Name);
Type objType = Model.GetDataObjectType(Model.GetEdmEntitySet(entityType).Name);

// Значение свойства.
object value;

// Получим значение ключа.
var keyProperty = entityType.Properties().FirstOrDefault(prop => prop.Name == _model.KeyPropertyName);
var keyProperty = entityType.Properties().FirstOrDefault(prop => prop.Name == Model.KeyPropertyName);
if (key != null)
{
value = key;
Expand Down Expand Up @@ -594,7 +594,7 @@ private DataObject GetDataObjectByEdmEntity(EdmEntityObject edmEntity, object ke
// Все свойства объекта данных означим из пришедшей сущности, если они были там установлены(изменены).
foreach (var prop in entityType.Properties())
{
string dataObjectPropName = _model.GetDataObjectProperty(entityType.FullTypeName(), prop.Name).Name;
string dataObjectPropName = Model.GetDataObjectProperty(entityType.FullTypeName(), prop.Name).Name;
if (edmEntity.GetChangedPropertyNames().Contains(prop.Name))
{
// Обработка мастеров и детейлов.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal IHttpActionResult ExecuteUserFunction(QueryParameters queryParameters)
Request.ODataProperties().SelectExpandClause = QueryOptions.SelectExpand.SelectExpandClause;
}

this.type = type;
this.Type = type;
CreateDynamicView();
IncludeCount = false;
if (queryOpt.Count != null && queryOpt.Count.Value)
Expand All @@ -149,7 +149,7 @@ internal IHttpActionResult ExecuteUserFunction(QueryParameters queryParameters)

NameValueCollection queryParams = Request.RequestUri.ParseQueryString();

if ((_model.ExportService != null || _model.ODataExportService != null) && (Request.Properties.ContainsKey(PostPatchHandler.AcceptApplicationMsExcel) || Convert.ToBoolean(queryParams.Get("exportExcel"))))
if ((Model.ExportService != null || Model.ODataExportService != null) && (Request.Properties.ContainsKey(PostPatchHandler.AcceptApplicationMsExcel) || Convert.ToBoolean(queryParams.Get("exportExcel"))))
{
_objs = (result as IEnumerable).Cast<DataObject>().ToArray();
return ResponseMessage(CreateExcel(queryParams));
Expand All @@ -170,9 +170,9 @@ internal IHttpActionResult ExecuteUserFunction(QueryParameters queryParameters)
Request.ODataProperties().SelectExpandClause = QueryOptions.SelectExpand.SelectExpandClause;
}

this.type = result.GetType();
this.Type = result.GetType();
CreateDynamicView();
var entityType = _model.GetEdmEntityType(this.type);
var entityType = Model.GetEdmEntityType(this.Type);
return SetResult(GetEdmObject(entityType, result, 1, null, _dynamicView));
}

Expand Down
Loading