Blog ala Vidar

SQL, AppFrame and other cool technologies

Monthly Archives: November 2009

LINQ to SQL

LINQ stands for Language INtegrated Query and is a part of .NET Framework 3.5. You can use LINQ to any object you want as long as it implements the IQueryable interface, including XML and SQL which makes it very interesting. When I first heard about LINQ I thought that it sounded cool, but I was worries about performance. I still am worried, but it’s even cooler than I imagined! To test it out I started creating TeamDoc in WPF, using LINQ. I connected to one of our SQL servers, drag and dropped a couple of tables and sim salabim my LINQ to SQL was ready to be used. I then started creating a user control for “recent updates”. The SQL query behind this looks something like this:

SELECT
  *,
  (SELECT TOP 1 Url
		FROM stbl_TeamDoc_Websites WITH (NOLOCK)
		WHERE TeamDocRef = Table1.PrimKey) AS Url
	FROM (SELECT TOP 100
		  C.PrimKey, C.Title, C.Status, C.Updated,
		  CASE WHEN C.Updated > ISNULL(US.LastRead,'1999-01-01')
			AND C.HideUntil  ISNULL(US.LastRead,'1999-01-01')
			     AND C.HideUntil <= GETUTCDATE()
			   THEN 1 ELSE 0 END DESC, C.Updated DESC) AS Table1

This, in LINQ looks something like this:

Dim vUpdatedDocuments = _
	(From d In vTeamDoc.Documents _
	Join us In vTeamDoc.UserSettings _
	On d.PrimKey Equals us.TeamDocRef _
	Where us.Login = Globals.Username _
	  AndAlso us.Notify = "Inbox" _
	  AndAlso d.Status = DocumentTypes.ToString() _
	  AndAlso d.Deleted Is Nothing _
	  AndAlso (From p In vTeamDoc.Permissions _
		   Join gm In vTeamDoc.GroupsMembers _
		   On p.GroupRef Equals gm.GroupRef
		   Where gm.Login = Globals.Username
		   Select p.TeamDocRef).Contains(d.PrimKey)
	Order By If(d.Updated > _
			If(us.LastRead.HasValue, us.LastRead, d.Updated.AddDays(-1)), 1, 0) Descending, _
	  d.Updated Descending _
	Take 30 _
	Distinct _
	Select New UpdatedDocument With _
	  {.Title = d.Title, .Updated = d.Updated, _
	   .LastRead = us.LastRead, .PrimKey = d.PrimKey})

I’m terrible sorry about the indenting and newlines, but I had to cut it to fit in here. Anyways, if you take a look at the LINQ query you’ll probably understand most of it. The only big difference is that I’m doing a Select New UpdatedDocument (on line 20). What this is doing is creating one UpdatedDocument (a class I’ve created) for each row returned by this query, and sets the properties .Title, .Updated etc. So, how do I loop this? VERY easy!

For Each vDocument As UpdatedDocument In vUpdatedDocuments
	Dim vTextBlox As New TextBlock With { _
		.Height = 15, _
		.VerticalAlignment = Windows.VerticalAlignment.Top, _
		.Text = vDocument.Title, _
		.Margin = New Thickness(0, vFromTop, 0, 0), _
		.Tag = vDocument _
	}

	If vDocument.Unread Then
		vTextBlox.FontWeight = Windows.FontWeights.Bold
	End If

	Me.RecentUpdates.Children.Add(vTextBlox)
Next

Here I’m creating a new textblock (some kind of mix between textbox and label in WPF), where I’m setting the .Tag property to my UpdatedDocument, so that I can use this object when for instance clicking on the textblock. And, if the document is unread, I’m setting it to Bold and then adding it to my RecentUpdates user-control.

I’ve struggled with LINQ a couple of days now, and I’m starting to get a hold of it. It’s still weird since I’m used to T-SQL, but I like the possibilities it gives me when developing. One thing I wasn’t too impressed by was the query it generated on the SQL Server though. I used profiler to check it out. It’s actually so ugly that I don’t dare to put it here 🙂 So, if you want to see it, test it yourself! Btw, to get started, Microsoft’s “LINQ To SQL Samples” is a good place to start.

