Skip to content

Commit

Permalink
Add more helper methods for serializing table configs (#351)
Browse files Browse the repository at this point in the history
* Add more helper methods for serializing table configs

* Add one more method without logger

* Refactor

* Use IEnumerable
  • Loading branch information
mslukebo authored Apr 9, 2024
1 parent 56ceedb commit 4c8247b
Showing 1 changed file with 115 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,25 @@ public class TableConfigurationsSerializer
}

/// <summary>
/// Serializes a table configuration to a stream.
/// Serializes a <see cref="Processing.TableConfiguration"/> to a stream.
/// </summary>
/// <param name="stream">
/// Target stream.
/// </param>
/// <param name="tableConfiguration">
/// Table configuration to serialize.
/// The <see cref="Processing.TableConfiguration"/> to serialize.
/// </param>
/// <param name="tableId">
/// Table identifier.
/// </param>
/// <remarks>
/// This will serialize a full <see cref="Processing.TableConfigurations"/> that has the given
/// <paramref name="tableId" /> as its <see cref="Processing.TableConfigurations.TableId"/>
/// and the given <paramref name="tableConfiguration"/> as its single element
/// <see cref="Processing.TableConfigurations.Configurations"/>.
/// The serialized <see cref="Processing.TableConfigurations"/> will have a null
/// <see cref="Processing.TableConfigurations.DefaultConfigurationName"/>.
/// </remarks>
public static void SerializeTableConfiguration(
Stream stream,
Processing.TableConfiguration tableConfiguration,
Expand All @@ -146,27 +154,129 @@ public static void SerializeTableConfiguration(
}

/// <summary>
/// Serializes a table configuration to a stream.
/// Serializes one or more <see cref="Processing.TableConfiguration"/> instances to a stream.
/// </summary>
/// <param name="stream">
/// Target stream.
/// </param>
/// <param name="tableConfigurations">
/// The <see cref="Processing.TableConfiguration"/> instances to serialize.
/// </param>
/// <param name="tableId">
/// Table identifier.
/// </param>
/// <remarks>
/// This will serialize a full <see cref="Processing.TableConfigurations"/> that has the given
/// <paramref name="tableId" /> as its <see cref="Processing.TableConfigurations.TableId"/>
/// and the given <paramref name="tableConfigurations"/> as its <see cref="Processing.TableConfigurations.Configurations"/>.
/// The serialized <see cref="Processing.TableConfigurations"/> will have a null
/// <see cref="Processing.TableConfigurations.DefaultConfigurationName"/>.
/// </remarks>
public static void SerializeTableConfigurations(
Stream stream,
IEnumerable<Processing.TableConfiguration> tableConfigurations,
Guid tableId)
{
SerializeTableConfigurations(stream, tableConfigurations, tableId, null);
}

/// <summary>
/// Serializes a <see cref="Processing.TableConfiguration"/> to a stream.
/// </summary>
/// <param name="stream">
/// Target stream.
/// </param>
/// <param name="tableConfiguration">
/// Table configuration to serialize.
/// The <see cref="Processing.TableConfiguration"/> to serialize.
/// </param>
/// <param name="tableId">
/// Table identifier.
/// </param>
/// <param name="logger">
/// Used to log relevant messages.
/// </param>
/// <remarks>
/// This will serialize a full <see cref="Processing.TableConfigurations"/> that has the given
/// <paramref name="tableId" /> as its <see cref="Processing.TableConfigurations.TableId"/>
/// and the given <paramref name="tableConfiguration"/> as its single element
/// <see cref="Processing.TableConfigurations.Configurations"/>.
/// The serialized <see cref="Processing.TableConfigurations"/> will have a null
/// <see cref="Processing.TableConfigurations.DefaultConfigurationName"/>.
/// </remarks>
public static void SerializeTableConfiguration(
Stream stream,
Processing.TableConfiguration tableConfiguration,
Guid tableId,
ILogger logger)
{
var tableConfigurations = new Processing.TableConfigurations(tableId) { Configurations = new[] { tableConfiguration } };
SerializeTableConfigurations(stream, new[] { tableConfiguration }, tableId, logger);
}

/// <summary>
/// Serializes one or more <see cref="Processing.TableConfiguration"/> instances to a stream.
/// </summary>
/// <param name="stream">
/// Target stream.
/// </param>
/// <param name="tableConfigurations">
/// The <see cref="Processing.TableConfiguration"/> instances to serialize.
/// </param>
/// <param name="tableId">
/// Table identifier.
/// </param>
/// <param name="logger">
/// Used to log relevant messages.
/// </param>
/// <remarks>
/// This will serialize a full <see cref="Processing.TableConfigurations"/> that has the given
/// <paramref name="tableId" /> as its <see cref="Processing.TableConfigurations.TableId"/>
/// and the given <paramref name="tableConfiguration"/> as its <see cref="Processing.TableConfigurations.Configurations"/>.
/// The serialized <see cref="Processing.TableConfigurations"/> will have a null
/// <see cref="Processing.TableConfigurations.DefaultConfigurationName"/>.
/// </remarks>
public static void SerializeTableConfigurations(
Stream stream,
IEnumerable<Processing.TableConfiguration> tableConfigurations,
Guid tableId,
ILogger logger)
{
var toSerialize = new Processing.TableConfigurations(tableId) { Configurations = tableConfigurations };
SerializeTableConfigurations(stream, toSerialize, logger);
}

/// <summary>
/// Serializes <see cref="Processing.TableConfigurations"/> to a stream.
/// </summary>
/// <param name="stream">
/// Target stream.
/// </param>
/// <param name="tableConfigurations">
/// The <see cref="Processing.TableConfigurations"/> to serialize.
/// </param>
public static void SerializeTableConfigurations(
Stream stream,
Processing.TableConfigurations tableConfigurations)
{
SerializeTableConfigurations(stream, tableConfigurations, null);
}

/// <summary>
/// Serializes <see cref="Processing.TableConfigurations"/> to a stream.
/// </summary>
/// <param name="stream">
/// Target stream.
/// </param>
/// <param name="tableConfigurations">
/// The <see cref="Processing.TableConfigurations"/> to serialize.
/// </param>
/// <param name="logger">
/// Used to log relevant messages.
/// </param>
public static void SerializeTableConfigurations(
Stream stream,
Processing.TableConfigurations tableConfigurations,
ILogger logger)
{
var prebuiltConfigurations = tableConfigurations.ConvertToDto();

SerializeTableConfigurations(stream, prebuiltConfigurations, logger);
Expand Down

0 comments on commit 4c8247b

Please sign in to comment.