Microsoft Study Bible

November 12, 2009

The improvement of VS 2010 and .NET 4.0 code Intellisense

The improvement of VS 2010 and .NET 4.0 code Intellisense
Today ,we will talk about the a small but really nice improvement to VS 2010 code intelligent hints with VS 2010 that better filter type and complete the member code ,which will make you more easily find and use APIs when writing code.
Code Intellisense with VS 2008
To show how improve code Intelisense of VS 2010, let us look at a example in VS 2008 where we want to write some code to enable an editing scenario with a GridView control. Maybe we start to type”GridView1.Edit”to bring up intellisense to see what Edit members there are in this control. It will bring up the intellisense drop-down box which move the current location into the members whose initial letters are “Edit”:

11

It was OK if we would like to use the initial letters of the method/property/event that are “Edit”. However, if the initial letters of the “Edit ” members we are looking for are other words such as “RowEditing” event or “SetEditRow()” helper method, this will can not be helpful for us .We have to either manually scroll up and down looking for the other edit members, or pull up the object browser or help system to find them.
Code Intellisense with VS 2010
Now,let us try out the above example in Visual Studio 2010。When we start to type “GridView1.Edit”, we’ll find that the EditIndex property is still highlighted by default. But the intellisense list has also been filtered so that it enables you to quickly locate all other members that have the word “Edit” anywhere in them:

21
This allows us to quickly see all of the edit related methods/properties/events and more quickly find what we are looking for.
Searching for Keywords
This new intellisense filtering feature of VS 2010 is useful for searching for any member – regardless of what word it starts with.  For example, if we want to enable paging on a datagrid and can’t remember how to-do it, we could just type “GridView1.Paging” and it would automatically filter out everything but members that have the word paging.  Notice below how no members on the GridView class actually start with the word “Paging” – but I am still finding the two members that do have paging in them later in their names.

31

Searching for Types
This new intellisense filtering capability of VS 2010 is also useful for quickly finding classes and types. For example, when we type “List” to declare a variable, the editor will provide automatic filtering to show all types that have the word “List” somewhere in them (including IList<> and SortedList<> – which do not start with List):
41

This makes it much easier to find type names you can’t entirely remember – without having to resort to searching through the object browser and/or using help documentation.
Pascal Case Intellisense
The .NET Framework naming guidelines specify that type and member names should be “Pascal Cased” by default.  This means that each word in a type or member should start with a capitalized letter (for example: PageIndexChanged). 
VS 2010’s intellisense filtering support now enables you to take advantage of this to quickly find and filter methods based on their pascal naming pattern.  For example, if we typed “GridView1.PIC” VS 2010 would filter to show us the members that have PIC in their name, as well as those members which have a pascal cased name where the word segments start with that letter sequence:

51

Notice above how PIC caused both “PageIndexChanged” and “PageIndexChanging” to show up.  This saves us a few keystrokes when resolving either member or type names.
Summary
I think you’ll find that the new intellisense filtering approach in VS 2010 makes it easier to quickly find and use classes and members when writing code.  You can take advantage of it with both VB and C#.
Hope this helps
This is from http://weblogs.asp.net/scottgu/archive/2009/10/22/vs-2010-code-intellisense-improvements-vs-2010-and-net-4-0-series.aspx

October 20, 2009

How to operate UI layer control state In C#

Filed under: Developer tools and applications — Tags: , , , — Jackson @ 5:40 am

Suppose that there is a form F, which has a button BtnA and a Label control.

Requirements: click the button BtnA and display the status in Label according to the Start() method .

The resolution is to use the delegate or event .Let’s look at the following codes:

The form code:

private void BtnA_Click(object sender, EventArgs e)
  
{
   A ms = new A();

ms.SetInfo += new EventHandler(ms_SetInfoTwo);
   Thread m = new Thread(new
ThreadStart(ms.Start));
   m.Start();

}

private delegate void mySetInfo(string s);
   void SetInfoOne(string
s)
  
{
   if (this
.InvokeRequired)
  
{
   this.Invoke(new
mySetInfo(SetInfoOne), s);
   return
;
  
}
   this
.Label1.Text = s;
   }

// event

void ms_SetInfoTwo(object sender, EventArgs e)
  
{
   if (this
.InvokeRequired)
  
{
   this.Invoke(new
System.EventHandler(ms_SetInfoTwo), sender);
   return
;
  
}
   this.Label1.Text = (string
)sender;
   }

Class A:

public class A
   {

public event EventHandler SetInfo;

private void SetSourceInfo(object sender, EventArgs e)
  
{
   if (SetInfo!= null
) { SetInfo(sender, e); }
   }

public dSetSourceInfo tt;
   public delegate void dSetSourceInfo(string str);

private void SetSourceInfott(string str)
  
{
   if (tt != null
) { tt(str); }
  
}
   public
A() { }
  

   /**////

/// Start

public void Start()
   {

SetSourceInfo(“hahaha”,null);
   Thread.Sleep(1000
);
   SetSourceInfo(“hahaha1″,null
);
   Thread.Sleep(1000
);
   SetSourceInfo(“hahaha2″,null
);
  
}
   }

September 18, 2009

How to Attain NIC MAC address with C# code??

Filed under: Developer tools and applications — Tags: , — Jackson @ 5:20 am

It’s known to everyone that the NIC MAC address could be gotten, when we input the command “ipconfig /all” in DOS and run it.

However, what about the detailed codes?? And how to intercept the output stream by running a dos command in C#?

The detailed codes will be shown below:

C# code

 tbResult.Text = “”;

 ProcessStartInfo start = new ProcessStartInfo(”Ping.exe”);

 start.Arguments = txtCommand.Text;// Setting Command Parameters

 start.CreateNoWindow = true;//no show DOS command prompt window

 start.RedirectStandardOutput = true;

 start.RedirectStandardInput = true;

 start.UseShellExecute = false;

 Process p=Process.Start(start);

 StreamReader reader = p.StandardOutput;//intercept the output stream

 string line = reader.ReadLine();//read one line every time

 while (!reader.EndOfStream)

 {

 tbResult.AppendText(line+” “);

 line = reader.ReadLine();

 }

 p.WaitForExit();//exit when the programs finish executing

 p.Close();//close process

 reader.Close();//close the stream

 

August 31, 2009

Visual Web Developer Express vs Visual Studio 2008?

I am currently reading Beginning ASP.NET with C# and it recommended using Visual Web Developer Express(VWD).But ,I have a battery of questions.Could I use Visual Web Developer Express for all the projects I am planning to do in Visual Studio 2008?Can the Free Express edition satisfy my needs?Or, Is there a need to buy Visual Studio even though I have a VWD?Could you tell me What I can do or can not when I just use the Visual Web developer Express 2008?

If you read this ,do you still recommended me to use UWDE,or any reasons ?
However,I was just thinking about what the Express version lacks ,compared with the Visual Studio.

1.Not Extensibile with other add-ons or third party tools.If I use Visual Web Developer 2008 Express Edition ,I can’t install and use Web Application Projects ,CSS Properties Window,HTML/ASP.net Spell Spell Checker, ReSharper etc like the third party tools.
2.Can not add a Class Library project. If you want to add a Class Library project or a Web Controls Library project to the solution,to be surprised ( Class libraries are popular way to sharing business logic code or any other utility code. ),you can not manage it . Because VWD Express 2008 only supports a single type of project: Web site.Also,VWD 2008 SP1 allows Web Application and Class Library Projects in the solution.
3.Lack of Source Code Control,while a good Source Code Control system can provide us with change history ,branches ,merges ,etc.SCC is key for a professional developer in team development.
4. no Accessibility checker.It is indispensible for you to develop Web sites that must be accessible.
5.Lack of the ability for automatic generation of resources for localization.This means that your Web can not be localized in multiple languages.
6.You want to attach debugger to a process in VWD Express ,sorry you can’t.For example,when you need to step through code in existing classic ASP pages in order to understand how it works or you have to maintain classic ASP pages, you need ASP debugging which requires ability to attach debugger to a running process, the Visual Web Developer Express Edition can not help you .
7. No Native code debugging.For example ,some legacy code, especially in classic ASP code may be using COM objects written in C++. Mixed mode debugging is not supported in Express.
8.Not support opening or editing SharePoint Web sites.
So much you can not do ,maybe you will give up the free Express edition.You will find Visual Studio 2008 more favorable.

However,VWD Express 2008 still has its merits.
The obvious advantage of VWD over VS2008 is that it is free and if you can work smart with it given the missing features, it may be the more pragmatic option for you. If those are features that you can’t live without, VS2008 may be a wise investment - you also get all of the features missing from other Express products (Visual Basic 2008, Visual C# 2008, etc).

In addition,Visual Web Developer Express 2008 is a free web tool that allows you to build CSS, HTML ASP.NET, C#, VB, and JavaScript and supports additional frameworks like ASP.NET MVC, AJAX, Silverlight and jQuery.

So,what should I choose ?Or,I can have a cake and eat it too ?

August 21, 2009

How to backup and recover database in C#??

Here, we well introduce a way to backup and recover database in C#: use SQL DMO.

Most SQL Server administrative tasks are programmable thanks to a set of objects known as SQL-DMO. Distributed Management Objects (DMO) is a set of programmable objects that come with SQL Server that make it easy to programmatically administer your databases. SQL-DMO is actually the foundation of Enterprise Manager, so you can pretty much do anything programmatically that you can do in the management tools. Some of these tasks include:
•1. Scripting Objects
•2. Backing up databases
•3. Creating jobs
•4. Altering tables
5. Recover database
… … much more.
SQLDMO is from SQL.DLL of Microsoft SQL Server. Because SQL.DLL is a com object, we had to add the reference to SQL.DLL in .net before it was used.
So, we start to introduce a class written in C#, which is used to backup and recover the Microsoft SQL Server:
using System;
namespace DbService
{
///
/// DbOper Object , primarily use SQLDMO to backup and recover Microsoft SQL Server database ///
public sealed class DbOper
{
///
/// the constructor of the object DbOper
///
private DbOper()
{
}
///
/// backup database
///
public static void DbBackup()
{
SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(”localhost”, “sa”, “1234″);
oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = “Northwind”;
oBackup.Files = @”d:Northwind.bak”;
oBackup.BackupSetName = “Northwind”;
oBackup.BackupSetDescription = “Recover Database”;
oBackup.Initialize = true;
oBackup.SQLBackup(oSQLServer);
}
catch
{
throw;
}
finally
{
oSQLServer.DisConnect();
}
}
///
/// Recover Database
///
public static void DbRestore()
{
SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(”localhost”, “sa”, “1234″);
oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
oRestore.Database = “Northwind”;
oRestore.Files = @”d:Northwind.bak”;
oRestore.FileNumber = 1;
oRestore.ReplaceDatabase = true;
oRestore.SQLRestore(oSQLServer);
}
catch
{
throw;
}
finally
{
oSQLServer.DisConnect();
}
}
}
}

Powered by WordPress

Close
E-mail It