MPOSAirDataCleanUp 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MPOSAirDataCleanUp --version 3.0.0
NuGet\Install-Package MPOSAirDataCleanUp -Version 3.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="MPOSAirDataCleanUp" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MPOSAirDataCleanUp --version 3.0.0
#r "nuget: MPOSAirDataCleanUp, 3.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 MPOSAirDataCleanUp as a Cake Addin
#addin nuget:?package=MPOSAirDataCleanUp&version=3.0.0

// Install MPOSAirDataCleanUp as a Cake Tool
#tool nuget:?package=MPOSAirDataCleanUp&version=3.0.0

MPOSAirDataCleanUp

MPOSAirDataCleanUp is a database table rows clean up library. It's usage it's enforced with the methods described bellow. However, the explanation can be simplified:

  • Specify the DbContext type to be used.
  • Add 1 or more SQL Delete from statements in a base64 encoded format
  • Add a start time.
  • Add a clean up period.
  • Optional: add restrictions

Installation

To install the package, simply search the MPOSAirDataCleanUp package on nuget.org and install it in the same project where Entity Framework Core resides.

The following example illustrates the usage within a Web API project.

  1. ServiceCollectionsExtensions Define the clean up services like so:
public static void AddDataCleanUp(this IServiceCollection services)
{
	services.AddDataCleanUpServices();

	services.AddSingleton<ICleanUpService, CleanUpService<VoucherDbContext>>();
}
  1. ApplicationBuilderExtensions The following method configures the clean up service:
public static void ConfigureDataCleanUp(this IApplicationBuilder app)
{
	var cleanUpService = (ICleanUpService)app.ApplicationServices.GetService(typeof(ICleanUpService));

	var service = cleanUpService = service.WithContext(typeof(InvoiceDbContext))
                                            .WithSqlDeleteStatements(deleteStatements)
                                            .WithPeriod(CleanUpPeriod.Daily)
                                            .WithUtcStartTime(cleanUpHour)
                                            .WithVacuum()
                                            .WithNoRestrictions();
	Task.Run(async () => await service.InitializeCleanUp(new System.Threading.CancellationToken()));
}

Then, in StartUp.cs, you have the following:

  1. ConfigureServices
         services.AddDataCleanUp();
  1. Configure
          app.ConfigureDataCleanUp();

Dependencies

A new table will need to be created in your database. This table is used by MPOSAirDataCleanUp to keep track of cleaned entities. To this end, the DataCleaningEntityTypeConfiguration file already exists in the package. Simply add it to your Entity Framework configuration. Example:

 protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfiguration(new DataCleaningEntityTypeConfiguration());
        }

It's ok if you are not using Configuration files. When overriding OnModelCreating just configure the DataCleaning entity type.

Remember to add the migration when using Code First approach.

Method Description

Currently, the CleanUpService supports the following methods. Their usage is strictly enforced. Example of usage in an appsettings.json file:

  "CLEANUPPERIOD": 0,
  "CLEANUPSTARTTIME": "02:00:00",
  "CLEANUPDELETESTATEMENTS": [
    "ZGVsZXRlIGZyb20gIkludm9pY2VzIiBpIHdoZXJlIGkuIkhlYWRlcl9Eb2N1bWVudFR5cGUiID0gJ1ZPSUQnIGFuZCBpLiJDcmVhdGVkRGF0ZSIgPCBub3coKSAtIGludGVydmFsJzMwIGRheXMn",
    "ZGVsZXRlIGZyb20gIkludm9pY2VzIiBpIHdoZXJlIGkuIkNyZWF0ZWREYXRlIiA8IG5vdygpIC0gaW50ZXJ2YWwnMzAgZGF5cyc=",
    "ZGVsZXRlIGZyb20gIkludm9pY2VzIiBpIHVzaW5nICJPcGVuSW52b2ljZURldGFpbHMiIG9pZDIgd2hlcmUgaS4iSWQiID0gb2lkMi4iSW52b2ljZUlkIiBhbmQgb2lkMi4iU3RhdHVzIiA9ICdPcGVuJyBhbmQgb2lkMi4iQ3JlYXRlZERhdGUiIDwgbm93KCkgLSBpbnRlcnZhbCcxIGRheXMn",
    "ZGVsZXRlIGZyb20gIk9wZW5JbnZvaWNlRGV0YWlscyIgb2lkMiB3aGVyZSBvaWQyLiJTdGF0dXMiID0gJ09wZW4nIGFuZCBvaWQyLiJDcmVhdGVkRGF0ZSIgPCBub3coKSAtIGludGVydmFsJzEgZGF5cyc="
  ]
Method Description Required
WithContext(Type contextType) The database context that needs cleaning. YES
WithSqlDeleteStatements(List<string> deleteStatements) A base64 endoded string list of SQL Delete statements that will be executed one by one on the database YES
WithUtcStartTime(string startTime) Add start time. CAUTION: Start time should be for UTC time. YES
WithVacuum(string startTime) Vacuums the database. If not set, the default behavior will be not to vacuum. CAUTION! Feature is not tested for other provider than PostgreSQL NO
WithPeriod(CleanUpPeriod period) Add the period to the cleaning process. V1.0.0 does not support other dates than the predefined ones for Weekly, Monthly and Yearly periods. YES
WithRestrictions(CleanUpRestrictions restrictions) Add restrictions to the cleaning process. Current restrictions include not cleaning during business hours. CAN HAVE NULL PARAMETER VALUE
InitializeCleanUp() Starts the cleaning process. YES

CleanUpPeriod Options

  • Daily - if the set time is before the current UTC time, then the next clean up will take place tomorrow.
  • Weekly - every Sunday
  • Monthly - the 1st of every month
  • Yearly - the last day of the year

CAUTION

Any and all exceptions are captured and shown into the console output of the application that uses the nuget.

Make sure the table DataCleanings exists, otherwise, the nuget throws the error into the console and the cleaning will not take place.

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 netcoreapp3.1 is compatible. 
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
4.0.1 662 10/17/2022
3.1.1 1,057 6/16/2022
3.1.0 1,340 5/4/2022
3.0.5 506 5/3/2022
3.0.4 521 5/3/2022
3.0.3 496 5/2/2022
3.0.2 1,070 9/30/2021
3.0.1 369 9/28/2021
3.0.0 408 9/27/2021
2.0.0 464 9/3/2021
1.4.0 426 8/23/2021
1.3.2 356 5/14/2021
1.3.1 365 4/12/2021
1.3.0 398 4/9/2021
1.2.10 385 3/24/2021
1.2.9 342 3/18/2021
1.2.8 373 3/10/2021
1.2.7 327 3/9/2021
1.2.6 357 2/8/2021
1.2.5 338 2/3/2021
1.2.4 332 2/2/2021
1.2.3 319 2/2/2021
1.2.2 390 1/22/2021
1.2.1 369 1/21/2021
1.2.0 343 1/21/2021
1.1.1 367 1/21/2021
1.1.0 375 1/21/2021
1.0.3 343 1/20/2021