onsdag den 14. maj 2014

Hello Conditional Compilation

When developing an application it is sometimes necessary to add code that will not be wanted in the final code. Fx. tracing code.

Defining the conditional constant

To make a conditional compilation you need to define a constant that tells which condition is the current.

This can be done directly in the sourcecode, but then you have to do it in all sourcefiles that use it.

#define Test

This can be handy for a small test, but if you have a general condition that is used across sourcefiles its a bit shaky. So you need to add it to the general build configuration in the projects properties.

image

As you can see here you have access to default constants TRACE and DEBUG.

Using the condition

When using the condition just add #if #else #endif around the conditional code.

#if Test
Runtestcode
#else
Runprocode
#endif

you can of course use the TRACE and DEBUG code here.

fredag den 7. februar 2014

Et tilbageblik – mit liv med computere

Alt det her med Facebooks lookback videoer får mig til at tænke tilbage - også til før FB.. Ja der var også en tid før.. og hvor er det egentligt fedt at min karriere endeligt begynder at forme sig som jeg drømte om for ca 28 år siden, da jeg valgte "Data" i skolen, hvor jeg lærte Skildpadde sprog af Poul Lybaek på en god gammel jerncomputer :-)

http://www.old-computers.com/museum/photos/Regnecentralen_rc700_1.jpg

Da jeg ikke havde nogen computer derhjemme, sad jeg og håndskrev programmer i et kladdehæfte, så jeg kunne stå tidligt op næste morgen og tage ind på skolen og vente på, at pedellen åbnede. Jeg havde fået lov at bruge Databehandlings-lokalet uden for normale timer. Jeg var meget entusiastisk og oplevede faktisk også at komme i skole en dag for tidligt, og sidde og undre mig over hvornår Regnar kom.

001

Senere fik jeg sparet op til en Commodore 64 hvor jeg så kunne sidde og lege med basic. De fleste der har været igennem bogen og lavet Commodore luftballonen der flyver over skærmen har vel prøvet at lave den om til andre billeder.. ;-)  http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Commodore_C64C.JPG/800px-Commodore_C64C.JPG

Men da jeg kun havde sparet op til selve computeren og lagringsmediet, hhv. båndstation eller diskettedrev var et køb for sig selv måtte jeg igen sidde og skrive programmerne, og når først der var slukket var det slut. Jeg nægtede dog pure at købe en båndstation, da jeg var sikker på at det med floppy var fremtiden.

Selvom jeg godt kunne se ideen når Radio Viborg havde deres ugentlige programmer om forskellige nye spil og programmer til Commodore 64 og Amiga og det altid sluttede af med at de sendte et program ud i æteren så man kunne optage det på bånd. I der var med på bølgen ved hvad jeg snakker om.. I andre undrer jer nok bare.

Men langt om længe fik jeg med hjælp sparet op til en 5 1/4” diskettestation. Den med dreje låsen og ikke den med kliklåsen.. Og derudover købte jeg et Comal80 addon så jeg kunne kode i det samme sprog som vi var gået over til i skolen. 

Farsø skole

Jeg skiftede så til Farsø skole og skulle vælge valgfag og det naturlige ud over Data var selvfølgelig at vælge maskinskrivning for at kunne skrive hurtigere. Da der på den tid ikke var så meget fokus på computere i undervisningen var min maskinskrivningslærer også min datalærer. Set i bakspejlet var det fordi tastaturet så ens ud. Så jeg brugte en del tid på at hjælpe de andre elever.

Derudover havde jeg god tid til at kode lidt for mig selv, og mit stolteste øjeblik var, da jeg solgte et program til indeksering af en kuglepennesamling for 100 kr. Jeg kan ikke huske hvordan det virkede, men jeg var stolt.

De andre fag gik knap så godt, da jeg var hurtigere til at skrive på tastatur end i hånden. Derfor var jeg glad da jeg, efter en del argumentering, fik overbevist min dansklærer om, at jeg måtte aflevere stile, skrevet på computeren. Selvom der jo ikke var æøå på den, hvilket betød at jeg, når jeg havde skrevet stilen ud, måtte gennemgå den og rette de danske bogstaver. Alligevel blev mine stile længere og læsbare og jeg steg fra 6-7 i karakter til 10.

Aars Handelsskole

Næste skridt var handelsskolen og det var igen tid at tage stilling til valgfag. Da jeg jo var ret hooked på at skulle arbejde med programmering og havde bestemt mig for at gå efter datamatiker uddannelsen i Aalborg, ringede jeg til EDB-skolen og forhørte mig hvad jeg skulle gøre for at have størst chance for at blive optaget.

IT-mæssigt var der ikke så meget indhold i uddannelsen. Vi arbejdede på UNIX, men kun som slutbrugere, og der var i bund og grund ikke noget jeg siden har haft brug for. Det kan godt være at kontorbrugere arbejdede sådan på det tidspunkt.

Hjemme havde jeg “graderet” til en PC. På det tidspunkt ved jeg ikke rigtigt om det var en opgradering eller en nedgradering fra Commodore 64. Det var en Schneider fra Bilka – 80286 med 16 mb harddisk og under 1 mb ram så vidt jeg husker. Wordperfect kørte jo fint, så det var ikke noget problem. Jeg fik da lavet alle mine opgaver på denne.

Jeg opgraderede til 80386 og købte Pascal samt en moppedreng af en dansk skrevet bog om programmering i Pascal og var ellers gået i gang med at kode til det.

