Tuesday, December 8, 2009

Log Out Funcationality in ASP.Net

to implement the log out functionality in asp.net application use the following code in the body of log out button event handler

                Session.Clear();
                Session.Abandon();
                Response.Clear();
                Response.Redirect(context.LoginPage);
and to prevent back feature of the browser or accessing the website after log out using the following line

                HttpContext.Current.Response.Cache.SetExpires(DateTime.Now);

Sunday, December 6, 2009

HttpContext in ASP.Net

The HttpContext object in the System.Web namespace encapsulates all of the information related to one request and allows you to access that information within or outside of the actual aspx page that is being processed. 


Let's Check Some Properties about the HttpContext Class: 


The static property Current on the HttpContext class can be useful whenever the flow of control leaves the code in your Page derived web form. Using this property you can reach out and magically grab the current Request, Response, Session, and Application objects (and more) for the request you are servicing





Wednesday, December 2, 2009

Difference Between XML Document & XML Fragment

XML fragments are similar to XML documents, the difference is that they are not in themselves a document. sound strange? the thought is just that an XML fragment is supposed to be part of an XML document, that is it has been taken out of the context of the document, this means that an XML fragment lacks the XML declaration () and does not have to have a root element

Monday, November 30, 2009

Cross Join in SQL

SQL CROSS JOIN will return all records where each row from the first table is combined with each row from the second table. Which also mean CROSS JOIN returns the Cartesian product of the sets of rows from the joined tables.
in other meaning Cross Joins produce results that consist of every combination of rows from two or more tables That means if table A has 3 rows and table B has 2 rows, a CROSS JOIN will result in 6 rows.  There is no relationship established between the two tables – you literally just produce every possible combination.


it is useful if you do lots of report writing in SQL, a CROSS JOIN can be your best friend.
you can create Cross join in two ways 
1. using join keyword 
2. list all the tables in the from clause separated by comma without using where 







Wednesday, November 25, 2009

AND & OR & NOT and its relation with SQL performance

* Using the AND operator typically results in a smaller result set, thus improving performance

* The NOT operator typically hurts performance because the query optimizer cannot use indexes for the where clause when a NOT operator is specified

* For Indexes to be utilized when an OR operator is specified, all columns referenced by the OR condition must be included in an index or none of the indexes are used

Saturday, November 21, 2009

Have Look at Data Type of SQL Server 2008

Character Types

  • The text and ntext types are both deprecated in SQL server 2008 so avoid using them, they have been replaced by varchar(max) and nvarchar(max).


  • The difference between char and varchar is that char is fixed length and varchar is variable length .


  • The advantage of using char over varchar is that updates made to a char column never require moving the row because the data that is entered always fits in the allocated space 


  • What about nchar and nvarchar? both of these data types store characters using the Unicode Universal Code Page (UCS-2). this means that if you use nchar or nvarchar, you can store any type of character regardless of the collation you choose because two bytes are always used to store each character. contrast with varchar and char, which store characters using one or two bytes depending on the collation. 
  • Note that: if you want to use different collation than the one specified on a column when making te comparsion

............  where Name='Mohamed' COLLATE Finnish_Swedish_CI_AS

  • To get all the collations of the SQL Server 2008 by using table valued function fn_helpcollations

Select  *
                        From  fn_helpcollations()

Exact Numbers 

  • Difference between Decimal Types & numeric: 
    • when using the decimal data type, you can specify the precision and scale of values stored using the data type. the precision defines the total number of digits that the data type holds, supporting a maximum precision of 38 and the scale defines how many of  the digits defined by the precision are used as decimals. 


Approximate Numeric Types 

  • the float data type accepts a parameter. the parameter supplied to the float data type defines the number of bits that are used to store the mantissa of the floating point number 

Thursday, November 19, 2009

Pointer in JAVA

The main difference between C++ and JAVA or C# is that C++ has pointers and Java or C# doesn't


in C++
Student bill;
bill = new Student();
bill.GPA = 4.0;


in Java
Student* bill;
bill = new Student;
bill->GPA = 4.0;


