Dispenser
Dispenser detects inserts, updates and deletes between previous and new versions of items, enabling easy change-based integrations. A sample using Channels is included.
Features:
- Compare new items with previous version of items
- Extensible hashing
Usage:
- Compare new items with previous version of items:
StockItem[] previousStock =
{
new StockItem("Lumber 2x2", 7),
new StockItem("Lumber 2x4", 5),
new StockItem("Lumber 2x8", 4),
new StockItem("Lumber 2x10", 2)
};
StockItem[] actualStock =
{
new StockItem("Lumber 2x2", 3),
new StockItem("Lumber 2x3", 6),
new StockItem("Lumber 2x4", 3),
new StockItem("Lumber 2x6", 3),
new StockItem("Lumber 2x8", 4)
};
var hasher = new Sha1Hasher();
var results = new Dispenser<StockItem, string>()
.Dispense(actualStock.Hash(hasher), previousStock.Hash(hasher), x => x.Sku);
Assert.NotNull(results);
Assert.True(results.HasChanges);
Assert.Contains(new StockItem("Lumber 2x3", 6), results.Inserts);
Assert.Contains(new StockItem("Lumber 2x6", 3), results.Inserts);
Assert.Contains(new StockItem("Lumber 2x2", 3), results.Updates);
Assert.Contains(new StockItem("Lumber 2x4", 3), results.Updates);
Assert.Contains(new StockItem("Lumber 2x10", 2), results.Deletes);
- Extensible hashing:
SHA256 and SHA1 hashing are provided in Dispenser.Hasher.Sha256 and Dispenser.Hasher.Sha1. To implement your own hashing:
public interface IHasher
{
string Hash(object obj);
}
Thanks
- Soap Dispenser icon by ProSymbols from The Noun Project