VersaTul.Collection.Streamers
1.0.31
Prefix Reserved
dotnet add package VersaTul.Collection.Streamers --version 1.0.31
NuGet\Install-Package VersaTul.Collection.Streamers -Version 1.0.31
<PackageReference Include="VersaTul.Collection.Streamers" Version="1.0.31" />
paket add VersaTul.Collection.Streamers --version 1.0.31
#r "nuget: VersaTul.Collection.Streamers, 1.0.31"
// Install VersaTul.Collection.Streamers as a Cake Addin #addin nuget:?package=VersaTul.Collection.Streamers&version=1.0.31 // Install VersaTul.Collection.Streamers as a Cake Tool #tool nuget:?package=VersaTul.Collection.Streamers&version=1.0.31
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 theIStreamer
andIStreamCreator
interfaces. Providing common functionality for all streamers.CsvStreamer
: A concrete implementation of theICsvStreamer
interface.JsonStreamer
: A concrete implementation of theIJsonStreamer
interface.TabStreamer
: A concrete implementation of theITabStreamer
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 theToReader
method that can be used to convert any collection to anIDataReader
.
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 directoryWrapper = new DirectoryWrapper();
var utility = new CommonUtility();
var flattener = new Flattener();
var zipper = new Zipper(new Archiver());
var compressor = new Compressor(zipper);
var fileUtil = new FileUtility(directoryWrapper, directoryWrapper);
var fileConvert = new FileConverter(fileUtil, compressor);
// Creating the CsvStreamer Instance
var csvStreamer = new CsvStreamer(utility, fileUtil, 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 | Versions 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. net9.0 is compatible. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- VersaTul.Compression (>= 1.0.16)
- VersaTul.Extensions (>= 1.0.15)
- VersaTul.Handler.File (>= 1.0.19)
- VersaTul.Mailer (>= 1.0.15)
- VersaTul.Object.Converters (>= 1.0.14)
- VersaTul.Utilities (>= 1.0.15)
-
net9.0
- Newtonsoft.Json (>= 13.0.3)
- VersaTul.Compression (>= 1.0.16)
- VersaTul.Extensions (>= 1.0.15)
- VersaTul.Handler.File (>= 1.0.19)
- VersaTul.Mailer (>= 1.0.15)
- VersaTul.Object.Converters (>= 1.0.14)
- VersaTul.Utilities (>= 1.0.15)
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 | 73 | 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 |