Note That
Yes, they are called "reference types". The references point to objects.
You mean that you cannot have objects as values, then yes.
simple data type called Yes, they are called primitive types.
Basically. There is no way to "take the address" of a variable. But you can copy the value of the variable into a field of a wrapper object, which then can be pointed to by a reference.



Difference between Component && Service From Martin Fowler Thinking

Martin Flower Says:


I use component to mean a glob of software that's intended to be used, without change, by application that is out of the control of the writers of the component. By 'without change' I mean that the using application doesn't change the source code of the components, although they may alter the component's behavior by extending it in ways allowed by the component writers.

A service is similar to a component in that it's used by foreign applications. The main difference is that I expect a component to be used locally (think jar file, assembly, dll, or a source import). A service will be used remotely through some remote interface, either synchronous or asynchronous (eg web service, messaging system, RPC, or socket.)

Sunday, November 8, 2009

PONO Plain old .Net object

i read this paragraph in other blog through searching the internet to discover the meaning of the PONO and i want to share this with you: 


I want to enforce that the domain is the core, the centerpiece, the kernel as you may of my application. I don’t want it to have any dependencies to other assemblies in my application, especially not the infrastructure assembly. This means that my domain assembly can only have a reference to the .NET framework assemblies and nothing else.


if domain objects are only made of primitive types, we could call PONO : Plain Old .NET Object in reference to Java POJO orPOCOPlain Old CLR Object. Such convention garantees that domain object are re-usable across layers and potentially increase performance since all these primitive types are CLR-optimized


so in other meaning we can Just say it is a normal class, no attributes describing infrastructure concerns or other responsibilities that your domain objects shouldn't have. POJO's (for java) are just classes which dont force inheritance or any attribute markup to make them "work" in whatever framework you are using.

POCO's are the same, except in .NET.
for example, .Net 3.5 sp1 ORM example: the Entity framework requires that classes inherit from a certain framework class. LINQ to SQL does not have this requirement. Therefore LINQ to SQL works with POCOs and the Entity framework does not
PONO (plain old .net object) is equivalent to POCO (plain old CLR object)

References 
http://codebetter.com/blogs/patricksmacchia/archive/2008/06/30/simple-core-domain-types-and-plain-old-net-objects.aspx



Monday, November 2, 2009

Separartion of Concerns .... thinking about Software Architecture

Concern is any piece of interest or focus in a program, in other meaning it is features or behaviors of the program.
Cross cutting concerns this concern of program which affects other concerns, these concerns often can’t be cleanly decomposed from the rest of the system in both the design and implementation. For example Security, Logging of the system, in other meaning our system won’t work alone with security and logging but with the core business logic concern. So we use cross cutting concern to integrate with core concern to get the overall functionality of the system. At the end we can say that cross cutting concerns likes the secondary concerns where the main business goals will be the primary concerns.
Separation of Concerns is the process of separating a computer program into distinct features (Concerns) that overlap in functionality as little as possible, layered designs in information systems are also often based on separation of concerns (e.g. presentation layer, business logic layer, data access layer, database layer). The goal is to design systems so that functions can be optimized independently of other functions  so that failure of one function does not cause other functions to fail, and in general to make it easier to understand, design and manage complex interdependent systems.
All programming languages apply separation of concern concepts in its architecture like:
·         Object-oriented programming à objects
·         MVC àseparate content from presentation
·         Service oriented design à separate in services
·         Procedural programming à procedures
·         Aspect oriented programming à aspects and objects 

Sunday, November 1, 2009

Const ,Readonly, Static .....Have a Loo0ook

const Keyword

  • A constant member is defined at compile time and cannot be changed at runtime.
  • Constants are declared as a field, using the const keyword and must be initialized as they are declared.
  • Since classes or structures are initialized at run time with the new keyword, and not at compile time, you can't set a constant to a class or structure.
    • for example       public const double PI=3.14 
      • so we the value of PI will be constant through all the application and can't change it and if we try to change it, will give us compilation error 
readonly Keyword 
  • A read only member is like a constant in that it represents an unchanging value
  • The difference is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared.
  • Because a readonly field can be initialized either at the declaration or in a constructor
  • readonly fields can have different values depending on the constructor used
  • readonly member can hold a complex object by using the new keyword at initialization.
  • readonly members cannot hold enumerations.
  • readonly members are not implicitly static, and therefore the static keyword can be applied to a readonly field explicitly if required.

static Keyword 
  • Use of the static modifier to declare a static member, means that the member is no longer tied to a specific object.
  • This means that the member can be accessed without creating an instance of the class
  • static methods and properties can only access static fields and static events
  • The static modifier can be used with classes, fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types other than classes.
  • To access a static class member, use the name of the class instead of a variable name to specify the location of the member.

Thursday, October 22, 2009

MaskedEdit in Ajax To0lKit... take a look

MaskedEditExtender is an ASP.NET AJAX extender that attaches to a TextBox control to restrict the kind of text that can be entered. the supported data formats are: Number, Date, Time, and DateTime


MaskedEditValidator is a custom validator which attaches to the MaskedEdit extender and its associated TextBox and verifies that the input text matches the pattern specified in the MaskedEdit extender.


to get more information please take a look at the following link

Monday, October 5, 2009

Difference Between Count(*) and Count(1) in SQL

Both will be same in terms of performance, as the execution is to retrieve information from the table. You are free to use any constant expression instead of * - you can use COUNT(0), COUNT('a') and even COUNT(NULL) - each with the same results. You can also use a column name as the parameter, but this means that rows with a NULL on that column will not be counted The 'normal' parameter for COUNT is * - in most cases there is no reason to use anything else

Thursday, October 1, 2009

Difference between First() && Single() in LINQ

The difference between First() and Single() methods in LINQ is that First grabs the first item it finds. The Single method expects only a single matching item and will throw an exception if it finds more than one. it is very semi note about the difference and i am preparing a lot about the LINQ and i will publish it in the Following Posts very sooon ... Waaaaaaaaaaaaaaaaaaaaaaiting

Monday, September 14, 2009

Passing Interface & object to Method in .Net

in this post i will illustrate the difference between passing object and interface to method, suppose that we have currency class and implement the interface ICurrency ...... Let's go through the code to discover the difference

public static decimal ExchangeRate(ICurrency FromCurrency, ICurrency targetCurrency)

{

}

public static decimal ExchangeRate(Currency FromCurrency, Currency targetCurrency)

{

}

the difference is so simple -->Using ICurrency in the method signature will allow you to pass any object of a class that implements ICurrency, while using Currency in the method signature will only allow you to pass a Currency object.

For example: If you only want the method signature to accept a System.Data.SqlClient.SqlDataReader object, then you would use that. However, if you wanted it to accept any DataReader object you would use System.Data.IDataReader since all DataReader classes implement System.Data.IDataReader. That is one of the nice things about interfaces





Sunday, June 7, 2009

2 Minute at Resource File in .Net

The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags. One advantage of a .resx file is that when opened with a text editor (such as Notepad or Microsoft Word) it can be written to, parsed, and manipulated. When viewing a .resx file, you can actually see the binary form of an embedded object (a picture for example) when this binary information is a part of the resource manifest. Apart from this binary information, a .resx file is completely readable and maintainable.

Note Do not use resource files to store passwords, security-sensitive information, or private data.

I think the main advantage of using .NET resource file(or resx file) is that you can make full use of the built-in API or coding syntax support. For example, .NET provide "ResourceManager Class" to help you programmatically load resource keys from resource file or resx file. Also, net resource file can be embeded into assembly. If you're using custom xml solution.

If you're using .net resource model(resource file or embeded in assembly), then, you should not change them frequently or dynamically at runtime. Because when .net application running, the resource items will be loaded into memory after it is used, just like it load the required assemblies. Therefore, it won't let you to flexibly update and refresh it immediately if you changed them when the application is running.


you can add multiple such resx files in a project. When you build the project, they will be compiled(as embeded resource) into your assembly(or separate satellite
assemlies that contains resource for specific cultures).

