Using Amazon RedShift with the AWS .NET API Part 4: code beginnings

Introduction

In the previous post we looked into how to connect to the Amazon RedShift master node using a tool called WorkBenchJ. We also went through some very basic Postgresql statements and tested an equally basic aggregation script.

In this post we’ll install the .NET SDK and start building some test code.

Note that we’ll be concentrating on showing and explaining the technical code examples related to AWS. We’ll ignore software principles like SOLID and layering so that we can stay focused. It’s your responsibility to organise your code properly. There are numerous posts on this blog that take up topics related to software architecture.

Installing the SDK

Read more of this post

Read the byte array representation of a C# date time

In this post we saw how to extract the byte array representation of primitive types in C#. Here we’ll look at how to do the same with DateTime objects.

DateTimes are not primitive types so the BitConverter.GetBytes method has no overload for it. Therefore we’ll need to go through some more steps. We’ll convert the date into its 64-bit (long) representation. The long can then be supplied to the GetBytes method:

DateTime utcNow = DateTime.UtcNow;
long utcNowAsLong = utcNow.ToBinary();
byte[] utcNowBytes = BitConverter.GetBytes(utcNowAsLong);

utcNowAsLong is a very large integer. It was 5247234542978972986 at time of running the code example. Then we get the bytes using GetBytes which will return a byte of 8 elements as a long is a 64-bit / 8-byte integer.

The reverse operation mirrors what we did above:

long utcNowLongBack = BitConverter.ToInt64(utcNowBytes, 0);
DateTime utcNowBack = DateTime.FromBinary(utcNowLongBack);

“utcNowBack” and the original “utcNow” will be set to the same time.

View all various C# language feature related posts here.

Read the byte array representation of a C# base type

The BitConverter class has a static GetBytes method that has overloads to accepts all the primitive types in C#: int, long, uint, char, bool, ulong, double, float, short, ushort. The method returns the byte array representation if the supplied primitive type.

Here comes an example:

private static void ReadByteArrayFromTypes()
{
	int value = 15;
	byte[] bytesOfValue = BitConverter.GetBytes(value);
}

Read more of this post

Using Amazon RedShift with the AWS .NET API Part 3: connecting to the master node

Introduction

In the previous post of this series we quickly looked at what a massively parallel processing database is. We also launched our first Amazon RedShift cluster.

In this post we’ll connect to the master node and start issuing Postgresql commands.

If you don’t have any RedShift cluster available at this point then you can follow the steps in the previous post so that you can try the example code.

Connecting to RedShift

Read more of this post

Python language basics 9: relational operators

Introduction

In the previous post we looked at how to assign nulls to a variable using the None keyword. In this post we’ll look at Python’s relational operators. These are operators that help us compare two values.

Those of you who have experience with other object-oriented languages like C# or Java can safely skip this post. The relational operators are the same in Python: ==, !=, ,=.

Read more of this post

Python language basics 8: assigning nulls

Introduction

In the previous post we finished looking into how boolean types are represented in Python. This short post will show how nulls are represented. We use nulls to indicate the absence of any value in a variable.

None

If you have a C# or Java background then you’ll first guess will be that nulls are assigned by the keyword ‘null’, right? Let’s see:

hello = null

Read more of this post

How to find directory level information with C# .NET

In this post we saw how to extract system-level information using the Environment class in .NET. Another group of methods and properties of the Environment class lets you easily extract directory level information. Here come a couple of examples.

Here’s how to find the directory that the application is currently running in:

string currentDirectory = Environment.CurrentDirectory;

If you call the above method from a .NET app in Visual Studio then this will point to the deploy folder configured for the project, e.g. “C:\TestProjects\VariousCSharpLanguageConstructs\Various\Various\bin\Debug”

The GetFolderPath method accepts an Environment.SpecialFolder enumeration. Using this method will help you easily get a full file path reference to some well-known Windows folders like the MyDocuments folder:

string myDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string startMenuFolder = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
string userProfileFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

It’s worth exploring the SpecialFolder enumeration and see what’s available there using IntelliSense.

Finally here’s how to find the location of the System directory:

string systemDirectory = Environment.SystemDirectory;

In my case it’s c:\Windows\system32

View all posts related to diagnostics here.

ultimatemindsettoday

A great WordPress.com site

iReadable { }

.NET Tips & Tricks

Robin Sedlaczek's Blog

Love to use Microsoft Technologies

HarsH ReaLiTy

My goal with this blog is to offend everyone in the world at least once with my words… so no one has a reason to have a heightened sense of themselves. We are all ignorant, we are all found wanting, we are all bad people sometimes.

Ricos Blog zu Softwaredesign- und architektur

Ideen und Gedanken rund um Softwaredesign und -architektur, Domain-Driven Design, C# und Windows Azure

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

.NET, SQL and Mobile

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET (WebForms / MVC), WCF, Web API & C#

Cyber Matters

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

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

Follow

Get every new post delivered to your Inbox.

Join 635 other followers

%d bloggers like this: