January 13, 2012

Hello RavenDB! Introducing RavenDB for ASP.NET Developers

2 comments


In this article, we will look at a NoSQL database called RavenDB. If you are new to NoSQL or RavenDB or Document Databases, don’t panic! We’ll walk you through an introduction for each.

What is NoSQL and what are NoSQL Databases?

Before we get into the classical definition, let’s look back at our approach towards building n-layer ASP.NET applications. Typically we have the RDBMS system with its schema at the bottom, immediately followed by an O-R Mapping layer that maps the tables into Entities. Rest of the application layers, are built on top of this entity layer. Be it business logic or View model, everything is supposed to work off the entity layer at the minimum. Views could be interacting with View layers etc.

This mandatory mapping from Tables to Entities often involves a non-trivial amount of work to shoehorn object relationships into table structures. At this point we all wonder, wouldn’t it be nice if we could just think in term of entities/business objects and by pass the O-R layer altogether?

NoSQL databases (specifically the Object Database or Document Database breed), aim to release us from this ‘impedance-mismatch’ of entities that we use for business logic and tables that we use for data storage, by saving Business Entities directly to a persistence store.

NoSQL as is somewhat obvious, stands for ‘Not only SQL’. Martin Fowler recently posted on his blog that calling NoSQL as ‘Not only SQL’ is unnecessarily polite. It should mean ‘NO-SQL’. Whichever way we go with the naming, NoSQL systems are schema-less and they can retrieve/store data either as complete object graphs or as key value pairs. A very good primer and categorization of NoSQL databases is available at http://nosql-database.org/. In short, NoSQL databases take a clean break from the table/column schema RDBMS and are designed with horizontal scaling, simpler serialization and commodity hardware requirements in mind.

Welcome RavenDB!

  • RavenDB is a Document Store (a type of NoSQL) database written in .NET. By Document Store, it does NOT imply you can store MS Word documents or Excel Spreadsheets in them. Here document stands for an object graph. Document Store DBs serialize object graphs to the data store directly.
  • The data is serialized as standard JSON stream.
  • Oren Eini (Ayende Rahien) at Hibernating Rhinos created RavenDB. It started out as a pet project that he used to learn the NoSql architecture. It has now grown to become a full-scale commercial NoSql database.
  • It is available under dual licenses (community and commercial).
  • It runs either on IIS or as a Windows Service
Unlike most NoSQL databases that adhere to the BASE properties, RavenDB supports ACID properties for write operations. (Indexing is however still ‘eventually consistent’ but RavenDB will tell you if it is getting you stale data). ACID as we call knows stands for (Atomicity, Consistency, Isolation and Durability) and support for ACID is what makes us so comfortable using RDBMS systems with respect to Data Integrity. BASE on the other hand stands for Basically Available, Soft state, Eventual consistency. You can read up more on BASE and CAP Theorem if you want to.

RavenDB still has a weakness that prevents it from becoming the instant choice of all green-field (a project starting fresh) ASP.NET MVC web projects. Most reporting solutions today work best off RDBMS systems and NoSQL databases are just getting their feet wet with respect to Reporting system connectivity.

So if you are building a system that doesn’t require traditional reporting systems to hook in and retrieve data, RavenDB is the perfect choice. More often that not, that’s not the case (specially Line of Business applications) and hence we tend to fallback on SQL Server/MySQL/Oracle etc.

I will soon post an article where we will see a use case that is typical of brown-field projects (projects involving enhancements to an existing application) where a handy functionality can be achieved by using RavenDB and ASP.NET MVC.

Update: To learn how to use RavenDB in an MVC project, check Using RavenDB in Brown-Field ASP.NET MVC projects

January 7, 2012

Use HTML 5 Elements in IE 8 using HTML 5 Shiv

1 comments


There are a lot of new HTML 5 elements like <header>, <article>, <footer> etc. that browsers like IE 8 and versions prior to that, do not support. These browsers need some help recognizing the new HTML5 elements and Remy Sharp’s HTML 5 Shiv provides just that.

To use this script, it must be included before the <body> element (i.e. in the <head>).

To improve performance, include the CSS first and then this script. Here’s how to declare this script

<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]—>

This script enables IE to acknowledge the new HTML 5 elements by directing it to create the elements using JavaScript. The conditional comment shown above only loads the html5 shiv code when the version of IE is lower than 9.

You also need some CSS styling to render the elements as  block-level elements

image

December 27, 2011

Most Popular .NET, jQuery and Web Development articles in 2011

