Skip to content

Commit

Permalink
Exposed IQueryExecutionOption options via Sql4CdsConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Feb 21, 2022
1 parent c23fd39 commit 80af695
Show file tree
Hide file tree
Showing 19 changed files with 461 additions and 191 deletions.
4 changes: 0 additions & 4 deletions MarkMpn.Sql4Cds.Engine.Tests/ExecutionPlanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ void IQueryExecutionOptions.Progress(double? progress, string message)
{
}

void IQueryExecutionOptions.RetrievingNextPage()
{
}

string IQueryExecutionOptions.PrimaryDataSource => "local";

Guid IQueryExecutionOptions.UserId => Guid.NewGuid();
Expand Down
5 changes: 0 additions & 5 deletions MarkMpn.Sql4Cds.Engine.Tests/OptionsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,5 @@ public void Progress(double? progress, string message)
{
_options.Progress(progress, message);
}

public void RetrievingNextPage()
{
_options.RetrievingNextPage();
}
}
}
4 changes: 0 additions & 4 deletions MarkMpn.Sql4Cds.Engine.Tests/Sql2FetchXmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public class Sql2FetchXmlTests : FakeXrmEasyTestsBase, IQueryExecutionOptions

bool IQueryExecutionOptions.BypassCustomPlugins => false;

void IQueryExecutionOptions.RetrievingNextPage()
{
}

string IQueryExecutionOptions.PrimaryDataSource => "local";

Guid IQueryExecutionOptions.UserId => Guid.NewGuid();
Expand Down
4 changes: 0 additions & 4 deletions MarkMpn.Sql4Cds.Engine.Tests/StubOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ void IQueryExecutionOptions.Progress(double? progress, string message)
{
}

void IQueryExecutionOptions.RetrievingNextPage()
{
}

string IQueryExecutionOptions.PrimaryDataSource => "local";

Guid IQueryExecutionOptions.UserId => Guid.NewGuid();
Expand Down
5 changes: 0 additions & 5 deletions MarkMpn.Sql4Cds.Engine/Ado/CancellationTokenOptionsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,5 @@ public void Progress(double? progress, string message)
{
_options.Progress(progress, message);
}

public void RetrievingNextPage()
{
_options.RetrievingNextPage();
}
}
}
96 changes: 73 additions & 23 deletions MarkMpn.Sql4Cds.Engine/Ado/ChangeDatabaseOptionsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,122 @@ namespace MarkMpn.Sql4Cds.Engine
{
class ChangeDatabaseOptionsWrapper : IQueryExecutionOptions
{
private readonly Sql4CdsConnection _connection;
private readonly IQueryExecutionOptions _options;

public ChangeDatabaseOptionsWrapper(IQueryExecutionOptions options)
public ChangeDatabaseOptionsWrapper(Sql4CdsConnection connection, IQueryExecutionOptions options)
{
_connection = connection;
_options = options;

PrimaryDataSource = options.PrimaryDataSource;
UseTDSEndpoint = options.UseTDSEndpoint;
BlockUpdateWithoutWhere = options.BlockUpdateWithoutWhere;
BlockDeleteWithoutWhere = options.BlockDeleteWithoutWhere;
UseBulkDelete = options.UseBulkDelete;
BatchSize = options.BatchSize;
UseRetrieveTotalRecordCount = options.UseRetrieveTotalRecordCount;
MaxDegreeOfParallelism = options.MaxDegreeOfParallelism;
ColumnComparisonAvailable = options.ColumnComparisonAvailable;
UseLocalTimeZone = options.UseLocalTimeZone;
BypassCustomPlugins = options.BypassCustomPlugins;
QuotedIdentifiers = options.QuotedIdentifiers;
}

public CancellationToken CancellationToken => _options.CancellationToken;

public bool BlockUpdateWithoutWhere => _options.BlockUpdateWithoutWhere;
public bool BlockUpdateWithoutWhere { get; set; }

public bool BlockDeleteWithoutWhere => _options.BlockDeleteWithoutWhere;
public bool BlockDeleteWithoutWhere { get; set; }

public bool UseBulkDelete => _options.UseBulkDelete;
public bool UseBulkDelete { get; set; }

public int BatchSize => _options.BatchSize;
public int BatchSize { get; set; }

public bool UseTDSEndpoint => _options.UseTDSEndpoint;
public bool UseTDSEndpoint { get; set; }

public bool UseRetrieveTotalRecordCount => _options.UseRetrieveTotalRecordCount;
public bool UseRetrieveTotalRecordCount { get; set; }

public int MaxDegreeOfParallelism => _options.MaxDegreeOfParallelism;
public int MaxDegreeOfParallelism { get; set; }

public bool ColumnComparisonAvailable => _options.ColumnComparisonAvailable;
public bool ColumnComparisonAvailable { get; }

public bool UseLocalTimeZone => _options.UseLocalTimeZone;
public bool UseLocalTimeZone { get; set; }

public List<JoinOperator> JoinOperatorsAvailable => _options.JoinOperatorsAvailable;

public bool BypassCustomPlugins => _options.BypassCustomPlugins;
public bool BypassCustomPlugins { get; set; }

public string PrimaryDataSource { get; set; }
public string PrimaryDataSource { get; set; } // TODO: Update UserId when changing data source

public Guid UserId => _options.UserId;

public bool QuotedIdentifiers => _options.QuotedIdentifiers;
public bool QuotedIdentifiers { get; set; }

public bool ConfirmDelete(int count, EntityMetadata meta)
{
return _options.ConfirmDelete(count, meta);
var cancelled = !_options.ConfirmDelete(count, meta);

if (!cancelled)
{
var args = new ConfirmDmlStatementEventArgs(count, meta);
_connection.OnPreDelete(args);

cancelled = args.Cancel;
}

return !cancelled;
}

public bool ConfirmInsert(int count, EntityMetadata meta)
{
return _options.ConfirmInsert(count, meta);
var cancelled = !_options.ConfirmInsert(count, meta);

if (!cancelled)
{
var args = new ConfirmDmlStatementEventArgs(count, meta);
_connection.OnPreInsert(args);

cancelled = args.Cancel;
}

return !cancelled;
}

public bool ConfirmUpdate(int count, EntityMetadata meta)
{
return _options.ConfirmUpdate(count, meta);
var cancelled = !_options.ConfirmUpdate(count, meta);

if (!cancelled)
{
var args = new ConfirmDmlStatementEventArgs(count, meta);
_connection.OnPreUpdate(args);

cancelled = args.Cancel;
}

return !cancelled;
}

public bool ContinueRetrieve(int count)
{
return _options.ContinueRetrieve(count);
var cancelled = !_options.ContinueRetrieve(count);

if (!cancelled)
{
var args = new ConfirmRetrieveEventArgs(count);
_connection.OnPreRetrieve(args);

cancelled = args.Cancel;
}

return !cancelled;
}

public void Progress(double? progress, string message)
{
_options.Progress(progress, message);
}

public void RetrievingNextPage()
{
_options.RetrievingNextPage();
_connection.OnProgress(new ProgressEventArgs(progress, message));
}
}
}
35 changes: 35 additions & 0 deletions MarkMpn.Sql4Cds.Engine/Ado/ConfirmDmlStatementEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Microsoft.Xrm.Sdk.Metadata;

