Saturday, November 19, 2016

CSLA Framework Overview

Hello Guys,

Today i was trying to understand CSLA Framework written by Rockford Lhotka, thought would be nice to share with you guys. Also i am working on one of the basic CRUD app using CSLA framework so i will post it soon here too.

What is Business Objects - as CSLA is business object based framework?

In traditional 3 tier programming you have three logical layers or tiers. You have a presentation layer which is the User Interface, the bottom layer would be the database layer. The middle layer would be the business objects layer. As pointed out above the business objects should be abstracted in that the site might not be about business at all. It is a layer of abstraction that makes it easier to make changes to the presentation layer or to switch to a different data source.

If your user interface level has no or very little code behind it. It makes it easier for designers to work with programmers. The designers can change the look and feel of the site without the programmers having to do a substantial rewrite of the code that makes that site work. With the business objects layer you do the heavy listing of the site. You make calls into the database layer without the business object knowing whether your database layer is in XML or relational database. And the business object layer then would update a response to the UI layer. Typically the example used is for a bank transaction. In the user interface a client enters the amount he would like to transfer from his savings account to his checking account.

The business object layer will contain the business rules for the bank . That means it will check the balance of the users savings account and make sure the amount to transfer does not exceed the balance of the account. The business layer will contain the classes that actually calculate the new balances for both the savings account and the checking account and it will alert the database layer to update the database.

What is CSLA(Component-based Scalable Logical Architecture) Framework ?

CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.The framework enables developers to leverage the power of object-oriented design as the basis for creating powerful applications. Business objects based on CSLA automatically gain many advanced features that simplify the creation of Windows, web, service, and mobile interfaces.

CSLA .NET allows great flexibility in object persistence, so business objects can use virtually any data sources available. The framework supports 1-, 2- and n-tier models through the concept of mobile objects. This provides the flexibility to optimize performance, scalability, security and fault tolerance with no changes to code in the UI or business objects.

What are the Benefits of using CSLA ?

1.CSLA takes away the burden of having to create a large programming infrastructure every time you undertake an enterprise application. Once you buy into CSLA, you never again have to worry about creating remoting architecture, implementing databinding support, or working consistently with hierarchical data in your objects. CSLA provides all the plumbing that you need.

2.We have discovered that once CSLA became our application's development framework, it was very hard for members of the development team to stray too far from the pack in terms of coding style and design implementation. For example, after a while we learned that if we wanted to see how another developer was doing data retrieval, we only needed to look in the object's DataPortal_Fetch()method. Also, the creation of collections of objects and the saving of hierarchical data became a consistent experience. We did not have to devote precious design-time discussion to how we were going to make and support collections. CSLA gives us a roadmap that eventually becomes a design standard.

3.Remember that CSLA stands for Component-based Scalable Logical Architecture. Not to be trite, but Scalability is CSLA's second name. The fact that data source location and network protocol are declarative settings in the app/web.config file provides a lot of leeway when it's time to move an application from working with data by way of a web service, to the faster-running operational environment provided by Enterprise Services. Granted, CSLA isn't magic, but it does reduce overhead in terms of environmental programming.

4.CSLA ships with a bunch of utility objects that make working with the framework a lot easier. Listing 7 demonstrates the use of the ObjectAdapter, one of these objects. The ObjectAdapter will transform a strong-typed collection of CSLA objects into a data source.

What are the cons of CSLA ?

1.Using CSLA is not intuitive. The framework has a considerable learning curve and requires a significant investment of time. You need practice to get the hang of it, particularly to take full advantage of the DataPortal functionality. CSLA is best suited for large projects in a distributed environment that will have a shelf life of many, many years. Mr. Lhotka's books are an excellent resource, but they are filled with detail, and every detail has an implication in terms of application design and writing CSLA code. Keep in mind that skipping a detail in the short term might come back to haunt you later. However, once you've got some skill with CSLA, the savings in heads-down programming time and quality assurance expense are significant.

