Blog ala Vidar

SQL, AppFrame and other cool technologies

Tag Archives: LINQ

Nordnes.Me

A couple of weeks ago I looked in the mirror. What did I see? I saw a guy that used most of his spare time on Xbox games. So, what did I do? Well, I had to find something else to do. What else? Build a new server! Yeah yeah, I could go outside having some fresh air etc., but fresh air also comes through the windows, at least if you open them. ANYHOW! I bought two domains; nordnes.me and nrdn.es and though I’d have some fun. A while back I bought a Quad Core AMD CPU for my HDPC, but I bought a new Intel CPU for that, so the AMD processor with the main board was just lying around without being used. I bought 8 GB RAM for it, and 2 x 2TB disks. I’ve also got a Microsoft TechNet subscription, which allows me to download almost any Microsoft product for free to use in a testing environment. What’s more testing environment than my home network? 😉

Now, everything is up and running and here are the specs.

Physical server
vs – Hyper-V Server

Virtual servers, all running with 1GB RAM (2-4 while setting them up):
vsAD – Active Directory, DNS and similar
vsHS – Home Server 2003 (not running. Will probably be deleted soon)
vsLINUX – Debian. Not running, but installed in case I need to test some Linux-stuff
vsMAIL – Exchange Server 2010 (hosting vidar@nordnes.me)
vsSQL – SQL Server, running 5 instances (2005, 2008, 2008R2, Express etc)
vsVAIL – Home Server VAIL
vsWEB – Web server, hosting Nordnes.me and nrdn.es

Home Server

I’ve learned a whole bunch of stuff in the process of installing and configuring everything. Today I finished moving over to the new home server (VAIL) which based on Windows Server 2008 R2. It’s awesome! One of the new features is that you can stream your videos via web (using Silverlight). Oh, while I’m talking about home server. If you’ve got more than one computer at home (or at the office), you might want to think about buying one. It makes sharing videos, music, backing up your computers and making sure all computers have updated antivirus etc. a whole lot easier. But wait till VAIL is released! VAIL will only run on x64 bit, while the old version only runs on x86.

One thing worth mentioning: DO NOT add your Home Server to AD. You will be able to do it, but it causes so many problems. The reason I wanted to do it was to use the same username and password as on all my other machines (both physical and virtual). Also, joining machines to the home server should be done on a wired network, not on wireless. When joined, you can put them back on wireless without any problems, but I haven’t been able to join any of my computers while on wireless. Have no clue why though, since my wireless router is set up as an AP (Access Point).

Active Directory

The main reason I installed AD is that I wanted to use the same username and password on all computers, but also to play around with group policies. Also, Exchange is pretty meaningless, if not impossible, without AD.

Web

This is the server I’ve played most with. I installed SharePoint, played with Office Web Apps and most recently Nordnes.me and nrdn.es. The last one (nrdn.es) is my own test-project for bit.ly/tinyurl.com-like sites. If you’re interested I can send you the project for this one, but there’s no rocket science here. I’ve also built Nordnes.me using Master pages in ASP.NET. This is actually my first site ever in ASP.NET!

Nordnes.me is just a place where I’ve gathered all my public feeds (blog, twitter etc) into one stream. I’m using a windows service to poll all the feeds every 15 minutes or something and then using LINQ to XML (which btw is AWESOME!) with ASP.NET to display them.

Exchange

Since Omega just moved over to Exchange, I felt I had to get some more knowledge about this. It would be interesting anyways since 99% of our customers use it, so I would probably eventually “have to” build something that communicated with Exchange. Before starting the installation I was convinced that this was just another “next next next next finish” project, and I was right. At least to get it up and running. To get it to send and receive mail took a couple of hours though. I am still not able to connect to Exchange outside my network although testexchangeconnectivity.com says everything is working as it should be. Since it’s working locally it’s very hard for me to test outside my network, so I might have to pick someone up from Microsoft and get them home to see my server-collection 😀

SQL

All SQL geeks with self-respect should have at least 5 instances running at home. I’m only using 2008 R2 at the moment, where I’ve got mainly two databases. One for the tiny URLs (nrdn.es) and one for polling twitter. The reason I’m polling twitter is to gather very much data, so I can start playing with SSAS (SQL Server Analysis Services). There are two arguments for polling twitter for this; it’s public and there’s A LOT of data being generated (by people) every second.

News from Ølen about stuff that matters

You might have noticed there was just a holiday. Something about Jesus eating some bad chicken, so everyone thought he died, but then he woke up a couple of days later feeling much better. Anyways, because of this bad chicken, I’ve been VERY busy the last week, playing Modern Warfare 2 on Xbox. Ai can has vacation 2!

AppFrame as a product!
Since I started in Omega I’ve been fighting for releasing AppFrame as a framework for developers outside Omega. Now that’s almost a reality. We’re soon going to offer AppFrame as a product, along side PIMS and our other products. There haven’t been any final decision on pricing and stuff, but I can guarantee it will be affordable. This means that all developers out there that want to use AppFrame as their Framework to make applications can soon start doing this! They MIGHT even get the source code! After releasing CR3 I’m now confident that this is an AWESOME product. If you’ve met me, you know I’m not a sales person. I always say what I mean, and I can say with my full heart that AppFrame is without a doubt a VERY good product to develop applications for customers! Contact me if you want a presentation (from a developer, or a sales person. Your choice!). I’ll probably post a blog about the details when there’s been a decision on price etc.

NNUG and MTUG Haugesund
I’m the chapter of NNUG (Norwegian .NET User Group) Haugesund. We had a meeting at Rica Maritim Hotel in Haugesund March 22nd. The speaker was Einar Ingebrigtsen, and he talked about creating games with managed code. That means, using Silverlight, XNA, DirectX and similar. We had a new record of attendees: 27! That’s really high, at least if you compare us to Bergen which is a MUCH bigger city, but they’ve got about an average of about 20 people every meeting.

Since I’m both interested in programming and hosting-related stuff, I thought it would be cool to start a user group that could concentrate about the IT Pro’s out there, just like NNUG is concentrating on MSDN-people. Timing perfect, as always, I read on twitter that a guy called Jan Egil Ring was about to start MTUG (Microsoft Technology User Group). I’ve offered myself as the contact person in Haugesund, and I’m now working on gathering people so we can get a committee to manage this group. I’ll keep all of you updated when we’ll start having meetings etc.

VB.NET 10
Except playing Xbox, what have I been doing lately? I’ve played a lot with Visual Studio 2010 RC. A hot tip for those of you thinking you’ll play with Silverlight 4 in the RC. Don’t even think about it. It doesn’t work. I didn’t know this, so after 6-7 hours of swearing, kicking, screaming etc. Erik (coworker and friend) told me that’s not possible. Well, thanks! After that I started playing with WPF, since it’s basically the same except that Silverlight is a wossy-version of WPF /me hides under the table, waiting for the Silverlight-folks to start screaming. I’ve already managed to create a simple twitter client, trying out LINQ to XML, LINQ to Entities and a couple of new minor changes to VB. The fact that you now can create a Property on a class with ONE line of code is awesome. And, yes, before you C#-fanatics say “we’ve had this for ages”, you now got optional parameters, which VB have had for about 1000 years. We now also got something that’s got a fancy name. “Implicit Line Continuation”, which basically means that you don’t have to end all lines with _ if you want to continue this line on the next. This was very annoying in for example LINQ, where you’ve got something like:

Dim v = From a In AppDomain.CurrentDomain.GetAssemblies _
		Where a.ToString.Length > 0
		Select a.ToString()

Here is a great example. On the first line you need to specify the _ at the end, if not you’re not “allowed” to continue, but you don’t need it on the Where-line. Pretty confusing. Well, now you don’t need it at all.

One other thing that I find really nice is the improved IntelliSense. Now you can start typing “To”, and you’ll get:

CompareTo, CopyTo, ToString etc

Before, you only got ToString, since that’s the only thing starting with To. You can also search for AD, and get AppDomain, since .NET uses Pascal Casing.

Blogs

We’ve been working a bit on the blogs site. Or, to be honest, I’ve been making tasks and Stian has been doing them. The new (some of them are old, but you might not have noticed them before) features are: Tags. This works the same ways as Categories, except that you can tag an article with more than one Tag. We’ve then got Tag Clouds, to show which Tags are the most mentioned, and which are rarer.

If you’re using TeamDocuments, you will be auto-logged in which gives you the possibility of rating all posts, and commenting on them! You can even comment as an anonym user.

Johnny said today that he’ll start blogging more. Peter also had this statement a couple of weeks ago. Guess it’s just like X-files, “Du tror det ikke før du får se det!” (something like You won’t believe it before you see it!). But I would be very happy to see some posts from them too!

Build 5

The technology department released Build 5 of AppFrame a couple of weeks ago. Peter was our “speaker” at our last cake-meeting where he went through most of the changes done in this build. I’m really excited to start upgrading our clients to this release!

Issue Tracker

To report bugs (yes, we as everyone else, including Microsoft!, produce bugs), the technology department released a new “issue tracker”. This makes it SOOO much easier for me, since I now don’t have to read 10-15 TeamDocs every day to check if the bugs I’ve reported have been fixed. Most of the things I’m reporting is even getting fixed within a couple of hours (sometimes days), depending on the severity of the bug/suggestion. I’m strongly recommending you all to report everything you find, so we’ll get an even better product! Just today I’ve reported two things; resizing issues with the calendar in chrome and the distribution lists not working. They haven’t been fixed yet, but the distribution lists-thing is “in process”.

 

If you’ve got any suggestions on what you want me to blog about, or you’ve got comments, please send them to me! And remember to rate the posts! Good or bad. I won’t bite… Changed my mind. I will bite 🙂

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.