How to emit compiler warnings and errors in C# .NET

In this post we saw how to use the “if” preprocessor in Visual Studio to “communicate” with the compiler. Here’s a reminder of the example code which we’ll re-use here:

private static void TryPreprocessors()
{
# if DEBUG
	Console.WriteLine("You are running the Debug build");
# elif RELEASE
	Console.WriteLine("You are running the Release build");
#else
	Console.WriteLine("This is some other build.");
# endif
}

In this post we’ll look at two more preprocessor types: warning and error. If you compile a project you can get one or more errors or warnings:

Read more of this post

Searching for elements in arrays in C# .NET

The Array class has a number of useful static methods. A group of them is used for searching purposes. The method names are generally quite descriptive. Here are some them with comments in the code:

string[] bands = new string[6] { "Queen", "ACDC", "Metallica", "Genesis", "INXS", "Motörhead" };

//find the first entry in the array which starts with Q, finds "Queen"
string firstBandStartingWithQ = Array.Find<string>(bands, s => s.StartsWith("Q"));
//finds last entry start with M, finds Motörhead
string lastBandStartingWithM = Array.FindLast<string>(bands, s => s.StartsWith("M"));
//finds Metallica and Motörhead and puts them in an array
string[] allWithM = Array.FindAll<string>(bands, s => s.StartsWith("M"));
//index will be 0 as Queen is the first item in the array
int queenIndex = Array.FindIndex<string>(bands, s => s == "Queen");
//yields true as ACDC figures in the array
bool acdIsThere = Array.Exists<string>(bands, s => s == "ACDC");	

View all various C# language feature related posts here.

Using Amazon Elastic MapReduce with the AWS.NET API Part 3: starting and logging into a cluster

Introduction

In the previous post we went through the long GUI in EMR which allows you to provide the settings of the Hadoop cluster. We didn’t actually start any machines, we’ll do that here.

In this post we’ll also log into the master node of the cluster and try a couple of Hive statements.

Starting a cluster

Navigate to the Create Cluster dialog in Amazon EMR. Let’s provide the following options for our first cluster:

Read more of this post

The ‘if’ preprocessor directive for the compiler in C# .NET

You can decorate your C# source code with “messages” to the compiler. There are a couple of predefined preprocessors that the compiler understands.

A common scenario is when you’d like to run some part of your code in Debug mode but not in Release mode or any other Build type. The following method shows the ‘if’ and ‘elif’ preprocessors:

Read more of this post

Using Amazon Elastic MapReduce with the AWS.NET API Part 2: the cluster startup GUI

Introduction

In the previous post we went through a quick introduction of Amazon Elastic MapReduce. In this post we’ll very shortly describe Hadoop first. Then we’ll log into EMR and go through the long section in the GUI which you fill in to specify the details of your cluster.

If you are entirely new to Hadoop and Amazon Web Services then you’ll see a lot of new tools mentioned on this page that hide some complex applications with their own learning curves. So get ready for a lot of reading and research. It can be of great help if you have people in your organisation who already have some prior knowledge of AWS when starting with EMR.

Read more of this post

Extending class definitions with partial classes in C# .NET

The ‘partial’ keyword helps you divide your classes into multiple files within the same namespace. One obvious usage of partial classes is to split the definition of a large type into smaller chunks. You cannot just use the partial keyword with classes but methods as well.

The partial classes will reside in two – or more – different cs files in the same namespace. Say you have a partial Customer class in the project-name/domains folder:

Read more of this post

How to find various machine-level system information with C# .NET

The Environment class holds a range of properties that help you describe the system your app is running on. Here come some examples with inline comments:

//returns true on my PC as it is a 64-bit OS
bool is64BitOperatingSystem = Environment.Is64BitOperatingSystem;
//returns the machine name, in my case ANDRAS1
string machineName = Environment.MachineName;
			
//returns information about the operating system version, build, major, minor etc.
OperatingSystem os = Environment.OSVersion;
//returns the platform id as an enumeration, in my case it's Win32NT
PlatformID platform = os.Platform;			
//the currently installed service pack, Service Pack 1 in my case
string servicePack = os.ServicePack;
//the toString version of the OS, this is "Microsoft Windows NT 6.1.7601 Service Pack 1" on this PC
string version = os.VersionString;

//I have 4 processors on this PC
int processorCount = Environment.ProcessorCount;

//returns 2 logical drives: C: and D:
string[] logicalDrives = Environment.GetLogicalDrives();

//this is how to find all environmental variables of the system and iterate through them
IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (string key in envVars.Keys)
{
	//e.g. the JAVA_HOME env.var is set to "C:\Progra~1\Java\jdk1.7.0_51\"
	Debug.WriteLine(string.Concat("key: ", key, ": ", envVars[key]));
}

//retrieve the current CLR version, in my case it's "4.0.30319.18444"
Version clrVersion = Environment.Version;

View all posts related to diagnostics here.

Using Amazon Elastic MapReduce with the AWS.NET API Part 1: introduction

Introduction

Big Data is everywhere nowadays. It’s one of the most (over)used keywords in IT nowadays. Organisations have to process large amounts of information in form of messages in real time in order to make decisions about the future of the company. Companies can also use these messages as data points of something they monitor constantly: sales, response times, stock prices, etc. Their goal is presumably to process the data and extract information from it that they themselves or their customers find useful and are willing to pay for.

Amazon Web Services have a solution for pretty much anything in IT so it’s no surprise that there are at least two solutions for data mining and analysis scenarios:

Read more of this post

Resolving null values in C#

Say you have a method which accepts a string parameter. The method may need to handle null values in some way. One strategy is to validate the parameter and throw an exception:

private static string Resolve(string input)
{
	if (input == null) throw new ArgumentNullException("Input");
.
.
.
}

Another strategy is to provide some default value with an if-else statement:

Read more of this post

Using Amazon DynamoDb with the AWS .NET API Part 7: its place in Big Data

Introduction

In the previous post we looked at how to query our test table in Amazon DynamoDb. That post also completed our main discussion on how to use DynamoDb in .NET.

This post is dedicated to a larger picture: Big Data. This series is part of a large series on cloud-based Big Data infrastructure along with the message handler Amazon Kinesis and the raw data storage S3. Therefore the pre-requisite of following the discussion in this post is familiarity with what we discussed in those posts or at least some knowledge of Big Data. However, I’ll try to write in a way that those of you who’ve only come here for DynamoDb may get a taste of the role it can play in a cloud-based Big Data architecture.

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.