5 minutes interview #19 – Nathan Lalonde

Nathan’s been with us for several years now. I’ve had the pleasure of having him in two AppFrame Trainings (R2 and R3) and we’ve been talking a lot on MSN, especially around build updates 🙂

How is it being American, working for a Norwegian company?
It’s been an interesting experience. I think there’s a fair amount of different views within Omega that you wouldn’t see in a typical American company. Some are good, some are just different. Working for an international company has given me a couple of chances to travel, so that’s been a good experience as well. My Norwegian coworkers have been great, and I’ve developed some really good relationships. Now, if I could just learn to read and partially speak in Norwegian, I’d feel totally assimilated. 🙂

What have you been doing in Omega PS? Your current position?
My current position in Omega PS is the Lead Systems Engineer in ConocoPhillips. I oversee the PIMS infrastructure in Conoco, am responsible for all upgrades, and have been supporting a group of about 10 projects in the Gasification, Regas, & Pipelines group. I also support the Shah Gas Development project, in Abu Dhabi, with their bidding phase. I’ve mostly been working on developing and updating the Bid Management System over the last year for the Shah project and the Yanbu Export Refinery Project, but have also spent a lot of time working on the Change Management System for the CORE Wood River Refinery project. The majority of my work has been done on the web using the web 2 templates, but I’ve recently been involved in heading up a rewrite of the Bid Management System within the CR3 and Web3 environment.

Last time we met you said you’re writing a book. What’s it about, and when can we get it in the stores?
My book is a science fiction novel with a good mixture of theological themes in it. Its a tale of the struggle of good versus evil, and how mankind plays into that spiritual struggle in physical ways. I’ve stalled out on it lately because work has been busy, and family and other responsibilities have been taking a good amount of my time. However, I’m still working on it, and I hope I can get it finished by next summer. I’ve got around 50-60 pages written. After I’m finished, I would imagine it will take some time to get it before a publisher and out into stores. Look for it on the shelves in 2011.  😉

Do you have any other hobbies, except computers?
I actually have TOO many hobbies.  I’m actively involved in my church. I teach a Bible study on Wednesday nights for an age range of 20-40. I also lead the worship on Sunday mornings, and play either the acoustic guitar or the bass for the services. I’m a HUGE fan of American football, and cheer on the Houston Texans every Sunday afternoon. I’m an avid reader (hence the novel I’m working on), enjoy playing a good video game, and like to stay physically active by going to the gym. I’m also involved in a conservative political action group in my community. I have two young daughters, and enjoy spending time with them and my wife. So, all that makes for a pretty busy schedule.

Google Chrome OS

A couple of months ago I heard (read?) a rumor about Google making their own OS (operating system). I wasn’t sure what to think of it, since there’s already way to many OSs. Google have now released a beta version of Chrome OS which I’ve just started testing. What’s the point of it? It’s not here to replace for instance my computer, where I run Visual Studio, SQL Server and other applications. It’s made to be installed on computers like my mom’s. The only thing she does on her computer is surfing the internet, sending mail, watching pictures of her first grandson and similar. To get a quick intro, check out this video.

To test this yourself, you can either download the source code and build it manually, or you can get a version from piratebay. Yes, it’s legal and no I don’t take ANY responsibly of the content of it!

After you’ve downloaded this VMware .vmdk file (which is a hard disk file for VMware), you can download either VMware Player or, as I did, Sun’s VirtualBox. After installing it, create a new virtual machine but be sure to check of that you’ve already got a virtual hard drive. Use the file you downloaded as your hard drive. Some people have said that you have to set the network adapter to be bridged, but I haven’t got mine to work in either bridged mode or NAT. Therefore I’m using NAT with “chronos” (yes, with “N” and not “M”) as username, and empty password. After logging in you’re immediately ready to start surfing. Be aware, that this is a beta release, released about a year before the planned release date, so don’t expect everything to work 100% 🙂 Mine have crashed three times the last 15 minutes. I’m running it with 512MB RAM on a laptop that doesn’t have hardware virtual machine support, so the performance is not great, but it works and I’m really looking forward to seeing this getting even better!

PDC

The Professional Developers Conference is Microsoft’s conference for developers (as you probably figured by the name). PDC is normally held around big releases, like this years Windows 7. Windows Server 2008 R2 was also released this year, and next year (hopefully first quarter) SQL Server 2008 R2, Visual Studio 2010, Office 2010 and .NET 4.0 will be released. I would love to be at the conference this year, but I’ll hope to go next time. Anyhow, the videos of all sessions have been published now, so go get them here!

5 minutes interview #18 – Thomas Buffon

First time I talked to Thomas Buffon was when I was on my way to Qatar a couple of years ago. I remember I called him from the airport in Amsterdam. For some weird reason I was convinced that he didn’t speak Norwegian, so I started with "Hi there. It’s Vidar here…". He answered me in Norwegian, but I kept going on English. After a minute or so he said "Hei, du kan snakke norsk til meg" (Hey, you can speak Norwegian to me). Of course, this was embarrassing, but I’m used to embarrass myself, so I didn’t think much of it.

What was your position in Qatar?
In Qatar, my position was PIMS development lead. We did mainly web development.

Do you remember your first day in Omega?
My first official day in Omega January 4th 2003, I was sitting on a plane heading to Houston. We were going to have one week preparation before going to South Korea running Mechanical Completion on a fast track FPSO project.

What is your current position?
My current position is System engineer in Karl Inge’s department in Oslo.

How was it working in an exotic country for all these years?
I was actually in 3 different locations from 2003 until march 2008. First Korea, then Houston and finally 2 years in Qatar. I must say I have a lot of fun memories from these years, and I really learned a lot from all the interesting people I met on various projects. However I must say it’s nice to be home for a while now.

Do you got any hobbies, except computer stuff?
Too many to mention, but I am a collector junkie and my room is filled with comics, trading cards, stamps and various other collectables. I also love Sci-Fi/Fantasy art, and have been drawing for years. Lately I also started using 3D programs for this. And as all programmers I like to spend time in the gym. I regularly work out 3-4 times a week. Not really a hobby, but an interest none the less 🙂

5 minutes interview #17 – Morten Emil Sørenes

My first meeting with Morten was at School. He was a substitute teacher for us in 4th or 5th grade. The first he did was sitting on his chair and put his legs up on the desk. This might explain why I always do this… When I started in Omega I heard his name, and after seeing his face, which hadn’t change much in 15 years, I recognized him. We’ve had a lot of fun about him being my teacher. Now he’s the head of all system departments.

What where your first position in Omega? Do you remember your first day?
I started as a trainee, and in fact I had never logged on a network before. In my interview I had a major fight with this dude they had hired to perform the interviews. So I can truly say I was really nervous!

What other positions have you had in Omega? Any programming?
Once upon a time, a looong, looong time ago I was actually able to program. Never a star, but I survived. After this period as a system engineer, I think I have had almost any and all positions possible: Project Manager, Department Manager, Business Development Manager and Head of Project Systems.

What are your responsibilities as chief of system departments?
My responsibilities today are many, but I think the most important is to try to make our division an exciting and good place to work by bringing new clients and challenges to the table and increase our professionalism. Of course, at the end of the day everything cooks down to money, but I try not to focus too much on this.

Do you have any hobbies?
Hobbies? Who’s got time for hobbies? When you get family and house, life changes quite some, and time for yourself is sometimes hard to get. Therefore I started bringing my daughter on hunting and fishing when she was 3 years old, and now we make a good team. Besides this I’ve bought diving equipment and been certified to dive, I’ll try it out this summer!

Wiki

I have set up a wiki for AppFrame developers. You can find it here. NB! This might not be available for some users (outside the Omega network), but will hopefully be available Monday morning. The reason this is set up is to gather all our resources, including all TeamDocuments like “Snippet Library”, “Technical problems for technical geeks” and similar. It is NOT set up to replace www.appframe.com, and this will still be our portal for developers. The difference will be that AppFrame.com will be “professional” articles, while wiki will be copy/paste code, small tips & tricks etc.