2.CSLA makes extensive use of the factory design pattern, reflection, serialization, generics, static methods, and programming using abstract classes. These are not beginner's topics. If you're planning to use CSLA, you'll find it advantageous to have at least one experienced person on your development team—someone who can write efficient, effective, advanced object-oriented code in the .NET environment. Otherwise, you run the risk of getting compile-time errors that are difficult to resolve, and runtime behavior that you won't understand.

3.CSLA is a framework, not a methodology—you have to learn it. And it's best to use the framework in the way it is meant to be used. You can use CSLA piecemeal, but in order to get full long-term flexibility and benefit from the framework, particularly in terms of the DataPortal mechanism, it's best to use all the parts of the framework all of the time. Otherwise you run the risk of having to go back and refactor code—definitely antithetical considering that avoiding refactoring down the road is what CSLA is all about.

4.CSLA is comprehensive but not magical. Although its benefit is that a lot of "plumbing" is already in place, you still need to know how to do things such as change an object state from new to old (invokeMarkNew()); how to declare an object as a child of a parent (invoke MarkAsChild()); and how to configure your environment so that a CSLA client application can work with a CSLA application server. These are detail-rich activities. Yet once you learn what you need to, you'll move much more quickly in subsequent iterations of your enterprise application.

Stay tuned for the simple demo of CSLA in near future.

You can explore CSLA here.

And as always thank you for reading guys.









Wednesday, October 26, 2016

My First Bot Using Microsoft Bot Framework

Hello Guys,

I am exploring Microsoft bot framework nowadays and i would like to share some of my experience with you all.

You might have heard about Internet Bots in current time there are many Bot Frameworks are build like Facebook, Microsoft Bot,Hubot,Lita (Chat bots) etc...There are many.

what is a bot exactly?

Generally we do use apps in daily life but apps are mostly one directional communication it works based on your inputs it never thinks. in case of bots generally bots are used with any AI framework so it can think what you want and they can understand your words (mostly).

Siri, Cortana and nowaydas Google Allo is best examples of bots.

what bots can do ?

Generally they can help us ordering food, book a cab,shop for cloths and can find restaurants for us. Many bots are programmed with AI which acts like humans when you talk to them so it feels like asking a person for help instead of just typing in a search engine so in short it is more interactive.


Lets build our first Bot using Microsoft Bot Framework

Prerequisite : 

1. Visual Studio 2015 ( i was facing issues while building my bot in 2012 - not sure why)
2.  Please download Bot Application template from here which will be used to create bot projects in VS. - Download
3. copy that template here : %USERPROFILE%\Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#

Once you are done with above setup you are ready to create your first Bot.

Step 1: Create in new Bot Application in Visual studio.


Step 2; Add Dictionary.cs in your project. Write following code into it.


Step 3: Add Following code in MessagesController.cs



You can play with json object which we are getting and display specific output to user.

Step 4: Update the service X-Mashape key i am using one of the service from there which will give me the meaning of any word i will send to Bot. here

Step 5; Press F5 it will start listening your requests on specific port.



Step 6: Open Microsoft Bot framework simulator which we downloaded in above steps. Please set your app URL as highlighted in below picture. You can host your on cloud as well and you can register your bot at Register your Bot here



That is all your bot is ready to provide you meaning of any English word. In next blog i will be connecting my bot to LUIS to make my bot intelligent. 










Sunday, March 20, 2016

What is Go Lang and How to Setup Go Lang on Windows .!!

What is Go Lang ?

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

You can read more about Go Lang From Here : https://golang.org/

Follow below Steps to Setup Go Lang on Windows Machine :

1.  Download the appropriate go version for your windows (x64 / x86) from here https://golang.org/dl/



