diff --git a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.ModifyData.cs b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.ModifyData.cs index d0d9422b..ef08ce03 100644 --- a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.ModifyData.cs +++ b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.ModifyData.cs @@ -221,7 +221,8 @@ private HttpResponseMessage DeleteEntity(object key) } else { - _dataService.UpdateObject(obj); + IDataService ds = GetDataService(obj.GetType()); + ds.UpdateObject(obj); } } @@ -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); } // При успешном обновлении вычищаем из файловой системы, файлы подлежащие удалению. @@ -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; + } } } diff --git a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs index af5c921c..a10ab116 100644 --- a/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs +++ b/NewPlatform.Flexberry.ORM.ODataService/Controllers/DataObjectController.cs @@ -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; @@ -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) @@ -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()); @@ -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); @@ -988,7 +984,8 @@ public LoadingCustomizationStruct CreateLcs() if (_dynamicView != null) view = _dynamicView.View; IEnumerable 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(); @@ -1018,6 +1015,16 @@ public LoadingCustomizationStruct CreateLcs() return lcs; } + /// + /// Получить сервис данных для обрабатываемого типа. + /// + /// Обрабатываемый тип данных. + /// Инстанция сервис данных. + protected virtual IDataService GetDataService(Type type) + { + return _dataService; + } + /// /// Инициализирует переменные класса значениями из запроса OData. /// @@ -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); } } @@ -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); } }