EPiServer property getter cleaner-upper

Just a daily time saver, for reuse at another time.

Any old time windows developer, will remember the fun of using the ini files with GetPrivateProfileString. As much as ini files sucked there is one nice aspect of that call – you can setup a default value it is to return in case a value is not specified in the file. Similarly in a daily episerver programming you usually want to read a value but if one is not epcified you will usually want to use another value and just move along with the progress, and not really care to have an if there to do the filling in. Not to limit the property to any specific type – the task can be nicely solved with generics to handle pretty much any type of property.

/// <summary> /// Gets a property from a page by its name - if a property does not exist or is not set - returns a default value. /// </summary> /// <typeparam name="T">The type of the property</typeparam> /// <param name="page">The page to pull the data from</param> /// <param name="propertyName">The name of the property</param> /// <param name="defaultValue">The value to be returned if the property does not exist or is not set.</param> /// <returns>The value of the property.</returns> public static T GetPropertyDefault<T>(PageData page, string propertyName, T defaultValue) { PropertyData property = page.Property[propertyName]; if (property == null || property.Value == null) { return defaultValue; } else { return (T) property.Value; } }

It’s hard not to appreciate how clean that resolve is (with strong typing being forced with use of generics):

string link = PageUtility.GetPropertyDefault(CurrentPage, "ALink", "#top");

Another speedup coming from the TryParse background – when I want to deviate from the normal execution if a property is not defined but still have a clean code and strong typing…

/// <summary> /// Gets a property from a page by its name - if a property does not exist or is not set, /// returns the presence status of the property existence as a boolean value. /// </summary> /// <typeparam name="T">The type of the property.</typeparam> /// <param name="page">The page to pull the data from</param> /// <param name="propertyName">The name of the property</param> /// <param name="value">The value to be returned if the property exist and has a value, /// if the proeprty does not exist or is not set the value witll remain unchanged.</param> /// <returns>True if the property was retrieved succesfully, false otherwise.</returns> public static bool TryGetProperty<T>(PageData page, string propertyName, ref T value) { PropertyData property = page.Property[propertyName]; if (property == null || property.Value == null) { return false; } value = (T)property.Value; return true; }

Nokia N95 – Just because I’m cheap!

Some time ago, with a little help of TDI some time ago I’ve successfully switched all my outgoing calls to Voipdiscount, while at the same time moving my incoming calls’ number to mobile provider through a Sagem base station, all of this nicely integrated in a Linksys SPA3102 gateway in a way that a regular person grabbing a phone at my desk cannot realize that at the current moment it’s a hybrid not really having much in common with the POTS, they expect to be using. All of this effectively reducing the monthly phone spending to a negligible monthly fee, just in time when my eldest starts to spend hours on the phone – great!

Consequently, one of the main reasons behind my getting a WIFI enabled Nokia was to use Voip as the primary outgoing calls channel, so after we got (one for each of us TDI and me :) ) it was a mildly shocking experience when I discovered that Fring as a Voip solution is, to put it gently, seriously lacking in voice quality. At the same time I’ve found out that the Nokia seems to have SIP support built in, but up till today it seemed that there is no way to force it to work with Voipdiscount – the Voip provider that most of us in here (that actually switched to Voip at home) use. But that problem’s gone now. As of today the Nokia is officially a Voip solution of choice also for the Betamax services (the operator behind VoipDiscount, VoipStunt and about a dozen other services that simply put differ only by the site template, while effectively linking to one backbone).

Definitely for TDI’s benefit – but perhaps anyone else will find it useful as well… the configuration goes as follows:

  • Service Profile: IETF
  • Default access point: Your preferred wireless network
  • Public username: sip:[username]@voipdiscount.com
  • Use compression: No
  • Registration: When needed (use always on if you want it to stay connected all the time) Call type selection screenshot
  • Use security: No
  • Proxy server
    • Proxy server address: sip:sip.voipdiscount.com
    • Realm: voipdiscount.com
    • Username: your username
    • Password: your password
    • Allow loose routing: Yes
    • Transport type: Auto
    • Port: 5060
  • Registrar server
    • Registrar server address: sip:sip.voipdiscount.com
    • Realm: voipdiscount.com
    • Username: your username
    • Password: your password
    • Allow loose routing: Yes
    • Transport type: UDP
    • Port: 5060

And the best thing of all is the integration of the Voip within the phone, you pick your number like you usually would – either by typing it form the keypad or by selecting it from the address book, and THEN the phone asks you by which means you want to connect to your destination… BLISS!

 

Posted in GSM, Mobile, Nokia, Symbian
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
| 45 Comments »

Misadventures with Database Engine Tuning Advisor

I’ve been on a sole task today to improve a database performance of the project we’ve been working on. As much as I enjoyed the task there is one thing that costed me quite a bit of head scratching. Being a standard nerd I usually have about 20-30 applications running on my machine at a time, I didn’t immediately associated the error with the tuning advisor but rather assumed it’s one of my other 29 applications/servers/daemons/services in background did something stupid, probably even some of my code craving for a bit of attention, right? So I moved to tune the database on the server via remote desktop, but when I hit a wall there I’ve looked around for the solution and it looks like that it’s been known to MS for almost 2 years now.

Found it hilarious enough though to post it here though :)

“This indicates a bug in your application”, how vicious of them show a dialog like this to a developer. It’s not in MY code you bad thing you! It’s in YOUR code!

The solution or rather a workaround is available here. And NO, you don’t need to restart your computer after applying the change to the registry, just kill and restart Explorer and then start the Tuning advisor again. Make sure to restart the SQL Server Management Studio as well if you’re launching the tuning advisor form it, the setting is applied on app startup.

Is EpiServer a hard-shelled clam or what?

As much as I seem to be enjoying my trip with EpiServer there are some little things I don’t seem to appreciate all that much and I’m not quite sure how to work around some of them in an elegant way.

EpiServer has a fairly advanced way of dealing with properties but it also seems to be a bit tough on the developer whenever you try to do something more than just strictly using its API-s. One of the areas I don’t really enjoy is the dealing with the pages that are expired or generally unavailable for the user for various reasons.

In the project that we’ve been implementing recently we needed to store page ids for further reference in numerous places and although this generally works, accessing a page that’s been deleted, expired or not published yet, has proven to be a challenge and I can’t seem to be able to find an elegant solution around it.

For instance, we have a list of bloggers, that are stored in our faceted navigation with links to their pages, our system lists them and the links to their pages, should someone’s page be unpublished yet – we run into problems.

Another good sample of where this is needed is a list of pages (A multi-page property of sorts). There seems to be no implementation of a multi-page property in EpiServer and the only reasonable implementation that I’ve been able to find is available through EpiCode. The following is it deals with the pages going in or out of the system, which leads me to think that the only way of checking whether a page is available for me is to instantiate it with all the consequences of it:

// get the page with error handling for // access denied or deleted page try { PageData page = Global.EPDataFactory.GetPage(pageref); isExternalLink = (page.StaticLinkURL != multipageLinkItem.Url); if (page != null && isExternalLink == false) _selectedPages.Add(page); } catch (PageNotFoundException notFoundEx) { // We should not add the page if it // does not exist } catch (EPiServer.Core.AccessDeniedException accessDeniedEx) { // User is not allowed to see page, skip it } catch (Exception ex) { // The page could not be loaded, for some other // reason. System.Diagnostics.Debug.Write("Page could not be loaded: " + pageref.ToString(), "PropertyMultiPage"); }

What I do not like about this part (of an otherwise remarkable piece) of code is that exceptions are not supposed to be the driving force of the program flow. But in this case they seem to have been forced to do it. It’s like I had to open a file to check its size or whether it even exists.