2.  Extract downloaded zip.
3. Copy Go folder from extracted folder to C:\Go to make thing easier.
4.Ensure the Go binaries (found in C:\Go\bin) are in your Path system environment variables. To check click System, Advanced system settings, Environment Variables... and open Path under System variables:

Easy way to confirm your path is by typing go version in command line tool.

5.Setup your Go workspace. This consists of three folders at the root: \bin,\pkg & \src.


 6.Create the GOPATH environment variable and reference your Go workspace path. To add, click System, Advanced system settings, Environment Variables... and click New... under System variables:


Set the variable name to GOPATH and value to your Go workspace path (e.g. C:\Projects\Go):

 Check quickly if path has been set correctly or not from command line:

7. Create new file hello.go at C:\Projects\Go\bin directory and write following code into it:


8. That's it you are ready to run your hello world program of go Lang. Just go to your projects folder \bin directory from command line and type go run hello.go.

 

Basics of TypeScript

I was just learning type script and i realized to publish it on internet so any one can easily get it in lay man language:

What is TypeScript ?

As described on official TypeScript website “TypeScript is a typed superset of JavaScript that compiles to plain JavaScript”. TypeScript is not a replacement of JavaScript, it does not add any new features in JavaScript. TypeScript provides developers with features like type safety, compile time type checking, object oriented constructs on top of JavaScript, basically lets developers think in object oriented terms when writing JavaScript. The most amazing thing about TypeScript is, it compiles in JavaScript so we don’t have to support any new VM to run TypeScript which then can be referenced in a web page, used in server side like in NodeJS.

TypeScript is an open-source developed by Microsoft, but is in no way ties to Microsoft platform and can be used anywhere in any environment where there is a need to write JavaScript. Though Microsoft does provide a great support in Visual Studio for TypeScript and we will be using Visual Studio for our examples but we can use TypeScript compiler as well from command prompt to compile TypeScript in JavaScript (we will see a brief example of that as well).

How to install TypeScript ?

Visual Studio has inbuilt support for type script from 2013 and of course any one can install it on 2012 as well. For creating TypeScript Project in Visual Studio 2015 follow below steps:-

1. Click on file-> New->Project-> Select HTML Application With TypeScript From TypeScript Tab.
2. After naming it you will have TypeScript project open which will have app.ts default type script written by Visual Studio and index.html file.


TypeScript file template can be created in similar way as other files are, by selecting “Add New Item” and then selecting a TypeScript file.
All TypeScript files have *.ts extension. Visual Studio plugin for TypeScript automatically creates and updates a corresponding JavaScript file with same name whenever we modify the TypeScript file and save. This generated JavaScript file can then be used as a normal file and included in any web page.

Features Of TypeScript:

Developers can write code in TypeScript which has object oriented concepts and compile time type checking on top of JavaScript which helps writing more structured, maintainable and robust code. TypeScript introduces few of the standard object oriented terms like Classes, Interfaces, Module and Variables which in end gets converted into various different forms of JavaScript.

1.  Module : Module is like a namespace in .Net world and can contain classes and interfaces.


Here Class Comedy is part of Movie module like namespaces in .Net.

2.Interfaces : Developers can create interfaces in type script and implements those in particular class like we are doing in .Net.Compiler will give errors here as well if we are not implementing any member of interface and that is the best feature of type script other wise it is same as java script.


Above is the simple example of interface and its implementation in type script. Interface IStudent has two members Student's yearOfBirth and second one is method which gives us age of student based on yearOfBirth. Here compiler will make sure that methods we are calling from classes has appropriate arguments on all those as we does in .net. When we compile type script interfaces those will go - those will be omitted in actual java script.

3. Classes : Classes are again very similar to .Net/Java world. Classes contains variables, properties and methods which form one logical entity. TypeScript also allows to set scope of the variable and functions with keyword like “private” and “public” though that scope does not have any effect on the JavaScript generated.

