Wednesday, July 09, 2014

Visual Studio "14" CTP 2 (version 14.0.21901.1.DP) details

This Visual Studio "14" version 14.0.21901.1.DP CTP release includes the following products: 

  • Microsoft Visual Studio Professional "14" CTP (web | iso)
  • Remote Tools for Visual Studio "14" CTP (x86 | x64 | arm)
  • Microsoft Visual Studio "14" SDK CTP (exe)

The following technology improvements have been made in this release.

 

Thursday, July 03, 2014

Visual Studio 2013 Update 3 Release Candidate is available

Microsoft released Visual Studio 2013 Update 3 Release Candidate (RC) on July 2, 2014.

Download links

Visual Studio 2013 updates are cumulative releases. The following download links always point you to the latest update:

If you do not have Visual Studio 2013 (original release version) and run one of these downloads, both Visual Studio 2013 and Update 3 RC are installed.

KB Article

KB2933779

Wednesday, June 18, 2014

Image Processing in .NET

.Net provides the core for Faster Image Processing using System.Drawing assembly and System.Drawing namespace.

 

Basic About Image

Raster Images are consists of Rows and Columns of Pixels.

A Pixel consists of bytes of values for Pixel

A pixel with 4 bytes usually consists of Alpha, Red, Green and Blue values

A pixel with 3 bytes usually consists of Red, Green and Blue values

A pixel with less than 3 bytes needs further processing like expansion or look up to built 3/4 byte Pixel

 

Steps for Image Processing

Thursday, June 05, 2014

Write DataTable as CSV Text File Using C#

Find below the code that write data from DataTable as a CSV text file

 

Using Section

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;

 

Methods for Writing data to CSV

public static DataTable WriteCSV(String filename, DataTable table) {
    var csvData = new DataTable();
    StreamWriter csvFile = null;
    try {
        csvFile = new StreamWriter(filename);

        // Write header
        csvFile.WriteLine(
                String.Join(",",
                    from DataColumn dc in table.Columns
                    select dc.ColumnName)
            );

        foreach (DataRow dr in table.Rows) {
            csvFile.WriteLine(
                    String.Join(",",
                        from DataColumn dc in table.Columns
                        select dr[dc])
                );
        }
    }
    finally {
        if (csvFile != null)
            csvFile.Close();
    }

    return csvData;
}
private static String CsvValue(Object obj) {
    if (obj == null)
        return "";
    else if (obj.GetType() == typeof(String) || obj.GetType() == typeof(DateTime))
        return "\"" + obj.ToString() + "\"";
    else
        return obj.ToString();
}

Parse CSV Text File to Data Table Using C#

Find below a code that parses the CSV text file and give you the records as a Data Table

 

Using Section

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;

 

Methods for Parsing CSV

public static DataTable ReadCSV(String filename) {
    var csvData = new DataTable();
    StreamReader csvFile = null;
    try {
        csvFile = new StreamReader(filename);

        // Parse header
        var headerLine = csvFile.ReadLine();
        var columns = ParseCSVLine(headerLine);
        columns.ForEach(c => csvData.Columns.Add(c, typeof(String)));

        var line = "";
        while ((line = csvFile.ReadLine()) != null) {
            if (line == "") // Skip empty line
                continue;
            csvData.Rows.Add(
                ParseCSVLine(line) // Parse CSV Line
                    .OfType<Object>() // Convert it to Object List
                    .ToArray()   // Convert it to Object Array, so that it can be added to DataTable
            ); // Add Csv Record to Data Table
        }
    }
    finally {
        if (csvFile != null)
            csvFile.Close();
    }

    return csvData;
}

private static List<String> ParseCSVLine(String line) {
    var quoteStarted = false;
    var values = new List<String>();
    var marker = 0;
    var currPos = 0;
    var prevChar = '\0';

    foreach (Char currChar in line) {
        if (currChar == ',' && !quoteStarted) {
            AddValue(line, marker, currPos - marker, values);
            marker = currPos + 1;
            quoteStarted = false;
        }
        else if (currChar == '\"')
            quoteStarted = (prevChar == '\"' && !quoteStarted)
                ? true
                : !quoteStarted;
        currPos++;
        prevChar = currChar;
    }
    AddValue(line, marker, currPos - marker, values);
    return values;
}

private static void AddValue(String line, Int32 start, Int32 count, List<String> values) {
    var val = line.Substring(start, count);
    if (val == "")
        values.Add("");
    else if (val[0] == '\"' && val[val.Length - 1] == '\"')
        values.Add(val.Trim('\"'));
    else
        values.Add(val.Trim());
}