I can see why the system will not let me visit the page if I’m not allowed to do it as a user, but the fact that the API frowns at me whenever I even try to instantiate it just to check its existence or my rights to it has proven to be quite problematic. After all a user is not supposed to see a login screen in the list of pages, but rather when he/she enters a page that he/she no no rights to. Better yet, give me a way to check whether I even can access it.

Is there one already? Has anyone heard? Did anyone see?

The great missing feature of EPiServer

As we’ve been debating with Steve in the EpiCode IRC channel (Come on, join us there! You know you want it!) a few days ago, probably one of the biggest missing features in EPiServer is multi-page property.

Yes there seems to be a fairly robust implementation of a similar functionality on EpiCode however it’s got 2 serious drawbacks:

  1. adding a great number of consecutive pages is a tedious process
  2. it’s not native to EPiServer, meaning – if I use it in my module that I would like to distribute later I need to put the control there. Short of potential licensing issues, this introduces an unnecessary complication level for such distributable modules

Another big issue with the page selecting dialog – apart form being unable to select multiple pages is its inability to root it anywhere outside the original EPiServer repository root. This really limits its quality in terms of re-using of its functionality to be able to use it for selecting of a limited set of pages.

I really wish I could have a clear API for it like I can use the Windows Forms  Open/Save Dialog in desktop applications. I mean seriously – I thought it was impossible that in a product as well thought out as EPiServer something as basic would be missing – there must be something out there to do it, right? WRONG. I looked all around the EPiServer code assemblies and short of re-coding the dialog form grounds up, all I have been able to dig out was a way to re-use the a part of the favorites functionality of the dialog.

You might find a way to reuse the following piece of code. If you put this in your .ASP :

Read the rest of this article »

Posted in ASP.NET, EPiServer, Software Development, Web applications
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading...
| 45 Comments »

Database-based paged EPiServer searches

Searches paged in the database have posed a problem in SQL Server at least prior to version 2005. I’ve found some solution to the problem on the net but they were so cludgy that I would never really put anything like that in a production server. I hope the following will shed some light on how they work in general by using in in EPiServer context.

Theoretically in EPiServer you can pull the pages that match the criteria from the database with EPiServer.Global.EPDataFactory.FindPagesWithCriteria() into the PageList but that seemed to be imposing a strong performance penalty with increased number of pages meeting the criteria. Since this search is sometimes done even multiple times on a page request in our project we needed something better.

Read the rest of this article »

Posted in EPiServer, Microsoft SqlServer, Web applications
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
| 15 Comments »

Our friends at EPiServer AB has just let us know that they are in need of EPiServer CMS specialists that might be looking forward to working with them directly, so if you’re an EPiServer professional and meet the requirements specified on the recruitment page give them a shout!

If you’re not already familiar with EPiServer you’re probably not going to make it this round, but then again I suggest you start looking at it now. EPiServer AB is a really dynamic company recently expanding aggresively on the international markets – and rightly so. EPiServer is deserving every credit it can get. I can say that my journey with it so far has been really smooth and I’ve enjoyed every bit of it. So if you’re not up to it, get ready for the next round, in the mean time, grab yourself a login – download a copy of the documentation from the Knowledge Center, a demo license and join us on the Developer Forum.

It’s a great bunch, really fun to work with.

Posted in Blogging, EPiServer, Software Development, Web applications
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 out of 5)
Loading...
| 9 Comments »

EPiCode hits IRC

I’ve discovered yesterday on Steve’s blog that him and our other friends on EpiCode have gathered on IRC (something I’ve been lobbying here at our company for quite a while). Come, drop by, let’s meet!

I’ll definitely try to hang out there as much as I can. great to meet you guys.

As Steve suggests – grab yourself a copy of XChat or aMirc, connect to irc.freenode.net and /join #epicode
Read the rest of this article »

Posted in EPiCode, EPiServer, Software Development, Web applications
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading...
| 12 Comments »

Common Language Runtime, now even more common

