Skip to content

Commit

Permalink
VP-364: Added complex data source support; (#19)
Browse files Browse the repository at this point in the history
* Added complex data source support;
* Fixed properties filling script error;
  • Loading branch information
yecli authored Sep 11, 2019
1 parent 2e6ec9d commit 87cdbb3
Show file tree
Hide file tree
Showing 27 changed files with 293 additions and 193 deletions.
4 changes: 2 additions & 2 deletions CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
[assembly: AssemblyProduct("Virto Commerce Export Module")]
[assembly: AssemblyCopyright("Copyright © VirtoCommerce 2011-2019")]

[assembly: AssemblyFileVersion("2.1.1.0")]
[assembly: AssemblyVersion("2.1.1.0")]
[assembly: AssemblyFileVersion("2.2.1.0")]
[assembly: AssemblyVersion("2.2.1.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using VirtoCommerce.Domain.Commerce.Model.Search;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.ExportModule.Core.Model
{
Expand Down
8 changes: 8 additions & 0 deletions VirtoCommerce.ExportModule.Core/Models/IPagedDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public interface IPagedDataSource
/// </summary>
int PageSize { get; set; }
/// <summary>
/// Specifies the offset for fetching records
/// </summary>
int? Skip { get; set; }
/// <summary>
/// Specifies the number of fetched records
/// </summary>
int? Take { get; set; }
/// <summary>
/// Gets total count of records for this data source
/// </summary>
/// <returns></returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="VirtoCommerce.Domain, Version=2.25.19.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Domain.2.25.19\lib\net461\VirtoCommerce.Domain.dll</HintPath>
<Reference Include="VirtoCommerce.Domain, Version=2.25.27.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Domain.2.25.27\lib\net461\VirtoCommerce.Domain.dll</HintPath>
</Reference>
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.39.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Core.2.13.39\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Core.2.13.42\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions VirtoCommerce.ExportModule.Core/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="VirtoCommerce.Domain" version="2.25.19" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.39" targetFramework="net461" />
<package id="VirtoCommerce.Domain" version="2.25.27" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.42" targetFramework="net461" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.39.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Core.2.13.39\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Core.2.13.42\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion VirtoCommerce.ExportModule.CsvProvider/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<package id="CsvHelper" version="12.1.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.39" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.42" targetFramework="net461" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VirtoCommerce.ExportModule.Core.Model;

namespace VirtoCommerce.ExportModule.Data.Extensions
{
public static class IPagedDataSourceCollectionExtensions
{
public static IEnumerable<IExportable> GetItems(this IEnumerable<IPagedDataSource> datasources, int skip, int take)
{
var taskList = new List<Task<IEnumerable<IExportable>>>();

foreach (var datasource in datasources)
{
var totalCount = datasource.GetTotalCount();

var currentSkip = Math.Min(totalCount, skip);
var currentTake = Math.Min(take, Math.Max(0, totalCount - skip));

if (currentSkip <= 0 && currentTake <= 0)
{
break;
}
else if (currentSkip < totalCount && currentTake > 0)
{
datasource.Skip = currentSkip;
datasource.Take = currentTake;
taskList.Add(Task.Factory.StartNew(() => datasource.Fetch() ? datasource.Items : Array.Empty<IExportable>()));
}

skip -= currentSkip;
take -= currentTake;
}

Task.WhenAll(taskList).GetAwaiter().GetResult();

return taskList.SelectMany(x => x.Result).ToList();
}
}
}

This file was deleted.

22 changes: 11 additions & 11 deletions VirtoCommerce.ExportModule.Data/Services/ExportPagedDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ public abstract class ExportPagedDataSource<TDataQuery, TSearchCriteria> : IPage
where TDataQuery : ExportDataQuery
where TSearchCriteria : SearchCriteriaBase
{
public IEnumerable<IExportable> Items { get; private set; }
public IEnumerable<IExportable> Items { get; protected set; }

public ExportDataQuery DataQuery => _dataQuery;
public TDataQuery DataQuery { get; protected set; }

private readonly TDataQuery _dataQuery;
protected int TotalCount = -1;

protected ExportPagedDataSource(TDataQuery dataQuery)
{
_dataQuery = dataQuery;

PageSize = _dataQuery.Take - _dataQuery.Skip ?? PageSize;
DataQuery = dataQuery ?? throw new ArgumentNullException(nameof(dataQuery));
}

public int CurrentPageNumber { get; protected set; } = 0;
public int CurrentPageNumber { get; protected set; }
public int PageSize { get; set; } = 50;
public int? Skip { get => DataQuery.Skip; set => DataQuery.Skip = value; }
public int? Take { get => DataQuery.Take; set => DataQuery.Take = value; }

public virtual int GetTotalCount()
{
if (TotalCount < 0)
{
var searchCriteria = BuildSearchCriteria(_dataQuery);
var searchCriteria = BuildSearchCriteria(DataQuery);

searchCriteria.Skip = 0;
searchCriteria.Take = 0;
Expand All @@ -52,7 +52,7 @@ public virtual int GetTotalCount()
public bool Fetch()
{
var hasData = true;
var searchCriteria = BuildSearchCriteria(_dataQuery);
var searchCriteria = BuildSearchCriteria(DataQuery);
var hasObjectIds = !searchCriteria.ObjectIds.IsNullOrEmpty();

if (hasObjectIds)
Expand Down Expand Up @@ -92,8 +92,8 @@ protected virtual TSearchCriteria BuildSearchCriteria(TDataQuery exportDataQuery
result.Sort = exportDataQuery.Sort;

// It is for proper pagination - client side for viewer (dataQuery.Skip/Take) should work together with iterating through pages when getting data for export
result.Skip = (exportDataQuery.Skip ?? 0) + CurrentPageNumber * PageSize;
result.Take = exportDataQuery.Take ?? PageSize;
result.Skip = Skip ?? CurrentPageNumber * PageSize;
result.Take = Take ?? PageSize;

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="VirtoCommerce.Domain, Version=2.25.19.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Domain.2.25.19\lib\net461\VirtoCommerce.Domain.dll</HintPath>
<Reference Include="VirtoCommerce.Domain, Version=2.25.27.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Domain.2.25.27\lib\net461\VirtoCommerce.Domain.dll</HintPath>
</Reference>
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.39.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Core.2.13.39\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\vc-module-catalog\packages\VirtoCommerce.Platform.Core.2.13.42\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
</Reference>
<Reference Include="VirtoCommerce.Platform.Data, Version=2.13.39.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Data.2.13.39\lib\net461\VirtoCommerce.Platform.Data.dll</HintPath>
<Reference Include="VirtoCommerce.Platform.Data, Version=2.13.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Data.2.13.42\lib\net461\VirtoCommerce.Platform.Data.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -82,11 +82,11 @@
<Compile Include="Extensions\ExportDataQueryExtensions.cs" />
<Compile Include="Extensions\ExportedTypeDefinitionBuilderExtensions.cs" />
<Compile Include="Extensions\ExportedTypeMetadataExtensions.cs" />
<Compile Include="Extensions\IPagedDataSourceCollectionExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Security\PermissionExportSecurityHandlerFactory.cs" />
<Compile Include="Security\PermissionExportSecurityHandler.cs" />
<Compile Include="Security\IPermissionExportSecurityHandlerFactory.cs" />
<Compile Include="Services\ComplexExportPagedDataSource.cs" />
<Compile Include="Services\DataExporter.cs" />
<Compile Include="Services\ExportedTypeDefinitionBuilder.cs" />
<Compile Include="Services\ExportPagedDataSource.cs" />
Expand Down
6 changes: 3 additions & 3 deletions VirtoCommerce.ExportModule.Data/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
<package id="valueinjecter" version="2.3.3" targetFramework="net461" />
<package id="VirtoCommerce.Domain" version="2.25.19" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.39" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Data" version="2.13.39" targetFramework="net461" />
<package id="VirtoCommerce.Domain" version="2.25.27" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.42" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Data" version="2.13.42" targetFramework="net461" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.39.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Core.2.13.39\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
<Reference Include="VirtoCommerce.Platform.Core, Version=2.13.42.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VirtoCommerce.Platform.Core.2.13.42\lib\net461\VirtoCommerce.Platform.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion VirtoCommerce.ExportModule.JsonProvider/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.39" targetFramework="net461" />
<package id="VirtoCommerce.Platform.Core" version="2.13.42" targetFramework="net461" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using VirtoCommerce.ExportModule.Core.Model;

namespace VirtoCommerce.ExportModule.Tests.ComplexExportPagedDataSourceTests.Mocks
{
public interface ITestSearchService
{
Task<ExportableSearchResult> SearchAsync(TestSearchCriteria searchCriteria);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using VirtoCommerce.ExportModule.Core.Model;

namespace VirtoCommerce.ExportModule.Tests.ComplexExportPagedDataSourceTests.Mocks
{
public class TestExportDataQuery : ExportDataQuery
{
}
}
Loading

0 comments on commit 87cdbb3

Please sign in to comment.