Perfil de ambatiProgramming Myself.. Amb...FotosBlogListasMás ![]() | Ayuda |
|
29 junio MVP vs MVChttp://ameleta.spaces.live.com/blog/cns!5F6316345A821420!163.entry MVP vs MVC Model View Presenter vs Model View Controller Intro It’s important to understand that in n-tier systems MVP/C patterns are responsible for the presentation layer only. It’s not about how you build data or services layers, it’s about separating the data (model) and the user interface(view), telling you how the user interface communicates with data. Using these patterns gives your application independence on changing presentation without depending on data and controlling logic. Generally: 1. Model means data & business logic model. It’s not always a DataSet, DataTable or such stuff. It’s kind of components or classes which can provide data and can receive the data to store it somewhere else. To simplify understanding of Model just think about it as “Façade” class. The main point of the MVC/P pattern is to split Model from View/Controller to make Model independent from them. So, Model cannot contain the references to the V/C. What is the MVC (model-view-controller)? Primary points are: 1. View does not use Controller to update Model. Controller handles the events from View to manage user’s interaction and data (via interaction with Model) The example below illustrates the “Active-MVC” pattern, also known as “the original MVC pattern”. There is also the “Passive-MVC” pattern. The differences are that:
And now we are close to MVP pattern. In the MVP View and Model are utterly separated from each other using the Presenter. Any interaction between View and Model take place in Presenter. Presenter is like the Controller, but which:
So, MVP has following pros: But there are cons: Also you need to understand that if you render too much data for View you are tied up on the particular View. So if View needs to be changed you need to update the Presenter either, For example, if you rendered html and need to render the pdf, there is a big possibility that View need to be changed too. Do Windows speakDo Windows speak
System.Speech.Synthesis; {
And that's all what you are need to hear a nice Hi World message!
· .NET Framework 3.0 · Visual Studio 2005 · Visual Studio 2005 extensions for .NET Framework 3.0 http://www.microsoft.com/downloads/details.aspx?familyid=5D61409E-1FA3-48CF-8023-E8F38E709BA6&displaylang=en#Overview to be able to add .NET 3.0 references to a project. · Speech SDK (which is also included into Windows Vista SDK (http://www.microsoft.com/downloads/details.aspx?familyid=4377f86d-c913-4b5c-b87e-ef72e5b4e065&displaylang=en) 28 junio Endpoints .. Expose a stored procedure as webservice(Part I)Yesterday I spoke with my friend (RaviKumar Palanivel) and colleague in Caritor(now Keane). After general discussions we discussed about the project NewCastle. We used WCF extensively there.And it is becoming as complex ntier application. So they thought of using Endpoints that came newly in sqlserver 2005.
How to expose a sqlserver stored procedure as webservice and consuming it in a windows application? By using Enpoints in sqlserver 2005 we can achieve this easily. Its a nice discussion with him. Then I started some R&D and done a sample application. Result is this: For Creating EndPoints:
Coming Articles1. How to expose a sqlserver stored procedure as webservice and consuming it in a windows application? 2. Sqlserver Notification services 3. MARS 4. SMO
27 junio Yellow Screen of DeathWhat is "Yellow Screen of Death "?
The yellow screen of death is the screen displayed by Mozilla-based applications when it meets XML parsing error. This happens when the XML document is not well-
formed, such as missing closing tag.
santhosh says: The yellow screen of death is the colloquial name given to an Exception report screen generated by ASP.NET.
The screen displays the exception message and a stack trace with a yellow
background. If the application was running in debug mode it also displays source
-code locations in the stack-trace. If the website employed inline server code
then it also displays the source code causing the error.
It is the ASP.NET Unhandled Expcetion Page http://www.ardentdev.com/blog/index.php/2007/05/14/giant-yellow-screen-of-death/ Anonymous Delegates Part2 (Suggested By Gaurav)
1. Basics of anonymous methodsAnonymous methods is a new language feature in C# 2.0. The focus of this article is to provide the readers with a better understanding of the internal implementation and working of anonymous methods. This article is not intended to be a complete language feature reference for anonymous methods. Anonymous methods allow us to define a code block where a delegate object is acceptable. This facility saves us an extra step of creating a delegate for small code blocks that we want to pass to a delegate. It also removes the cluttering of small methods in the class code. Let us say, for instance, that we have a public class MyCollection
{
public delegate bool SelectItem(string sItem);
public string[] GetFilteredItemArray(SelectItem itemFilter)
{
List<string> sList = new List<string>();
foreach(string sItem in m_sList)
{
if (itemFilter(sItem) == true) sList.Add(sItem);
}
return sList.ToArray();
}
public List<string> ItemList
{
get
{
return m_sList;
}
}
private List<string> m_sList = new List<string>();
}
We can write code as shown below to use the above defined class: public class Program
{
public static void Main(string[] args)
{
MyCollection objMyCol = new MyCollection();
objMyCol.ItemList.Add("Aditya");
objMyCol.ItemList.Add("Tanu");
objMyCol.ItemList.Add("Manoj");
objMyCol.ItemList.Add("Ahan");
objMyCol.ItemList.Add("Hasi");
// get an array of string items in the collection that start
// with letter 'A'
//
string[] AStrings = objMyCol.GetFilteredItemArray(FilterStringWithA);
Console.WriteLine("----- Strings starting with letter 'A' -----");
foreach(string s in AStrings)
{
Console.WriteLine(s);
}
// get an array of string items in the collection that start
// with letter 'T'
//
string[] TStrings = objMyCol.GetFilteredItemArray(FilterStringWithT);
Console.WriteLine("----- Strings starting with letter 'T' -----");
foreach(string s in TStrings)
{
Console.WriteLine(s);
}
}
public static bool FilterStringWithA(string sItem)
{
if (sItem[0] == 'A')
return true;
else
return false;
}
public static bool FilterStringWithT(string sItem)
{
if (sItem[0] == 'T')
return true;
else
return false;
}
}
One can see that for each simple criteria we want to provide, we should define a method (static or instance). This soon clutters the class code. With anonymous methods, the code becomes much natural. Below is the class public class Program
{
public delegate void MyDelegate();
public static void Main(string[] args)
{
MyCollection objMyCol = new MyCollection();
objMyCol.ItemList.Add("Aditya");
objMyCol.ItemList.Add("Tanu");
objMyCol.ItemList.Add("Manoj");
objMyCol.ItemList.Add("Ahan");
objMyCol.ItemList.Add("Hasi");
// get an array of string items in the collection that start
// with letter 'A'
//
string[] AStrings = objMyCol.GetFilteredItemArray(delegate(string sItem)
{
if (sItem[0] == 'A')
return true;
else
return false;
});
Console.WriteLine("----- Strings starting with letter 'A' -----");
foreach (string s in AStrings)
{
Console.WriteLine(s);
}
// get an array of string items in the collection that start
// with letter 'T'
//
string[] TStrings = objMyCol.GetFilteredItemArray(delegate(string sItem)
{
if (sItem[0] == 'T')
return true;
else
return false;
});
Console.WriteLine("----- Strings starting with letter 'T' -----");
foreach (string s in TStrings)
{
Console.WriteLine(s);
}
}
}
As shown in the above sample, we were able to define the criteria with in-line code blocks instead of defining a new method to represent each criteria. Truly speaking, using such inline code may look natural and avoid defining new methods, but if this technique is used for larger inline code blocks, then the code soon becomes unmanageable and may lead to duplications. So, be selective in using methods vs. inline anonymous methods as delegates/event handlers. Now, this is the basics of anonymous methods. The rest of the article deals with how anonymous methods work internally in different scenarios. Understanding how anonymous methods are implemented and work internally is important for their correct usage. Else, the results of your code using anonymous methods will look unpredictable. 2. Static data member usage with anonymous methodsAnonymous methods always start with a When you compile the above sample, the C# compiler creates two private static methods inside the class '
If we had used any static data of the ' 3. Instance data member usage with anonymous methodsLet us define a new instance method in the ' public class Program
{
public delegate void MyDelegate();
public static void Main(string[] args)
{
// Instance Data Member test
//
Program p = new Program();
for(int i=1;i<=5;i++)
p.TestInstanceDataMembers();
}
public void TestInstanceDataMembers()
{
MyDelegate d = delegate
{
Console.WriteLine("Count: {0}",++m_iCount);
};
d();
}
public int m_iCount = 0;
}
We defined a new instance method,
4. Local variable usage with anonymous methodsBy now, we have a basic understanding of how anonymous methods work and are internally implemented. Ultimately, C# creates private methods to wrap anonymous methods. And these method signatures match that of the delegate that they are being assigned to. Now, let's take a look at the code below: public class Program
{
public delegate void MyDelegate();
public static void Main(string[] args)
{
int iTemp = 100;
MyDelegate dlg = delegate
{
Console.WriteLine(iTemp);
};
dlg();
}
}
According to what we have learned about anonymous method till now, this code should not compile. Because we are not using any instance data members, the C# compiler should create a private static method in the ' Let us enter the advanced world of anonymous methods. An anonymous method has the capability of encapsulating the values of the surrounding variables that are used inside its method body. This encapsulation applies to all the variables that are local to the method in which the anonymous method is defined. When the C# compiler identifies the usage of a local variable within the body of an anonymous method, it does the following:
So during compilation, the code above will be transformed by the C# compiler as shown below: public class Program
{
private class InnerClass
{
private void InstanceMethod()
{
Console.WriteLine(iTemp);
}
public int iTemp;
}
public delegate void MyDelegate();
public static void Main(string[] args)
{
InnerClass localObject = new InnerClass();
localObject.iTemp = 100;
MyDelegate dlg = new MyDelegate(localObject.InstanceMethod);
dlg();
}
}
As shown in the above pseudo-code, the C# compiler generates a private inner class for the '
The local variables that are used in the anonymous methods have life outside the regular method in which they are used. This technique, in other languages, is popularly known as closures. Apart from the simple syntax convenience that anonymous methods provide, closures is one powerful technique that anonymous methods provide a developer. This technique allows the delegate handler code (anonymous method) access to the local variables within the regular method scope in which it is being defined. This allows out-of-band data, data other than the delegate parameters, to be passed on to the delegate, which can be used during its method execution. Without this technique, each delegate and its corresponding handler method has to declare parameters that represent the local contextual data, which may become un-manageable over time. 5. Scoping and local variable usage with anonymous methodsWe discussed about the implementation of anonymous methods within the main scope of a method. When an anonymous method is defined within a nested scope, and individual scope level local variables are used inside the anonymous method, C# creates a private inner class for each scope. For instance, let scope 1 has local variable public class Program
{
public delegate void MyDelegate();
public static void Main(string[] args)
{
MyDelegate dlg = null;
int iTemp = 100;
if (iTemp > 50)
{
int jTemp = 200;
dlg = delegate
{
Console.WriteLine("iTemp: {0}, jTemp: {1}",iTemp,jTemp);
};
}
dlg();
}
}
When the above code is compiled, the C# compiler creates two inner classes within the ' public class Program
{
// Class wrapping local variable 'iTemp' from the
// outer scope
//
private class InnerClassScope1
{
public int iTemp;
}
// Class wrapping local variable 'jTemp' from the
// inner scope and anonymous method
//
private class InnerClassScope2
{
public void InstanceMethod()
{
Console.WriteLine("iTemp: {0}, jTemp: {1}",
localObjectScope1.iTemp, jTemp);
}
public InnerClassScope1 localObjectScope1;
public int jTemp;
}
public delegate void MyDelegate();
public static void Main(string[] args)
{
MyDelegate dlg = null;
InnerClassScope1 localObject1 = new InnerClassScope1();
localObject1.iTemp = 100;
if (localObject1.iTemp > 50)
{
InnerClassScope2 localObject2 = new InnerClassScope2();
localObject2.localObjectScope1 = localObject1;
localObject2.jTemp = 200;
dlg = new MyDelegate(localObject2.InstanceMethod);
}
dlg();
}
}
As shown in the above code, the inner class that wraps the anonymous method will have objects for all the inner classes that represent the outer scope local variables, which are used in its anonymous method, as public data members. The below image shows the ILDASM view of the inner classes that are silently created by the C# compiler:
6. Local variable usage with anonymous methods within loop control structuresThe encapsulation of local variables into class data members has an interesting but dangerous side effect when dealing with loop control structures. Let us take a look at the code shown below: public class Program
{
public delegate void MyDelegate();
public static void Main(string[] args)
{
MyDelegate d = null;
for (int i = 1; i <= 5; i++)
{
MyDelegate tempD = delegate
{
Console.WriteLine(i);
};
d += tempD;
}
d();
}
}
What will be the output when the above code is run? Our intention is to capture the loop counter variable ' 1
2
3
4
5
But if you run the above code, the output will be as follows: 6
6
6
6
6
If we carefully recall our knowledge of the inner workings of anonymous methods, I mentioned that any local variable captured within the anonymous method would be replaced by an instance data member of a newly created inner class for that scope. For the loop control variable, the scope is the scope containing the To overcome this issue and achieve the expected results, the anonymous method should capture a local variable within the scope of the public class Program
{
public delegate void MyDelegate();
public static void Main(string[] args)
{
MyDelegate d = null;
for (int i = 1; i <= 5; i++)
{
int k = i;
MyDelegate tempD = delegate
{
Console.WriteLine(k);
};
d += tempD;
}
d();
}
}
When you run the above code sample, the output would be as expected, i.e.: 1
2
3
4
5
The reason is that, the C# compiler would create the instance of the inner class wrapping the local variable ' 7. SummaryAnonymous methods are a very useful and powerful addition to C# 2.0 language. Apart from introducing some syntactic sugar to the delegate declaration and usage, Microsoft has gone to great lengths in making the anonymous method code mix naturally into the containing method body, including access to the local variables within the scope of the containing method definition. Finally, I hope that this article provides C# developers with insight required to utilize anonymous methods correctly and intelligently. Anonymous Methods Part IThe implementation of anonymous methods in C# and its consequences (part 1)You may not even have realized that there are two types of anonymous methods. I'll call them the easy kind and the hard kind, not because they're actually easy and hard for you the programmer, but because they are easy and hard for the compiler. The easy kind is the anonymous method that doesn't use any local variables from its lexically-enclosing method. These are anonymous methods that could have been their own separate member functions; all the anonymization does is save you the trouble of coming up with names for them: class MyClass1 {
int v = 0;
delegate void MyDelegate(string s);
MyDelegate MemberFunc()
{
int i = 1;
return delegate(string s) {
System.Console.WriteLine(s);
};
}
}
This particular anonymous method doesn't access any class MyClass1_converted {
int v = 0;
delegate void MyDelegate(string s);
// Autogenerated by the compiler
static void __AnonymousMethod$0(string s)
{
System.Console.WriteLine(s);
}
MyDelegate MemberFunc()
{
int i = 1;
return __AnonymousMethod$0;
// which is in turn shorthand for
// return new MyDelegate(MyClass1.__AnonymousMethod$0);
}
}
All the compiler did was give your anonymous methods a name and use that name in place of the " On the other hand, if your anonymous method used the class MyClass2 {
int v = 0;
delegate void MyDelegate(string s);
MyDelegate MemberFunc()
{
int i = 1;
return delegate(string s) {
System.Console.WriteLine("{0} {1}", v, s);
};
}
}
The anonymous method in class MyClass2_converted {
int v = 0;
delegate void MyDelegate(string s);
// Autogenerated by the compiler
void __AnonymousMethod$0(string s)
{
System.Console.WriteLine("{0} {1}", v, s);
}
MyDelegate MemberFunc()
{
int i = 1;
return this.__AnonymousMethod$0;
// which is in turn shorthand for
// return new MyDelegate(this.__AnonymousMethod$0);
}
}
So far, we've only dealt with the easy cases. The transformation is local and not particularly complicated. These are the sorts of transformations you could make yourself without too much difficulty in the absence of anonymous methods. The hard case is where things get interesting. The body of an anonymous method is permitted to access the local variables of its lexically-enclosing method, in which case the compiler needs to keep those variables alive so that the body of your anonymous method can access them. Here's a sample anonymous method that accesses local variables from its lexically-enclosing method: class MyClass3 {
int v = 0;
delegate void MyDelegate(string s);
MyDelegate MemberFunc()
{
int i = 1;
return delegate(string s) {
System.Console.WriteLine("{0} {1} {2}", i++, v, s);
};
}
}
In this example, the anonymous method prints "1 v s" the first time it is called, then "2 v s" the second time it is called, and so on, with the integer increasing by one. (And where class MyClass4 {
int v = 0;
delegate void MyDelegate(string s);
MyDelegate MemberFunc()
{
int i = 0;
MyDelegate d = delegate(string s) {
System.Console.WriteLine("{0} {1} {2}", i++, v, s);
};
i = 1;
return d;
}
}
the behavior would be the same as in When faced with this "hard" type of anonymous method, wherein variables are shared with the lexically-enclosing method, the compiler generates a helper class: class MyClass3_converted {
int v = 0;
delegate void MyDelegate(string s);
// Autogenerated by the compiler
class __AnonymousClass$0 {
MyClass this$0;
int i;
public void __AnonymousMethod$0(string s)
{
System.Console.WriteLine("{0} {1} {2}", i++, this$0.v, s);
}
}
MyDelegate MemberFunc()
{
__AnonymousClass$0 locals$ = new __AnonymousClass$0();
locals$.this$0 = this;
locals$.i = 0;
return locals$.__AnonymousMethod$0;
// which is in turn shorthand for
// return new MyDelegate(locals$.__AnonymousMethod$0);
}
}
Wow, there was a lot of rewriting this time. A helper class was created to contain the local variables that were shared between the Notice that the assignment to Those who have done a good amount of C++ programming (or C# 1.0 programming) are well familiar with this technique, since C++ callbacks typically are given only one context variable; that context variable is usually a pointer to a larger structure that contains all the complex context you really want to operate on. C# 1.0 programmers went through a similar exercise. The "hard" type of anonymous method provides syntactic sugar that saves you the hassle of having to declare and manage the helper class. If you thought about it some, you'd have realized that the way it's done is pretty much the only way it could have been done. It turns out that most computer programming doesn't consist of being clever or making hard decisions. You just have one kernel of an idea ("hey let's have anonymous methods") and then the rest is just doing what has to be done, no actual decisions needed. You just do the obvious thing. Most programming consists of just doing the obvious thing. Okay, so that's a quick introduction to the implementation of anonymous methods in C#. Mind you, this information isn't just for your personal edification. It's actually important that you understand how these works (and not just treat it as "magic"), because lack of said understanding can lead to subtle programming errors. We'll look at those types of errors over the next few days. 23 junio Links for learning LINQ,WebParts,SilverLightLINQ
====== http://www.infoq.com/news/LINQ-Examples http://channel9.msdn.com/tags/LINQ http://weblogs.asp.net/scottgu/archive/2006/08/27/Building-and-using-a-LINQ-for-SQL-Class-Library-with-ASP.NET-2.0.aspx http://weblogs.asp.net/scottgu/archive/2007/05/29/linq-to-sql-part-2-defining-our-data-model-classes.aspx lazy loading http://weblogs.asp.net/scottgu/ SilverLight =========== http://msdn2.microsoft.com/en-us/silverlight/default.aspx http://msdn2.microsoft.com/en-us/library/bb404709.aspx http://oakleafblog.blogspot.com/search/label/Sample%20Code http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx http://msdn2.microsoft.com/en-us/vcsharp/aa336758.aspx http://blogs.msdn.com/jomo_fisher/archive/2005/09/13/464884.aspx http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx http://groups.msn.com/DotNETIndia/netarticle.msnw?action=get_message&mview=0&ID_Message=69&LastModified=4675540631178398107 http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx Asp.Net 2.0 webparts and Spring.Net ==================================== http://quickstarts.asp.net/QuickStartv20/aspnet/doc/webparts/intro.aspx http://www.ondotnet.com/pub/a/dotnet/2005/01/10/liberty.html http://www.springframework.net/doc-1.1-P3/reference/html/validation.html http://www.springframework.net/doc-1.1-P3/reference/html/aop-quickstart.html 22 junio What is SCRUM· Scrum is an iterative, incremental process for developing any product or managing any work. It produces a potentially shippable set of functionality at the end of every sprint (iteration). It's attributes are: a) Scrum is an agile process to manage and control development work. b) Scrum is a team-based approach to iteratively, incrementally develop systems and products when requirements are rapidly changing c) Scrum is a process that controls the chaos of conflicting interests and needs. d) Scrum is a way to improve communications and maximize co-operation. e) Scrum is a way to detect and cause the removal of anything that gets in the way of developing and delivering products. f) Scrum is a way to maximize productivity. g) Scrum is scalable from single projects to entire organizations. Scrum has controlled and organized development and implementation for multiple interrelated products and projects with over a thousand developers and implementers. Scrum is a way for everyone to feel good about their job, their contributions, and that they have done the very best they possibly could.
Referenced from Prakash J webblog Videos & Podcasts on Microsoft technologiesVideos, Podcasts on Microsoft TechnologiesI have recently prepared a list of Videos, Podcasts sites on Microsoft Technologies known to me. Add up the sites you know .NET Rocks - .NET Rocks! is twice a week talk show for anyone interested in programming on the Microsoft .NET platform. The shows range from introductory information to hardcore geekiness. The show is hosted by CarlFranklin & Richard Campbell. The best show by far in the .NET World. Check out the shows Archive.
18 junio Bdotnet Session 16th Jun 2007Security Session:
1. For input and data validation use regular expressions .One can get good help from http://regexlib.com/default.aspx
2. For protecting viewstate use HMACs. Referred article : http://channel9.msdn.com/wiki/default.aspx/Channel9.ASPNET2SecurityFAQ0029
3. He gave session by referring this article: http://msdn2.microsoft.com/en-us/library/ms998258.aspx
4. Microsoft Anti-Cross Site Scripting Library V1.0
DataBase migration tool:
Microsoft SQL Server Migration Assistant (SSMA)
15 junio Microsoft ESrum"Many development teams inside Microsoft are now using the agile methodology for software development and had been looking for a way to track their daily progress. http://blogs.msdn.com/somasegar/archive/2007/06/13/escrum-1-0.aspx 14 junio c# 3.5 new featureshttp://dotnetwithme.blogspot.com/2007/05/what-new-in-net-35.html ASP.NET
Base Classes & CLR
Others
C#3.0 features* What's New in CSharp 3.0
Here is a point wise summary of features introduced newly in C# 3.0 http://dotnetwithme.blogspot.com/2007/05/what-new-in-csharp-30.html Implicitly Typed Local Variables
Object & Collection Initializers
Extension Methods
Anonymous Types
Lambda Expressions
Auto-Implemented Properties
Hacking Site
http://www.iimi-iris.com/iris/irising/klueLESS Getting master pages things in Content pagesEvents in Master page / Content Pages When you work with master pages and content pages, both can use the same events (such as Page_Load).Be sure you know which events come before others. You are bringing two classes together to create a singlepage class, and a specific order is required. When an end user requests a content page in the browser, the event ordering is as follows: Master page child controls initialization: All server controls contained within the master page are first initialized. Content page child controls initialization: All server controls contained in the content page are initialized. Master page initialization: The master page itself is initialized. Content page initialization: The content page is initialized. Content page load: The content page is loaded (this is the Page_Load event followed by the Page_LoadComplete event). Master page load: The master page is loaded (this is also the Page_Load event). Master page child controls load: The server controls on the master page are loaded onto the page. Content page child controls load: The server controls on the content page are loaded onto the page. How to access master page controls from content pages Consider the following scenario Master Page <%@ master language="C#" %> <html> <head id="Head1" runat="server"> <title>Master Page</title> </head> <body> <form id="Form1" runat="server"> <table id="header" style="WIDTH: 100%; HEIGHT:80px" cellspacing="1" cellpadding="1" border="1"> <tr> <td width="100%" style="TEXT-ALIGN: center"> <asp:label runat="server" id="Header"> This is the default header in the MasterPage</asp:label> </td> </tr> </table> ------------------------------------------------------------------------------------- Content Page <%@ page language="C#" master="~/ExposeHeader.master" %> <script runat="server"> void Page_Load(object sender, System.EventArgs e) { Label headerLabel = (Label) Master.FindControl("Header"); // Header is my master page label id. headerLabel.Text = "This label content is set through the Page_Load event of the child page"; } </script> Here I am using Master.FindControl with the master page control's id (The identifier for the control to be found). Find control will search the current naming container for a server control with the specified id parameter. It returns the specified control or null if the specified control does not exist. |
|
|