Code Highlighter

Saturday 26 May 2012

Installing Windows Server 2008 R2 domain controller in the VMBox - Part 1

Installing Windows 2008 R2 server domain controller in the VMBox - Part 1

Why do we want to setup a domain controller on a VM ?
As a developer,  sometime I need to test the cross domain access, thus it's useful to have a  domain controller on the VM.


1. Download the VMBox from the oracle's web site https://www.virtualbox.org/wiki/Downloads

2. Download the Windows Server 2008 Server R2 64 bits iso file from the Microsoftt website for 180 days-trial.  the file name is 7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso and it's about 3GB.
 note : If your server trial-time is expired. You could extend the trial time by entered the following command at the dos command prompt.  "slmgr -rearm"


3. Run the VMBox

4.  Create the machine : Click on the Machine->New (or Ctrl-N), a popup Create New Virtual Machine appears, click Next.


5. Select the OS and the Version.

6. The next step is to select the memory for your VM.  I selected 4G of memory because I have 12G on my machine.

7. Select the hard disk size



  • Select the harddisk file type, use the default selection (VDI).
  • Select  Dynamically allocated virtual disk type. 
  • Select the  80G hardisk size.


 8. Setting the number of CPU.  By default, only 1 CPU is selected.  We want change to 4 CPUs.
Setting->System->Processor

9. Setting the Display to 128M Video Memory and Enable 2D Video Acceleration.

10. Setting the Network.  Select the Bridged Adapter so your could have access to the internet.

11. Setting the Shared Folder.  Click in the + folder on the right,  Select the folder that your want to share between your PC and the VM. 

Do not forget to select the Auto-mount.



12.  Setting the CD/DVD.  We want to map the Windows Server R2 iso file to the DVD drive.  Select the IDE Controller - Empty DVD, Then click on the DVD Icon on right in the Attributes section. Subsequently, chose the file 7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso




Now you are ready to boot-up your VM and start installing the Windows Server 2008 R2.



13.  Click on the Start button on the Oracle VM VirtualBox Manager. The Windows Server 2008 R2 is loading and start to install on the VM

14. Select English as the language to install.  The installation process will take about 10 minutes.







15. First time login, you need to enter a strong password for the Administrator account.

 "Hello001" 

Configure the Domain Controller

At this point, your Server is liked and Desktop. On start the Initial Configuration Tasks appears for configuring the server.



16. Setting the time zone.

 



Saturday 14 April 2012

WPF - Namespace One-to-Many

You develop WPF applications, you may realize that there are 3 types of namespace as shown below.

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:sys="clr-namespace:System;assembly=mscorlib"        
xmlns:mylib1="http://schemas.mycorp.com/mylibrary/2012" 

This blog, I will only discuss about the namespace of type one-to-many and its purpose.
xmlns:mylib1="http://schemas.mycorp.com/mylibrary/2012" 
You develop a WPF library and in your library has many namespaces, if you decide refactoring your library namespace. Off course,you do not want all your client applications have to change their XAML codes. This is the main reason why you should provide one-to-many namespace.

How to do it ?

Example : you have a WPF library that has 3 namespaces : 
  • MyWPFLib.Commands
  • MyWPFLib.Controls
  • MyWPFLib.Pages

All you have to do, it's to add the namespace definitions to the AssemblyInfo.cs
[assembly: XmlnsPrefix("http://schemas.mycorp.com/mylibrary/2012", "mylib")]
[assembly: XmlnsDefinition("http://schemas.mycorp.com/mylibrary/2012", "MyWPFLib.Commands")]
[assembly: XmlnsDefinition("http://schemas.mycorp.com/mylibrary/2012", "MyWPFLib.Controls")]
[assembly: XmlnsDefinition("http://schemas.mycorp.com/mylibrary/2012", "MyWPFLib.Pages")]

You can download the example here.
http://www.4shared.com/zip/ZwX8Wc-x/NameSpace.html




Wednesday 28 March 2012

Debugging JavaScript with VS2010 + Intellisense

If you are a .NET developer and you want to learn JavaScript.  Definitely using VS2010 for debugging your JavaScript is your 1st choice.  Also VS2010 provides  intellisense for JavaScript. You can find more information about the intellinsense here.

Make your IE as a default browser.
Open the IE ->Tools->Internet Options->Programs-> Select "Make default" button.



Enable the Script Debugging Option from the Advanced tab.
deselect the 2 options "Disable script Debugging".



Create an empty web project.


Once you have created your project then add a new html page and name it as "index.htm".


It's  now ready to code your 1st JavaScript with VS2010.  You can copy a sample code from below.
Also do not forget to set the index.htm as the starting page.

<head>
    <title>Debug My JavaScript</title>
</head>
<body>
 
<script type="text/javascript">
<!--
 /*Email Check script credit-JavaScript Kit (www.javascriptkit.com) 200+ free JavaScripts here!*/
    //-->
    function emailcheck(cur) {
        var string1 = cur.email.value;
        if (string1.indexOf("@") == -1) {
            alert("Please input a valid email address!")
            return false
        }
    }
    window.status = "Hello Dac";

</script>
 <form onsubmit="return emailcheck(this)">
    <strong>Enter your email address please:</strong><br>
    <input type="text" size="20" name="email">
    <input type="submit" value="Submit!">
</form>
</body>

You should able to get the intellisense as shown in figure below.



Debugging.
Now, you debug the JavaScript code as you normally debugging the C# code. Set the break point at the line 12 and press the F5.  The IE will appear as the illustrated image below. 



Enter "bad email".  Click on the Submit button, the debugger will stop at the line 12 and you can examine the string1 variable.






Sunday 26 February 2012

Add SyntaxHighlighter to the Google Blogspot Gadget

I am a developer and I want to have my code high light on the Google Blogspot. I searched on the web for the solution. There are many references to http://alexgorbatchev.com but non of them provide Step by Step of how to add SyntaxHighlighter to the Google Blogspot gadget.

Step by Step
  • Select the Design Tab.


  • Select the first "Add a Gadget".
  • The Gadget popup appears, Select the HTML/Javascript item by clicking on the + button.
  • A dialog box appears. Enter Code Highlighter for the Title.
  • For the content, cut and paste the following lines to it. Those links are pointing to the current SyntaxHighligher JavaScript and CSS version available at http://alexgorbatchev.com/pub/sh/ .

<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"/> 
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"/> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script> 
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js" type="text/javascript"></script> 
<script language="javascript"> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = "http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf";
SyntaxHighlighter.all();
</script>
Use SynxtaxHighligter 
If you want your code to high light, you have to enclose your code inside the <pre> tag as below.

There is a brush option for specifying different type of codes : C#, JavaScript, Java, Xml..etc.

Here is the link to the available brushes http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/

Note : Use the Html-Encode to encode the < and > if you want to hight lighting a XML or a HTML syntaxes.