There seems to be a storm over at over at the Internet about Microsoft going Cross platform and “opening the common language runtime to a multitude of platforms”. What seems to be a false perception that even such respectable podcasts as Buzz Out Loud or even TWIT fail to realize and mislead people on is that this has NOTHING to do with portable .Net desktop applications. Someone even suggested at one of the BOL podcasts that it’s Microsoft’s attempt to put .Net Framework on Linux servers. (Huh? Beg your pardon?) You may have not noticed it but when they say about cross-platform capability of Silverlight it always says Windows, Mac.. and then on a single breath they start enumerating browsers. A casual listener just measures the quantity and the list has an impressive 5-6 bullets. heh… wait… erm… not really… it’s actually only 2 platforms. You cannot enumerate browsers as platforms! You share 99% implementation between them, the only cross-browser thing is the interaction between the plugin and the host browser!

As a .Net developer this pretty much makes me laugh through tears. What an excellent publicity stunt. First of all, Microsoft does not plan to release a Linux version. It’s cross-platformedness (is that a word?) refers strictly to the fact that there has been a runtime engine port made for a Mac. What was ported? The CLR and the DLR. Big deal! This has been there in a form of Mono years ago! And the CLR is available for Linux for a few years now. How is that suddenly an exciting thing?

If you’re interested in what exactly was done you may want to look at the interview with Scott Guthrie, GM of the Silverlight team. GAC was not ported. Wait! GAC WAS NOT PORTED?! Only a subset of classes that are needed inside a browser. Basic GC, no ASP.Net. It’s nothing like a cross platform version of a full .Net framework. this is also nothing really that new from the cross platform point of view – this kind of stunt was already pulled by Microsoft in form of the Compact version of the .Net framework. Something similar has already been done in terms of XNA – which is a form of .Net framework for XBox. In fact Silverlight is much more like XNA than it is like the full .Net framework.

Second of all the only open part is the DLR which is actually developed in an “embrace and devour” fashion. Ruby, Python and the likes developers – we love you! come join us under our Common Language runtime! Of course Microsoft will open it. Those developers are all about open and free this makes a lot of sense doing it this way. Give something, get a lot in return. Don’t get me wrong, I love the dynamic extensions, and I really like what’s being developed in the DLR, but make no mistake, the motives haven’t changed.

In the end CLR has been open for a long time and it’s not where the most exciting part of the development is. It’s the framework. I’ve not seen a word about Windows forms being ported. Or any of the ASP.Net namespaces on that mater. Heck even Mono has big ASP.Net 1.0 and chunks of 2.0. If you look at the image where do you see the CLR?

It’s the small middle circle inside the big one. That’s a far cry from releasing .Net as a standalone portable framework. And if you think about it, it does not make any sense from Microsoft’s point of view to go the whole way. What for? for it to make Windows expendable? Ridiculous!

My feeling is that (other than making another bucket of money), partially the motives behind is is to kick Adobe’s butt. If it did not occur to you yet, Microsoft and Adobe are full-out at war at this point. PDF is combated with XML Digital Paper, Flash has its Silverlight, Shockwave (& Macromedia Director) has Blend and XAML now and so on…

Adobe already takes shots back at Microsoft

While Adobe made PDF readily-available to other software companies such as Apple, Sun, Corel, and OpenOffice, when it came to deep-pocketed Microsoft, Adobe took a different stance, demanding that it remove the feature and charge a separate fee.

In response, Microsoft agreed to remove the feature, but refused to charge consumers separately for it. Adobe consequently sought negotiating leverage by threatening to sue before the EC, despite the fact that neither Adobe nor Microsoft are based in Europe, neither operates major production facilities there, and neither maintains primary business locations there.

Now that we have a few myths busted, I don’t want you to think that I am not excited by Silverlight.

The coolness ensues

