<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: rodrigohfnogueiraOBatman</title>
    <description>The latest articles on DEV Community by rodrigohfnogueiraOBatman (@meudeusdoceunaoencontronome).</description>
    <link>https://dev.to/meudeusdoceunaoencontronome</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F86553%2F4d586f43-a9af-455a-a784-c3bd4218fd40.jpeg</url>
      <title>DEV Community: rodrigohfnogueiraOBatman</title>
      <link>https://dev.to/meudeusdoceunaoencontronome</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/meudeusdoceunaoencontronome"/>
    <language>en</language>
    <item>
      <title>Let's talk about A.I.</title>
      <dc:creator>rodrigohfnogueiraOBatman</dc:creator>
      <pubDate>Tue, 12 Mar 2019 01:32:19 +0000</pubDate>
      <link>https://dev.to/meudeusdoceunaoencontronome/lets-talk-about-ai-4f4p</link>
      <guid>https://dev.to/meudeusdoceunaoencontronome/lets-talk-about-ai-4f4p</guid>
      <description>&lt;h1&gt;
  
  
  Human brain
&lt;/h1&gt;

&lt;p&gt;Before talking about real A.I. we need to try to understand what our brain does when making a decision. Let's imagine I have three cups, two cups made of glass and one made of plastic. I have one kid in the house, of course, I'll leave the plastic cup for childrens, in my memory I know that the cup in the children's hand has a bigger chance to fall on the floor.&lt;/p&gt;

&lt;p&gt;Subconsciously I remember all the times a cup fell on the floor, and noticed a pattern. In my experience (for example), 80% of the times a cup has broken, it was on the hands of a children, and 60% of the times a plastic cup fell on the floor it didn't broke. So I found two facts, based on memories, that can help solve a problem.&lt;/p&gt;

&lt;p&gt;So, we need to: &lt;/p&gt;

&lt;p&gt;-Identify the entities of my problem.&lt;br&gt;
-Identify the problem.&lt;br&gt;
-Identify patterns coorelating the problem's entity and the result of my problem.&lt;br&gt;
-Remember the possibilities of the patterns.&lt;br&gt;
-Identify patterns that deny the effects of my problem.&lt;br&gt;
-Use this pattern knowledge to solve future problems.&lt;/p&gt;

&lt;p&gt;This is one simple kind of problem, the problem could be resolved by any different ways, proportional logic, trees, and other kind of organization our brain choose.&lt;/p&gt;

&lt;h1&gt;
  
  
  A.I.
&lt;/h1&gt;

&lt;p&gt;Let's work the ideia inside the computer science field, using object-oriented programing.&lt;/p&gt;

&lt;p&gt;We can first identify our entities to the problem:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Cup
-Person
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And then the problem happens when&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Cup.situation = broken;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And we know that a "Person" can be:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Children
-Teeneger
-GrownUp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And we know that in our memory we have an inference motor wich will coorelate the facts, the rules and produce new memories with the learning. So, we know that after the lunch the inference motor will coorelate the final state of the cup and the person type to produce a memory (a fact). Let's understand a children has broke a cup, the fact will be "children - cup - broken".&lt;/p&gt;

&lt;p&gt;After a number of lunchs we will have a combination of memories, like:&lt;/p&gt;

&lt;p&gt;-"children - cup - broken"&lt;br&gt;
-"Teeneger - cup - ok"&lt;br&gt;
-"Teeneger - cup - broken"&lt;br&gt;
-"GrownUp  - cup - ok"&lt;br&gt;
-"GrownUp  - cup - ok"&lt;br&gt;
-"children - cup - broken"&lt;br&gt;
-"children - cup - ok"&lt;br&gt;
-"children - cup - broken"&lt;br&gt;
-"GrownUp  - cup - ok"&lt;/p&gt;

&lt;p&gt;So when I have to know for wich user will I give the thoughest cup, I just have to find all the percentage of broken devolutions of cups and choose the type of user wich has the biggest... In out example:&lt;/p&gt;

