# statistical scattering

So taking huge data-sources and looking at it is not enough to have an idea what values we really got here. So most of the times we need to break it down to just one or at least less values that we can check out to have an idea what data-source-values we got. So every one of this “less-values” that we want to see to have an idea about the complete data-values is called a parameter in the statistic. Every parameter is like an attribute of the data-source-values. The most common parameter is the average.

sum(x_i) / x_count

But we can not see how the scattering is. For this the easiest way to describe the scattering is by taking the max-value and the min-value and subtracting one by the other. This is called Range (R):

R = x_max – x_min

But this just takes 2 of all values and this is bad. We want to express the scattering of all values. So the next idea would be to take every singe value and compare it to the average. After this we could sum all these values. But by doing this we could get to zero in sum because it is the difference between the average. So to have the real range we also need to use amount strokes. At the end we divide this by the count of the values. This is called: Middle linear difference

sum(|x – x_average|) / x_count

To go further it is easier to calculate this by ^2 instead of amount strokes because you avoid of many case-differences. This is called variance:

sum((x – x_average)^2) / x_count

So many times we will get a higher value with this as the range is which does not make to much sense at all so we have to take the square root. This is called std-difference:

squareroot(sum((x – x_average)^2) / x_count)

However we still can improve her because just with this value we can not see the average. And it is a clear difference about having a std-difference of 1k with an average of 1k or having a std-difference of 1k with an average of 100k. So So handle this we just make sure we use the value more relatively by dividing std-difference by average. This is called variance-coefficient:

squareroot(sum((x – x_average)^2) / x_count) / sum(x_i) / x_count

# mvc design/pattern

MVC is one of the most common pattern or designs to build your project and to locate your code. So you split everything you code into this three parts:

• Model: This is your context or your class. Here you define and have your data
• View: This is your UI that shows the user what is going on.
• Controller: This controller will use the models to prepare your data and bring it to the view.

There are some examples that completely use the mvc-pattern like ASP.NET MVC for example. Here everything is prepared to work in a mvc-concept. I mean if you do not know the mvc-pattern, anyway you probably will code something like this because it is quit a way to code clean. In every project you think about where to put on the code. And most of the times you will separate the view and the controller and in every object-oriented-language you do something like classes. And hopefully you separate the classes and the controller as well … so there are not to many opportunities that are different to the mvc-pattern and are still clean and reasonable as well.

# c# throw windows event

To make a running server-application a way more professional we can not just write our own log about what is going good or bad. We can go instead and use windows events. In the following example I will write a Windows-Event in a created event-source. By doing this I can separate all the events that I will throw out in my applications from the other event-messages and errors of the other applications.

```class Program
{
const string APP_SOURCE = "LiveCodeBlog";

static void Main(string[] args)
{
EventLog.CreateEventSource(APP_SOURCE , APP_SOURCE);

EventLog myLog = new EventLog
{
Source = APP_SOURCE
};

myLog.WriteEntry("Writing to event log with the source " + APP_SOURCE);

}
}
```

The final result looks like this:

However to create a event-source you need to have the rights to do this. Exactly you need full-rights to create the even-source and as well read-rights for all other event sources. This is because .Net wants to check if there is another eventsource named like this. So you can check your right like this:

# c# avoid constructor redundancy

Sometimes we need to define several constructors that just get different types – but all do do same like the following here:

```class MyClass
{
int x;
public int X { get => x; set => x = value; }

MyClass(int x)
{
this.x = x;
//... do further things
}

MyClass(string x)
{
this.x = int.Parse(x);
//... do other further things
}
}
```

But we can do this in a better way by inheriting from one constructor like this:

```class MyClass
{
int x;
public int X { get => x; set => x = value; }

MyClass(int x)
{
this.x = x;
//... do further things
}

MyClass(string x) : this(int.Parse(x))
{
//... do other further things
}
}
```

By doing this the string-parameter-constructor inherit the int-parameter-constructor and does every thing. We also could call the int-parameter-constructor -method in the string-parameter-parameter like “this(int.Parse(x))”.

# docker basics

So right now every one talks about docker. Some of them use it and others just talk about it, but anyway its a hot subject right now. So here is what it is for me right now:

Docker is an an open-source-project that extends and improves your virtualization. You can work with docker on all three main systems like windows, MacOS and Linux. Docker does two nice main parts to me:

• Change the platform-background-operation
• Easy to use and control

The platform-background-operation compared to a normal virtualization-process is shown up here:

In docker you do not create a OS for every app you want to virtualize. So that saves you a lot of server-power and server components. Everything you need is a server with a host-OS choosen by you. Than you install docker and there you go. To start you just to install docker and register, because docker works with a docker(-user)-id. After this you can start.

I type my docker statements in powershell. You always have to start by starting docker if it ist not running. If docker is running on your system and you never used it you have to start with the command “docker login”. After this I use the following statement to see what containers are out there. The parameter -a will show me also containers that are not running right now:

```docker ps -a
```

To have a container there are to main-steps: pull & run.
But how ever if you wanna run a std. container that is out there as a image and you do not have it it will check out and pull before running automatic. So to run your first program you can do something like this:

```docker run busybox echo "hello world"
```

After doing this you should see your busybox echo “hello world” container with the docker ps -a command.
If you have lot containers and want to delete all that are status = exited you can do something like this:

```docker rm \$(docker ps -a -q -f status=exited)
```

the parameter -q will just display the number and the parameter -f will describe a filter. You also can add –help to every command to see possible parameters for a statement like this:

```docker ps -a --help
```

To have a ubuntu machine you can do something like this:

```docker run ubuntu
```

Now docker will download an ubuntu image and create a container up for you. You can go and and go to the commando line of that linux machine by using:

```docker run -ti ubuntu
```

# SOAP API in Visual Studio in C#

To create a api there are alot opporunities. Right now I prefer SOAP-APIs in Visual Studio because it is easy as possible to create such one.

I will do this with Visual Studio 2017 and a console-application, so nothing special:

For the example I googled for free SOAP-Webservice and got this one here that can handle some information about the BLZ:

http://www.thomas-bayer.com/axis2/services/BLZService?wsdl

To start in Visual Studio I add a reference like this:

1. Rightclick in the solution explorer at references.
2. Click “Add Service Reference”
4. Click “Add Web Reference…”
5. Paste the URL and click on the arrow.
6. Type in a name that specifies the webservice-name in your project.
7. Click “Add Reference”.
8. Done!

<

pre>This will add a folder to your projects called “Web References” and will add the service. Like this you will also get every object and method that you need. So I am able to write this code:

```var BLZService = new OpenSOAPBLZService.BLZService();
var Bank = BLZService.getBank("10070100");
Console.WriteLine(Bank.bezeichnung + " - " + Bank.ort);
```

Here we create a new object based on the service that we created, create a new bank object (which class is also created by the Add-Reference-Function) and show the bank description and the location of the bank in the console. So we get this out here:

# how to start with xamarin forms

Lets get some xamarin.forms basics done and check out how we can emulate this with focus to android. Why android focus? My test phone is based on android. So lets start here with some action. For this we need visual studio (in my case 2017 professional). So we create a new project -> Cross Plattform App (Xamarin) -> Emty App -> Xamarin.Forms -> portable class library (PCL). Just do not think to much about it if you are new to xamarin.

Now I choosed CameraApp.Android to debug things:

So visual studio got some emulator if you just installed the xamarin-part. Problem here is that it is incompatible with hyper-v. So if you do not want to disable hyper-v you should the Visual Studio Android Emulator for example. So check out this. With that you can set up some emulators that work with hyper-v without any further problems. I use the 5” KitKat (4.4) XXHDPI Phone. Install that one and it should look like this:

If you got this you should go for 2 further things to avoid problems with dll-uploading:

• Go to hyper-v -> your new device -> settings -> processor -> compatibility -> and make sure that you put on the migration to other physical computers.
• In visual-studio -> solution-explorer -> android solution -> properties -> android-options -> disable fast deployment
• Update alle nuGet packages

So now we have to start our emulator by using the vs-android-emulator. Here we need to enable developer-mode and maybe usb-debugging. Than start debugging in visual studio and you should see the emulator running your code. If you get problems here you always have to check the output in vs. A lot of problems you can not see as a real fail in vs. But instead you get some information in the output-window. As well if you have trouble make sure that all nuget-packages are updated to the correct/last version. BTW: the last version is not the correct version in any case. And another thing that may can confuse you: Rebuild your solution. Sometimes you have to rebuild your solution to make vs get all new things that you did. However you should see something like this:

# mysql basics in c#

Today I want to describe how we can work with MySQL-DBs in C#. Before Using queries and other things we have to connect to the database. Todo this set up an MySQLMgt-code-file that contains all things we need to have to work with our database. Here we got some properties like this. To use the MySsqlConnection just include the library “MySql.Data.MySqlClient”.

```    static private MySqlConnection connection;
static private string server;
static private string database;
static private string uid;
static private string password;
```

I decide to fill these properties in the constructor and connect than to the server:

```
static MySqlManagement()
{
connectServer();
}
```

For sure we can fill the properties hard-coded but I want to make it better and I put the things into the appsettings. Just put in the things you need and you can write these values into the class-properties:

```static private void loadServerSettings()
{
server = ConfigurationManager.AppSettings["server"];
database = ConfigurationManager.AppSettings["database"];
uid = ConfigurationManager.AppSettings["uid"];
}
```

To connect to the server we need a connection-string and a MySQL-Connection.

```static private void connectServer()
{
string connectionString =
"SERVER=" + server + ";" +
"DATABASE=" + database + ";" +
"UID=" + uid + ";" +

connection = new MySqlConnection(connectionString);

try
{
connection.Open();
}
catch (Exception ex)
{
throw ex;
}
}
```

Wit the connection. Open we are able to give some instruction/queries into our database. Here we can insert, modify and delete data or change the structure of the data as well. In the following you will see an easy insert-mysql-stament fired into the mysql-db.

```string query = "INSERT INTO link (url, provider_id, posting_datetime) VALUES(" +
"'" + url + "', " +
"'" + providerId + "', " +
"'" + postingDateTime.ToString("yyyy-MM-dd H:mm:ss") + "')";

MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
```

Another thing that you should know in term of mysql-c# basics is the use of return value of queries. Here is method that tells me if an entry already exists:

```static public bool UrlExists(string url)
{
string query = "SELECT COUNT(*) FROM link WHERE url = '" + url + "'";
MySqlCommand cmd = new MySqlCommand(query, connection);

int Count;
Count = int.Parse(cmd.ExecuteScalar() + "");

return Count > 0;
}
```

@ the end of your code: Make sure to close the connection to the MySQLServer with:

```connection.Close();
```

Have fun with it! 🙂

# c# webcrawling basics

To download the metadata and the content of a website you have some opportunities like this for example:

```HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
WebRequest webRequest = (WebRequest)httpWebRequest;
WebResponse webResponse = webRequest.GetResponse();
string htmlStr = sr.ReadToEnd();
```

While doing this you create a http-web-request and a web-response. With the stream-reader you will get the metadata and the content of the website and are able to write this into string.

# ACID

To understand a transaction in a database you can think of a single unit of database-processing like updating, deleting, …

You can start and complete a transaction. If there is a problem is between you can go for a rollback and everything is like the state of the beginning. The ACID-properties are properties of such an transaction. ACID is:

A = atomicity
Atmoicity tells that a transaction is there or is not. You just can go for the whole transaction or everthing will turn back to the start of the transaction via a rollback. So we just can have all operation or none. This is maintained by the transaction management component.

C = consistency
Consistency means nothing else than correctness. The best example for this is a financial transaction form account A to account B. For this we have to decrease the balance of account A by the value X. Than we add the value of X to the balance of account B. Consistency now says that there is no opportunity to run into an error and having the decrease account A without a increased account B. The responsibility to have consistency has to be assumed by the programmer.

BTW: In new databases like facebook uses for example, the database-consistency is compromised to run faster queries.

I = isolation
Isolation means that if there are two transactions (1 and 2) parallel completed that this should be the same result as if you run first transaction 1 and than transaction two and the other way around. So every transaction should not be affected by another transaction. This tasks is done by the concurrency control management.

D = durability
This property says that transactions and their changes must not be lost due some database failure. So whatever will happend the database will not loose some changes. The responsibility for this is in the recovery management.