It is still incredibly cool that they are doing it and not for the cross platform reasons (although it’s nice), and not for the multi browser compatibility (even nicer), but for it’s roots in the full framework. For us .Net developers it’s like one day we woke up and we knew how to write Action Script (Flash) applications. The Silverlight download is only 5 meg, so in the broadband world it’s going to be on almost every computer fairly quick. We will have a robust development environment for developing those applets in less than a year. It’s root in the .Net framework roots will make it talk seamlessly to our IIS embedded apps and services. You wanted web applications?

You asked for web applications? We will deliver…
… only they will be desktop applications running inside a browser we approve....
… and on any platform we choose for you…
the best of both worlds – no matter if you want to run them in Windows OR in Internet Explorer. :)

But honestly – should you use some artificial and clunky surrogates of instantly-responsive-interactivity in forms of AJAX when you can have the real thing running faster and delivering much wider functionality? Developing a browser apps was possible before, but .Net was never perceived as a platform specifically designed for that kind of activity, the quasi multi-platform/browser compatibility has a chance to change that perception. Perfect crime :)

I can’t wait for Silverlight to turn gold. It’s a brave new world.

Posted in .Net Framework, C#, Internet Information Services, Rants, Software Development, Web applications
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)
Loading...
| 18 Comments »

I’ve recently been asked by one of our new dotNet developers whether it’s possible to cast your regular everyday .Net 1.x System.Collections.ArrayList or the like onto a generic System.Collections.Generic.List<T> . I have to admit, I seem to suffer from some kind of Obsessive-Compulsive Disorder when it comes to programming problems. I mean my original reaction is usually “Of course not, what kind of frivolous idea is that?“, but then I cannot go about without solving the problem. So it was this time.

There seems to be no pre-coded framework solution for the problem, you should iterate over the items instead.  

At first I thought we could make use of the the framework supported conversion of  List<T> into List<Y>through a somewhat awkward method in the List<T>

public List<TOutput> ConvertAll<TOutput> (
	Converter<T,TOutput> converter
)

which requires you to implement a delegate that will do the conversion for every item. One problem with this solution though is that it does something exactly oposite to what we needed. It exports rather than importing and it does so between two generic types. However, there is an easy enough way to add this functionality in and you will only need to code it once and you will probably want to place it in some kind of static utility class.

 public static void copyToGenericList<T>(IEnumerable list, IList<T> genericList)
{
    foreach (object o in list)
    {
        genericList.Add((T) o);
    }
}

With the help of this method you will copy any enumerable type into whatever generic list you may find. Granted the method is not doing any type checking and will fail in case of any type mismatch it may encounter, but you would want to know about it nonetheles, wouldn’t you? Simple try/catch it around will do the trick, either that or a simple modification: 

public static void copyToGenericListChecked<T>
    (IEnumerable list, IList<T> genericList)
{
    foreach (object o in list)
    {
        if (o is T)
        {
            genericList.Add((T)o);
        }
    }
}

Which however will fail silently if the objects in the original list are of a wrong type, which in turn makes using it quite dangerous.

The copying now becomes quite effortless:

//Create a non generic list of type in with some data in it
IList list = new ArrayList();
list.Add(456);
list.Add(123);
 
//our generic target
IList<int> intList = new List<int>();
 
//and the copy routine - completely effortless
SomeUtilClass.copyToGenericList(list, intList);

But better yet, why not simply create the list of the type you expect and populate its contents in one go from the non-generic? Sure:

public static List<T> convertToGenericList<T>(IEnumerable list)
{
    List<T> result = new List<T>();
    foreach (object o in list)
    {
        result.Add((T) o);
    }
    return result;
}

And the sample usage becomes exactly what we hoped for:

//Create a non generic list of type in with some data in it
IList list = new ArrayList();
list.Add(456);
list.Add(123);
 
//and the one line conversion - nice!
IList<int> intList2 = SomeUtilClass.convertToGenericList<int>(list);

Generics rule!

Posted in .Net Framework, C#, Software Development
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
| 33 Comments »