Skip to content

Commit

Permalink
CSHARP-4955: Add Render overload with RenderArgs (#1278)
Browse files Browse the repository at this point in the history
* CSHARP-4955: Add Render overload with RenderArgs
  • Loading branch information
BorisDog authored Jul 24, 2024
1 parent 0d8134e commit 452b06f
Show file tree
Hide file tree
Showing 118 changed files with 7,308 additions and 7,083 deletions.
6 changes: 5 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Compile Include="..\MongoDB.Shared\IsExternalInit.cs" Visible="false" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\packageIcon.png" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
</ItemGroup>
</Project>
</Project>
5 changes: 3 additions & 2 deletions src/MongoDB.Driver.GridFS/GridFSBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,9 @@ private FindOperation<GridFSFileInfo<TFileId>> CreateFindOperation(FilterDefinit
var filesCollectionNamespace = this.GetFilesCollectionNamespace();
var messageEncoderSettings = this.GetMessageEncoderSettings();
var linqProvider = _database.Client.Settings.LinqProvider;
var renderedFilter = filter.Render(_fileInfoSerializer, _options.SerializerRegistry, linqProvider);
var renderedSort = options.Sort == null ? null : options.Sort.Render(_fileInfoSerializer, _options.SerializerRegistry, linqProvider);
var args = new RenderArgs<GridFSFileInfo<TFileId>>(_fileInfoSerializer, _options.SerializerRegistry, linqProvider);
var renderedFilter = filter.Render(args);
var renderedSort = options.Sort == null ? null : options.Sort.Render(args);

return new FindOperation<GridFSFileInfo<TFileId>>(
filesCollectionNamespace,
Expand Down
5 changes: 2 additions & 3 deletions src/MongoDB.Driver.GridFS/GridFSBucketCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -242,7 +241,7 @@ private IEnumerable<GridFSFileInfo> TransformFileInfos(IEnumerable<GridFSFileInf
private FilterDefinition<GridFSFileInfo<ObjectId>> WrapFilter(FilterDefinition<GridFSFileInfo> filter)
{
var linqProvider = Database.Client.Settings.LinqProvider;
var renderedFilter = filter.Render(GridFSFileInfoSerializer.Instance, BsonSerializer.SerializerRegistry, linqProvider);
var renderedFilter = filter.Render(new(GridFSFileInfoSerializer.Instance, BsonSerializer.SerializerRegistry, linqProvider));
return new BsonDocumentFilterDefinition<GridFSFileInfo<ObjectId>>(renderedFilter);
}

Expand All @@ -251,7 +250,7 @@ private GridFSFindOptions<ObjectId> WrapFindOptions(GridFSFindOptions options)
if (options != null)
{
var linqProvider = Database.Client.Settings.LinqProvider;
var renderedSort = options.Sort == null ? null : options.Sort.Render(GridFSFileInfoSerializer.Instance, BsonSerializer.SerializerRegistry, linqProvider);
var renderedSort = options.Sort == null ? null : options.Sort.Render(new(GridFSFileInfoSerializer.Instance, BsonSerializer.SerializerRegistry, linqProvider));
var wrappedSort = renderedSort == null ? null : new BsonDocumentSortDefinition<GridFSFileInfo<ObjectId>>(renderedSort);
return new GridFSFindOptions<ObjectId>
{
Expand Down
25 changes: 18 additions & 7 deletions src/MongoDB.Driver/AggregateExpressionDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ public static implicit operator AggregateExpressionDefinition<TSource, TResult>(
/// <param name="serializerRegistry">The serializer registry.</param>
/// <param name="linqProvider">The LINQ provider.</param>
/// <returns>The rendered aggregation expression.</returns>
public abstract BsonValue Render(IBsonSerializer<TSource> sourceSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider);
[Obsolete("Use Render(RenderArgs<TSource> args) overload instead.")]
public virtual BsonValue Render(IBsonSerializer<TSource> sourceSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
{
return Render(new(sourceSerializer, serializerRegistry, linqProvider));
}

/// <summary>
/// Renders the aggregation expression to a <see cref="BsonValue"/>.
/// </summary>
/// <param name="args">The render arguments.</param>
/// <returns>A <see cref="BsonValue"/>.</returns>
public abstract BsonValue Render(RenderArgs<TSource> args);
}

/// <summary>
Expand All @@ -101,7 +112,7 @@ public BsonValueAggregateExpressionDefinition(BsonValue expression)

// public methods
/// <inheritdoc/>
public override BsonValue Render(IBsonSerializer<TSource> sourceSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
public override BsonValue Render(RenderArgs<TSource> args)
{
return _expression;
}
Expand Down Expand Up @@ -143,10 +154,10 @@ internal ExpressionAggregateExpressionDefinition(

// public methods
/// <inheritdoc/>
public override BsonValue Render(IBsonSerializer<TSource> sourceSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
public override BsonValue Render(RenderArgs<TSource> args)
{
var contextData = _contextData?.With("SerializerRegistry", serializerRegistry);
return linqProvider.GetAdapter().TranslateExpressionToAggregateExpression(_expression, sourceSerializer, serializerRegistry, _translationOptions, contextData);
var contextData = _contextData?.With("SerializerRegistry", args.SerializerRegistry);
return args.LinqProvider.GetAdapter().TranslateExpressionToAggregateExpression(_expression, args.DocumentSerializer, args.SerializerRegistry, _translationOptions, contextData);
}
}

Expand Down Expand Up @@ -177,9 +188,9 @@ public DocumentsAggregateExpressionDefinition(

// public methods
/// <inheritdoc/>
public override BsonValue Render(IBsonSerializer<NoPipelineInput> sourceSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
public override BsonValue Render(RenderArgs<NoPipelineInput> args)
{
var documentSerializer = _documentSerializer ?? serializerRegistry.GetSerializer<TDocument>();
var documentSerializer = _documentSerializer ?? args.SerializerRegistry.GetSerializer<TDocument>();
return SerializationHelper.SerializeValues(documentSerializer, _documents);
}
}
Expand Down
19 changes: 15 additions & 4 deletions src/MongoDB.Driver/AggregateFacet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,25 @@ protected AggregateFacet(string name)
/// <param name="serializerRegistry">The serializer registry.</param>
/// <param name="linqProvider">The LINQ provider.</param>
/// <returns>The rendered pipeline.</returns>
public abstract BsonArray RenderPipeline(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider);
[Obsolete("Use Render(RenderArgs<TInput> args) overload instead.")]
public virtual BsonArray RenderPipeline(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
{
return RenderPipeline(new(inputSerializer, serializerRegistry, linqProvider));
}

/// <summary>
/// Renders the facet pipeline.
/// </summary>
/// <param name="args">The render arguments.</param>
/// <returns>A <see cref="BsonValue"/>.</returns>
public abstract BsonArray RenderPipeline(RenderArgs<TInput> args);
}

/// <summary>
/// Represents a facet to be passed to the Facet method.
/// </summary>
/// <typeparam name="TInput">The type of the input documents.</typeparam>
/// <typeparam name="TOutput">The type of the otuput documents.</typeparam>
/// <typeparam name="TOutput">The type of the output documents.</typeparam>
public class AggregateFacet<TInput, TOutput> : AggregateFacet<TInput>
{
/// <summary>
Expand All @@ -112,9 +123,9 @@ public AggregateFacet(string name, PipelineDefinition<TInput, TOutput> pipeline)
public PipelineDefinition<TInput, TOutput> Pipeline { get; private set; }

/// <inheritdoc/>
public override BsonArray RenderPipeline(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)
public override BsonArray RenderPipeline(RenderArgs<TInput> args)
{
var renderedPipeline = Pipeline.Render(inputSerializer, serializerRegistry, linqProvider);
var renderedPipeline = Pipeline.Render(args);
return new BsonArray(renderedPipeline.Documents);
}
}
Expand Down
Loading

0 comments on commit 452b06f

Please sign in to comment.