Skip to content

Commit

Permalink
Merge pull request #76 from KinsonDigital/preview/v1.0.0-preview.13
Browse files Browse the repository at this point in the history
🚀Preview Release
  • Loading branch information
CalvinWilkinson authored Jan 18, 2023
2 parents 3ba1eb4 + a80b718 commit 80eb538
Show file tree
Hide file tree
Showing 52 changed files with 289 additions and 1,043 deletions.
4 changes: 2 additions & 2 deletions Carbonate/BiDirectional/IPullReactable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Carbonate.BiDirectional;
/// <summary>
/// Defines a provider for pull-based responses.
/// </summary>
/// <typeparam name="TDataIn">The type of data packaged in the outgoing <see cref="IMessage{TDataIn}"/>.</typeparam>
/// <typeparam name="TDataOut">The type of data to pull.</typeparam>
/// <typeparam name="TDataIn">The type of data coming in.</typeparam>
/// <typeparam name="TDataOut">The type of data going out.</typeparam>
public interface IPullReactable<TDataIn, TDataOut> : IReactable<IRespondReactor<TDataIn, TDataOut>>, IPullable<TDataIn, TDataOut>
{
}
14 changes: 6 additions & 8 deletions Carbonate/BiDirectional/IPullable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
namespace Carbonate.BiDirectional;

using System.Diagnostics.CodeAnalysis;
using Core;

/// <summary>
/// Gives the ability to pull data from a source using a messaging mechanism.
/// </summary>
/// <typeparam name="TDataIn">The type of data packaged in the <see cref="IMessage{TDataIn}"/>.</typeparam>
/// <typeparam name="TDataOut">The type of data to be pulled.</typeparam>
/// <typeparam name="TDataIn">The type of data coming in.</typeparam>
/// <typeparam name="TDataOut">The type of data going out.</typeparam>
public interface IPullable<TDataIn, out TDataOut>
{
/// <summary>
/// Requests to pull data from a source that matches the given <paramref name="respondId"/>,
/// with the given additional <paramref name="msg"/>.
/// with the given additional <paramref name="data"/>.
/// </summary>
/// <param name="msg">The data to send to the responder.</param>
/// <param name="data">The data to send to the responder.</param>
/// <param name="respondId">The ID of the response.</param>
/// <typeparam name="TDataOut">The type of data to send to the responder.</typeparam>
/// <returns>The response result.</returns>
/// <returns>The data result going out.</returns>
[SuppressMessage("ReSharper", "UnusedParameter.Global", Justification = "Public API.")]
[SuppressMessage("ReSharper", "UnusedMemberInSuper.Global", Justification = "Public API.")]
IResult<TDataOut> Pull(in IMessage<TDataIn> msg, Guid respondId);
TDataOut? Pull(in TDataIn data, Guid respondId);
}
9 changes: 3 additions & 6 deletions Carbonate/BiDirectional/PullReactable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
// ReSharper disable LoopCanBeConvertedToQuery
namespace Carbonate.BiDirectional;

using Core;
using Core.BiDirectional;

/// <inheritdoc cref="IPullReactable{TDataIn,TDataOut}"/>
public class PullReactable<TDataIn, TDataOut>
: ReactableBase<IRespondReactor<TDataIn, TDataOut>>, IPullReactable<TDataIn, TDataOut>
{
/// <inheritdoc/>
public IResult<TDataOut> Pull(in IMessage<TDataIn> msg, Guid respondId)
public TDataOut? Pull(in TDataIn data, Guid respondId)
{
for (var i = 0; i < Reactors.Count; i++)
{
Expand All @@ -24,11 +23,9 @@ public IResult<TDataOut> Pull(in IMessage<TDataIn> msg, Guid respondId)
continue;
}

var result = Reactors[i].OnRespond(msg);

return result ?? ResultFactory.CreateEmptyResult<TDataOut>();
return Reactors[i].OnRespond(data);
}

return ResultFactory.CreateEmptyResult<TDataOut>();
return default(TDataOut);
}
}
19 changes: 9 additions & 10 deletions Carbonate/BiDirectional/RespondReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

namespace Carbonate.BiDirectional;

using Core;
using Core.BiDirectional;

/// <inheritdoc cref="IRespondReactor{TDataIn,TDataOut}"/>
public sealed class RespondReactor<TDataIn, TDataOut> : ReactorBase, IRespondReactor<TDataIn, TDataOut>
{
private readonly Func<IMessage<TDataIn>, IResult<TDataOut>?>? onRespondMsg;
private readonly Func<TDataIn, TDataOut?>? onRespondData;

/// <summary>
/// Initializes a new instance of the <see cref="RespondReactor{TDataIn,TDataOut}"/> class.
/// </summary>
/// <param name="respondId">The ID of the <see cref="PullReactable{TDataIn,TDataOut}"/> requiring a response.</param>
/// <param name="name">The name of the <see cref="RespondReactor{TDataIn,TDataOut}"/>.</param>
/// <param name="onRespondMsg">Executed when requesting a response with data.</param>
/// <param name="onRespondData">Executed when requesting a response with data.</param>
/// <param name="onUnsubscribe">
/// Executed when the provider has finished sending push-based notifications and is unsubscribed.
/// </param>
Expand All @@ -30,25 +29,25 @@ public sealed class RespondReactor<TDataIn, TDataOut> : ReactorBase, IRespondRea
public RespondReactor(
Guid respondId,
string name = "",
Func<IMessage<TDataIn>, IResult<TDataOut>?>? onRespondMsg = null,
Func<TDataIn, TDataOut?>? onRespondData = null,
Action? onUnsubscribe = null,
Action<Exception>? onError = null)
: base(respondId, name, onUnsubscribe, onError) => this.onRespondMsg = onRespondMsg;
: base(respondId, name, onUnsubscribe, onError) => this.onRespondData = onRespondData;

/// <inheritdoc/>
public IResult<TDataOut> OnRespond(IMessage<TDataIn> message)
public TDataOut? OnRespond(TDataIn data)
{
if (Unsubscribed)
{
return ResultFactory.CreateEmptyResult<TDataOut>();
return default(TDataOut);
}

if (message is null)
if (data is null)
{
throw new ArgumentNullException(nameof(message), "The parameter must not be null.");
throw new ArgumentNullException(nameof(data), "The parameter must not be null.");
}

return this.onRespondMsg?.Invoke(message) ?? ResultFactory.CreateEmptyResult<TDataOut>();
return this.onRespondData is null ? default(TDataOut) : this.onRespondData.Invoke(data);
}

/// <inheritdoc cref="object.ToString"/>
Expand Down
10 changes: 7 additions & 3 deletions Carbonate/Carbonate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<Nullable>enable</Nullable>

<!--Update this for production and preview releases-->
<Version>1.0.0-preview.12</Version>
<Version>1.0.0-preview.13</Version>

<!--Update this for production and preview releases-->
<FileVersion>1.0.0-preview.12</FileVersion>
<FileVersion>1.0.0-preview.13</FileVersion>

<!--
DO NOT UPDATE THIS FOR PREVIEW RELEASES!!
Expand All @@ -23,7 +23,7 @@
<Company>Kinson Digital</Company>
<Product>Carbonate</Product>
<Description>Library for doing internal messaging using the observable pattern.</Description>
<Copyright>Copyright ©2022 Kinson Digital</Copyright>
<Copyright>Copyright ©2023 Kinson Digital</Copyright>
<PackageTags>messaging observable subscribe</PackageTags>
<RootNamespace>Carbonate</RootNamespace>
<ApplicationIcon>carbonate-logo.ico</ApplicationIcon>
Expand All @@ -41,6 +41,10 @@
<Configurations>Debug;Release</Configurations>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>bin\x64\Carbonate.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Include="carbonate-logo.ico" Pack="true" PackagePath="\" />
<None Include="..\Documentation\Images\carbonate-logo-light-mode.png" Pack="true" PackagePath="\" />
Expand Down
4 changes: 2 additions & 2 deletions Carbonate/Core/BiDirectional/IRespondReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Carbonate.Core.BiDirectional;
/// <summary>
/// Provides a mechanism for receiving responses.
/// </summary>
/// <typeparam name="TDataIn">The type of data packaged in the incoming <see cref="IMessage{TDataIn}"/>.</typeparam>
/// <typeparam name="TDataOut">The type of data being returned in the response.</typeparam>
/// <typeparam name="TDataIn">The type of data coming in.</typeparam>
/// <typeparam name="TDataOut">The type of data going out.</typeparam>
public interface IRespondReactor<in TDataIn, out TDataOut> : IReactor, IResponder<TDataIn, TDataOut>
{
}
10 changes: 5 additions & 5 deletions Carbonate/Core/BiDirectional/IResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace Carbonate.Core.BiDirectional;
/// <summary>
/// Gives the ability to respond to a pull request from an <see cref="IReactable{IResponder}"/>.
/// </summary>
/// <typeparam name="TDataIn">The data packaged in the <see cref="IMessage{TDataIn}"/>.</typeparam>
/// <typeparam name="TDataOut">The type of data being returned in the <see cref="IResult{TDataOut}"/>.</typeparam>
/// <typeparam name="TDataIn">The type of data coming in.</typeparam>
/// <typeparam name="TDataOut">The type of data going out.</typeparam>
public interface IResponder<in TDataIn, out TDataOut>
{
/// <summary>
/// Returns a response.
/// </summary>
/// <param name="message">The message for the <see cref="IReactable{IResponder}"/>.</param>
/// <returns>The response result.</returns>
IResult<TDataOut>? OnRespond(IMessage<TDataIn> message);
/// <param name="data">The data for the <see cref="IReactable{IResponder}"/>.</param>
/// <returns>The data result going out.</returns>>
TDataOut? OnRespond(TDataIn data);
}
19 changes: 0 additions & 19 deletions Carbonate/Core/IMessage.cs

This file was deleted.

28 changes: 0 additions & 28 deletions Carbonate/Core/IResult.cs

This file was deleted.

60 changes: 0 additions & 60 deletions Carbonate/Core/JsonMessage.cs

This file was deleted.

78 changes: 0 additions & 78 deletions Carbonate/Core/Result.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Carbonate/Core/UniDirectional/IReceiveReactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Carbonate.Core.UniDirectional;
/// <summary>
/// A reactor capable of standard functionality that can receive push notifications.
/// </summary>
/// <typeparam name="TDataIn">The data packaged in the message received.</typeparam>
/// <typeparam name="TDataIn">The type of data coming in.</typeparam>
public interface IReceiveReactor<in TDataIn> : IReactor, IReceiver<TDataIn>
{
}
Loading

0 comments on commit 80eb538

Please sign in to comment.