FluentPollingTriggerBuilder 1.0.0

dotnet add package FluentPollingTriggerBuilder --version 1.0.0
NuGet\Install-Package FluentPollingTriggerBuilder -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluentPollingTriggerBuilder" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentPollingTriggerBuilder --version 1.0.0
#r "nuget: FluentPollingTriggerBuilder, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FluentPollingTriggerBuilder as a Cake Addin
#addin nuget:?package=FluentPollingTriggerBuilder&version=1.0.0

// Install FluentPollingTriggerBuilder as a Cake Tool
#tool nuget:?package=FluentPollingTriggerBuilder&version=1.0.0

NETWORG.Utilities.LogicApps.FluentPollingTriggerBuilder

The easiest way, how to support Logic Apps Polling Trigger in your .Net Core API.

alternate text is missing from this package README image

Features

  • Fluent API - easy to use functional API, just like others
  • State handling - first polling, previous polling, changes detected, no changes detected
  • Splitting - start new Logic App workflow for every polled item

How to start

  1. Initial state factory - How to create initial state when the Logic App start polling
  2. Initial state predicate - Recognize empty state - Logic App started polling (timestamp not specified, etc)
  3. Polling task - Task that can poll changes based on a current state
  4. State transfer - compute new polling state based on previous state and polled data

What is done automatically

  • State serialization and deserialization
  • Providing correct Status Code for Logic App
  • Providing correct location for next polling in response headers
  • Providing correct retry time for next polling in reponse headers

Use

Basic usage - polling with timestamp

public class PollingDto
{
    public PollingDto()
    {
    }

    public PollingDto(DateTime? timeStamp) => TimeStamp = timeStamp;
    public DateTime? TimeStamp { get; set; }
}

// ------------------------------------------------------------------------
private readonly IHttpContextAccessor _contextAccessor;

[HttpGet(nameof(OnItemsUpdated))]
[ProducesResponseType(202)]
[ProducesResponseType(200)]
public Task<IActionResult> OnItemsUpdated([FromQuery] PollingDto pollingState)
{
    var now = DateTime.UtcNow; //record tiem before polling started
    return new FluentAsyncPollingTrigger<PollingDto, PollingOutput>()
        .SetStateFactory(() => new PollingDto(DateTime.UtcNow))
        .SetStateUpdate((oldState, polled) => new PollingDto(now))
        .SetPollingStateEmptyPredicate(state => !state.TimeStamp.HasValue) // timestamp empty, Logic App is polling for the first time
        .SetPollingTask(async state => await items.Where(x => x.UpdatedAt > state.TimeStamp).ToListAsync())
        .PollAsAction(pollingState, _contextAccessor);
}
  • FluentAsyncPollingTrigger is strongly typed
  • You don't have to create new instance every time
  • All you have to do is take infromation from the request, and poll data

Advanced usage - polling with filters

Sometime we only want to track specific data

public class PollingDto
{
    public PollingDto()
    {
    }

    public PollingDto(DateTime? timeStamp, string companyName)
    {
        TimeStamp = timeStamp;
        CompanyName = companyName;
    }
    public DateTime? TimeStamp { get; set; }
    public string CompanyName {get; set; }
}

// ------------------------------------------------------------------------
private readonly IHttpContextAccessor _contextAccessor;

[HttpGet(nameof(OnItemsUpdated))]
[ProducesResponseType(202)]
[ProducesResponseType(200)]
public Task<IActionResult> OnItemsUpdated([FromQuery] PollingDto pollingState)
{
    var now = DateTime.UtcNow; //record tiem before polling started
    return new FluentAsyncPollingTrigger<PollingDto, PollingOutput>()
    // first, Logic App sends empty state with specified filter (e.g. CompanyName)
    // we create initial polling state, with current timestamp and we keep, filter (CompanyName) unchanged
        .SetStateFactory(() => new PollingDto(DateTime.UtcNow, pollingState.CompanyName))
        .SetStateUpdate((oldState, polled) => {oldState.Timestamp = now; return oldState;})
        .SetPollingStateEmptyPredicate(state => !state.TimeStamp.HasValue) // timestamp empty, Logic App is polling for the first time
        .SetPollingTask(async state => await items.Where(x => x.UpdatedAt > state.TimeStamp && x.Company.Name == state.CompanyName).ToListAsync())
        .PollAsAction(pollingState, _contextAccessor);
}
  • Timestamp and CompanyName are automatically serialized as query parametrs
  • So the next polling location for Logic App would be https://myapi/OnItemsUpdated?timestamp=2020.3.3&companyName=contoso
  • Once the Logic App polling trigger calls our API again, the query parameters gets deserialized into PollingDto automatically
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 969 2/3/2020