2 comments


With 2012 fast approaching and 2011 drawing to an end, we've put together our list of the Most Popular .NET articles on DevCurry.com this year. The year 2011 featured articles on DevCurry covering many technologies like jQuery, HTML 5, ASP.NET, MVC, Silverlight, WPF, .NET, VS 2010, Entity Framework and Sharepoint, just to name a few.

I would like to thank each one of you who has visited my blog or contributed to it by submitting a Guest post, Subscribing to RSS Feed, by joining me on Twitter or the Facebook page or promoting the articles and giving regular feedbacks via rating, comments or Emails. Many thanks to those too who purchased my jQuery ASP.NET eBook.

Here are some articles that were liked the most by readers like you. Have a very Happy New Year 2012!

.NET Articles


jQuery & JavaScript Articles


HTML 5 & CSS Articles

December 22, 2011

Create Triangles using Plain CSS and No Images

1 comments


If someone asks you to create a graphic on a webpage using four triangles in a Square, how would you suggest he/she goes about it? Use JavaScript or Images?

image

I recently picked up a nice CSS trick from Paul (CSS guru) who told me how to achieve the above output using pure CSS. Here’s the code

image

CSS code:

#one{
height:0;
width:0;
border-top:80px solid #FFFF01;
border-left:80px solid #00FF00;
border-right:80px solid #0080FF;
border-bottom:80px solid #FE0002;
margin:20px;
}


and voila! You have your artwork! As you can see, by using simple CSS properties such as border, you can produce complex shapes and orientations without using JavaScript or Images

See a Live Demo

December 17, 2011

HTML 5 Developer's Dilemma - Which Video File Format to Convert and Support

3 comments


Until recently, the only way to embed video in web pages was using third-party plugins like Silverlight, Flash and QuickTime. HTML5 has made it easier to include multimedia in your web pages without any plugins, by just using the <video> element. However support for video and audio file formats varies across browsers. HTML5 capable browsers support different video formats.
They are:
  • Theora (.ogg, .ogv) - The free and open source container format from the Xiph.org foundation, for the open source Theora codec. Results in lower quality than H.264 and uses the application/ogg MIME type and the video/ogg video attribute type
  • MP4/ H.268 (.m4v) - The compressed container format for the H.264 codec, with high definition support and uses video/mpeg MIME type and the video/mp4 video attribute type
  • WebM (.webm) – Open source container format supported by Mozilla, Opera, Adobe, and Google., compressed by VP8 codec and uses the video/webm MIME type and the video/webm video attribute type
A standard video format has not yet emerged. So as a web developer, to make sure you handle all major web browsers and that as many users  as possible can see your content, you have to encode video in different formats.

Let’s us first quickly see what browsers support what file formats

html5-video-formats

Looking at the chart above, one can conclude that if you serve ‘at least’ two different formats: MP4 and WebM or MP4 and Theora, you can handle all the ‘latest’ browsers. The easiest way to provide content in different formats is to convert your video format into Mp4, WebM or Ogg formats

Free Encoding Tools to Convert Video Formats

Here are some free encoding tools to convert video formats:
  • HandBrake – Open source transcoder for generating .mp4 files.
  • Firefogg - Firefox extension for performing Ogg encoding.
  • Miro Video Converter – Converts video files to Theora Ogg, MP4, and WebM
  • Media Converter -  Convert files to MP4, Theora Ogg, Flash FLV etc.
  • Vid.ly Converter -  Converts your source video into 22 output renditions to cover more that 6,000 devices and browsers in market.
    This tool was shared by Elijah Manor in the comments section

Using HTML 5 with a Flash Fallback

Faced with these format differences, a web developer should prepare multimedia in different formats (as we explored above) and also support old browsers that do not support HTML 5.

Here’s an example of how you can write your markup

html5-video-fallback

As you can see, in addition to different file formats, we have a fallback to a Flash video and a further fallback to an Image, in case the flash plug-in is also not installed. While providing Flash support, Firefox uses the `data` attribute above and IE/Safari uses the param attribute, hence we have included both.

December 13, 2011

What’s New in Silverlight 5

3 comments


Now that Silverlight 5 has been Released To Web (RTW), let’s take a quick overview of what’s new in Silverlight 5


Here’s a summary of the new features in Silverlight 5, since it’s Beta release and since Silverlight 4.0

Performance Improvements
  • Improved XAML Parser Performance
  • Improved ClientHTTPWebRequest scenarios
  • Network Latency Improvements by using background thread
  • H/W accelerated rendering in IE9 windowless mode
  • Multicore JIT for speeding up startup time
  • 64-bit browser support on Windows