&lt;p&gt;-Children { &lt;br&gt;
            count: 4,&lt;br&gt;
            broken: 3,&lt;br&gt;
            ok: 1,&lt;br&gt;
            brokenPercentage: 75%&lt;br&gt;
          };&lt;br&gt;
-GrownUp { &lt;br&gt;
            count: 3,&lt;br&gt;
            broken: 0,&lt;br&gt;
            ok: 3,&lt;br&gt;
            brokenPercentage: 0&lt;br&gt;
          };&lt;br&gt;
-Teeneger { &lt;br&gt;
            count: 2,&lt;br&gt;
            broken: 1,&lt;br&gt;
            ok: 1,&lt;br&gt;
            brokenPercentage: 50%&lt;br&gt;
          };&lt;/p&gt;

&lt;p&gt;So the biggest chance to break a cup is to give it to a children.&lt;/p&gt;

&lt;h1&gt;
  
  
  Components
&lt;/h1&gt;

&lt;p&gt;There are 3 main components, we have the rules, the inference motor, and the memory (facts).&lt;/p&gt;

&lt;p&gt;The inference motor matches the rules that can be executed based on the facts avaible on the memory and process new memories.&lt;/p&gt;

&lt;p&gt;So the components are:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Inference Motor
-Facts
-Rules
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The rules has the expert system conditions, it's where the expertise of your analysis is present.&lt;/p&gt;

&lt;h1&gt;
  
  
  Big Data
&lt;/h1&gt;

&lt;p&gt;A basic introduction to big data is necessary in this posts because just as we can't remember everything in our life, the computer does not need to process everything to get to the correct answer in decisions.&lt;/p&gt;

&lt;p&gt;Usually it's done using a percentage of the real memory size, we have, for example 10.000.000 registers. So we can just generate a random identifier in each register, and then just find, using statistics, a size of sample wich can give us the better margin of success with less computer processing and time. &lt;/p&gt;

&lt;p&gt;When we select the sample to analyse we must order by the random identifier and take the firsts results, this way we can use a random sample to get the conclusion. If the statistic model has been done right, we will get the same result as if we processed all the registers in the database.&lt;/p&gt;

&lt;p&gt;This is a simple and pratical exemple of big data's use for the AI.&lt;/p&gt;

&lt;h1&gt;
  
  
  Trees, Graphs and Neural Networks
&lt;/h1&gt;

&lt;p&gt;There is a lot to talk about this topics so I will make one to each one of those, but for us in this posts is to understand how it can be used in de decision making process.&lt;/p&gt;

&lt;p&gt;Another kind of decision is using graphs, where all the possibilities are considered using graphs and the decision is made using the DFS or BFS and others.&lt;/p&gt;

&lt;p&gt;The trees are a lot similar to the graphs decisions, but more limited, it can be combined with linear algebra to get into the decision faster, it will be explain in another post.&lt;/p&gt;

&lt;p&gt;Neural Networks had it's researchs stopped for something like 10 years, until the back propagation algorithm was developed, it has a lot of experience in the game learning, and the success point is the most important in the algorithms. It basically has neurons wich receive an input and execute a math formula to get the output, the math formula is influenced by the correction weight wich in each case of failure it auto corrects until gets success on the output. Knowing that, we have to understand there is input layers, hidden layers and output layers, and the backpropagation algorithm gives a way to send feedback with corrections in the formulas of the previous neurons.&lt;/p&gt;

&lt;p&gt;Neural Network is a complex subject and will have a post just for it.&lt;/p&gt;

&lt;p&gt;For now, that's enough to a "introduction" to AI.&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
    <item>
      <title>Let's talk about webdrivers</title>
      <dc:creator>rodrigohfnogueiraOBatman</dc:creator>
      <pubDate>Mon, 11 Mar 2019 19:14:20 +0000</pubDate>
      <link>https://dev.to/meudeusdoceunaoencontronome/lets-talk-about-webdrivers-2f4l</link>
      <guid>https://dev.to/meudeusdoceunaoencontronome/lets-talk-about-webdrivers-2f4l</guid>
      <description>&lt;h1&gt;
  
  
  The internet
&lt;/h1&gt;

