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

DataObjectController events have new argument - DataObjectController #55

Open
wants to merge 1 commit into
base: develop
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
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text eol=lf

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
*.bmp binary
*.png binary
18 changes: 12 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/packages/
**/packages/
**/bin/
*/obj/
*/*/obj/
.vs
*/*/FakesAssemblies/
**/*.vspscc
**/obj/
**/.vs/
*.coverage
*.xml
*.cache

#Ignore thumbnails created by Windows
Thumbs.db

#Ignore files built by Visual Studio
*.user
3 changes: 2 additions & 1 deletion NewPlatform.Flexberry.ORM.ODataService.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>NewPlatform.Flexberry.ORM.ODataService</id>
<version>5.1.0-beta01</version>
<version>5.1.0-beta02</version>
<title>Flexberry ORM ODataService</title>
<authors>New Platform Ltd.</authors>
<owners>New Platform Ltd.</owners>
Expand All @@ -22,6 +22,7 @@
2. [BREAKINGCHANGE] Method MapODataServiceDataObjectRoute now requires HttpServer as parameter.
3. At creation of dynamic views of the master in them are added with primary keys.
4. Use common DataObjectCache for all sql queries per http request.
5. [BREAKINGCHANGE] DataObjectController events have new argument - `DataObjectController controller`.

Fixed
1. Fix error with POST request and header "Prefer".
Expand Down
6 changes: 3 additions & 3 deletions NewPlatform.Flexberry.ORM.ODataService.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2036
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewPlatform.Flexberry.ORM.ODataService", "NewPlatform.Flexberry.ORM.ODataService\NewPlatform.Flexberry.ORM.ODataService.csproj", "{01BBE45A-3A3F-4EA5-9457-8C62167B5E99}"
EndProject
Expand All @@ -20,6 +20,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewPlatform.Flexberry.ORM.O
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Open Source", "Open Source", "{DB00E5CF-65B6-4A94-8C83-A80DB75E9B02}"
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
.travis.yml = .travis.yml
CHANGELOG.md = CHANGELOG.md
Expand Down Expand Up @@ -61,6 +62,5 @@ Global
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {611B715C-AD46-45B1-BA4E-36C8F1A1896E}
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35;packages\Unity.Interception.2.1.505.0\lib\NET35;packages\EnterpriseLibrary.Common.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Data.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Logging.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Logging.Database.5.0.505.0\lib\NET35
EndGlobalSection
EndGlobal
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace NewPlatform.Flexberry.ORM.ODataService.Controllers
{
using System;
using System.Net;

using ICSSoft.STORMNET;
using ICSSoft.STORMNET.Business;

using NewPlatform.Flexberry.ORM.ODataService.Events;
using System;
using System.Net;

/// <summary>
/// OData controller class.
Expand All @@ -25,7 +26,7 @@ public partial class DataObjectController
/// <returns></returns>
internal bool ExecuteCallbackBeforeGet(ref LoadingCustomizationStruct lcs)
{
return _events.CallbackBeforeGet == null || _events.CallbackBeforeGet(ref lcs);
return _events.CallbackBeforeGet == null || _events.CallbackBeforeGet(this, ref lcs);
}

/// <summary>
Expand All @@ -35,7 +36,7 @@ internal bool ExecuteCallbackBeforeGet(ref LoadingCustomizationStruct lcs)
/// <returns></returns>
internal bool ExecuteCallbackBeforeCreate(DataObject obj)
{
return _events.CallbackBeforeCreate == null || _events.CallbackBeforeCreate(obj);
return _events.CallbackBeforeCreate == null || _events.CallbackBeforeCreate(this, obj);
}

/// <summary>
Expand All @@ -45,7 +46,7 @@ internal bool ExecuteCallbackBeforeCreate(DataObject obj)
/// <returns></returns>
internal bool ExecuteCallbackBeforeUpdate(DataObject obj)
{
return _events.CallbackBeforeUpdate == null || _events.CallbackBeforeUpdate(obj);
return _events.CallbackBeforeUpdate == null || _events.CallbackBeforeUpdate(this, obj);
}

/// <summary>
Expand All @@ -55,7 +56,7 @@ internal bool ExecuteCallbackBeforeUpdate(DataObject obj)
/// <returns></returns>
internal bool ExecuteCallbackBeforeDelete(DataObject obj)
{
return _events.CallbackBeforeDelete == null || _events.CallbackBeforeDelete(obj);
return _events.CallbackBeforeDelete == null || _events.CallbackBeforeDelete(this, obj);
}

/// <summary>
Expand All @@ -64,7 +65,7 @@ internal bool ExecuteCallbackBeforeDelete(DataObject obj)
/// <param name="objs">Объект после создания.</param>
internal void ExecuteCallbackAfterGet(ref DataObject[] objs)
{
_events.CallbackAfterGet?.Invoke(ref objs);
_events.CallbackAfterGet?.Invoke(this, ref objs);
}

/// <summary>
Expand All @@ -73,7 +74,7 @@ internal void ExecuteCallbackAfterGet(ref DataObject[] objs)
/// <param name="obj">Объект после создания.</param>
internal void ExecuteCallbackAfterCreate(DataObject obj)
{
_events.CallbackAfterCreate?.Invoke(obj);
_events.CallbackAfterCreate?.Invoke(this, obj);
}

/// <summary>
Expand All @@ -82,7 +83,7 @@ internal void ExecuteCallbackAfterCreate(DataObject obj)
/// <param name="obj">Объект после обновления.</param>
internal void ExecuteCallbackAfterUpdate(DataObject obj)
{
_events.CallbackAfterUpdate?.Invoke(obj);
_events.CallbackAfterUpdate?.Invoke(this, obj);
}

/// <summary>
Expand All @@ -91,7 +92,7 @@ internal void ExecuteCallbackAfterUpdate(DataObject obj)
/// <param name="obj">Объект перед удалением.</param>
internal void ExecuteCallbackAfterDelete(DataObject obj)
{
_events.CallbackAfterDelete?.Invoke(obj);
_events.CallbackAfterDelete?.Invoke(this, obj);
}

/// <summary>
Expand All @@ -107,7 +108,7 @@ internal Exception ExecuteCallbackAfterInternalServerError(Exception ex, ref Htt
return ex;
}

return _events.CallbackAfterInternalServerError(ex, ref code);
return _events.CallbackAfterInternalServerError(this, ex, ref code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public HttpResponseMessage Post([FromBody] EdmEntityObject edmEntity)
DataObject obj = UpdateObject(edmEntity, null);
ExecuteCallbackAfterCreate(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 @@ -146,7 +146,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 @@ -194,7 +194,7 @@ private HttpResponseMessage DeleteEntity(object key)

Init();

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

// Раз объект данных удаляется, то и все ассоциированные с ним файлы должны быть удалены.
// Запоминаем метаданные всех ассоциированных файлов, кроме файлов соответствующих файловым свойствам типа File
Expand All @@ -221,7 +221,7 @@ private HttpResponseMessage DeleteEntity(object key)
}
else
{
_dataService.UpdateObject(obj);
DataService.UpdateObject(obj);
}
}

Expand Down Expand Up @@ -465,7 +465,7 @@ private DataObject UpdateObject(EdmEntityObject edmEntity, object key)
}
else
{
_dataService.UpdateObjects(ref objsArrSmall);
DataService.UpdateObjects(ref objsArrSmall);
}

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