For ASP.NET application, it has some further encapsulated functionality.You can provide a local resource file for each aspx page or serveral global resource files for the entire application. These resource items are easy to reference in your aspx page(both through declarative syntax or programatic code)

Monday, May 25, 2009

Asp.Net Caching Part 1

Caching is a technique that temporarily stores valuable information in server memory so it can be reused.

Caching is often used to store information that's retrieved from a database, so they'll retrieve the information directly from server memory which is a much faster proposition instead of database connection and running query.

The right time to use Caching: 
A good caching strategy identifies the most frequently used pieces of data that are the most time consuming to create, and stores them.
  1. cache data (or web pages) that are expensive--> which uses database or file connection.
  2. cache data (or web pages) that are used frequently 
Caching types in ASP.Net
  1. Output caching-->it stores a copy of the final rendered HTML page that is sent to the client, so when client require the same page, the page isn't executed again and send directly to client.  
  • fragment caching --> instead of caching the HTML for the whole page, it allows you to cache the HTML for a portion of it (like caching user control of certain page)
      2. Data Caching --> carried out manually in your code, store important pieces of information that are time consuming 

  • Data source caching --> caching that's built into the data source controls including the SqlDataSource, ObjectDataSource and XmlDataSource. you simply configure the properties and the data source control manages the caching storage and retrieval. 
BUT NOTE THAT:
Using data caching is conceptually the same as using application state but it is much more server friendly because items will be removed from the cache automatically when it grows too large and performance could be affected.


**TRY Output Caching...
you have two alternatives to carry out output caching 


1. insert outputcache directive at the top to .aspx page 
%@ OutputCache Duration="20" VaryByParam="None" %

* Duration paramter: it is duration which asp.net will cache the page in seconds

2. caching page at client side by insert the outputcache directive with location attribute location = "client"
%@ OutputCache Duration="20" VaryByParam="None" Location="Client" %


*browser caches the page at client side, and client can get it by retype the same link or   back to the page but if the client refresh the page, the page will be abandoned and the                    page will be reqested again from the server.  
*can be useful technique if your cached page uses some sort of personalized data. even   though each user is in a separate session, the page will be created only one and reused for all         clients ensuring that most will receive the wrong greeting.

if the page is receiving information from another page through the query string

*VaryByParam="None" --> tells ASP.Net that ou need to store only one copy of the cached    page which is suitable for al scenarios

*VaryByParam="*" --> to indicate that the page uses the query string and to instruct   ASP.Net to cache separate copies of the page for different query string arguments (i.e.           ASP.Net will examine the query string. if the string matches a previous request and a        cached copy of that page exists, it will be reused)

*VaryByParam="ProductID" && VaryByParam="ProductID;CurrencyType" --> ASP.Net   will examine the query string, looking for the ProductID parameter. Requests with         different ProductID parameters wil be cached separatelym but all other parameters will be    ignored.

i will working on my next blogs to complete full image of ASP.Net Caching methdology to get better web applications performance... any feedback will be welcome......... :D 

Saturday, May 23, 2009

Look at Difference between XmlDocument and XmlDataDocument

The DataSet class in ADO.NET provides the developer with a relational view of data. Using the DataSet, data are stored as tables, which allows for easy retrievals using SQL statements. However, there are times when you need a hierarchical representation of the data, allowing you to perform quick searches using, say, XPath queries. You may also need to transform a set of data into another format using XSLT. In such cases, the .NET framework provides you with the XmlDocument class for this purpose.

However, the DataSet and XmlDocument classes only allow one way of data representation--either you have a relational or hierarchical view, but not both. It is with this purpose that the XmlDataDocument class was designed. The XmlDataDocument class is derived from the XmlDocument class, providing a hierarchical view of data as well as a relational view by binding it to a DataSet. Best of all, it automatically synchronizes the data changes made by either one of the two views. XmlDataDocument provides the best of both worlds--it can manipulate the data using the familiarDataSet, as well as support the various services in the XML classes (such as DOM, XPath, and XSLT). In this case, I will show you how you how to use the XmlDataDocument class