&lt;p&gt;The connections between your computer and a server (Google server, Amazon server) any of those is based on HTTP (or HTTPS) requests and "code" files as Html, CSS, and Javascript. As a client-server connection, your computer has a client software installed, wich can be Google Chrome, Firefox or any other. This software manage the communication between the client and the server.&lt;/p&gt;

&lt;p&gt;So we can organize in this way: You (Web Browser) requests Server (online service) using HTTP(S) as communication protocol. When the files are delivered by the server the browser can design the web site and it's functions can be load.&lt;/p&gt;

&lt;p&gt;Ok, this was a basic review.&lt;/p&gt;

&lt;h1&gt;
  
  
  A webdriver
&lt;/h1&gt;

&lt;p&gt;We can now work a little further on the client's interpretations.&lt;/p&gt;

&lt;p&gt;A webdriver pretends to be a web client making requests to the server as if it were a normal user. This way the software can access the Html of each page, capturing informations when needed.&lt;/p&gt;

&lt;p&gt;I can give you usage examples, I'm from Brazil, and here we have some startups, and big companies that use this kind of system everyday, financial industry uses to capture information about their client's money situation, other companies can use to check company's money situation in government web sites.&lt;/p&gt;

&lt;h1&gt;
  
  
  How does it work
&lt;/h1&gt;

&lt;p&gt;Inside the HTTP or HTTPS request we have the CRUD operations (Create, Read, Update Delete). In the HTTP it's called GET (Read), POST (Create), PUT (Update), DELETE (Delete). This is the first thing to know.&lt;/p&gt;

&lt;p&gt;The HTTP request carries a body and a header, when it's a POST or a PUT request, it's expected to have a body content. When the request is a GET or DELETE, it usually does not have a body content, just headers and the URL.&lt;/p&gt;

&lt;p&gt;We know that we need to pretend to be a browser, so we can receive the information that we want. But how will we know wich request and when we have to do? Usually you have to use a "sniffer" to track every request sent by your web client and then do the exactly same requests.&lt;/p&gt;

&lt;p&gt;I like to use "Fiddler" (&lt;a href="https://www.telerik.com/fiddler"&gt;https://www.telerik.com/fiddler&lt;/a&gt;) it's very simple to use, you can just target the web client and track the requests of any navigation you want. Of course you have to target the web client and access the web site, the exactly path you want the webdriver to process.&lt;/p&gt;

&lt;p&gt;The hardest part will be understand wich request is done, when and why, and of course where are the variables of each request.&lt;/p&gt;

&lt;h1&gt;
  
  
  Architecture
&lt;/h1&gt;

&lt;p&gt;Everything is a state machine, your webdriver couldn't be different. I will show a model of architecture, wich can be good or not for your usage, but I have used many times this architecture in my webdrivers.&lt;/p&gt;

&lt;p&gt;This is a really simple architecture that will be represented without the fixation of a specific language.&lt;/p&gt;

&lt;p&gt;Goals:&lt;/p&gt;

&lt;p&gt;-Map all the pages of the navigation.&lt;br&gt;
-Parameters for each request and each page.&lt;br&gt;
-Cookies (Parameters and navigation).&lt;br&gt;
-Identify the informations of interest in each page (Regex).&lt;/p&gt;

&lt;p&gt;So in your code you will need...&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Enum (example):

    -Page 1.
    -Page 2.
    -Page 3.
    -Page 4.

Extract (example)

    -Url
    -Dictionary&amp;lt;string, string&amp;gt; query
    -List&amp;lt;string&amp;gt; regexs
    -Dictionary&amp;lt;string, string&amp;gt; header
    -object body

Dictionary &amp;lt;Enum, Extract&amp;gt; (example):

    -Page 1, Extract.
    -Page 2, Extract.
    -Page 3, Extract.
    -Page 4, Extract.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And the main function (example):&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-Loop (navigation.situation != End):

    -Execute the functions NavigateTo(currentPage).
    -Get the response content (Html, JS and CSS).
    -Execute the regex of the page.
    -Get the parameters (including cookies, and Html         
    variables) for the next page navigation.

-End Loop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And for the end the extract module, wich can be done in markup languages, databases, tables, and whatever you would want to.&lt;/p&gt;

&lt;p&gt;This was a introduction to webdrivers and it's architecture, of course it's a complex subject, and this is not even a half of it. What is usually done is make frameworks to deal with Html readings (the Regex for example), and even a automation of the navigation. Using XML tags to describe regex, urls, query url, and the others properties, it can just be uploaded to a generic webdriver, wich will just use the XML uploaded to navigate whatever web site you need.&lt;/p&gt;

</description>
      <category>webdrivers</category>
    </item>
    <item>
      <title>Let's make a framework</title>
      <dc:creator>rodrigohfnogueiraOBatman</dc:creator>
      <pubDate>Tue, 24 Jul 2018 13:32:59 +0000</pubDate>
      <link>https://dev.to/meudeusdoceunaoencontronome/lets-make-a-framework-4dhc</link>
      <guid>https://dev.to/meudeusdoceunaoencontronome/lets-make-a-framework-4dhc</guid>
      <description>&lt;p&gt;Hello guys, this is my first post, so I'm a little nervous.&lt;/p&gt;

&lt;p&gt;I would like to talk about making a framework.&lt;/p&gt;

&lt;p&gt;First things first. In this post I would like to make a code to database interaction framework using MongoDB.&lt;/p&gt;

&lt;p&gt;Using MongoDB with C#, we already have a good framework: mongodriver.&lt;br&gt;
Let's make a abstraction to some operations of mongodriver, so we can code de business faster in other layers of code.&lt;/p&gt;

&lt;p&gt;Let's start with the Configuration.&lt;/p&gt;

&lt;p&gt;Using mongodb, we used to link the database with a "MongoUrl" class, wich we can build dynamically using a Configuration class to abstract.&lt;/p&gt;

&lt;p&gt;Let's code (using C#) a simple configuration class to our framework of MongoDB:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Configuration
{
    public MongoUrl mongoUrl { get; set; }
    public string dbName { get; set; }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's remember the format of a simple mongodb Url to localhost: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MongoUrl mongoUrl = new MongoUrl("mongodb://localhost:27017/CONTROLE_OD_DB")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this simple configuration example, we will not care to build dynamically or abstract the MongoUrl, this is not the point of the post.&lt;br&gt;
Now we will get in the real point of this post, the art of write a generic framework, even a small one.&lt;/p&gt;

&lt;p&gt;Let's make a class with the generic operations.&lt;/p&gt;

&lt;p&gt;Again, first things first. Let's make the configuration.&lt;br&gt;
I will name it class Context.&lt;/p&gt;

&lt;p&gt;So:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Context
{
    #region Configuration
    public static Configuration _configuration { get; set; }
    static MongoClient client;
    static IMongoDatabase db;

    public static void Initializer(Configuration configuration)
    {
        _configuration = new Configuration();
        _configuration = configuration;
        client = new MongoClient(_configuration.mongoUrl);
        db = client.GetDatabase(_configuration.dbName);
    }
    public static void Dispose()
    {
        client = null;
    }
    #endregion
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's understand the post. &lt;br&gt;
We want to make our life easier making a framework. &lt;br&gt;
First thing is to identify the boring parts of writing the code using just the old framework, mongodriver. The first boring part is to deal with the configuration. We had to get the database, make the mongoUrl every time, so we made here a "Context" class to save the configuration in a static variable, so it will not need a new instance all the time.&lt;br&gt;
We will only get the database one time and get the IMongoDatabase one time. Better than that is the fact that we will not worry about them anymore.&lt;/p&gt;

&lt;p&gt;So let's start to build a basic "collection" operations region.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    #region Collections

    public static void CreateCollection(string collectionName)
    {
        db.CreateCollection(collectionName);
    }
    public static IMongoCollection&amp;lt;T&amp;gt; GetCollection&amp;lt;T&amp;gt;(string collectionName)
    {

        return db.GetCollection&amp;lt;T&amp;gt;(collectionName);
    }
    public static IMongoCollection&amp;lt;T&amp;gt; GetCollection&amp;lt;T&amp;gt;()
    {
        return GetCollection&amp;lt;T&amp;gt;(typeof(T).Name + "_COLLECTION");
    }
    #endregion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can use generic types to get whatever collection we want and set the collection using the type of the "T" class of our method. So, let's remove the problem of set the string name of a collection, and make the framework set the name of the collection using the class name. Just for organization we can write a "_COLLECTION" at the end, so it will be better to read.&lt;/p&gt;

&lt;p&gt;Now we have this class.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Context
{
    #region Configuration
    public static Configuration _configuration { get; set; }
    static MongoClient client;
    static IMongoDatabase db;

    public static void Initializer(Configuration configuration)
    {
        _configuration = new Configuration();
        _configuration = configuration;
        client = new MongoClient(_configuration.mongoUrl);
        db = client.GetDatabase(_configuration.dbName);
    }
    public static void Dispose()
    {
        client = null;
    }
    #endregion
    #region Collections

    public static void CreateCollection(string collectionName)
    {
        db.CreateCollection(collectionName);
    }
    public static IMongoCollection&amp;lt;T&amp;gt; GetCollection&amp;lt;T&amp;gt;(string collectionName)
    {
        return db.GetCollection&amp;lt;T&amp;gt;(collectionName);
    }
    public static IMongoCollection&amp;lt;T&amp;gt; GetCollection&amp;lt;T&amp;gt;()
    {
        return GetCollection&amp;lt;T&amp;gt;(typeof(T).Name + "_COLLECTION");
    }
    #endregion
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here we have the database creation, and the collections creation, just what we need to start to write a operations region, CRUD (Create, Read, Update, Delete) region.&lt;/p&gt;

&lt;p&gt;Let's make the insert:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    #region CRUD
    public static T Insert&amp;lt;T&amp;gt;(T document)
    {
        var collection = GetCollection&amp;lt;T&amp;gt;(typeof(T).Name + "_COLLECTION");
        collection.InsertOne(document);
        return document;
    }
    public static List&amp;lt;T&amp;gt; Insert&amp;lt;T&amp;gt;(List&amp;lt;T&amp;gt; documents)
    {
        GetCollection&amp;lt;T&amp;gt;(typeof(T).Name + "_COLLECTION").InsertManyAsync(documents);
        return documents;
    }
    public static List&amp;lt;T&amp;gt; Insert&amp;lt;T&amp;gt;(string collectioName, List&amp;lt;T&amp;gt; documents)
    {
        GetCollection&amp;lt;T&amp;gt;(collectioName).InsertManyAsync(documents);
        return documents;
    }
    public static T Insert&amp;lt;T&amp;gt;(string collectioName, T document)
    {
        GetCollection&amp;lt;T&amp;gt;(collectioName).InsertOne(document);
        return document;
    }
    public static List&amp;lt;BsonDocument&amp;gt; Insert(string collectioName, List&amp;lt;BsonDocument&amp;gt; documents)
    {
        GetCollection&amp;lt;BsonDocument&amp;gt;(collectioName).InsertManyAsync(documents);
        return documents;
    }
    public static BsonDocument Insert(string collectioName, BsonDocument document)
    {
        GetCollection&amp;lt;BsonDocument&amp;gt;(collectioName).InsertOneAsync(document);
        return document;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In mongodriver we have always to choose between insert many, or insert one, insert one async, insert bson, insert object, I don't want to worry about that anymore, let the framework choose each one to use.&lt;br&gt;
For all the inserts methods (and all the operations we will make of the CRUD sequence) we will use the database already declared and the getcollection method.&lt;/p&gt;

&lt;p&gt;We are choosing each things not to worry, and making generic methods to abstract them.&lt;/p&gt;

&lt;p&gt;Going on...&lt;/p&gt;

&lt;p&gt;Let's make a the R (Read) of the "CRUD":&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public static List&amp;lt;T&amp;gt; GetDocuments&amp;lt;T&amp;gt;(FilterDefinition&amp;lt;T&amp;gt; filter)
    {
        return GetCollection&amp;lt;T&amp;gt;().FindAsync(filter).Result.ToList&amp;lt;T&amp;gt;();
    }

    public static List&amp;lt;T&amp;gt; GetDocuments&amp;lt;T&amp;gt;(string collectionName, FilterDefinition&amp;lt;T&amp;gt; filter)
    {
        return GetCollection&amp;lt;T&amp;gt;(collectionName).FindAsync(filter).Result.ToList&amp;lt;T&amp;gt;();
    }

    public static T GetDocument&amp;lt;T&amp;gt;(FilterDefinition&amp;lt;T&amp;gt; filter)
    {
        return GetCollection&amp;lt;T&amp;gt;().FindAsync(filter).Result.SingleOrDefault&amp;lt;T&amp;gt;();
    }
    public static T GetDocument&amp;lt;T&amp;gt;(string collectionName, FilterDefinition&amp;lt;T&amp;gt; filter)
    {
        return GetCollection&amp;lt;T&amp;gt;(collectionName).FindAsync(filter).Result.SingleOrDefault&amp;lt;T&amp;gt;();
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A good thing to do is get everything returning in the type of object I want to use, I don't want to convert c# collections into lists for example, I want every return of each method right how I want to use them, in this example, it would be a List or a simple T.&lt;/p&gt;

&lt;p&gt;Let`s make the D (Delete) and the U (Update) :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public static void Update&amp;lt;T&amp;gt;(MongoDB.Driver.FilterDefinition&amp;lt;T&amp;gt; filter, KeyValuePair&amp;lt;string, object&amp;gt; property, bool updateOne, bool IsUpsert)
    {
        var update = Builders&amp;lt;T&amp;gt;.Update.Set(property.Key, property.Value);            
        if (updateOne)
            GetCollection&amp;lt;T&amp;gt;()
                .UpdateOneAsync(filter, update, new UpdateOptions { IsUpsert = IsUpsert });
        else
            GetCollection&amp;lt;T&amp;gt;()
                .UpdateMany(filter, update, new UpdateOptions { IsUpsert = IsUpsert });
    }
    public static void Update&amp;lt;T&amp;gt;(MongoDB.Driver.FilterDefinition&amp;lt;T&amp;gt; filter, Dictionary&amp;lt;string, object&amp;gt; properties, bool updateOne, bool IsUpsert)
    {
        foreach(var property in properties)
            Update&amp;lt;T&amp;gt;(filter, property, false, true);
    }
    public static void Update&amp;lt;T&amp;gt;(MongoDB.Driver.FilterDefinition&amp;lt;T&amp;gt; filter, Dictionary&amp;lt;string, object&amp;gt; properties)
    {
        foreach(var property in properties)
            Update&amp;lt;T&amp;gt;(filter, property, false, true);
    }
    public static void Update&amp;lt;T&amp;gt;(MongoDB.Driver.FilterDefinition&amp;lt;T&amp;gt; filter, Dictionary&amp;lt;string, object&amp;gt; properties, bool updateOne)
    {
        foreach(var property in properties)
            Update&amp;lt;T&amp;gt;(filter, property, false, true);
    }
    public static void Update&amp;lt;T&amp;gt;(MongoDB.Driver.FilterDefinition&amp;lt;T&amp;gt; filter, KeyValuePair&amp;lt;string, object&amp;gt; property)
    {
        Update&amp;lt;T&amp;gt;(filter, property, false, true);
    }

    public static void Update&amp;lt;T&amp;gt;(MongoDB.Driver.FilterDefinition&amp;lt;T&amp;gt; filter, KeyValuePair&amp;lt;string, object&amp;gt; property, bool updateOne)
    {
        Update&amp;lt;T&amp;gt;(filter, property, false, true);
    }

    public static void Delete&amp;lt;T&amp;gt;(FilterDefinition&amp;lt;T&amp;gt; filter, bool DeleteOne)
    {
        if (DeleteOne)
            GetCollection&amp;lt;T&amp;gt;().DeleteOne(filter);
        else
            GetCollection&amp;lt;T&amp;gt;().DeleteMany(filter);

    }
    public static void Delete&amp;lt;T&amp;gt;(FilterDefinition&amp;lt;T&amp;gt; filter)
    {
        Delete&amp;lt;T&amp;gt;(filter, false);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So we can go on to the beautiful part of the post.&lt;br&gt;
Let's make more new methods, to get everything even easier.&lt;/p&gt;

&lt;p&gt;Everything by now was changing the Context class, or making a basic Configuration class. Now let's create a Base class.&lt;/p&gt;

&lt;p&gt;I will create a new class named "Base".&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Base&amp;lt;T&amp;gt;
{
    public T Insert(T T)=&amp;gt;Context.Insert&amp;lt;T&amp;gt;(T);
    public void Upsert(FilterDefinition&amp;lt;T&amp;gt; filter, T entity)
    {
        if(List(filter).Count &amp;gt; 0)
        {
            Dictionary&amp;lt;string, object&amp;gt; props = new Dictionary&amp;lt;string, object&amp;gt;();
            foreach (var responsibleProp in entity.GetType().GetProperties()) props.Add(responsibleProp.Name, responsibleProp.GetValue(entity));
            Context.Update&amp;lt;T&amp;gt;(filter, props);        
        }
        else Context.Insert&amp;lt;T&amp;gt;(entity);    
    }
    public T Find(FilterDefinition&amp;lt;T&amp;gt; filter)=&amp;gt;Context.GetDocument&amp;lt;T&amp;gt;(filter);
    public List&amp;lt;T&amp;gt; List(FilterDefinition&amp;lt;T&amp;gt; filter)=&amp;gt;Context.GetDocuments&amp;lt;T&amp;gt;(filter);
    public void Delete(FilterDefinition&amp;lt;T&amp;gt; filter)=&amp;gt;Context.Delete&amp;lt;T&amp;gt;(filter);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;One of the things I don't want to worry is if we are making a Insert or a Update, so we can create a Upsert method. If the filter get's any result in the query, it will update these results with the entity, else it will insert a new entity in the database.&lt;/p&gt;

&lt;p&gt;"Find" with a simple filter, and "List" returning a "List"(List of generic objects), and then the update.&lt;/p&gt;

&lt;p&gt;Now we can configure the framework into a new software: let's create a ConfigDB class :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class ConfigDB&amp;lt;T&amp;gt; : Base&amp;lt;T&amp;gt;
{
    public ConfigDB()
    {
        Configuration configuration = new Configuration();
        Connection conn = new Connection();
        configuration.dbName = conn.GetDatabaseName();
        configuration.mongoUrl = new MongoUrl(conn.GetUrl());
        Context.Initializer(configuration);

    }
    ~ConfigDB()
    {
        Context.Dispose();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And let's make a simple agent class, just to use the base operations :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Agent&amp;lt;T&amp;gt; : ConfigDB&amp;lt;T&amp;gt;
{

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we can create our business class, I will name it UserBusiness :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class User
{
    public string login {get;set;}
    public string password {get;set;}
    public string curriculum {get;set;}
    public string aboutMe {get;set;}


    [BsonId(IdGenerator = typeof(StringObjectIdGenerator))]
    public string ID { get; set; }
    public bool deleted { get; set; } = false;
    public bool active { get; set; } = true;
    [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
    public DateTime creationDate { get; set; } = DateTime.Now;
}


public class UserBusiness
{
    public User InsertUser(User user) =&amp;gt; new Agent&amp;lt;User&amp;gt;().Insert(user);
    public User findUserByID(string ID)=&amp;gt; new Agent&amp;lt;User&amp;gt;().Find(Builders&amp;lt;User&amp;gt;.Filter.Where(u =&amp;gt; u.ID == ID));
    public User findUserByLogin(string login)=&amp;gt; new Agent&amp;lt;User&amp;gt;().Find(Builders&amp;lt;User&amp;gt;.Filter.Where(u =&amp;gt; u.active == true &amp;amp;&amp;amp; u.login == login));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This was just a small example of how to think when building a framework.&lt;/p&gt;

&lt;p&gt;We need to worry, now, about what we don't want to worry about in the future.&lt;/p&gt;

&lt;p&gt;This was my message, hope you like it.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>dotnet</category>
      <category>dotnetcore</category>
    </item>
  </channel>
</rss>