if (keyValue != null)
{
DataObject dataObjectFromCache = _dataObjectCache.GetLivingDataObject(objType, keyValue);
var view = _model.GetDataObjectDefaultView(objType);
DataObject dataObjectFromCache = DataObjectCache.GetLivingDataObject(objType, keyValue);
var view = Model.GetDataObjectDefaultView(objType);

if (dataObjectFromCache != null)
{
Expand All @@ -509,7 +509,7 @@ private DataObject ReturnDataObject(Type objType, object keyValue)
&& dataObjectFromCache.GetLoadedProperties().Length == 1
&& dataObjectFromCache.CheckLoadedProperty(x => x.__PrimaryKey))
{
_dataService.LoadObject(view, dataObjectFromCache);
DataService.LoadObject(view, dataObjectFromCache);
}

return dataObjectFromCache;
Expand All @@ -518,7 +518,7 @@ private DataObject ReturnDataObject(Type objType, object keyValue)
// Проверим существование объекта в базе.
LoadingCustomizationStruct lcs = LoadingCustomizationStruct.GetSimpleStruct(objType, view);
lcs.LimitFunction = FunctionBuilder.BuildEquals(keyValue);
DataObject[] dobjs = _dataService.LoadObjects(lcs, _dataObjectCache);
DataObject[] dobjs = DataService.LoadObjects(lcs, DataObjectCache);
if (dobjs.Length == 1)
{
DataObject dataObject = dobjs[0];
Expand All @@ -532,12 +532,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 @@ -560,13 +560,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 @@ -599,7 +599,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