In above example we have class Student which has members like firstName ( private) and lastName (public) if we do not specify any access modifier by default it is public in type script. also Constructor can be created using Key word constructor().  When compiler converts type script to java script there is no meaning of Public and private keywords.

4.Functions : Functions are methods which can have logic written in side. in above example FullName is a tyoe script function which alerts fullName of Student.

5. Variables : Variables are the fields defined inside a class or a function. TypeScript allows us to define a variable using keyword “var” and assign a data type to it. Once a data type is assigned any further usage of the variable has to be with same data type else TypeScript will generate error on design and compile time.


Note:
For each of the features in TypeScript we have been relating to corresponding features in OOPs language such as C# and Java but, we need to keep in mind that TypeScript is not a OOPs language. In fact, TypeScript is just a tool on top of JavaScript which provides us with more robust code structure, type safety. TypeScript enhances the productivity of developers writing JavaScript code and it in itself does not provide any specific functionalities or features like libraries such as Jquery.
Most of the features which we use in TypeScript gets removed from the compiled JavaScript file and we are left with nothing more than a pure JavaScript code.

Saturday, February 13, 2016

What is Reflection in C# ?


Reflection is the ability of a managed code to read its own metadata for the purpose of finding assemblies, modules and type information at runtime. In other words, reflection provides objects that encapsulate assemblies, modules and types. A program reflects on itself by extracting metadata from its assembly and using that metadata either to inform the user or to modify its own behavior. Reflection is similar to C++ RTTI (Runtime Type Information), but much broader in scope and capability. By using Reflection in C#, one is able to find out details of an object, method, and create objects and invoke methods at runtime. The System.Reflectionnamespace contains classes and interfaces that provide a managed view of loaded types, methods, and fields, with the ability to dynamically create and invoke types. When writing a C# code that uses reflection, the coder can use the typeof operator to get the object's type or use the GetType() method to get the type of the current instance. Here are sample codes that demonstrate the use of reflection:
Example:

using System; 
using System.Reflection;

 public class MyClass 
  public virtual int Add(int numb1,int numb2) 
   { 
          int result = numb1 + numb2; return result;
    } 

 class MyMainClass 
  public static int Main() 
 { 
     Console.WriteLine ("\nReflection.MethodInfo"); 

    // Create MyClass object 
    MyClass myClassObj = new MyClass();
 
   // Get the Type information. 
   Type myTypeObj = myClassObj.GetType("MyClass");  // we can check which type of class is this

 // Get Method Information.
   MethodInfo myMethodInfo = myTypeObj.GetMethod("Add"); 
 
 object[] mParam = new object[] {5, 10}; 
// Get and display the Invoke method. 

 Console.Write("\nFirst method - " + myTypeObj.FullName + " returns " + myMethodInfo.Invoke(myClassObj, mParam) + "\n"); return 0; 
 } 
}

We can do many things with reflection. Like we can know if property exists in class, class is abstract o not ? , which method have how many parameters ?, we can decide runtime which method to invoke.

For more visit MSDN : https://msdn.microsoft.com/en-us/library/ms173183.aspx

Tuesday, February 9, 2016

What are Strongly Typed Views in MVC



A Strongly Typed view means it has a ViewModel associated to it that the controller is passing to it and all the elements in that View can use those ViewModel properties You can have strongly typed partials as well. Meaning that piece of Html needs specific data so you type it to a certain ViewModel.

 Here is an example of a Strongly Typed View @model SomeViewModel ...// all the html comes after A view that is strongly typed have a @model SomeViewModel line

 Here's one that renders a strongly typed View 

public ActionResult Index()
 {
   var model = new SomeViewModel();
    return View(model); 

And the view makes use of that ViewModel by having the @model SomeViewModel at the top of the file. So now that the view has a ViewModel I can display elements that are bound to the ViewModel like

@Model.Name

@Model.Location

OR for Controls------ @Html.TextBoxFor(m => m.Name) @Html.TextBoxFor(m => m.Location)