XmlDataDocument Allows structured data to be stored, retrieved, and manipulated through a relational DataSetThis class extends XmlDocument. It enables you to load either relational data or XML data and manipulate that data using the World Wide Web Consortium (W3C) Document Object Model (DOM). The DOM presents data as a hierarchy of node objects. Because XmlDataDocument implements the IXPathNavigable interface, it can also be used as the source document for the XslTransform class.

XmlDataDocument has a close affiliation with the DataSet class, which provides a relational view of the loaded XML data. Any changes made to theXmlDataDocument are reflected in the DataSet and vice versa.
 
And Now let's go through the difference between XmlDocument and XmlDataDocument 

  • XML Document
  1. The XmlDocument, XmlNode and other classes implement the W3C Document Object Model Level 1 Core and the Core DOM Level 2 specifications. 
  2. The XmlDocument is an in-memory (cache) tree representation of an XML document. 
  3. There are different node types specializing from XmlNode to enable you to manipulate the XML document. 
  4. You can get faster, non-cached, forward-only stream access to XML using the XmlTextReader and XmlTextWriter classes
  • XML DataDocument
  1. The XmlDataDocument class provides an in memory cache for XML data. 
  2. The XmlDataDocument extends the XmlDocument class. XmlDataDocument can be used anywhere the XmlDocument class is used. 
  3. There is a close association between the XmlDataDocument and the DataSet classes. In fact, you can regard the XmlDataDocument as a DataSet-aware XmlDocument. 

Friday, May 15, 2009

Jump 1 into WFF, Let's Jump

In the business world, workflow is how an item is moved from one person to another through a process. That process is the business process, and it defines the steps necessary to complete a piece of work. Steps in the process can be required or optional. Let’s spot on the second two business workflow:

For Example, you might have a process that automatically updates a sales order as complete, and sends an e-mail notice to the customer and the sales person when a sales order is shipped.

Another Example, a business process for a vacation request might be that the employee must provide some information, such as the dates requested, to his or her supervisor. Then, the employee's supervisor must determine if the employee has vacation time to use, and if the date or dates requested are available for vacation. The supervisor must provide the date information to the human resources department. Finally, the human resources department verifies that all policies have been followed, and provides the information to accounting at the appropriate time so payroll adjustments can be made.

So in software planet, we try to build solution that fit the business requirements for our customers with different rules & conditions including variety of business workflows. Implementing workflows would require a lot of while loops and if branching but Microsoft introduces a new component in .Net 3.0 framework called workflow foundation (WFF)

Microsoft .Net 3.0 consists of the following component:
  • .Net Framework
  • Microsoft Windows Communication Foundation
  • Microsoft Windows Presentation Foundation
  • Microsoft Windows Workflow Foundation

But why we go for consuming time and effort to learn WFF, The biggest reason to create workflow, is that you're creating a model (like flowchart, UML diagram) but in WFF the model and workflow is the same thing. Finally, WF allows processes to change on the fly. You can change the process while instances of the process are running, and the instances will adhere to the new process.

In this series, we will jump into workflow foundation, and extend our skills to develop business solutions depending on WFF but note that workflow is not an application or a server product, and is included as a component of the .Net 3.0 framework. So once you develop workflow you can host it on any application according to your business requirements such as windows forms, windows services, ASP.Net, web services, console application, and SharePoint server.

You can build workflow by using markup or code or combination between markup and code

Before we start our jump I want to mention the difference between workflow foundation and BizTalk server is WFF is a platform for developing workflow within applications but BizTalk server is a server product targeted for business process automation.

There are two major types of workflows:
  1. Sequential workflows: used for well-defined, process workflows, Sequential workflow is a workflow whose steps are performed one right after the other, but might include branching. Steps in a Sequential workflow don't wait for an external entity to perform the next step.
  2. State Machine workflows: Organized as state machine diagrams, typically used for workflows with human interaction. A state-based workflow means that each step of the flow has criteria that must be met before the flow can continue to the next step. A state-based workflow waits on external entities to perform some action before moving to the next step.