Jeg mener det var mit første møde med Windows 3.11 og WordPerfect 5.2 som var et lidt halvhjertet windows implementering af WordPerfect 5.1. Selvom WordPerfect 5.1. længe var bedre end Word, så var det stadig ingenting værd når de ikke investerede i windows udviklingen.

Datamatikeruddannelsen

Nu var jeg jo så endeligt kommet til den uddannelse jeg havde stilet efter siden 5. klasse og jeg valgte så sjovt nok at sørge for at kunne leve godt selvom jeg var på SU ved at have et par jobs ved siden af. Så reelt kunne jeg nok have fået bedre karakterer, men til gengæld fik jeg mere erhvervserfaring og på den måde mere karakter, end hvis jeg havde helliget mig uddannelsen. Så jeg ville nok ikke gøre det anderledes hvis jeg skulle gøre det om.

Det ene af mine jobs var som udvikler i et lille konsulent firma hvor jeg igen opgraderede udviklingsværktøjet til Pascal til Windows og derefter til Delphi. Computeren blev opgraderet til en 80586 med windows 95 som blev købt alt for dyrt til en auktion hos en nystartet virksomhed.

Jeg fik købt et modem så jeg kunne snuse til nettet. Fidonet var det eneste jeg umiddelbart kunne komme til på det tidspunkt. Det var ikke meget interessant der var ved det. På skolen var der kommet internet og vi kunne komme på IRC, gopher, ftp og telnet som jo alt var tekstbaseret. Men så kom Netscape med deres browser og det var der jo lidt mere ved. Så derfor begyndte jeg at arbejde med html, hvilket jo var et ret stort tilbageskridt i starten.

Webbet var en sjov størrelse. Alt var klistret ind i reklamer der var endnu mere klodsede end i dag. Selv søgemaskinerne og det var stort set umuligt at finde noget fornuftigt, og så var det tungt. Altavista var det bedste bud på en søgemaskine efter min mening. Noget mere clean end de andre.

En ny ting for mig i den periode var mobiltelefonen. En alcatel klods til en krone - igen fra Bilka. Det var dog ikke en af dem med et lastbil batteri, der gjorde det nødvendigt at have en bil for at have en mobil. For at være helt ærlig troede jeg ikke rigtigt på ideen. Hvorfor skulle det være så vigtigt for mig at kunne ringe og blive ringet til hele tiden. Det tog jo bare masser af tid og jeg risikerede at komme til at gøre noget dumt hvis jeg havde været i byen og fået lidt for meget at drikke. Så det endte med at jeg tænkte at det var dumt, og da jeg lavede  “Datamatikerbladet” smadrede jeg telefonen og brugte den som billedmateriale til en artikel om at man brugte for meget tid på mobiltelefoner og at det var de færreste der var så vigtige at det krævedes, at de var tilgængelige hele døgnet rundt. Lidt i retning af de artikler der kører i øjeblikket.

“Datamatikerbladet” var en hjemmeside som var meningen skulle være blevet til et fagblad for nyuddannede datamatikere, og jeg skulle have solgt konceptet til skolen efter et års tid, men sådan gik det ikke. I dag ville man nok bare kalde det en blog.

Installing Lync Server 2013

When installing Lync Server 2013 on Server 2012 I recommend this
http://windowspbx.blogspot.dk/2012/07/step-by-step-installing-lync-server.html
And if you install on server 2008 R2 I recommendthis blog for the prerequisites.
http://y0av.wordpress.com/2012/07/31/lync-2013-prerequisites/
REMEMBER to install with the right user from the start. And this user NEEDS to be domain admin.
I tried to install with a local admin and got help from a domain admin on steps that required this. This gave some problems on the installation.

First problem

The Shared directory was created by local adm and the domain adm hadn’t any rights. So I put the Domain Admins in the RTCUniversalServerAdmins.

Second problem

Some how I couldn’t reach SQLServer instance though FQDN? Normally this wouldn’t be a problem, but as the Lync Server setup used FQDN I needed it..
Some googling told me, that I needed to activate Name Pipes on the server configuration.

Third problem

The third problem was Error: Prerequisite installation failed: SqlInstanceLyncLocal  I checked the SQL Server and found that the Domain Adm wasn’t admin in the SQL Server..
I tried again but the same error?!?!
After some Googliung I found that the installation should have a RFCLocal, and found that it had the same problem with missing rights..

Fourth problem

The fourth problem gave more problems.. It seemed like the same problem as above.
Error: Prerequisite installation failed: SqlInstanceLyncLocal
Installation result: -2068578302
image
Googling didn’t help as the result code wasn’t findable.
Then I dived into the log and looked at what was being executed.
Executing external command: C:\ProgramData\Microsoft\Lync Server\Deployment\cache\5.0.8308.0\SQLEXPR_x64.exe /QUIET /IACCEPTSQLSERVERLICENSETERMS /HIDECONSOLE /ACTION=Install /FEATURES=SQLEngine,Tools /INSTANCENAME=LYNCLOCAL /TCPENABLED=1 /SQLSVCACCOUNT="NT AUTHORITY\NetworkService" /SQLSYSADMINACCOUNTS="Builtin\Administrators" /BROWSERSVCSTARTUPTYPE="Automatic" /AGTSVCACCOUNT="NT AUTHORITY\NetworkService" /SQLSVCSTARTUPTYPE=Automatic
Actually Lync should have yet another SQL-instance - LYNCLocal. Icouldn’t reach it at apparently it couldn’t be created. So finally I looked into the Services and found the instance was stopped. I tried to start it but without luck.
Actually the service didn’t depend on the SQLServer and to fix it i uninstalled the instance and ran the installation again and.. Woosh it worked.

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