tirsdag den 26. november 2013

Booting from VHD - Part 1 - Preparation

I have heard so many great things about this - and finally I got to do this myself. But it was not without problems so I have put together another step by step description.

This takes quite some time, so I was quite annoyed when I found out that I couldn't use windows Professional to do this.

Part 1 will be about preparation.
Make sure, that you run on windows Enterprise or Ultima on the computer you want to double boot from.

If you are using ISO-files I can recommen a nice tool from Microsoft for making an install USB key was http://download.cnet.com/Windows-7-USB-DVD-Download-Tool/3000-18513_4-10972600.html

Download and install a virtual CD emulator - I recommend Daemon Tools, its free and fairly simple to use
Download Windows AIK from Microsoft HERE
Prepare installation CDs or ISOfiles

Ok so now you have
  • a computer with windows 7 Enterprise or Ultima
  • a CD Emulator (Daemon Tools)
  • an installation of Windows AIK
And you are ready for the next step!

onsdag den 20. marts 2013

Deploying Web Api Rest Services

I just started working with web api rest services. A very nice template in visual studio made it very easy to start. I'd allready made a backend so all I had to do was to make the controllers, which was a piece of cake from the template.

The debugging in IIS express wasn't a problem neither, but when I came to the deployment in IIS I faced some problems. 

My setup is, as follows:
  • Windows 8 Professional
  • Visual studio 2013
  • IIS 8
And the test server runs 
  • Windows server 2008
  • IIS 7

Debugging in IIS

When I pressed F5 to run and debug the service I had no problems. But I needed to know how to deploy the files. So I took properties on the project in VS and under "Web" it was possible to uncheck the "Use IIS Express" and Create Virtual Directory. And then the troubles started. 

First I got a error 500.19 and I started from the bottom and pressed help, which was an error. Instead I found out, that I had to edit the "C:\Windows\System32\inetsrv\config\applicationHost.config" file. 
I needed to set overrideModeDefault="Allow" for handlers.. And actually.. the page told me, if I started from the top instead. 


This took care of the 500.19 error but then I got a 404 and found this link. 
http://www.aheil.de/2012/11/05/fixing-asp-net-mvc-4-web-api-404/

So I installed
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -i
or actually I had to do it through "Programs and Features" - "Turn Windows features on or off"

This wasn't enough but when I put the following line in web.config - system.webServer section


I was up and running.. All I needed was an iisreset and a VS restart to be able to debug.

Deploying to IIS 7

Now I could copy 
  • bin
  • Content
  • Scripts
  • Views
  • Global.asax
  • Web.config
to the server. Make an application in the IIS and run it... Of course I had to set the application pool to .NET 4.0

The only thing I am missing now, is an installation package for the customer. 

   

onsdag den 6. februar 2013

Hello Windows 8

At last I installed Windows 8 on my work computer. It's a Lenovo W520 with 32 Gb ram and overall it runs fine.

But what is this new beast? I'll try to figure out what can be done smarter than windows 7.

Start

The first thing you'll find out is the start screen.. This is smarter on a touchscreen where you can use gestures. On a normal screen its just indifferent, and sometimes a little annoying.

When you go to the desktop you'll see that the startbutton is gone. But then again, why use it, when you have the windows-button. But what happens when you press the windows-buton.. You'll go to the start-page and without a touchscreen, its just a screen with buttons.

Apps vs. Applications

In windows 8 Microsoft has followed the wave of apps as you see them on mobiles and tablets, but what is the smart thing about apps on windows?? 

In my opinion: On a normal laptop or desktop computer.. absolutely nothing or at least so close to nothing as it can be. 

We are now split up in to environments
  1. The App/Modern UI style/Windows Store App environment
  2. The desktop environment. 

Security

In the app model you need to allow the app to use your system. That sounds appealing.. But on the other hand.. How often does a user read a dialog.. and if they want to play a game, do they really wonder if it requires access to the local network or webcamera?
Of course it's easier to send the responsibility to Microsoft as they have to approve the app, and then the IT-pro can use the UAC again, and disallow the users to install desktop applications. 

The desktop application has the same security level as usual, and you cannot actually trust them as a ground rule. Of course that will be a paranoid world and who wouldn't take a chance. 

App/Modern UI environment

Or Windows Store App/Desktop app. What's the user experience on these? Well, the easiest way is taking a look at the Internet Explorer. It's in a app and a application version out of the box. If you take a normal website as http://msn.com it's ok. Its in full screen but otherwise it's working as expected. But then try to go to a web chat or something that requires some kind of update.. It actually uses the F5 update, which causes it to crash..
So you cannot use it on all sites. 
But in apps you can use the contracts. That means, that you can use the different buttons when you open the right side bar.. 

Share

The sharebutton is, well for sharing.. So if you have a page in the internet explorer - you can share the link to what ever can receive it.. Fx. Facebook - through "Persons". 

Search

With the search button you search the current app as the search contract is implementet. In internet explorer it's through Bing but it can be anything. 

Multitasking

Windows 8 can multitask, BUT the app environment takes the human part of it away.. You cannot run 2 apps beside each other if you work with one screen. Furthermore, the mediaplayer app stops playing when you cannot see it.. so you'll still need a desktop version. Which is the case for many apps.
A Little edit: the Windows+. actually makes it possible to have 2 app Windows available at the same time

Shortcuts

I like to use the keyboard.. A lot of these shortcuts also work in previous versions of windows
  • Alt+Tab: Switch between apps.. Both windows store and desktop
  • Ctrl+Tab: Switch between tabs/dialogs in an application. Application dependend. 
  • Ctrl+Shift+Esc: Opens the taskbar
  • Windows+Tab: Switch between windows store apps. 
  • Windows + : Switch to desktop app no. if there are more than one window in that app, switch between those
  • Windows+q: search installed apps or the search for the current app. This is smart when you have to open an app fast.. Try to press windows+q and then write "note".. but, it can also be a bit confusing
  • Windows+w: starts settings.. again start typing and you'll find the right setting
  • Windows+e: starts the windows desktop explorer
  • Windows+r: starts the "Run" dialog
  • Windows+t: opens the preview of applications in the task line
  • Windows+u: starts the "Ease of access" 
  • Windows+i: opens the settings sidebar.. 
  • Windows+p: opens the "Project to a connected screen" sidebar
  • Windows+s: Sends screenshot to OneNote (if installed)
  • Windows+d: Shows the desktop environment - if in app environment - and the desktop otherwise.. 
  • Windows+f: Starts the filesearch bar
  • Windows+h: Starts the Share contract - only for windows store apps
  • Windows+k: Sends to devices
  • Windows+l: Locks the workstation
  • Windows+x: Opens a quickstart for controlpanel
  • Windows+c: Opens the start sidebar.. The same as if you take the mouse to the right corner
  • Windows+n: Starts new onenotenote
  • Windows+m: Minimizes all windows
  • Windows+,: Quickshows the desktop, as long as you hold down windows key
  • Windows+.: I don't get this

Conclusion

It's faster than Windows 7 I think.. But the user experience on a normal laptop requires a lot of shortcuts to be really good, and the apps.. Well they are fun for the enduser, but not applicable for heavy use. 

Hello blogger app

Just installed blogger for android

tirsdag den 13. november 2012

Hello layered programming

Groft sagt gør alle applikationer det samme

  • Modtager bruger data
  • Behandler data/Gemmer data
  • Returnerer behandlede data
Så endnu simplere har vi en brugergrænseflade og en behandlingsflade. 
Brugergænsefladen kan være forskellige flader:
  • Windows form applikation
  • Web applikation
  • Mobil applikation
  • Powershell script
  • Kommando prompt
Behandlingsfladen kan ligeledes deles op i forskellige flader:
  • Funktionsflade
  • Filflade
  • Databaseflade
  • Webserviceflade 
og for at man kan genbruge fladerne bedst muligt, deler man det op i mindre dele/byggeklodser, som kan bruges i de forskellige sammenhænge. Det svarer til at man har stikkontakter i huset, som kan bruges til forskellige elektriske enheder. 

I udvikling (i windows) kan man gøre det med klassebiblioteker. 

Lav et klassebibliotek

Lad os starte med at lave et simpelt beregningsbibliotek. (Nyt projekt, Windows C#, Class Library)
Det generer et projekt med en Class.cs fil. Start med at ændre filnavnet til Calculator.cs, hvilket også ændrer navnet på klassen. 

Vi vil gerne have de 4 grundlæggende regneformer. 
  • Addition +
  • Subtraktion -
  • Division /
  • Multiplikation *

så vi starter med at tilføje en funktion, der kan addere 2 decimaltal
        public decimal Add(decimal value1, decimal value2)
        {
            return value1 + value2;
        }

Vi kan jo ikke se hvordan det virker, så vi starter med at lave et ekstra projekt - en Console Application. (Højreklik på solution og vælg Add > New Project)
Her skal vi have tilføjet en reference til Calculator projektet, så højreklik på References og vælg Add Reference... og under fanen Projects vælges Calculator projektet. 
Derefter højreklikkes på ConsoleCalc projektet og Select as Startup Project, da man ikke kan køre et klasse bibliotek. 

I program.cs skal vi lægge kode ind til at kalde vores calculator funktioner, en meget simpel udgave er her. 

            Calculator.Calculator calc = new Calculator.Calculator();

            decimal value1 = decimal.Parse(Console.ReadLine());

            decimal value2 = decimal.Parse(Console.ReadLine());

            Console.WriteLine(calc.Add(value1, value2));

            Console.ReadKey();

Bemærk: Der er INGEN fejlhåndtering i koden. 
Tryk F5 for at køre programmet og prøv at indtaste nogle værdier. 
Nu kan du tilføje de resterende funktioner til koden for at kunne bruge regneformerne. 

tirsdag den 21. februar 2012

Hello Powershell xml

I remember when I started looking at xml and I thought that I had to write a parser myself. Then I started looking at mssql which made it a lot easier. But it still had some bugs. Then I tried powershell and xml. This is quite smart.

Lets see. To read a text file, we need to call the Get-Content. This returns an object and by putting the [XML] in front of the returned object, we can use it as a structure of objects. Lets see, first we'll make an xmlfile with a couple of services in them:



wininit explorer



Let's just read the information on the process, so we read the xml file and gets the process info for each service in the xml-file


[xml]$xmlFile=Get-Content "D:\temp\test.xml"
$xmlFile.Services.Service | ForEach-Object {     Get-Process $_ | Format-List }


Voila, we now have read an xmlfile and tested the processes. But what if we want to write the Ids back to an xmlfile.. 

Lets see - first we make an xml template of what we want. 







and lets use the xml in another way.. just for fun, you can still use [XML]


cls
[xml]$xmlFile=Get-Content "D:\temp\test.xml"
$processFile=New-Object xml
$processFile.Load("D:\temp\processes.xml")
$newProcess=(@($processFile.processes.process)[0]).Clone()
Write-Host $newProcess.pId
$xmlFile.Services.Service | ForEach-Object {
    Get-Process $_ | ForEach-Object {
        $newProcess = $newProcess.Clone()
        $newProcess.Id = $_.Id.ToString()
        write-host $newProcess.Id
        $processFile.processes.AppendChild($newProcess)
    }
}
$processFile.processes.RemoveChild($processFile.processes.process[0])
$processFile.Save("D:\temp\proc.xml")

This reads from the first xmlfile, opens the next as a template. Makes a cloneable object, clones it and inserts values. It appends the new object to the xml and at last it removes the first child as it was the template and voila, we have ourselves a written xml



 
    844   
    4056 

lørdag den 21. januar 2012

Hello Powershell

For a long time I have thought about writing a hello world  on Powershell.. I have done a lot of scripting in my career and Powershell is a great step in the right direction.

So lets get it fired up.
But.. it just looks like a command prompt.. whats so special about that.. Well wait and see. First of all lets do the general Hello world.  In the prompt write:

Write-host "Hello world"

And it returns Hello world as you might imagine.. WOW?? not yet.. Lets try another little thing. Try to write get-pr and press the Tab key. It now fills out the rest and writes Get-Process. Thats great, it has autocompletion .. Press enter, and see the running processes.. Impressed??

Now for something even better. The pipelining. (|) when you write a command it returns an object. This object can be further processed by another command after the pipecharacter through the variable $_. So when you write Get-Process you'll receive a collection of processes, and if you see at the top of the list, the propertynames are shown.
This'll lead us to the first wow.. Try to write :

Get_Process |  Where-Object {$_.ProcessName -like "wi*" }

Now you should see only the processes where the processname starts with wi. So to make a final Hello world in this blog. Try to write


Get-Process | Where-Object {$_.ProcessName -like "wi*" } | ForEach-Object {Write-Host "Hello" $_.ProcessName }

Now you should have a hello for the processes.