Hi Guys, I've now moved my blog to http://www.mackolicious.com/blog please follow that link to see my latest posts
Wednesday, 9 May 2012
JSONP aka JSON with PADDING
JSONP is a hack pattern which allows JavaScript from one domain to execute with JavaScript from another domain. This is technically not allowed as it violates cross-domain polcy, howeber throught the JSO work-aroud it can be acieved.
"Why?" I hear you ask, well the answer is simple, someone exposes a service on one machine and you want to consume that service on another. "But that's already possible!" you cry, well yes however you can't execute that service inline, look at the following example:
On my.domain.com you have a local script called myscript.js, so the full URL to that script is my.domain.com/myscript.js. Inside this script you want to make a call to other.domain2.com/their.js and execute their JavaScript, it doesn't work, unless you explicitly ue the <script> tags. But that's pointless because you want to execute their inline with yours; that's where JSONP comes in.
Using JSONP you are able to overcome this hurdle by setting up an 'understanding' between the service and the requesting JavaScript. This can be achieved by placing a query string parameter in the URL that the service understands, e.g. other.domain.com/their.js?jsonp=yes. The service will 'wrap' it's response in a JavaScript function, which the requesting JavaScript will execute once it's received the request. Once it executes this request, it will hopefully get some meaningful JSON that it can interpret and use for it's own devices.
Tuesday, 10 April 2012
ASP.NET Web API (Beta)
I have been recently looking into the new ASP.NET Web API to find out what features it offers and it's quite interesting.
It seems to following a convention over code model similar to that of ASP.NET MVC, so for those familiar with those constructs it should be an easy API to follow.
You use the global.asax.cs file to name your routes (just like ASP.NET MVC), however you use the MapHttpRoute overload instead e.g.
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/notifications"
);
This is a typical route where the {controller} template representes the controller name that is found beneath the controllers folder.
Wednesday, 11 January 2012
Using Modinizer
Modinizer is a great new javascript library for detecting browser features without having to write too much unnecessary code for abstracting cross-browser compatibilities.
For example rounded corners is a feature that was desired for many UX (user experience) developers and before CSS3 could only be accomplished with javascript hackery. Now with modinizer it is possible to detect using the library whether the feature is enabled and code corresponding classes appropriately.
When modinizer is included on a page it dynamically updates the HTML class attribute with a set of classes that identify what that browser understands, e.g. multiplebgs = multiple backgrounds, or no-multiplebgs meaning doesn't support multiple backgrounds. Allowing you the developer to code accordingly for both scenarios and thus future proof your web application.
The same also applies to new HTML5 elements such as video, and localstorage. A quick Modiziner.localStorage test will reveal whether or not the browser supports that.
Tuesday, 10 January 2012
Reading Files Across Servers
There are many ways to access data across servers that are shared on the same network. Depending on your setup will determine what is the best approach. It is possible to use the COM model to access the UNC as and authenticated user of that machine, i.e. machine name = CPU123, user = CPU123\user.whoever.
The problem with this is approach is that if your servers are on different domains then is will be a huge headache to maintain all of those users, configuration file sounds like the best approach, but that will still yield a huge file. One app setting for each user.
The approach I adopted was to use MSMQ and created a WCF service for sending messages to that queue and reading the state of the particular file using a FileWatcher.
Worked well!
Saturday, 15 October 2011
Using NCover with Cruise Control.NET and Nant
I had the task of integrating NCover into our continuous builds and integration.
At the time I was using Cruise Control.NET v 1.5, NCover v 3.4.18 (classic), and Nant v0.91.
I came across several problems when doing this, however I finally came across a solution where by using Nant I was able to build my application, run my Nunit tests and the run my coverage.
The route I took involved using the NCover Nant task DLL that comes with NCover and running it over my tests.
The issue which held me up the longest was the fact that in order to run coverage over your test DLLs you need to ensure that you include the pdb symbols in your build output, otherwise you'll be going nuts!
Sunday, 9 October 2011
IOC - Inversion of Control
Currently, I'm using Inversion of Control (IOC) for most of my application building which I'm finding really useful and quite powerful.
Some people consider IOC to be a pattern which follows the three R's: Register, Resolve and Release which is how you would use it by default.
IOC usually takes some kind of container which holds all the mappings between objects, for example, if you wanted to use the class Chicken everytime you referenced the interface IAnimal then in you container you may have the following registration:
_container.Register.To();
The syntax depends on which IOC library you are using; there are several.
My current preferred choice of IOC library is Castle Windsor, which makes using IOC inside applications quite fun and simple.
Sunday, 10 July 2011
ASP.NET MVC
Hi all, I'm back after a long time off. What I would like to discuss is ASP.NET MVC in comparison to ASP.NET.
Let’s give a quick introduction ASP.NET (Active Server Pages) is a server side coding language used for rendering HTML (Hyper-Text Markup Language). This is achieved by using the notoriously infamous server tags <% code goes here %>.
The ASP.NET runtime was built as an abstraction to allow developers to code in their native .Net languages, e.g. C# to create powerful web applications. The problem (amongst other things) was that the level of abstraction meant that coding “simple straight-forward” applications was quite easy and efficient, however coding custom or complex applications became quite difficult, e.g. two form tags on the same page.
The main problem was that through this level of abstraction some granular control was taken away from the developer in order to have a windows forms style development experience. Even controlling Ids on a particular HTML element became quite a laborious and painful task.
With ASP.NET version 4.0 some vast improvements had been introduced to make most coding scenarios easier, however with the revolution of test driven development, the improvements (in my opinion) still weren’t enough – introducing ASP.NET MVC.
MVC (Model View Controller) for those who do no t know is a design pattern used throughout all kinds of programming languages. It essentially boils down to one primary concept “separation of concerts”, meaning everyone has a job and they should only be concerned with fulfilling the requirements of their job. Fox example, in a typical restaurant theirs a chef, a waiter, and a manager. It’s not chef’s responsibility to take your jackets and make sure your comfortable in your seat, just like it’s not the waiter’s responsibility to ensure that the restaurant’s targets are met and that everyone shows up to work on time.
The MVC design pattern has been so successful in coding web applications that Microsoft and the ASP.NET team decided to introduce their own implementation. What this means is that we now have a design pattern directly “embedded” into the .NET framework, and used correctly can lead to power web applications as with ASP.NET but also powerful unit testing. ASP.NET MVC gives some of the control back to the developer and allows you to deepen your understanding of ASP.NET runtime.
With ASP.NET MVC 3.0 there is a new syntax introduced for creating ASPX pages called Razor. It is what I would describe as very clean and concise. The reason being that a lot of the repetitive tags and directives are no longer needed and writing C# inline with HTML (or even JavaScript) looks a lot nicer to read! Which for some developers such as myself is very important. What this means that less keystrokes are now required to produce the same content with ASP.NET thus allowing the developer to get on with other important tasks, such as, poking people of Facebook.
Let’s give a quick introduction ASP.NET (Active Server Pages) is a server side coding language used for rendering HTML (Hyper-Text Markup Language). This is achieved by using the notoriously infamous server tags <% code goes here %>.
The ASP.NET runtime was built as an abstraction to allow developers to code in their native .Net languages, e.g. C# to create powerful web applications. The problem (amongst other things) was that the level of abstraction meant that coding “simple straight-forward” applications was quite easy and efficient, however coding custom or complex applications became quite difficult, e.g. two form tags on the same page.
The main problem was that through this level of abstraction some granular control was taken away from the developer in order to have a windows forms style development experience. Even controlling Ids on a particular HTML element became quite a laborious and painful task.
With ASP.NET version 4.0 some vast improvements had been introduced to make most coding scenarios easier, however with the revolution of test driven development, the improvements (in my opinion) still weren’t enough – introducing ASP.NET MVC.
MVC (Model View Controller) for those who do no t know is a design pattern used throughout all kinds of programming languages. It essentially boils down to one primary concept “separation of concerts”, meaning everyone has a job and they should only be concerned with fulfilling the requirements of their job. Fox example, in a typical restaurant theirs a chef, a waiter, and a manager. It’s not chef’s responsibility to take your jackets and make sure your comfortable in your seat, just like it’s not the waiter’s responsibility to ensure that the restaurant’s targets are met and that everyone shows up to work on time.
The MVC design pattern has been so successful in coding web applications that Microsoft and the ASP.NET team decided to introduce their own implementation. What this means is that we now have a design pattern directly “embedded” into the .NET framework, and used correctly can lead to power web applications as with ASP.NET but also powerful unit testing. ASP.NET MVC gives some of the control back to the developer and allows you to deepen your understanding of ASP.NET runtime.
With ASP.NET MVC 3.0 there is a new syntax introduced for creating ASPX pages called Razor. It is what I would describe as very clean and concise. The reason being that a lot of the repetitive tags and directives are no longer needed and writing C# inline with HTML (or even JavaScript) looks a lot nicer to read! Which for some developers such as myself is very important. What this means that less keystrokes are now required to produce the same content with ASP.NET thus allowing the developer to get on with other important tasks, such as, poking people of Facebook.
Friday, 18 September 2009
Extensions, extensions
Once again the .Net framework has brought out another fantastic feature which makes development smarter and easier.
Extensions are a very simple but very useful feature in .Net. so what are they? They are methods which extend the functionality of an existing object, what this means is that you the developer can add a method to any object (as far as I know!). For example, if we look at the boring String class we see methods such as Contains(), EndsWith(), Join(), LastIndexOf(), ToLower(), Trim() and many more! However what about the ConvertToMackolicious() method!!? It doesn’t exists! So everytime I want to convert a string to “Mackolicious“ I either have to create a private method or create a class.
The disadvantages, if I had 50 classes that required this functionality I would need at least 50 private methods! That’s dumb! So naturally I would create a class right, but every time my application gets compiled so would the class thus creating an unnecessary object in memory, boooo.
Welcome extensions! Now I can write a static method within a static class and provide a certain method signature and can achieve a functionality which is identical to the functionality of a regular instance method, such as those examples above.
This is an example of the syntax required for an extension method: public static string ConvertToMackolicious(this String stringObject){}. Using the keyword ‘this’ tells the runtime what object you are extending, here I’m extending a string, hence all strings within this scope (namespace) will be able to benefit from the ConvertToMackolicious() method yippee!
Disadvantages of extension methods (from my personal experience). Acting on an object within the .Net framework is easy and produces good results, however acting on a type built by yourself or someone else may not always be a good idea. The reason being that they might one day change the implementation of that type making your extended method produce wrong results or make it stop working altogether! Be careful!
Extensions are a very simple but very useful feature in .Net. so what are they? They are methods which extend the functionality of an existing object, what this means is that you the developer can add a method to any object (as far as I know!). For example, if we look at the boring String class we see methods such as Contains(), EndsWith(), Join(), LastIndexOf(), ToLower(), Trim() and many more! However what about the ConvertToMackolicious() method!!? It doesn’t exists! So everytime I want to convert a string to “Mackolicious“ I either have to create a private method or create a class.
The disadvantages, if I had 50 classes that required this functionality I would need at least 50 private methods! That’s dumb! So naturally I would create a class right, but every time my application gets compiled so would the class thus creating an unnecessary object in memory, boooo.
Welcome extensions! Now I can write a static method within a static class and provide a certain method signature and can achieve a functionality which is identical to the functionality of a regular instance method, such as those examples above.
This is an example of the syntax required for an extension method: public static string ConvertToMackolicious(this String stringObject){}. Using the keyword ‘this’ tells the runtime what object you are extending, here I’m extending a string, hence all strings within this scope (namespace) will be able to benefit from the ConvertToMackolicious() method yippee!
Disadvantages of extension methods (from my personal experience). Acting on an object within the .Net framework is easy and produces good results, however acting on a type built by yourself or someone else may not always be a good idea. The reason being that they might one day change the implementation of that type making your extended method produce wrong results or make it stop working altogether! Be careful!
Sunday, 30 August 2009
Windows Workflow Foundation
During my research into Windows Workflow Foundation I discovered many things, the most important discoverey of all was the actual reason for using it. This was probably the most difficult aspect of my research, but after hours of heading banging and implementation I found several good reasons for using Windows Workflow Foundation (WF).
Image a scenario where you have been given the developement task of building a specific aspect of an application. Here you are responsible for only one part and other members of the team are responsible for the other aspects, for example, you have been told to build a function that takes text and determines whether or not the word "Microsoft" appeared within the text. So most likely you build your simple application which uses a regular expression (of some kind) and returns some kind of boolean.
Now what happens to that boolean that is return you have no idea, nor do you know where the text comes from. All you know is that your function works! Now the project manager has thanked you for your working function and has reveiled to you how integral your function is to the company's applications. In fact he has told you that several existing applications and several new ones will be using your function in order to determine some kind of process, for example, one application may use your function to send emails to every address where "Microsoft" is in the domain.
Achieving this portability can be done in many ways, however using WF it can be achieved in a strongly-typed diagrammtic way. All this means is that you can view the various execution processes whislt it being tied into the code. Before this had to be done seperately with the business processes being dis-connected from the code, with WF however, this business logic achieved through a UML designer is built into to the .NET framework allowing true business logic to be programmed directly into the application logic.
So to go back to the inital problem, a team-lead or manager can easily integrate other applications or remove exisiting applications by using the WF. He can also ensure that your function is doing what its supposed to be doing by simpliy integratin unit tests and making sure that the application exits correctly!
Perfect, problem solved you work on your existing code whislt it gets integrated seemlessly with everything else!!
Image a scenario where you have been given the developement task of building a specific aspect of an application. Here you are responsible for only one part and other members of the team are responsible for the other aspects, for example, you have been told to build a function that takes text and determines whether or not the word "Microsoft" appeared within the text. So most likely you build your simple application which uses a regular expression (of some kind) and returns some kind of boolean.
Now what happens to that boolean that is return you have no idea, nor do you know where the text comes from. All you know is that your function works! Now the project manager has thanked you for your working function and has reveiled to you how integral your function is to the company's applications. In fact he has told you that several existing applications and several new ones will be using your function in order to determine some kind of process, for example, one application may use your function to send emails to every address where "Microsoft" is in the domain.
Achieving this portability can be done in many ways, however using WF it can be achieved in a strongly-typed diagrammtic way. All this means is that you can view the various execution processes whislt it being tied into the code. Before this had to be done seperately with the business processes being dis-connected from the code, with WF however, this business logic achieved through a UML designer is built into to the .NET framework allowing true business logic to be programmed directly into the application logic.
So to go back to the inital problem, a team-lead or manager can easily integrate other applications or remove exisiting applications by using the WF. He can also ensure that your function is doing what its supposed to be doing by simpliy integratin unit tests and making sure that the application exits correctly!
Perfect, problem solved you work on your existing code whislt it gets integrated seemlessly with everything else!!
Subscribe to:
Posts (Atom)