Skip to content

maitlandmarshall/MAD.IntegrationFramework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repository

This project is licensed under the MIT license.

MAD.IntegrationFramework

MAD.IntegrationFramework is a .NET Standard 2.1 framework which exposes a simple unit of work pattern allowing you to quickly and easily create timed or scheduled "integrations". The framework automatically logs errors to a Microsoft SQL Server database and provides a robust and simple way to save, load and extend on configuration / meta data.

Installation

For now, clone the repo and add it as a dependency to your .NET Core 3.1 project.

Usage

First, you must bootstrap the framework by calling

MIF.Start();

Now the framework will pick up any classes which inherit from TimedIntegration automatically and start a timer based on its interval.

public class ExampleIntegration : TimedIntegration
{
    public override TimeSpan Interval => TimeSpan.FromMinutes(1);
    public override bool IsEnabled => true;

    public override Task Execute()
    {
        // Execute your unit of work here. 
        // Any errors will be automatically logged to the database if a SQL Connection String is provided in the configuration class.

        throw new NotImplementedException();
    }
}

Configuration

The framework provides a base MIFConfig class for you to extend. Inherited properties will be automatically saved to a settings.json file next to the executable.

The base MIFConfig:

public class MIFConfig
{
    internal const int DefaultBindingPort = 666;

    public string SqlConnectionString { get; set; }

    public int BindingPort { get; set; } = DefaultBindingPort;
    public string BindingPath { get; set; }
}

An example of adding new properties:

public class ExampleMIFConfig : MIFConfig
{
    public string EmailAddress { get; set; }

    public ExampleMIFConfig()
    {
        this.SqlConnectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;";
    }
}

The MAD.IntegrationFramework exposes a web frontend bound to the BindingPort property. By default, you can save / load your MIFConfig meta data by browsing to http://localhost:666/configuration

Screenshot of config page

Using your MIFConfig

In order to access the settings in your MIFConfig, simply add it as a constructor parameter and the framework will automatically inject it for you.

public class ExampleIntegration : TimedIntegration
{
    private readonly ExampleMIFConfig config;

    public override TimeSpan Interval => TimeSpan.FromMinutes(1);
    public override bool IsEnabled => true;

    public ExampleIntegration(ExampleMIFConfig config)
    {
        this.config = config;
    }

    public override Task Execute()
    {
        // Execute your unit of work here. 
        // Any errors will be automatically logged to the database if a SQL Connection String is provided in the configuration class.

        throw new NotImplementedException();
    }
}

[Savable] Attribute

Any properties marked with [Savable] inside a TimedIntegration will automatically be saved to a file named [className].json in the name directory of the executable. These properties are saved after Execute completes, regardless of if it was successful.

public class ExampleIntegration : TimedIntegration
{
    public override TimeSpan Interval => TimeSpan.FromMinutes(1);
    public override bool IsEnabled => true;

    [Savable]
    public string AStringToSave { get; set; } 

    public override Task Execute()
    {
        throw new NotImplementedException();
    }
}

Contributing

Go for it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages