Galin Iliev's blog

Software Architecture & Development

Reboot PC from network

Today I tried to to RDC(Remote Desktop Connection) to a remote computer (of course) and I got a nasty error basically saying that I need to restart the machine in order to connect to it :) So I searched the web for a bit, connected to another computer in same LAN, shot the command and waited for about 5 minutes and… voila. I was able to connect.

So what is the command?! shutdown, of course :)

shutdown -m //computername -r -f
-s shutdown
-r restart
-f force close any applications
//computername or ip

Or just run
shutdown /i
and the UI on the right will appear to make you feel more

For more information see Microsoft Knowledge Base Article: How To Use the Remote Shutdown Tool to Shut Down and Restart a Computer in Windows 2000.

P.S. The target machine was Windows Server 2008 so this one still works :)

comfortable.
image

Cross-site request forgery or how dangerous REST can be if not implemented properly

A friend of mine send me link to article in Wikipedia describing Cross-site request forgery attack.

Cross-site request forgery, also known as one-click attack or session riding and abbreviated as CSRF ("sea-surf"[1]) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts.[2] Unlike cross-site scripting (XSS), which exploits the trust a user has for a particular site, CSRF exploits the trust that a site has in a user's browser.

(source Wikipedia)

This is how the attack is performed:

<img src="http://bank.example/withdraw?account=bob&amount=1000000&for=mallory">

Note how simple this would be?! And end user won’t see anything – not even image :).

This illustrates why is so important when implementing REST in your services to do only read on GET requests.

C# 4.0 vs Visual Basic 10

This is how close will become C# and VB in next release:

C# 4.0 Visual Basic "10"
Named/Optional Parameters Named/Optional Parameters
Dynamic Scoping Dynamic Scoping
Statement Lambdas Statement Lambdas
Multiline Lambdas Multiline Lambdas
Auto-Implemented Properties Auto-Implemented Properties
Collection Initializers Collection Initializers
Generic Variance Generic Variance
Extension Properties Extension Properties

The items in white-bold are new features…

(Source: PPTX from VS2010 and .NET Framework 4.0 Training Kit)

MSBuild resources

MSBuild is very powerful language for automating build process but as every computer thing it could be confusing.

So for a start this should work as Visual Studio solution files (*.sln/*.proj) files are valid MSBuild files:

MSBuild MySolution.sln

So for more script-like example this can show how complex solution with Web Application project can be build and files (result of publish operation) copied to drop location.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns=http://schemas.microsoft.com/developer/msbuild/2003 
ToolsVersion="3.5">
  <PropertyGroup>
    <OutputFiles>.\OutputFiles\</OutputFiles>
    <ReleseFolder>D:\WcfFileTransfer\Release\</ReleseFolder>
    <PrecompiledWeb>$(OutputFiles)_PublishedWebsites\WebHostApp\</PrecompiledWeb>
  </PropertyGroup>
  <Target Name="Clean">
    <Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Clean" />
  </Target>
 
  <Target Name="Build">
    <Exec Command="MSBuild.exe WcfFileTransfer.sln /t:Rebuild /p:Configuration=Release 
/p:OutDir=..\$(OutputFiles)" ContinueOnError="False" />

    <ItemGroup>
      <!--include needed files-->
      <WebFiles Include="$(PrecompiledWeb)**\*.*"
                Exclude="$(PrecompiledWeb)**\developer.config;$(PrecompiledWeb)**\HOWTO*.*"/>
    </ItemGroup>
     
    <!--show message-->
    <Message Text="Copying to Deployment Dir:@(WebFiles) to $(ReleseFolder) :" />
    
    <!--perform recursive copy-->
    <Copy
            SourceFiles="@(WebFiles)"
            DestinationFiles="@(WebFiles->'$(ReleseFolder)\%(RecursiveDir)\%(Filename)%(Extension)')"  />
  </Target>
</Project>

This script is executed from Visual Studio Command Prompt like this

MSBuild build.proj

For more information  about MSBuild you can take a look at MSDN reference page or Channel9 Wiki:

* Project File Format
* Shipping Tasks
* Loggers
* Tasks
* VS / Integration
* Conversion
* MSBuild.exe Command Line
* Object Model
* Scenarios
* Does Microsoft use to build its own products?
* How to execute CS templates from MSBuild?
* External Links and Resources
* Quick Start Tutorials
* Write a simple project
* Clean my Build
* Specify which Target to Build First
* Build All Files in a Directory
* Build All Files in a Directory Except One
* Build the Same Sources with Different Options

* Use Environment Variables in a Build
* Check whether an Environment Variable has been set
* Build a Project with Resources
* Build Incrementally
* Use the Same Target in Multiple Project Files
* Tell to Ignore Errors in Tasks
* Extend with a New Task
* Build a Set of Dependant Projects
* Run a Custom Tool From my Project
* Specify Several Build Options on the Command Line
* Use Reserved XML Characters in Project Files
* Display an Item List Separated with Commas
* Convert an Item List into a scalar string
* Reference the Name or Location of the Project File in the Project File
* How do I do a recursive copy?
* Batching Examples
* MSBuild Specifications
* How the batching algorithm works
* How to find targets files in a canonical place

Or the MSBuild: By Example tutorial:

  1. Introducing Well-Known Metadata
  2. Formatting Your Output
  3. Editing MSBuild Files with IntelliSense
  4. Integrating MSBuild into Visual Studio
  5. Introducing Custom Metadata
  6. Understanding the Difference Between @ and %
  7. Using Environment Variables in Your Project
  8. Reusing MSBuild Project Elements
  9. Dealing with MSBuild Errors

I hope this is good as a start.

It’s playtime… with C# 4.0

After being quite busy for last 4 months it is a time to ramp up with new cool technologies that are on the product line.

So while installing VS 2010 it is a good reading to find out what to do once it is done:

And of course get some free time – a night or two should be enough :) should be enough for starting…

How cool is that…

What is it if not the future :)

This could solve the biggest two issues for cell phones and mobile computers – keyboard and screen size

x64bit Development with .NET

Today the hardware is cheap (and getting cheaper) so it is easily affordable to have multiple quad code CPUs, 8 GB RAM and more. In order to fully utilize this hardware x64b OS is needed and Windows has x64b editions for a while.

But what happens with the software we write?! if you use managed code only then is easy – IJW – It Just Works (do you remember that term for compiling unmanaged code C++ into IL? well that’s different)

As MSDN article “Migrating 32-bit Managed Code to 64-bit” says

Consider a .NET application that is 100% type safe code. In this scenario it is possible to take your .NET executable that you run on your 32-bit machine and move it to the 64-bit system and have it run successfully. Why does this work? Since the assembly is 100% type safe we know that there are no dependencies on native code or COM objects and that there is no 'unsafe' code which means that the application runs entirely under the control of the CLR. The CLR guarantees that while the binary code that is generated as the result of Just-in-time (JIT) compilation will be different between 32-bit and 64-bit, the code that executes will both be semantically the same. (You cannot install the .NET Framework version 2.0 on Windows 2000. Output files produced using .NET Framework versions 1.0 and 1.1 will run under WOW64 on a 64-bit operating system.)

If you want to dig into x64 vs x86 differences read Scott Hanselman’s article “Back to Basics: 32-bit and 64-bit confusion around x86 and x64 and the .NET Framework and CLR

Also check Brian Peek’s blog post on the subject

Finally up & running

As you might noticed this week the site was down. This was due to hosting upgrade to favorite IIS7 and some issues with dasBlog and one of it’s controls. Luckily I was able to fix it and also upgraded to dasBlog v2.2.

Hopefully there won’t be any downtime next… 10 years (next upgrade should be handled nicely :) ) Not like I am planning uptime 5 nines – 99.99999% :)

Now seriously:

If you planning your servers’ availability you might want to check how Microsoft.com Ops are doing it by taking a consultation from them for free. Why?! Because these are the results (as of 2005) – just imagine what are now:

*.Microsoft.com:

  • 3 Data Centers
  • 1606 Data Center Servers
  • 506 Servers in Labs
  • 111 Web Sites
  • 1069 Databases
  • 1000’s of Web Applications
  • 80+Gbit/sec Network Traffic

WWW.Microsoft.com

  • 13 million unique users/day
  • 70 million page views per day
  • 10,000 requests/sec, 300 concurrent connection on 80 servers
  • 350 Vroots

Windows Update/Download:

  • 150 million unique client scans/day
  • 12,000 ASP.NET requests/sec
  • 500K concurrent connections
  • 1 Billion Downloads and 750K client installs in 2 weeks (April 2006)
  • 4Gbit/sec Web Site Egress (Web Pages Only…No Downloads)
  • 20+ Billion Downloads in 2005…Routinely 150M+/Day

Application Architecture Guide 2.0

“To deal with the many technology additions since then, J. D. Meier and his team from Microsoft patterns & practices have created a new application architecture guide to provide insightful guidance for designing .NET applications based on the latest practices and technologies. The outcome is Application Architecture Guide 2.0, a guide targeted to help solution architects and developers design effective applications on the .NET platform. The guide gives an overview of the Microsoft .NET platform and the main technologies and capabilities within it. It provides not only principles-based guidance, but also platform-independent, pattern-oriented guidance for designing your application. Even though the guide itself is comprehensive on its own, the team has also provided a Knowledge Base on the Web, which provides informative expansion on the topics and concepts outlined in the guide.”

Forewords by Scott Guthrie
Corporate Vice President of .NET Developer Platform
Microsoft

Go grab it or read online @ http://www.codeplex.com/AppArchGuide/