Pages

Monday, October 26, 2015

Windows Batch Script for Incremental Backup



Recently I faced with the problem when I wanted to do a backup of some directory just by one click. I didn't want to rename or change something manually each time I need to do a backup. All I want is just copy the content of one folder to some destination many times by one single mouse click. 

This means that each time I run a backup I want my script to check if there already exist some previous backup folder and if yes then to increment it's name and actually perform the backup. Thus if I will run the script 5 times then the destination directory will look like this:

incremental-backup-folders-structure

Well I must confess it was not easy to find a solution for this relatively simple task. Therefore I decided to put a result of my research here in order to do someone's life easier.
Here is a Windows batch script that will do incremental backup for you:

Thursday, October 15, 2015

Java Spring Restful Web Service with Configurable MongoDB



Today I'll show you how to build Java RESTful Web Service that uses MongoDB database for storing and retrieving data. The service is written using Java Spring 4 technology. 

In this project I will show how to configure MongoDB database parameters in java properties file and how to consume it using Java Spring. If you're new to MongoDB then I suggest to read my previous article on How to Install and Run MongoDB on Windows.

I will not describe in details maven pom.xml structure just because you can simply download the whole project by clicking on the download link at the bottom of this page.

Here is the structure of the project:

spring-rest-webservice-mongodb-project-structure
Ok, so what this all about?

Monday, October 12, 2015

How to Install and Run MongoDB on Windows

This particular article is for those who are going to install and run MongoDB database for the first time.

  • First, download MongoDB from official MongoDB website

  • Once you done Unzip and put its content to your location, for instance C:\MongoDB\ 

  • This is how MongoDB server directory tree looks like after extraction

  • mongodb-directory-structure

  • Then go to C:\MongoDB\Server\config\ and create MongoDB configuration file - mongo.config 

  • Fill in corresponding data, for example this is content of my mongo.config:

                                   ## database directory
                                   dbpath = c:\MongoDB\Server\data

                                   ## database port number
                                   port = 27017

                                   ## logs will be created here
                                   logpath = c:\MongoDB\Server\logs\mongo.log

Monday, March 23, 2015

C# Dependency Injection Simple Example



People are often confused about what Dependency Injection is and when they might need or want to use it. Some time ago I wrote an article Managing Dependency Injection in C# with Autofac which explains how to manage DI in C#, but today I want to show by simple code sample what actually Dependency Injection is.

Imaging situation where you have a class, let's say Employee, and two or more different loggers for that class. Each logger prints messages in his own particular way and you want to have control of which logger to use for Employee during its instantiation.

Just take a look at this code and I'm sure you will get the idea of Dependency Injection:

public class Employee
{
    public Employee(ILogger logger)
    {
        logger.WriteToLog("New employee created");
    }
}

public interface ILogger
{
    void WriteToLog(string text);
}

public class LoggerOne : ILogger
{
    public void WriteToLog(string text)
    {
        Console.WriteLine(text);
    }
}

public class LoggerTwo : ILogger
{
    public void WriteToLog(string text)
    {
        Console.WriteLine("***********\n {0}\n***********", text);
    }
}