C#

C Sharp

Neo4jClient 1.1.0.1

Big milestone this one, Neo4jClient now supports Transactions, Authentication and some other little changes. Transaction info is all here: https://github.com/Readify/... You can find the connecting stuff here (at the bottom): https://github.com/Readify/... And the other big(ish) change is the change to make the ‘CollectAs’ method return the class type specified (<T>) instead of Node<T>. Big thanks for this go to Arturo Sevilla (https://github.com/arturos... ......

Writing Neo4j Console

So, Neo4j Console is now open sourced at: https://github.com/tournr/n... feel free to branch, fix, edit whatever and issue pull requests, or even just have a gander and code review :) I thought I’d write some notes on what I’ve done and why. Let’s split it into 2 main areas, UI and Backend. The UI Extremely simple WPF front end – I mean – it’s only got 3 text boxes! If I’m honest, it’s not what I want – I want to create a console window like the F# console, something which really does act ......

The Neo4j 1.9 to 2.0 Upgrade

So, with Neo4j 2.0 on the near horizon (RC1 out), it seemed appropriate to upgrade all my current codebase from 1.9 to 2.0. Generally, as a rule of thumb, the conversion has been pretty smooth, there are some pre-2.0 gaffs I’ve made which have made it slightly harder than it needed to be – but the ability to use 1.9 cypher in 2.0 db is incredibly useful. So – I’m (as you can probably tell) a .NET developer, which means I use the excellent neo4jclient to perform pretty much all of my interaction with ......

Another day, another blog post update

Gist: https://gist.github.com/csk... I know! Another question on StackOverflow leads to yet another blog post being updated to use the newer Neo4jClient. So here goes: Darko Micics has written a post about using Neo4jClient with C#.Net, and a question has arisen on StackOverflow asking about how to (in effect) do this in the new version of the Neo4JClient – the version where ‘CreateRelationship’ et al have been marked as obsolete. Luckily, this is a pretty simple (twitter-ish) data set ......

Extending Blend for Visual Studio 2013

So, I got a comment yesterday on my post about Extending Blend 4 and Blend for Visual Studio 2012 asking if I knew how to get it working for Blend for Visual Studio 2013.. My initial thoughts were, just change the location to get the blend dlls from Visual Studio 11.0 to 12.0 and you’re all set, so I went to do that, only to discover that the dlls I normally reference, well – they don’t exist. So… I’ve made a presumption that the actual process of using MEF etc is still the same. I was wrong. So, ......

Comprehensive redesigns

