VersaTul.Collection.Streamers 1.0.26

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

// Install VersaTul.Collection.Streamers as a Cake Tool
#tool nuget:?package=VersaTul.Collection.Streamers&version=1.0.26                

VersaTul Collection Streamers

VersaTul Collection Streamers is a library that provides functionality to quickly convert a collection of objects in memory into a data-reader that can be used for bulk inserting data into a SQL Database, or be used to generate flat files. It also works with display attributes to manipulate the properties on the objects in the collection.

Features

  • Convert from a data-reader to other file formats such as CSV, TAB or JSON
  • Use display attributes to format or rename the properties
  • Send streamers via email attachments
  • Save streamers to physical files on disk
  • Compress streamers for transport over the network
  • Convert any collection to an IDataReader

Installation

To use VersaTul Collection Streamers, first install it using nuget:

PM> NuGet\Install-Package VersaTul.Collection.Streamers -Version latest

Usage

The library provides several interfaces and classes to create and manipulate streamers. Here are some of the main ones:

  • IStreamer: A base interface that represents the data contained in the stream and the functionality that can be applied to the data.
  • IStreamCreator: A base interface that represents the functionality for creating streamers.
  • ICsvStreamer: A specific stream type interface that represents the functionality for creating csv streamers.
  • ITabStreamer: A specific stream type interface that represents the functionality for creating tab streamers.
  • IJsonStreamer: A specific stream type interface that represents the functionality for creating json streamers.
  • BaseStreamer: A concrete implementation of the IStreamer and IStreamCreator interfaces. Providing common functionality for all streamers.
  • CsvStreamer: A concrete implementation of the ICsvStreamer interface.
  • JsonStreamer: A concrete implementation of the IJsonStreamer interface.
  • TabStreamer: A concrete implementation of the ITabStreamer interface.
  • IMailTransporter: Represents a set of functionality to send streamers via email attachments.
  • IStreamFileConverter: Represent a set of conversion techniques that can be applied to a streamer.
  • ICompressTransport: Represents a set of functionality to reduce streamers for transport over the network.
  • CollectionReaderExtensions: Contains the ToReader method that can be used to convert any collection to an IDataReader.

Here is a simple example of using the CsvStreamer to create a csv file from a collection of Person objects:

using VersaTul.Collection.Streamers;
using VersaTul.Collection.Streamers.Compressions;
using VersaTul.Collection.Streamers.Converters;
using VersaTul.Compression;
using VersaTul.Handler.File;
using VersaTul.Object.Converters;
using VersaTul.Utilities;

namespace CollectionStreamers
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create N number of data model
            var people = GetPeople(1000);

            // Create Needed Instances
            var iOWrapper = new IOWrapper();
            var utility = new CommonUtility();
            var handler = new FileHandler(iOWrapper, iOWrapper);
            var flattener = new Flattener();
            var zipper = new Zipper(new Archiver());
            var compressor = new Compressor(zipper);
            var fileUtil = new FileUtility(handler, iOWrapper);
            var fileConvert = new FileConverter(fileUtil, handler, compressor);

            // Creating the CsvStreamer Instance
            var csvStreamer = new CsvStreamer(utility, handler, flattener);

            // Create CSV from given people collection
            var csv = csvStreamer.Create(people, "people");

            // Save csv to Path
            fileConvert.Save(csv, "C:\\your\\file\\path\\here\\", false);
        }

        // Helper method for generating list of data model.
        private static IEnumerable<Person> GetPeople(int amount)
        {
            var people = new List<Person>(amount);
            var names = new[] { "John Doe", "Jane Smith", "Susan Williams", "Mike Burger", "Joe Williams", "Timmy Smith", "Lisa Ray", "Stanley Smith", "Sam Jones", };

            for (int i = 0; i < amount; i++)
            {
                people.Add(new Person
                {
                    Age = i + 10,
                    Name = CommonUtil.RandomSampler(names),
                    AccountBalance = (100.99m * i),
                    BestFriend = CommonUtil.RandomSampler(people)
                });
            }

            return people;
        }
    }

    // Data Model
    public class Person
    {
        public int Age { get; set; }
        public string? Name { get; set; }
        public decimal AccountBalance { get; set; }
        public IEnumerable<Person>? Friends { get; set; }
        public Person? BestFriend { get; set; }
    }

    // Helper class
    public static class CommonUtil
    {
        public static T? RandomSampler<T>(IList<T> source)
        {
            var max = source.Count;
            if (max == 0) return default;
            var rand = new Random();
            var position = rand.Next(max);
            return source[position];
        }
    }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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.31 77 12/10/2024
1.0.30 98 10/12/2024
1.0.29 122 5/30/2024
1.0.28 122 4/5/2024
1.0.27 116 4/4/2024
1.0.26 118 4/4/2024
1.0.25 132 3/1/2024
1.0.24 111 2/2/2024
1.0.23 126 1/28/2024
1.0.22 105 1/25/2024
1.0.21 104 1/23/2024
1.0.20 103 1/23/2024
1.0.19 107 1/15/2024
1.0.18 117 1/11/2024
1.0.17 107 1/11/2024
1.0.16 110 1/11/2024
1.0.15 134 12/16/2023
1.0.14 178 11/2/2023
1.0.13 186 7/24/2023
1.0.12 161 7/22/2023