namespace MarkMpn.Sql4Cds.Engine
{
/// <summary>
/// Contains information about a DML statement (INSERT/UPDATE/DELETE) that is about to be executed
/// </summary>
public class ConfirmDmlStatementEventArgs : CancelEventArgs
{
/// <summary>
/// Creates a new <see cref="ConfirmDmlStatementEventArgs"/>
/// </summary>
/// <param name="count">The number of records that will be affected</param>
/// <param name="metadata">The metadata of the entity that will be affected</param>
internal ConfirmDmlStatementEventArgs(int count, EntityMetadata metadata)
{
Count = count;
Metadata = metadata;
}

/// <summary>
/// Returns the number of records that will be affected by the operation
/// </summary>
public int Count { get; }

/// <summary>
/// Returns the metadata of the entity that will be affected
/// </summary>
public EntityMetadata Metadata { get; }
}
}
27 changes: 27 additions & 0 deletions MarkMpn.Sql4Cds.Engine/Ado/ConfirmRetrieveEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace MarkMpn.Sql4Cds.Engine
{
/// <summary>
/// Contains information about a page of data that is about to be retrieved
/// </summary>
public class ConfirmRetrieveEventArgs : CancelEventArgs
{
/// <summary>
/// Creates a new <see cref="ConfirmRetrieveEventArgs"/>
/// </summary>
/// <param name="count">The number of records retrieved so far</param>
public ConfirmRetrieveEventArgs(int count)
{
Count = count;
}

/// <summary>
/// Returns the number of records retrieved so far
/// </summary>
public int Count { get; }
}
}
36 changes: 36 additions & 0 deletions MarkMpn.Sql4Cds.Engine/Ado/ProgressEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MarkMpn.Sql4Cds.Engine
{
/// <summary>
/// Holds information about the progress of a query
/// </summary>
public class ProgressEventArgs
{
/// <summary>
/// Creates a new <see cref="ProgressEventArgs"/>
/// </summary>
/// <param name="progress">The percentage of the operation that has completed so far</param>
/// <param name="message">A human-readable status message to display</param>
internal ProgressEventArgs(double? progress, string message)
{
Progress = progress;
Message = message;
}

/// <summary>
/// The percentage of the operation that has completed so far
/// </summary>
/// <remarks>
/// This is expressed as a number between 0 and 1.
/// </remarks>
public double? Progress { get; }

/// <summary>
/// A human-readable status message to display
/// </summary>
public string Message { get; }
}
}
Loading

0 comments on commit 80af695

Please sign in to comment.