So, last night I realised that I’d made some bad decisions with the database, structure and naming, so… I’ve now refactored it all, and I’m feeling… hmmm… meh about it. I suspect I will redo it all later, but for now it will do…. I’ve also come to the conclusion that I was maybe trying too much for the initial release, so as a consequence I have removed one part of the project… (which, by-the-by, I intend to have published in a month or so – and yes Andy, that is one month longer than I mentioned ......

CdnFallbackExpression for JQuery, JQuery.UI, Modernizr and Bootstrap

So, like a total chump, I didn’t really understand what the CdnFallbackExpression on a Bundle actually meant. It didn’t help that pretty much every example you find online shows you what to write for jQuery, but nothing else. With Tournr, I want to use CDN’s where I can for obvious reasons – and so I dutifully tried the jQuery example: var bundle = new Bundle("~/Scripts/jQuery").... bundle.CdnFallbackExpression = "window.jQuery"; bundle.CdnPath = "https://ajax.aspnetcdn.com... ......

Neo4jClient with LinqPad

Quite often I want to just try out some code, usually useful when answering a question on StackOverflow, but typically these don’t require a full solution, and it’s a bit heavy handed to whip out Visual Studio for a simple create / match query, so what about LinqPad? One of the most awesome tools for a .NET developer (if you haven’t got it, you should get it). I’m going to assume a few things here: You have got Neo4j running and know the url (if you’ve changed it) You have downloaded and installed ......

Ninjecting Neo4jClient into MVC5/4/3

First, create your new MVC project (or load your existing one!) Then add the Ninject.MVC nuget package: We’ll also want the Neo4jClient package Now we have those two, we can hook it up, first off we need to tell Ninject how to bind to Neo4jClient, I use a Module for this, so add this class to your project (usually I have them in a sub-folder called ‘Modules’ in the App_Start folder – but it can be anywhere):public class Neo4jModule : NinjectModule { /// <summary>Loads the module into the kernel.</summary> ......

ImageResizer - AzureReader2 with Azure SDK 2.2

So Azure SDK 2.2 came out recently, which means I can open my azure projects in VS 2013 (yay), so I decided to do an upgrade of my MVC4 project to MVC5, I followed this link on how to do the upgrade, and generally things went ok. I fire up my app, and run into a ‘binding’ issue, that AzureReader2 was trying to use Microsoft.WindowsAzure.Stor... Version=2.1.0.0 but alas, it couldn’t find it. I am not the only one (see stackoverflow), and one solution is to run ‘Add-BindingRedirect’ from the Package ......

ImageResizer, AzureReader2 and well… Azure (duh!)

So, as part of my on-going project I’ve recently made the decision to shift all my images (uploaded by ME and my USERS) to Azure Blob Storage, instead of the quite frankly ridiculous ‘unique folder system’ ™ that I had been using. Now, originally I’d been using ImageResizer which was working well, buut, it didn’t work (the way I was using it) with Azure Blobs (at least not in an efficient way). So. I do the standard of searching for ‘ImageResizer Azure’ on google, and first on the list: AzureReader ......

Extending Expression Blend 4 & Blend for Visual Studio 2012

Just getting this off the bat, I presume this will also work for Blend 5, but I can’t confirm it… Anyhews, I imagine you’re here because you want to know how to create an addin for Blend, so let’s jump right in there! First, and foremost, we’re going to need to ensure our development environment has the right setup, so the checklist: Visual Studio 2012 Blend for Visual Studio 2012 OK, let’s create a new project (class library, .NET 4.5): Hello.Extension The ‘.Extension’ bit is very very important. ......

MousePath

A while ago, (and by that I mean over a year ago now) I was catching up on the blogs I read and came across this post: http://blog.iso50.com/14644... I thought – Awesomeness! I’ll give that a go… downloaded the app, and ran it, all good – but only on one monitor… :( I work with two monitors, and found that a lot of the time I’d end up with a no lines as I was on the other monitor… So, I thought I’d give it a go and write one myself… I actually had a working version pretty ......

It’s ok to throw System.Exception…

No. No it’s not. It’s not just me saying that, it’s the Microsoft guidelines: http://msdn.microsoft.com/e... Do not throw System.Exception or System.SystemException. Also – as important: Do not catch System.Exception or System.SystemException in framework code, unless you intend to re-throw.. Throwing: Always, always try to pick the most specific exception type you can, if the parameter you have received in your method is null, throw an ArgumentNullException, value received ......

Mocking ITable<T>

I have to do some mocking of an ITable to be able to test some of my code, as you may imagine this is the point where we’re crossing the data boundary… Now, ITable is a total bugger to mock, I’ve tried on (at least) 3 separate occasions to get it mocked, and have only now, finally achieved an 80% solution. (Nothing is ever 100%) I’m not using any mock framework, they just take too long to setup (in this case) and instead have a concrete class that implements ITable and uses an IList as it’s base. ......

InitParams in Silverlight – passed via MVC

The old skool way of passing InitParams in aspx is well documented, adding a: <param name="initParams" value="<%=InitParams%>" /> which is accessing the public ‘InitParams’ member in the code-behind file, which is inevitably set up via the ‘Page_Init’ handler. All well and good, but not practical in MVC, so… how to do this? (NB. This is just how I’ve done it, it’s not the only solution) There are a few things to change: 1. The Model I’ve created a SilverlightHostModel, it only has one ......

Unknown C# keywords: params

Often overlooked, and (some may say) unloved, is the params keyword, but it’s an awesome keyword, and one you should definitely check out. What does it do? Well, it lets you specify a single parameter that can have a variable number of arguments. You what? Best shown with an example, let’s say we write an add method: public int Add(int first, int second) { return first + second; } meh, it’s alright, does what it says on the tin, but it’s not exactly awe-inspiring… Oh noes! You need to add 3 things ......

Deploying, but without those pesky test files!

Silverlight testing is great, we all know that (don’t we??), we’re expected to do it as part of the development process, but once we’ve got an awesome application written and we come to deploy it, we don’t want the test files going out with it… You might be like me, have the files in a Web project – let’s face it, that’s how we’re pushed into doing it… So let’s stick with it! Now. I’m deploying via the wonders of the Web Deployment shizzle, but this also applies to the classic ‘installer’ project ......

Enum driving a Visual State change via the ViewModel

Exciting title eh? So, here’s the problem, I want to use my ViewModel to drive my Visual State, I’ve used the ‘DataStateBehavior’ before, but the trouble with it is that it only works for bool values, and the minute you jump to more than 2 Visual States, you’re kind of screwed. A quick search has shown up a couple of points of interest, first, the DataStateSwitchBehavior, which is part of the Expression Samples (on Codeplex), and also available via Pete Blois’ blog. The second interest is to use ......

Publishing a DeepZoom project to IIS

I’ve just been helping a colleague work out how to publish their Silverlight DeepZoom project to their local IIS instance. Went through the Publish settings in VS2010, published, connected to it via IE and… ah. No Images. OK, no worries, let’s copy the files from the ClientBin folder across that weren’t published… Hmmm, still no joy… Seems to be just the zoom images that aren’t there… Ok, how about trying to access those files.. You get this error when you attempt to access the .dzc file directly: ......

Path Animation in Silverlight

I’ve been spending some time working on prototyping some things I want to get working for a game I’m developing, and one thing I wanted was to get a couple of fly’s flying (buzzing?) around a lightbulb. Ideally I wanted to draw a path and say – Fly – use this path and follow it until the end of time! Turns out in WPF I could do this, but not so in Silverlight. Everything I saw explaining how to do it, involved working out complex (to me) equations to get the motion correct, or using a set of key ......

Further thoughts on the ObservableCollection extensions

Firstly (thanks Matt) – it should really be an ICollection extension – and so now it is, but also I’ve just ported it to a .NET 4.0 project, and can now make use of optional parameters, and so 3 methods now become 1! /// <summary>Adds a range of items to an <see cref="ICollection{T}"/>.... /// <typeparam name="T">The type held in the <see cref="ICollection{T}"/>.... /// <param name="collection">The <see cref="ICollection{T}"/> instance ......

ObservableCollection Extensions

I’ve had to create a couple of Extensions for the ObservableCollection, (well – I didn’t have to), erm, and so here they are! All are ‘AddRange’ just with different args for different usages.. namespace Extensions { using System; using System.Collections.Generic; using System.Collections.ObjectMo... using System.Linq; /// <summary>Extension methods for the <see cref="ObservableCollection{... class.</summary> public static class ObservableCollectionExtensions { /// <summary>Adds ......

XElement case insensitive 'Element' extension

Just a small bit of code, I've been playing around with converting some Xml* code to Linq to Xml code, and pretty successfully achieved everything I wanted, one thing missing was the ability to retrieve an XElement ignoring case. First - I'd like mention that yes I know Xml is case sensitive - and this is a bad thing to do - but I needed to do it due to some wierdness in the input xml... Anyhews, below is the extension method I wrote to deal with this.. public static class XElementExtensions { /// ......

WCF and LINQ to SQL (Part 4 – Updates)

If you’ve read parts 1, 2 and indeed 3 you’ll know we’ve covered the CRD of CRUD, today we will cover the ‘U’ – updates! Updates are more complex than the other scenario’s we’ve covered so far, but not unmanageable. Also – in fairness this is a very simple update, more complex updates will require more thought (duh!) but this should be a good starting point. Let’s get to it! We’ll start on familiar ground – updating the interface, adding an ‘UpdateCar’ method: [OperationContract] void UpdateCar(Car ......

WCF and LINQ to SQL (Part 3 (Deletes))

If you’ve read parts 1 and 2 you’ll know we’ve covered the CR of CRUD, today we will cover the ‘D’ – deletions. We’ll need to update our interface to actually provide this functionality: [ServiceContract] public interface ICarsService { [OperationContract] Car GetCar(int id); [OperationContract] void SubmitCar(Car car); [OperationContract] void DeleteCar(int id); } I’ve decided to delete the car via the identifier we created initially, though there is nothing to stop us using a ‘Car’ instance. Anyhews, ......

WCF and LINQ to SQL (Part 2 (Creates))

Right, in my last post I wrote about creating a DBML file and hooking it all up through WCF, however, we only got to ‘retrieving’ from the database via the service. So, let’s presume you want to upload… We already had our contract: [ServiceContract] public interface ICarsService { [OperationContract] Car GetCar(int id); [OperationContract] void SubmitCar(Car car); } Of which we’ve tested the ‘GetCar’ method, let’s get to implementing the ‘SubmitCar’ method. We actually did implement some code in ......

EntitySet.Contains – uses Reference comparisons

A gotcha that got me :) If you’re used to using List<T> collections, and in particular the way they compare, then you need to know that an EntitySet (from LINQ to SQL) does the comparison differently… In my experience, if I’ve created a class, for example: internal class Simple { public int TheInt { get; set; } public string TheString { get; set; } public Simple(int theInt, string theString) { TheInt = theInt; TheString = theString; } } And I then add some instances of this class to a List<Simple>, ......

WCF and LINQ to SQL

Now, I may be doing this wrong, but at the moment, it works :) I’m writing a service to communicate with a database, and provide a consistent front end for the applications that will be using it. In the past that has meant writing tonnes of CRUD (Create Read Update Delete) code, usually via Stored Procs, which are then accessed by a ‘DbAccess’ helper class of some variety. Not to mention the added bonus of writing the classes to store the data as it comes out. Fortunately the database I’m accessing ......

Hunting those elusive Public Folders using Exchange Web Services (Part 3)

In the last two posts (Part 1, Part 2) I've been going over some of the API calls to the Exchange Web Services, and so far we have retrieved an Item, but not any of the attachments held therein... So, lets go get that attachment! We have an ItemType, which lets us know we have attachments, and now will even let us pull some basic properties but not to save... so, how do we save? What we're (well, *I'm*) going to do is get the Item, then if it has attachments, save the attachments to my temp directory, ......

Hunting those elusive Public Folders using Exchange Web Services (Part 2)

In the first of these posts, we created a binding to the Exchange Web Services (EWS) and managed to hunt down our public folder identity. But, as we left it, we're now stuck with just the identity and not anything else. Really, we want the items from inside a given folder, and to do that we need to use the 'FindItems' API call.. FindItems needs a FolderId and of course the our old friend - the ExchangeServiceBinding (see part 1 for how to create that!). Once again, in a familiar pattern, we need ......

Hunting those elusive Public Folders using Exchange Web Services (Part 1)

Recently the Exchange server at work has been upgraded to an Exchange 2007 SP1 server. With this has come the chance to finally get rid of the MAPI CDO solutions we have, by switching to using Exchange Web Services (EWS). I've spent quite a while looking for easy ways of doing this, and for the majority of the time, it seems ok, but the biggest issue I've had (and unfortunately the solution I needed) was accessing public folders. Specifically public folders in a hierarchy. Public Folders\ \Testing ......

SL: Where TF are the Brushes??

Holy Smokes! A SilverLight post???!!! Yes - I've entered the SilverLight realms... so far so good - one app is nearly ready for release (internal only) and I have to say the experience has been pretty good. I've had a couple of issues - mainly down to the fact that I'm not sure about some things - Cross Domain Policies for example... but on the whole it's been ok... One of the things I did struggle with was the programatic setting of brushes, for example, say I wanted to set the Foreground property ......

Boxing / Unboxing and passing by 'ref'.

I recently heard a question stating something along the lines of: "What is Boxing?" My initial thoughts were the classic example using an ArrayList, whereby storing a value type (int etc) is 'boxed' into an object so the ArrayList can contain it. But the question was followed up with: "Ok, so is this how you think passing a value by ref to a method works?" Personally I hadn't thought about that, I've used 'ref' on numerous occasions, but hadn't really considered how the CLR does this.... So. How ......

Quick Serialization / Deserialization Helper Method

After discovering some pretty significant serializaton issues in the code base, and approximately 0% testing of the implementation of ISerializable, I've been spending the last couple of days writing tests for the serialization... I've been using the following code to do the serialization, easy to use: MyObject m = new MyObject("Test"); Assert.IsTrue( m.Equals( Serialization.SerializeAndD... m ) ) ); Of course, this uses the 'Serialization' class, which is defined below! using System.IO; ......

Local const strings - do they give better performance?

I just installed Resharper 4 (www.jetbrains.com) on my dev machine, and aside from the usual hints etc, there are some new ones, most notably the way it asks to insert a const string locally, for example: private void ShowMessage() { string msg = "Hello!!"; Console.WriteLine( msg ); } ReSharper suggests should be replaced with: private void ShowMessage() { const string msg = "Hello!!"; Console.WriteLine( msg ); } Now, I've never done that in my code in the past, but, presumably there is some performance ......

The decidedly badly named LoadingCircle WPF Control Pt 2

Badly named Loading Circle PT2 ---------------------------... So, in my last post (http://geekswithblogs.net/... I created a square LoadingCircle UserControl, using old skool WinForms multi-threading in the code behind file, and Xamly fun on the front end.. But there were problems (of course there were), firstly, the animation, whilst it *did* move, was a very 'on/off' affair, i.e. the Ellipse was ......

The decidedly badly named LoadingCircle WPF Control Pt 1

Soooo... I've been playing around with WPF for a while now, generally building small apps for peeps at work, or my own stuff, and one of the things that happens in quite a few cases is the dreaded 'data retrieval' phase. During said phase, the app will go into a state of nothingness whilst the data is retrieved, at which point it'll come back and be useable again. Now, we all know the way to keep the UI active is to multi-thread that bad boy, and that's where I'm at. In the app I'm thinking of, whilst ......

Dispose of a WPF UserControl (ish)

I've been playing with WPF a little bit, and quite frankly got a bit stuck, (Meh! Who'd have thought). The problem is as follows: I create a UserControl - we'll call it 'MyUserControl' (wouldn't want to break traditions now would we). In said user control I have a button, that when pressed will fire off a new thread. This new thread will (say) poll a file / service - whatever - every 10 seconds or so, and update a Label accordingly. When I close the app, if the app is polling, then the app won't ......

RoundedButton Button Style (WPF)

So far, I have only one style which I'm currently using on all my buttons, and to be honest, I'm still working on it, but it's been in a pretty stable state of development for a while now, so I thought I'd share it. Let me introduce you to the imaginatively titled: RoundedButton. The above picture shows 3 buttons, the first (top-most) is the bog standard WPF button, no styles applied. <Button Height="30" Width="100" Margin="20">Normal Button</Button> The second two are RoundedButton styled, ......