GraphDiff v1.3.5

Latest release of GraphDiff v1.3.5

– Master has been updated to EF 6
– MIT license
– XML documentation on all public methods
– Merged 2 PR’s and small bugfixes

Nuget package: https://www.nuget.org/packages/RefactorThis.GraphDiff/
Source: https://github.com/refactorthis/GraphDiff

Any issues to GitHub please.

Advertisements

Latest Update

Hi everyone,

So I’ve been quite busy and just realized there are many comments I haven’t had a chance to view yet. I will try and get to them in the next week. This will include some updates to GraphDiff, as I’ve seen some great pull requests which I will need to migrate, and I have other bugfixes which I had planned to migrate earlier but then had problems with my PC at home.

For now though I’ll post a link to my latest project called Topic Reel http://www.topicreel.com. I don’t often post about my front-end dev work but I truly love working the whole stack.

The stack I have used for this project is AngularJS, NodeJS & MongoDB. I’ve built applications with these technologies before but I really wanted to work on something that I could release as my own.

The idea was to create an easy to use real-time front page which aggregates popular posts/images/tweets across multiple social media feeds and allows for searching across the real-time Internet as a whole.

I should warn that it’s beta and it’s still very much in the early stages but I have big ideas for where it could head, if given the time that is!

Anyways if you can please do check it out and if you like it let me know, or find any problems that’s even better to know.

Also I have a virtualized grid built for AngularJS which I’m not quite ready to release yet but it basically contains most of what ng-grid provides but uses html markup in the page rather than javascript templating, it also allows for binding events as attributes much like a Silverlight grid control. It seems more ‘Angular’ to me than the way ng-grid expects things to work. Perhaps I will have some time soon to work on that too.

Cheers guys,
Enjoy coding.

Group or Order by sub type using LINQ to Entities

It’s a little hard to see how to group by a sub type in Linq to Entities. Since the discriminating field (when using table per hierarchy inheritance) or table name (when using table per type inheritance) is of course not exposed past the ORM layer. This essentially leaves us with the type of the object to discriminate sub types.

If we try to use GetType() in a LINQ to Entites query we get an exception of the sort:
“LINQ to Entities does not recognize the method ‘System.Type GetType()’ method, and this method cannot be translated into a store expression.”

On the other hand however EF can recognise the ‘is’ keyword. Now lets see how to group by using this new found knowledge.

Scenario: A PERSON is subdivided into ADULT, TEENAGER, etc like below:


public class Person
{
    public int Age { get; set; }
}

public class Teenager : Person { //... }
public class Adult : Person { //... }

Now how do I find the count of people who are adults and teenagers in one LINQ query? (without ToList() as this no longer performs the query in SQL)
The trick is to to use nested ternary operators inside of your GroupBy keySelector parameter using the ‘is’ keyword.


var results = Context.Persons
    .GroupBy(p => p is Adult? "Adult" : p is Teenager ? "Teenager" : "", (key, results) =>
    {
        k,
        results.Count()
    }).ToDictionary(p => p.key);

The same can be done for OrderBy queries. Hope this helps you as it did me.

Windows Identity Foundation : A SignInResponse message may only redirect within the current web application

We have run into an issue in the WSFederationAuthenticationModule class within WIF.

The bug has been posted here on Microsoft connect.
http://connect.microsoft.com/site642/feedback/details/573589/wsfederationauthenticationelement-web-config-requires-trailing-slash-after-home-realm-otherwise-an-error-occurs

Basically the issue comes when the application requesting authentication from your STS sends a redirection url without a trailing slash. The slash cannot always be guaranteed as the return URI is created from the accessed application URI. Therefore if a user bookmarks the wrong URI or a link doesn’t have the trailing slash you will get the above exception message.

In trying to fix this problem I had a look through the WSFederationAuthenticationModule’s public event listings. None of the events that we could see occurred before the offending code in OnAuthenticateRequest().

The workaround listed on Microsoft Connect was quite bad as it forced us to check every single request in each RP to ensure that the trailing slash was in the URI, and if not redirect back to itself with the trailing slash.

I came up with a simpler solution to the problem which only needs a change to the STS itself. Since we couldn’t get into a public event before the offending code we added a HttpModule to the pipeline and ensured it ran before the WS modules.

This custom http module simply checked the ‘ru’ return URI field (within the wctx entry in the query string) for a trailing slash and if none was provided redirected back to itself with the trailing slash in the ‘ru’ field.

I’ve updated the Microsoft Connect website for the new work around.

Getting back into it.

Well I’ve been back from the holiday for a month or so. Been staying away from the blog for a while as I’ve had so much work to do since I got back that I need to prioritise.

I’m currently working on starting a new project in ASP.NET MVC 3 so you might see a few posts pop up about that. At the moment we are just going through the early stages of release planning and story estimation.

Stay tuned.

Multi Tenant update

Hi,
I’ve received messages and I know a few of you are waiting for a good tutorial on multi tenancy.

I’ve been busy working as I’m going on a trip and will be away for the next 6 weeks. So it’s going to have to wait, we haven’t gone live with my changes I’ve made at work yet as they are not complete however in development it is working very nicely.

I’ll write up some posts when I get back. Basically my solution for the back-end involved:

  • MEF for drop-in client overrides of business logic in a services layer
  • EF 4.1 for POCO classes implementing an interface which allows for a hash set of key,value pair custom fields

This gives us a flexible back-end. As for the UI we have PHP, Webforms and MVC so that’s taking quite a bit of work to change. There are already great tutorials on multi tenancy MVC so I’d refer to those.

Looking forward to getting into it when I’m back.

IIS 6 Session timeout issue (Web.Config cannot solve all timeout problems)

We were receiving calls from a client saying that they kept being kicked out of one of our systems quite regularly usually after 20-30 mins of inactivity.

We got to work and firstly checked the usual suspects, the web.config file sessionState timeout and the forms timeout for forms authentication. Both of those were set to > 2 hours so it couldn’t have been those.

I debugged on my local machine and found that everything was working fine and the session was being killed after the correct timeout stated in the web.config file. It seemed it was a server configuration issue. Now our situation is complex as we share authentication across multiple systems including legacy PHP code, So i tried all of those configs, to no avail.

At last eureka! It seems the actual application pool was being recycled after 20 mins of inactivity. This was an application pool being used by only 1 client so was not being hit as often as most. If your having similar problems check your application pool’s session time out values and application recycle values.. Ours was set to 20 mins of inactivity which I believe is the default.

Javascript parseInt gotcha (All browsers)

I wanted to keep this blog to put up interesting gotchas that I’ve found whilst programming. This is definitely one of the craziest I’ve seen.

I had a problem with my jquery calendar where I was parsing a string as an int. I was calling this:

parseInt("08");

So you would assume an int of 8 yeah?
The actual returned value is ZERO, which was a bit of a shock to me. Apparently the javascript parseInt function will take a string leading with a zero as an octal number. To force it to read a base 10 number you will have to call

parseInt("08", 10);

See this post for a great explanation http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C85006A6604. Its amazing how long I have been programming in javascript and have never picked up this one..

First Post

Welcome to Refactor(this)!

I’m basically starting this to write down all the tips and gotchas I run into everyday as I work as a .NET developer.¬†Currently the blog will probably focus on¬†Silverlight MVVM and PRISM development as that is what I am currently working with.

Hope to have some helpful posts up soon