Flettu 1.4.0

dotnet add package Flettu --version 1.4.0
NuGet\Install-Package Flettu -Version 1.4.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="Flettu" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Flettu --version 1.4.0
#r "nuget: Flettu, 1.4.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 Flettu as a Cake Addin
#addin nuget:?package=Flettu&version=1.4.0

// Install Flettu as a Cake Tool
#tool nuget:?package=Flettu&version=1.4.0

Flettu Library

It contains many small pieces of codes for reducing preliminary coding overheads, such as Async/Await locks on object, ids, string.. or store password safely or reduce boiler plate code such as checking for nulls.

Features

  • Async/Await Task base locking/synchronizations on built-in value types which supports lock reentrance (i.e. Int32, Int64, string and etc)
  • Extension functions for value types and reference types
  • Password encryption and authentication.
  • Concurrent Pipe Stream for multiple reading and writing simultanously for multiplexing/duplexing on any given underline stream like MemoryStream or FileStream (Underline stream must support both read and write operations)

Namespaces

  • Flettu.IO: helps in threadsafe reading and writing, also Pipe Stream for multiple readers and writers support recursive function calls.
  • Flettu.Lock: helps acquiring locks with await support on object, integer, long and etc ids and supports lock reentrace in recursive function calls.
  • Flettu.Security: Store password safely as random hash value to prevent against brute force attacks, or encrypt sensitive data quickly.
  • Flettu.Extensions: Difference extension methods for primitive types like string, integer, IEnumerable
  • Flettu.Util: Helper methods to check for empty values
  • Flettu.Collections: Contains ConcurrentList<T> and ConcurrentHashSet<T> for maximum performance, since reads can be simultaneous

Getting Started

Install it from NuGet packages

Async/Await Lock Example

private AsyncLock asynMutex = new AsyncLock;

// Do something async..
public async Task DoSomethingAsync(CancellationToken cancellationToken = default(CancellationToken))
{
    using(await asyncMutex.AcquireAsync())
    {
       await Task.Delay(10000, cancellationToken);
    }
}

// Take locks recursively and allow reenterance
public async Task DoRecursionAsync(int maxRecursion = 2, CancellationToken cancellationToken = default(CancellationToken))
{
    using(await asyncMutex.AcquireAsync())
    {
       if(maxRecursion > 0)
          await DoRecursionAsync(maxRecursion - 1, cancellationToken);
          
       await Task.Delay(10000, cancellationToken);
    }
}

// ... Dispose pattern implemenation
protected virtual void Dispose(bool disposing)
{
    if(!disposed)
    {
        if(disposing)
        {   
            // .. disposing other resources here
            this.asyncMuxtex.Dispose();
        }
        
        // ..Releasing unmanage resources here if any
        
        disposed = true;
    }
}

Pipe Stream Example

static void Main(string[] args)
{
    var buffer = new byte[768];
    using (var underlineStream = new MemoryStream())
    {
        int count = 0;
        using (var writer = new ConcurrentPipeWriter(underlineStream))
        {
            var readTask1 = Task.Run(async () => await ReadAllAsync(writer, 512)); 
            var readTask2 = Task.Run(async () => await CopyToAsync(writer));

            while (count++ < 10)
            {
                writer.WriteAsync(buffer, 0, buffer.Length).Wait();
                Console.WriteLine($"Write index: {count}, size: {buffer.Length}, press key to proceed");

                //Console.ReadKey();
                Thread.Sleep(1000);
            }

            // writer.EndOfStream()
        }
    }

    Console.ReadKey();
}

private static async Task ReadAllAsync(ConcurrentPipeWriter writer, int bufferSize)
{
    var buffer = new byte[bufferSize];
    var totalRead = 0;

    Console.WriteLine($"ReadAllAsync => Started");
    using (var memoryStream = new MemoryStream())
    using (var reader = writer.OpenStreamReader())
    {
        int readSize = 0;
        while ((readSize = await reader.ReadAsync(buffer, 0, buffer.Length)) != 0)
        {
            totalRead += readSize;
            Console.WriteLine($"ReadAllAsync => Read size: {readSize}, total read size: {totalRead}, buffer length: {buffer.Length}");
        }
    }

    Console.WriteLine($"ReadAllAsync => Ended");
}

private static async Task CopyToAsync(ConcurrentPipeWriter writer)
{
    Console.WriteLine($"CopyToAsync => Started");
    using (var memoryStream = new MemoryStream())
    using (var reader = writer.OpenStreamReader())
    {
        var copyTask = reader.CopyToAsync(memoryStream);
        while (!copyTask.IsCompleted)
        {
            Console.WriteLine($"CopyToAsync => Copying external stream position: {memoryStream.Position}, length: {memoryStream.Length}");
            await Task.Delay(500);
        }

        Console.WriteLine($"CopyToAsync => Copied size to external stream: {memoryStream.Length}");
    }

    Console.WriteLine($"CopyToAsync => Ended");
}
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.
  • .NETStandard 2.0

    • No dependencies.

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.4.0 486 11/16/2023
1.3.0 725 2/5/2023
1.2.3 733 1/18/2023
1.2.2 705 1/18/2023
1.2.1 743 1/14/2023
1.2.0 749 1/12/2023
1.1.2 949 5/2/2021
1.1.1 1,007 7/2/2020
1.1.0 908 7/2/2020
1.0.3 1,044 9/19/2019
1.0.2 973 9/9/2019
1.0.1 1,005 9/8/2019
1.0.0 2,305 9/7/2019