24 October, 2011

Netduino: HelloWorld

I have always found it intriguing to be able to motion the physical world from your PC. Due to this reason – I’ve invested in a Netduino microcontroller (from the UK) which runs the .NET Microframework and therefore programmed in C#.

Every new technology is best learned by writing the famous “Hello World” sample for this technology which is also the case here. Below is the very few lines needed to make the onboard LED flash in a blinking fashion (as long as it is powered ;-)).

image       image

HelloWorld.cs

using System.Threading;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace HelloLED
{
public class Program
{
public static void Main()
{
//init ports
var port = new OutputPort(Pins.ONBOARD_LED, false);
bool on = true;

//loop
while (true)
{
port.Write(on);
Thread.Sleep(1000);
on = !on; //invert value
}
}
}
}
How easy can it get…?

Link: http://www.netduino.com/

Why is Windows taking so long time to boot?

If you (like me!) want’s to know what makes Windows take so excessive long time to boot and become operational – I today stumbled upon a very good source of information in that context.

It allows you to actually identity what makes it lag, instead of just guessing and having a “feeling” as to what it is. This article goes through a number of steps to identity the processes & services that makes your Windows machine lag when starting.

Read and enjoy!
http://itexpertvoice.com/home/what%E2%80%99s-taking-so-long-how-to-fight-slow-startup-times-in-windows-7/

 

StackOverflow Tags: ,

16 October, 2011

WP7: Protecting connection strings and passwords

When you are dealing with sensitive data, such as passwords etc. in a Windows Phone 7 application, you can make use of the DPAPI (Data Protection API). This is roughly the same as the one found on the Windows Operating System.

The neat thing about the wrapping found in Silverlight for WP7 is, that Encryption and Decryption has been wrapped so nicely that they have become very easy to use. In the below – I’m encrypting a simple textbox value just for the proof-of-concept. Next – the value is retrieved from disk and decrypted for plain text view.

image

Note: the DPAPI of WIndows Phone uses the logged in UserID as well as the applicationID to generate the secret keys that allows the DPAPI to revert the encrypted bytes when you need them again.

The 2 buttons seen above invokes this code:

Encrypt:

/// <summary>
///
save encrypted data -> "datafile" (in isolated storage)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Encrypt_Click(object sender, RoutedEventArgs e)
{
//convert to bytes
byte[] plainData = Encoding.UTF8.GetBytes(textBox1.Text);
byte[] encryptedData = ProtectedData.Protect(plainData, null);

IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
using (var fs = file.OpenFile("datafile.dat", System.IO.FileMode.OpenOrCreate))
{
//write files into file
var bw = new BinaryWriter(fs);
bw.Write(encryptedData);
bw.Flush();
}
}

Decrypt;

/// <summary>
///
load file and decrypt
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Decrypt_Click(object sender, RoutedEventArgs e)
{
using (var fs = IsolatedStorageFile.GetUserStoreForApplication().OpenFile("datafile.dat", FileMode.Open))
{
var br = new BinaryReader(fs);
byte[] encryptedData = br.ReadBytes((int)fs.Length);

byte[] plainData = ProtectedData.Unprotect(encryptedData, null);
textBox1.Text = Encoding.UTF8.GetString(plainData, 0, plainData.Length);
}

}


How easy can it get?


StackOverflow Tags:

06 October, 2011

Fusion: What assemblies are in fact loaded?

Sometimes you are really puzzled as to what is happening when you start a .NET application. Sometimes it insists on loading a different assembly than the one you want it to; even you just copied the new assembly to the bin-folder of your application? Does this sound familiar?

I today had that exact experience. My system kept loading a different assembly than the one I wanted it to; even I in fact did copy the right (new) assembly to the bin folder of the application.

So how do you troubleshoot this scenario? You simply can’t get your head around what is happening? Here there is only 1 way of moving forward: Fusion Log Viewer

The process of starting/loading an exe-file in .NET, begins with the task of merging the exe-file together with dependent assemblies (.dll) into one coherent whole. This is in .NET known as “fusion” (to merge together different artifacts into one). Here lies the key to the whole scenario – the Fusion process.

The fusion process can be made evident to you by using the tool Fusion Log Viewer:

image

It is found here:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64\FUSLOGVW.exe

How to do:

1) Open this application and set these values:

image

2) Launch your application (exe) of interest

3) Observe how entries are inserted into the Fusion Log Viewer

image

4) Double click one of the entries to observe details.

In my case, I got this information:

image

As evident from the assembly loading log above, the dependent assembly actually being loaded was coming from the GAC (Omada.Common.License.dll), explaining why I did not see my new assembly (Omada.Common.License.dll) which is placed next to my exe-file.

The probing process goes like this:

1) Look in the GAC

2) Look in the folder of the exe-file

3) Look in any subfolder (first level) of the folder holding the exe-file

4) Give up!

Hope it helps you in your debugging…

Update: You need to start this FusionLogViewer with Administrative Rights. Otherwise it is just blank.

StackOverflow Tags: ,

iPhone/XCode - not all cases are equal!

This bit me! Having made some changes to an iPhone application (Obj-C); everything worked fine in the simulator. But, when deploying the s...