Thursday, February 28, 2013

Opensource Javascript Framework : Ember.js

JavaScript – an indispensable part for developing websites and web pages, whether that is simple pages or professional website. Nowadays, JavaScript frameworks become more powerful and more specialized; they can do many things in just a few basic steps. A Javascript framework is a library of pre-written javascript controls, functions and methods that make it easier for the developer to quickly and accurately produce cross browser compliant code. Example popular frameworks are: YUI, ExtJS, Prototype, MooTools and of course, jQuery.
The massive growth in rich, JavaScript-heavy web applications has lead to a huge array of frameworks designed to help us build apps. There are so many that it can often be difficult to choose which best suits our needs. Most frameworks follow roughly what's known as an MVC pattern: model, views and controllers. Models deal with data, fetching it from databases and returning it. Views then display the data, and controllers link the models and views together.

Ember.js

Unlike the other javascript framework, Ember.js does a lot of work for us, such as code to update the view when model data changes. Ember's main features are its data binding; obejcts in Ember can bind properties to each other, so when a property changes in one object, the other is kept in sync. Another is the ability to define functions on an object that can then treat as properties.
Ember also has more traditional controllers. Views (usually written in Handlebars) provide ways of attaching certain buttons or links to Ember controller actions. Ember.js also gives us helpful tools for managing the state while developing the interactive web applications, in a way to scales the applications.

Getting Started

Below are the core concepts that one need to understand before getting started development of Ember.js app.
Templates
A template, written in the Handlebars templating language, describes the user interface of your application. In addition to plain HTML, templates can contain:
    Expressions, like {{firstName}}, which take information from controllers and models, place them into HTML, and automatically keep them updated.
   Outlets, which are placeholders for other templates. As your user moves around your app, different templates can be plugged into the outlet by the router. You can put outlets into your template using the {{outlet}} helper.
    Views, which are responsible for handling user events. You can put views into your templates using the {{view}} helper.
Views
A view is embedded inside a template and is responsible for translating primitive events (like clicks, taps, and swipes) into semantic events that have meaning to your application and are sent to the controller.
For example, a view might translate a click event into the more meaningful deleteItem event, which would be sent to the controller. If the controller does not implement the deleteItem event, the event will be sent to the current route.
Controllers
A controller is an object that stores application state. Templates are connected to controllers and translate the current state of the controller into HTML.
Controllers often act as representations of models for templates. In these cases, the controller passes the properties of the model to the template, and can transform or augment the model to present it in a way the template is expecting.
Models
A model is an object that stores persistent state. This is the data that your application operates on and what gives it value to your users. These objects are usually loaded from your server, then saved back when changes are made on the client.
Usually, you'll use Ember Data to translate the raw JSON payloads delivered by your API server into full-blown Ember.js objects with associations, computed properties, and more.
Router
The router is the object responsible for managing application state.
When your user starts your application, it will look at the URL and make sure that the right set of templates is displayed, as well as pairing those templates with the right model objects.
As you move around the different states of your application, the router automatically keeps the URL up-to-date. Users can save the URL and re-enter the application at this state later, or share the app in its current state with others.

Wednesday, February 6, 2013

Visual Studio Solution Files

Solution and project files are an essential part of working with Visual Studio. A solution is a grouping of one or more projects that work together to create an application. The project and status information pertaining to the solution are stored in two different solution files. 

Solution Files
The first file that Visual Studio creates is the ".sln" (solution) file. This is text-based file and can be placed under source code control and shared between users. This file stores information about the projects that make up this solution, source control settings, and other global settings that apply to all of the projects in the solution. The .sln file contains text-based information the environment uses to find and load the name-value parameters for the persisted data and the project VSPackages it references. When a user opens a solution, the environment cycles through the preSolution, Project, and postSolution information in the .sln file to load the solution, projects within the solution, and any persisted information attached to the solution. Each project's file contains additional information read by the environment to populate the hierarchy with that project's items.

The second file is the ".suo" (solution user options) file, which stores user settings such as the location of your breakpoints. This file is stored in binary format. As this file contains user-specific information, it cannot be placed under source code control. The solution user options (.suo) file is a structured storage, or compound, file stored in a binary format. It is a hidden file in the same path as the .sln file

TIP: The simple resolution for the error "The project file has been moved renamed or not on your computer", is to delete ".suo" file. Visual Studio will create a new one when you open the solution and save it when you close the IDE. By deleting the file, you will lose any of your user-specific settings like breakpoints.


Thursday, January 31, 2013

ASP.NET MVC

ASP.Net MVC provides an alternative to Web Forms for building web applications on the .Net platform. As an alternative to Web Forms, ASP.Net MVC takes a different approach when it comes to structuring web applications. This means user won't deals with ASPX pages and controls, postbacks or view state, or complicated event lifecycles. Instead, user has to define controllers, actions, and views.
Benefits of ASP.Net MVC
  • Closer to the protocol
    While ASP.Net Web Forms attempts to completely hide the stateless nature of HTTP, ASP.Net MVC doesn't. The model is also drastically simplified - gone are the complex page lifecycle events of Web Forms, and the abstractions over HTTP are minimal.
  • Separation of concerns
    While ASP.Net Web Forms tightly coupltes the user interface to its code-behind, ASP.Net MVC encourages a design where the user interface (the view) is kept seperate from the code that derives it (the controller).
  • Testability
    By separating applicaiton logic from the user interface, ASP.Net MVC makes it easier to test individual components in isolation. Unlike Web Forms, MVC controllers do not have a direct dependency on the infamously untestable HttpContext class and instead rely on an abstraction, which makes it far easier to write automated unit tests.
Whats new in ASP.Net MVC 3/4
MVC 3 and 4 comes with many improvements and several new features in addition to the new dependency on .Net 4. These new features include
  • The Razor view engine
  • Package management with NuGet
  • Improved extensibility
  • Global action filters
  • Dynamic language features
  • Partial page output caching
  • Ajax improvements
  • Enhancements to the validation infrastructure
  • Mobile templates
  • Web API

Wednesday, January 30, 2013

Could not load file or assembly... or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Few time we encounter the "Could not load file or assembly... or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" error while working on ASP.Net.
Error Description:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Resolution: delete temporary asp.net files in -
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\

This will resolve the problem. You don't to re-install anything.

Tuesday, January 29, 2013

Use of Extension Method in NVelocity

NVelocity is a .Net-based template engine. It permits anyone to use the simple yet powerful template language to reference objects defined in .Net code. NVelocity is a port of the excellent Apache Jakarta Velocity project for .NET platform. It is a very simple, easy to learn and extensible template engine.
Library: 
  • NVelocity.dll
  • NVelocityTemplateEngine.dll
Below example shows how to incorporate dynamic content from xml file to simple text file. Consider we have "customer.xml" and  "customer.vm" files as:

customer.vm
Loop :

List of Customer Details:
#foreach($customer in $helper.MakeCollection($root.testdocument.ListOfCustomerDetail.CustomerDetail))
UID: $customer.UID
Language: $customer.Language
BusinessUnit: $customer.BusinessUnit
#end

List of Leads:
#foreach($customer in $helper.MakeCollection($root.testdocument.ListOfLeadDetail.CustomerDetail))
UID: $customer.UID
Language: $customer.Language
BusinessUnit: $customer.BusinessUnit
#end

customer.xml
<?xml version="1.0" encoding="UTF-8"?>
<testdocument>
  <ListOfCustomerDetail>
    <firstname>hello</firstname>
    <CustomerDetail>
      <UID>1</UID>
      <Language>English</Language>
      <BusinessUnit>ITD</BusinessUnit>
    </CustomerDetail>
    <CustomerDetail>
      <UID>2</UID>
      <Language>English</Language>
      <BusinessUnit>Eolution</BusinessUnit>
    </CustomerDetail>
    <CustomerDetail>
      <UID>3</UID>
      <Language>English</Language>
      <BusinessUnit>Continuty</BusinessUnit>
    </CustomerDetail>
  </ListOfCustomerDetail>
  <ListOfLeadDetail>
  <firstname>hello</firstname>
    <CustomerDetail>
      <UID>1</UID>
      <Language>English</Language>
      <BusinessUnit>ITD</BusinessUnit>
    </CustomerDetail>
    <CustomerDetail>
      <UID>2</UID>
      <Language>English</Language>
      <BusinessUnit>Eolution</BusinessUnit>
    </CustomerDetail>
    <CustomerDetail>
      <UID>3</UID>
      <Language>English</Language>
      <BusinessUnit>Continuty</BusinessUnit>
    </CustomerDetail>
  </ListOfLeadDetail>