Binding Enhancements
  • Debug DataBinding statements (XAML)
  • Reuse Data Templates across application
  • DataContextChanged event to notify when DataContext has changed
  • Added PropertyChanged to the UpdateSourceTrigger enum
  • Binding on Style Setters
Media Support
  • New classes for sound effects with low latency audio playback
  • Variable Playback Rate
  • Hardware acceleration for H.264 media
  • DRM Key Rotation to support Live TV
  • Common remote control button commands for users to control media playback
Graphics Enhancements
  • Independent animations on separate threads
  • Core of the XNA Games Studio 4.0 graphics 3D API included
  • XNA 3D API provides XNA built-in effect, low-level GPU access, 3D primitives, multi-sample anti-aliasing etc.
  • Project Template support via Toolkit
Trusted Applications
  • Display Multiple windows in out-of-browser apps
  • Full-Trust in-browser for deployment and update scenarios
  • Unrestricted File System access
  • In-browser HTML support
  • P/Invoke support to call native windows API
Improved Text Support
  • Support for Pixel snapped text and Open Type fonts for better Text Clarity
  • Multi-Column Text and Linked Text Container support via the new RichTextBlock and RichTextBlockOverflow elements
  • Support for vector based printing
Input Support
  • Detect double-clicks using ClickCount property
  • Search Listbox/ComboBox using keyboard input
Other Support
  • Visual Studio Team Test support
  • New controls like PivotViewer and Drawing Surface
  • New capabilities for OpenFileDialog and SaveFileDialog, with default file name support

Tools You Should Download

December 7, 2011

.NET Programming for Absolute Beginners [Free Video Series]

0 comments


Channel 9 has just launched an absolute beginner programming series to help people learn to program. This FREE training series is created for programmers who have no experience with C# or VB.NET

The series of 49 episodes (24 episodes for C# and 25 for VB.NET) walks you through fundamentals, getting the .NET tools, writing C# and VB.NET code, debugging features, customizations and much more to learn concepts applicable to video games, mobile environments, and client applications

You can access the series as well as read descriptions for each episode in the link given below:



Similarly you may also want to look at the Free Learning Resources section to access .NET training videos, articles, podcasts, ebooks and much more.

December 2, 2011

jQuery 1.7 Custom Events Using .on Method

2 comments


The browser event model can behave differently in different browsers. jQuery provides a consistent framework to handle standard events like the mouse click in browsers with an easy to understand syntax. However we are not limited to the set of events provided by jQuery. jQuery provides support for custom events as well.

Custom events provide a great way to decouple your application code and architect new libraries, similar to how we create our own jQuery plugins. You can use them to handle custom scenarios in your application like mail_sent or implement a pattern like the Obeserver pattern (publish-subscribe).

Till version 1.6, jQuery lets you register handlers for custom events using the bind() function and you can fire these custom events using the trigger() function. With jQuery 1.7, you can now use the .on() method that provides all functionality required for attaching event handlers. It’s similar to bind() except that you can now bind multiple events at once, and select a set of children that actually trigger this event.

Let us see a simple example of using the new .on() method to register custom events in jQuery 1.7

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>DevCurry.com - jQuery Custom Events</title>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#myDiv').on('myEvent', function (e, somesampledata) {
                // write custom code
                $(this).text('Custom Event Triggered. ' + somesampledata);
            });

            $("button").click(function () {
                $("#myDiv").trigger("myEvent", "somedata");
            })
        });
    </script>
    
</head>
<body>
<div id="myDiv">This is a Div with an Attached Custom Event</div>
<button>Trigger custom event</button>
</body>
</html>

As you can see, the on() method listens for events and the trigger() method notifies listeners that an event just occurred. Trigger() method takes two arguments, the event name and an extra optional parameter, if you want to pass any data to the custom event handlers. In our case, we are passing “somedata” to the event handler.

Run the application, click the button and you get this.

image


If you are curious, in jQuery 1.6 you would use bind() to do the same thing . The syntax remains the same, bind() gets replaced with .on(). Here’s the same code without passing an optional param to the trigger() method.

jQuery Custom Events

Note: Just like browser native events, custom events also propagate the DOM Tree
To remove events bound with .on(), use the .off() method. To attach an event that runs only once and then removes itself, use the .one() method.

You may also want to read Create a Custom jQuery Selector

See a Live Demo
 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions