Catch.Catcher 0.1.11

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

// Install Catch.Catcher as a Cake Tool
#tool nuget:?package=Catch.Catcher&version=0.1.11                

<p align="center"> <img width="192" height="192" src="catcherlogo.png"/> </p>


Catcher

CosmosDB Based with MongoDB Interface, with generic DAO Design Pattern for .NET Framework with C# Language.

We're sorry that version before 0.1.4 are have many API changes through the version. After 0.1.4, there will be consistency in the framework API.


Changelog

for changelog check here


Features

  • Factory pattern
  • Automatic query generator
  • Automatic Dao creator
  • Can search most similiar(not necessary equal) object
  • Automatic connection creator
  • Using attributes to exposed metadata

Requirements

  • .NET standard 1.5 and higher

Installation

Visual Studio NuGet Package Manager

You can use default NuGet Package Manager in visual studio and search "Catch.Cather" and install it, as easy as that.
Don't forget to resolve double dependency if you have one.

Package Manager

Execute this line in your package manager terminal inside your project :

Install-Package Catch.Catcher -Version 0.1.9

.NET CLI

Execute this line in your .NET CLI inside your project :

dotnet add package Catch.Catcher --version 0.1.9

Manually

  1. Clone this repository.
  2. Added to your project.
  3. Congratulation!

Usage example

Initialize Framework

You need to inject your config once before you can use this framework.

  1. Create Configuration Provider.
using Catcher.DB.DAO;

namespace YourNameSpace
{
    public class ConfigurationProvider : IConfigurationProvider
    {
        public string DBName => "YOUR_DB_NAME";

        public string DBHost => "www.your.db.host.com";

        public int DBPort => 1234;

        //insert DBUserName and DBPassword null if your db don't have credential
        public string DBUserName => "yourUserName";
        
        public string DBPassword => "y0UR_p4$sW0Rd";

        public bool IsUseSsl => true;

    }
}
  1. Inject Your Configuration Provider.
//this context will stored your configuration as long as your program run
DaoConfigurationContext.Provider = new ConfigurationProvider();

Create Dto

All you need to do is create model class which extends our Dto abstract class and put DtoClass Attribute above your class.
Keep in mind that Dto is using Bson library from mongoDB, so you can manipulate field name using BsonElement attribute.
Don't forget to add "?" at primitive property (int, float, double, long, bool, decimal) so its default value is null.

using Catcher.DB.DTO;

namespace YourProject.Model
{
    [DtoClass("NAME_OF_YOUR_DB", "NAME_OF_YOUR_COLLECTION")]
    public class Tag : Dto
    {   
        public string TagName { get; set; }

        public int? View { get; set; }
    }
}

If your model have unique field other than default object id, then you can put DtoUniqueField attribute on your property.
The acceptable type for unique field type is : string, int, MongoDBRef(Or Dto with ObjectRef attribute), ObjectId.
Remember, this field should not be null when you want to insert it to the database.
You can have more than one unique field.

using Catcher.DB.DTO;

namespace YourProject.Model
{
    [DtoClass("NAME_OF_YOUR_DB", "NAME_OF_YOUR_COLLECTION")]
    public class User : Dto
    {   
        [DtoUniqueField]
        public string UserName { get; set; }

        public string Password { get; set; }
    }
}

If your model have composite id just put DtoCompositeField attribute on your property.
Obviously, minimum number of composite property is two.
The acceptable type for composite field type is : string, int, MongoDBRef(Or Dto with ObjectRef attribute), ObjectId.
Remember, this field should not be null when you want to insert it to the database.

using Catcher.DB.DTO;

namespace YourProject.Model
{
    [DtoClass("NAME_OF_YOUR_DB", "NAME_OF_YOUR_COLLECTION")]
    public class Item : Dto
    {   
        [DtoCompositeField]
        public MongoDBRef user { get; set; }

        [DtoCompositeField]
        public string itemName { get; set; }
    }
}

If your model have MongoDBRef and you want it to auto connect with the related Dto class, you can use BsonSerializer Attribute and pass the type of DBRef attribute.
Keep in mind that this method will multiply time of your query because its actually do extra query to fetch MongoDBRef into the object especially when the object is not exist in the cache.
There is two type of object ref :

  • ObjectRef<T> for single MongoDBRef
  • ListObjectRef<T> for list of MongoDBRef
    T must be Dto and must be the same type as its attributed property
    Remember, query using this field as parameter will convert the object into MongoDBRef and will ignore any Dto field.