</testdocument>

Here, XML document contents are converted into Json Object. This Json object then registered with the NVelocity context.

Similarly to access the extension method inside the template, we have to register Helper class instance with the NVelocity context. We have to make helper class non-static for this.
using System;
using System.Globalization;
using System.IO;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NVelocity;

namespace NvelocityTest
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("customer.xml");

            JObject jobject = JObject.Parse(JsonConvert.SerializeXmlNode(doc.DocumentElement).ToString());

            NVelocity.VelocityContext context = new NVelocity.VelocityContext();
            context.Put("helper", new Helper());
            context.Put("root", jobject);
          
            NVelocity.App.Velocity.Init();

            NVelocity.Template template = NVelocity.App.Velocity.GetTemplate("customer.vm");

            StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);

            template.Merge(context, writer);

            Console.WriteLine(writer.ToString());

            Console.ReadKey();
        }
    }

    public class Helper
    {
        public JArray MakeCollection(JObject value)
        {
            string text = "[" + value.ToString() + "]";
         
            return JArray.Parse(text);
        }

        public JArray MakeCollection(JArray value)
        {
            string text = value.ToString();

            return JArray.Parse(text);
        }
    }
}

Wednesday, January 2, 2013

Happy New Year


Cheers to a new year and another chance for us to get it right.

Monday, October 29, 2012

Understanding the SQL Server Reporting Services

History of Reporting Services:
Initial development began in 2000. Below Figure-1 tracks in chronological order the major events that have shaped Reporting Services. The black milestones represent the reporting technologies that Microsoft acquired to enhance Reporting Services.
Figure-1 : The Reporting Services history
Components of Reporting Servies:
  • Report Server : At the heart of the Reporting Services architecture is the report server, a web-based middle-tier layer that receives incoming report requests and generates reports. The Figure-2 shows a simplified logical view of the report server. To facilitate integration with external client applications, the report server provides two communication interfaces: URL access and a Web service. Consequently, both off-the-shelf and custom tools can communicate with the report server via HTTP or SOAP. The Report Processor component of the report server is responsible for processing the reports at run time.
Figure-2 : The major Reporting Services components
  • Report Server Database : In Reporting Services, report definitions and properties are saved in the report server database. The report server database is implemented as two SQL Server databases that get installed when you configure the report server. The report server database is a logical term for two physical databases: ReportServer and ReportServerTempDB. The ReportServer database hosts the report catalog. It stores the report definitions and management settings. The ReportServerTempDB stores temporary information about the report execution.
Reporting Services supports two deployment modes.
  • Native mode (default) : The report server as a stand-alone application server that provides all processing and management capability exclusively through Reporting Services components.
  • SharePoint mode : The report server is integrated with Windows SharePoint Services or Microsoft Office SharePoint Server. Report viewing and management happens inside the SharePoint portal.
Report Definition Language (RDL) is an XML-based schema for defining reports. RDL is an open standard proposed by Microsoft to promote interoperability of commercial reporting products.
Reporting Services Architecture:
Figure-3 : The Reporting Services Service hosts the three report server applications: Report Manager, Report Server Web Service, and Background Processor
  • Report Manager : Report Manager is an ASP.NET web application that provides report management and viewing capabilities for a Reporting Services instance configured in native mode. You can view Report Manager as a client application that integrates with the report server.
  • Report Server Web Service : The Report Server Web service handles on-demand report processing. The Report Server Web service is the primary programmatic interface for custom applications that integrate with Reporting Services. The Report Server Web service provides four Web service endpoints that expose the Reporting Services feature set to external clients.
  • Background Processor : The Background Processor application is responsible for handling all tasks that run in an unattended mode.