Introduction to CouchDB with .NET part 8: data replication

Introduction

In the previous post we saw how to view changes made to a database. The _changes API endpoint returns a JSON with the list of changes. There are various filter functions to view only certain document IDs or include the properties of the document in the response.

In this post we’ll take a look at data replication between two databases.

Read more of this post

Summary of thread-safe collections in .NET

The System.Collections.Concurrent namespace has 4 thread-safe collections that you can use in multi-threaded applications. The starting point is that you have a multi-threaded app where the same collection needs to be accessed by different threads. In that case the well-know collection types, like HashSet, List, Dictionary etc. simply won’t be enough.

If many different threads have access to the same resource then there’s no guarantee on the state of that resource in the moment a thread accesses it in some way: deletion, lookup, insertion or modification. Another thread may have accessed the same resource just milliseconds before that and the other thread will access the resource under the wrong assumptions. You’ll end up with buggy code with unpredictable results and ad-hoc fixes and patches that probably won’t solve the root of the problem.

Read more of this post

Introduction to CouchDB with .NET part 7: viewing changes made in the database

Introduction

In the previous post we looked at batch insertions and updates in CouchDB. Batch operations are very useful if we intend to insert or update multiple documents at once. We can mix insertions, updates and deletions in the same batch operation. The individual modifications in the batch are treated in isolation. This implies that if one modification fails then it won’t affect the others. In other words batch operations are non-atomic in CouchDB.

In this post we’ll look at a way to check what changes have been made to a CouchDB database.

Read more of this post

Introduction to CouchDB with .NET part 6: batch updates and insertions

Introduction

In the previous post we looked at the CouchDB concurrency implementation and the notion of eventual consistency. Concurrency in a database means that multiple threads might want to access and modify the same data record at the same time. CouchDB solves the concurrency problem by a mechanism called Multi-Version Concurrency Control MVCC. With MVCC CouchDB keeps the various revisions of the same document. If a thread wants to read the document while it is being updated then the reading thread will get the most recent complete copy of the document. The caller will in such a case get an outdated revision of the document. However, a subsequent request will then get the updated copy. This scenario is called eventual consistency. CouchDB reaches high availability due to the absence of data locks and sacrifices data consistency to some degree.

In this post we’ll look at batch updates and insertions.

Read more of this post

Cancel multiple Tasks at once in .NET C#

You cannot directly interrupt a Task in .NET while it’s running. You can do it indirectly through the CancellationTokenSource object. This object has a CancellationToken property which must be passed into the constructor of the Task:

CancellationTokenSource cancellationTokenSource	= new CancellationTokenSource();
CancellationToken cancellationToken = cancellationTokenSource.Token;

You can re-use the same token in the constructor or several tasks:

Read more of this post

Introduction to CouchDB with .NET part 5: concurrency and eventual consistency

Introduction

In the previous post we continued our discussion of the CouchDB HTTP API. In particular we looked at those endpoints that modify the database and the documents. We inserted a new database and some documents. We also saw how to update documents. An interesting feature of CouchDB is that it keeps the old versions of an updated document until the database is compacted. Document deletion marks a document with the “_deleted” flag set to true. We can still read the older versions of the document and restore it like it was before. Again, this can only be done until the database has been compacted. DB compaction generally removes old versions of a document and those documents that were marked with the “_deleted” flag. These versions are called revisions and we saw the role of revision IDs

In this post we’ll briefly discuss how concurrency is handled in CouchDB.

Read more of this post

An example of using the dynamic keyword in C# .NET

The dynamic keyword in C# is similar to Reflection. It helps you deal with cases where you’re not sure of the concrete type of an object. However, you may expect the object to have a certain method that you can invoke at runtime. E.g. you have a framework that external users can write plugins for. You may set up a list of rules for the plugin to be valid, e.g. it must have a method called “Execute” and a property called “Visible”.

There are various ways you can solve this problem and one of them is dynamic objects. Using the dynamic keyword will turn off the automatic type checking when C# code is compiled. The validity of the code will only be checked at runtime.

Read more of this post

Introduction to CouchDB with .NET part 4: continuing with the CouchDB HTTP API

Introduction

In the previous post we started looking into the CouchDB HTTP Web API. The API allows us to communicate with the CouchDB server using HTTP calls. This and the ubiquitous JSON arguments make integration with CouchDB quite straightforward for all platforms that are capable to execute HTTP calls and surely any serious programming language should be equipped with web request execution. The HTTP API responds with JSON by default and that also makes for a seamless integration.

We have primarily looked at various requests that did not modify the database or the documents. In this post we’ll continue with testing the database and document modification endpoints in the API.

Read more of this post

Introduction to CouchDB with .NET part 3: starting with the CouchDB HTTP API

Introduction

In the previous post we looked at the CouchDB administrative UI called Fauxton. The UI that shipped with earlier versions of CouchDB is called Futon so you will still come across that name if you work with older CouchDB projects. Fauxton is quite easy and straightforward to use. The database section allows us to create, update and delete databases and documents. Many functions are meant to be handled by database admins such as CouchDB users, access rights, processes and configuration.

In this post we’ll start exploring the CouchDB HTTP-based API.

Read more of this post

Dynamically finding the value of a static field with Reflection in .NET C#

Say you do not have access to a .NET assembly at compile time but you want to execute code in it or read programmatic data from it.

One such scenario is when you’d like to extract some important field information from a class. Why would you ever need that?

Imagine that you have an application where people can upload their own plugins in the form of DLL’s. However, users do not programmatically build their own libraries in Visual Studio but rather use a GUI which will dynamically build a class file and compile it into a DLL based on the user’s selections on the GUI. This is possible if your users are not programmers or if the rules for the plugins are so complex that you wouldn’t want people to write their own solutions.

In such a scenario the class builder could write some important metadata in the form of static fields in the class, such as Version. E.g. if your app has multiple versions then the code generator would put the current version into the class so that your app can verify it. Then you can disallow plugins that were created with an older version of the app if the current version is not backward compatible.

Open Visual and create a new C# class library project called Domain. Add the following Customer class to it:

Read more of this post

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

ARCHIVED: Bite-size insight on Cyber Security for the not too technical.