using Catcher.DB.DTO;

namespace YourProject.Model
{
    [DtoClass("NAME_OF_YOUR_DB", "NAME_OF_YOUR_COLLECTION")]
    public class Item : Dto
    {   
        [DtoCompositeField]
		[BsonSerializer(typeof(ObjectRef<User>))]
        public User user { get; set; }

        [DtoCompositeField]
        public string itemName { get; set; }
    }
}

If your model have different connection than default ConfigurationProvider, you can add DtoCustomConnection attribute to the Dto class

namespace YourProject.Model
{
    [DtoClass("NAME_OF_YOUR_DB", "NAME_OF_YOUR_COLLECTION")]
	[DtoCustomConnection("www.yourhost.com", 1234, "NAME_OF_YOUR_DB")]
    public class User : Dto
    {   
        [DtoUniqueField]
        public string UserName { get; set; }

        public string Password { get; set; }
    }
}

What Dto can do

//Dto at default have getter setter for ID
ObjectId id = user.ID;

//Dto can fetch itself to update the object to newer version from the database
user.Fetch<User>();

//get MongoDBRef to user
MongoDBRef ref = user.ToDBRef<User>();

//get object from MongoDBRef
User userFromRef = ref.Retrieve<User>();

//update object from the database
Dto.Fetch(userFromRef);

Get Dao

To get Dao for your specific Dto, you can get it from DaoContext class. It will only create one Dao object for every Dto class and reuse it.

//import this namespace
using Catcher.DB.DAO;
IDao<User> dao = DaoContext.GetDao<User>();

Using Dao

Here are some of Dao can do :

//inserting. Any null property will be ignored. If there is object in the database with same ObjectId/UniqueId/CompositeId, then it will return false and abandon the insert task, otherwise it will return true.
var isSuccess = dao.Insert(user);

//Deleting user. It will search by its objectId first and unique id / composite id if you did not provide one
dao.Delete(user);

Find using Dao

Here are some of method to find object in the database :

//Find by object id
User user = dao.Find.ByObjectID(id);

//Find object that looks like (not necessary equal) your object
IList<User> usersLike = dao.Find.WhenLike(user);

//Find object that equal with your object (except its ObjectId and unique field name) and ignore it's null property
IList<User> usersLike = dao.Find.WhenEqual(user, true);

Create Rollback Action

The framework contains method to create sequence of query task which will automatically rollback if failed in the middle of query
If the rollback is failed, then it will try to rollback again after the given interval and times
If the rollback still faild, it will create Trace error with information about the query its try to rollback so you can rollback it manually later

//Create rollbacker object which will rollback every 5 minutes if failed for 3 times
var rollbacker = new Rollbacker(5, 3);
rollbacker.AddInsertTask(object1);
rollbacker.AddDeleteTask(object2);
rollbacker.Execute();

Contribute

We would love you for the contribution to Catcher, just contact me to nayanda@catch.co.id

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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.5 is compatible.  netstandard1.6 was computed.  netstandard2.0 was computed.  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 tizen30 was computed.  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.

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
0.2.19 1,581 3/23/2018
0.2.18 1,054 2/21/2018
0.2.17 1,176 2/5/2018
0.2.16 1,106 2/1/2018
0.2.15 1,114 2/1/2018
0.2.13 1,215 1/31/2018
0.2.12 1,224 1/30/2018
0.2.11 1,212 1/30/2018
0.2.10 1,103 1/25/2018
0.2.9 1,141 1/23/2018
0.2.8 1,252 1/4/2018
0.2.7 1,265 1/3/2018
0.2.6 1,241 12/22/2017
0.2.3 1,162 12/11/2017
0.2.1 1,108 12/7/2017
0.2.0 1,115 12/7/2017
0.1.11 1,060 12/4/2017
0.1.10 1,132 11/17/2017
0.1.9 1,112 11/9/2017
0.1.8 1,161 11/2/2017
0.1.7 1,106 10/31/2017
0.1.6 1,084 10/30/2017
0.1.5 1,224 10/28/2017
0.1.4 1,061 10/26/2017
0.1.3 1,075 10/25/2017
0.1.2 1,090 10/25/2017
0.1.1 1,051 10/24/2017
0.1.0 1,253 10/24/2017
0.0.5 1,195 10/10/2017

Added Serializer