In the main page you’ll see two main headlines; Development and Setup & Maintenance. Under Development you’ll find the most important categories. Click for example “AppFrameR3” and you’ll be referred to the category which shows all articles in this category.

So, how do you start using wiki? First you of course need to register. After that’s done, you can click any “edit” you want. We’re using mediawiki (the same engine as Wikipedia.org) which means that there are some tags that are special here. You can use most HTML tags, but also a couple of mediawiki special tags. For a list of all, go to this site. To add an article to a category, just add the following:
[[Category:YourCategory]]

Also, you can edit existing articles to see which tags are used. The longest article so far is a copy of my AppFrame Security blog post.

The most used formatting tags are:

‘’italic’’
’’’bold’’’
’’’’’bold & italic’’’’’

=Heading, level 1=
==Heading, level 2==

* Bullet list one
* Bullet list two
** Bullet list three, child of two

# Numbered list one
## Numbered list two, child of one

<source lang=”tsql”>
SELECT *
    FROM Table
</source>

[[Main Page]]
[[Main Page|Link to Main Page]]
#REDIRECT [[Main Page]]
[[:Category:YourCategory|Link to YourCategory]]
[http://www.appframe.com AppFrame.com]
[mailto:vidar@omega.no email me]
[[Image:Database.png]]

5 minutes interview #16 – Øyvind Vik

Øyvind has been working from Houston as long as I’ve been in Omega. I’ve meet him a couple of times. We (me, him and his brother Johnny) also had a typing contest a couple of years ago. I didn’t have a chance! But, at least I’ve beaten Johnny a couple of times, so I’m hoping to beat Øyvind when he’s visiting us the next time.

Do you remember your first day in Omega? What was it like?
I’ve had many first days in Omega…The first working experience with Omega was about twenty years ago when, as part of a two-week school-sponsored practical work program, I was assigned to Omega. The first task was to write some code on what I believe to remember was SuperBase on Atari, to scan through all names in a database and convert them to Sentence Case (instead of all UPPER CASE).
In 1997 I did some work for them in Stavanger while working for my own company, and in January 1998 they wondered if I was interested in going to Venezuela to implement PIMS. This sounded exciting, I didn’t know anything about the country back then, but I said yes and went scrambling for summer clothes in Stavanger in January 1998. After searching in the store’s back-rooms, I ended up with a few short sleeved shirts with screaming colors, like orange and glowing green and yellow, and went off. This was my first major international assignment, and I haven’t stopped since!

How long have you been in the states? What’s your role there?
I moved to Houston in June 2002, and been here since, interrupted by another project in Venezuela 2003-2005. Here I am responsible for all market activities, business development, client and personnel activities related to PIMS and consultants in the US. I also get involved in advisory roles and project management as required by clients.

Is there any new projects coming over there?
We just reached agreement with a multi-billion dollar project in Malaysia to implement PIMS R3 as their Project Information and Cost Management system. This is an exciting opportunity for the fortunate people from Omega that will go – not only because it is an extremely important PIMS R3 Cost implementation for a major project, but also because they will be able to brag about having worked in the famous Petronas Towers (once the tallest building in the world)!

You’ve just started using wave. What do you think about it?
After having seen the demo, I got sandbox access to Google Wave back in August, and have played just a little bit with it so far. I think it is a promising tool, and merges ideas from mail, TeamDocuments, Messenger and other apps into an interesting mix. The Robot features, a path Microsoft was following for a while with Messenger and later scrapped, hold a lot of potential for creating some clever applications. But for years to come, it is going to be a novelty with limited use for enterprises, and will not pose any threat to established players. I think we will see some cool apps for consumers, though, and long-term the Wave will likely little by little find its way into the enterprise as well. If anyone needs an invitation to the preview, drop me a note. I still got 7 left.

Besides computers, what do you do on your spare time?
In my spare time I spend a lot of time teaching my daughter (3 ½ years) computers; currently teaching her how to move windows around! Apart from that I read a lot, walk, eat & drink, and smoke an occasional cigar while dreaming about getting time to play golf. I have a genuine interest in all sorts of technology – the latest gadget I am waiting for is the Tacx Fortius Multiplayer bike system, which I am going to use to beat Johnny real-time in cycling!