Showing posts with label orcas. Show all posts
Showing posts with label orcas. Show all posts

Thursday, August 14, 2008

Visual Studio 2008 Remote Debugger

With all the great additions Visual Studio team has introduced, there is one more tool which has not gain the attention that it deserves. This tool is Remote Debugger.

Since it talks about remote stuff so there must be some host computer running the debugger and there must be a remote computer running the application. The Debugging monitor (msvmon.exe) is installed on the remote computer. This remote process is then attached to the host computer through Visual Studio 2008 for debugging.

Host computer: Running debugger (Visual Studio 2008)
Remote Computer: Running application to debug and debug monitor (msvmon.exe)

There are two tool installed when Visual Studio 2008 Remote debugger is installed. They are as follows:
1. Visual Studio 2008 Remote Debugger Configuration Wizard
2. Visual Studio 2008 Remote Debugger

The remote debugger is configured through Visual Studio 2008 Remote Debugger Configuration Wizard. This is a separate utility. This tool allows us to specify how remote debugger should be run. Specifically all these questions are answered using this tool.

There are two options to run Remote Debugger.
1. as a service
2. as Windows application

Generally, the first option is used for server applications like ASP.net. Using this option, the one doesn't have to login on the server. We have to specify the username and password whose privileges this service would be using. Since the service is always running, it is not recommended for client applications as it will be always running if this option is used.

Remote debugger also requires some ports to be unblocked. The ports are as follows:
1. TCP port 135 (Used for DCOM)
2. UDP port 450 or 500)

The configuration should allow the remote debugger that it could receive relevant information from the network. There are two options:




The second option would allow the application debugging from outside the local network. This is an excellent option if we want to debug our application running on client side right from our office thousands of miles apart. This is very good option for organizations involved in off-shore development.

Surely we don’t want anyone else to start debugging our application. There are two options for this:
1. We can specify whether this feature is only available to all the users belonging to our local network or debugger may come through a public network. This is configured using Remote Debugger Configuration utility).

2. We can also specify which users / groups have permissions to run the debugger. As shown in the figure:




So this security arrangement is very refined. We can not define rights based on the applications i.e. we can not specify that it can debug Application1 and Application2 but he can not debug Application3.

The remote debugger is not supported in any edition of Visual Web Developer. For the visual studio, it is only supported in Pro and Team editions. This means you cannot run this on Express or Standard editions of Visual Studio 2008.

If your operating system is not configured properly, then the following error message appears:



There are a few questions to answer. The answers will prove to be the configuration setting of the remote debugger feature. The questions are as follows:

1. Should it be running as a service or an application?
2. Will the users on the local network would be debugging application or from any public network?
3. What changes in the network security would be required to allow this?

Wednesday, July 23, 2008

Batch Update ADO .net OPENXML

I wanted to use the Batch Update in one of my project and I explored the following information. This might be of interest to some of you.

I thought that using the Batch update option in .net 2.0 command, I can go with this. This is achieved using the rows in a dataset which are updated using a DataAdapter object. In reality one has to set the UpdateBatch size property to a specific value. But this is not the same. When i started the profiler, the trace showed that each statements are executed individually instead a single Update / Insert statement. When i studied the documentation, it became clear that Microsoft never claimed that a single statement would be executed. It says that a batch of statements are passed to SQL Server instead of individual statement. You can study the following article for further details:

http://msdn.microsoft.com/en-us/library/kbbwt18a(VS.80).aspx

But those who are like me and want that a single Update/ Insert statement is executed instead, have an alternate option. This is through the use of OPENXML feature of SQL Server. All the rows are provided to a stored procedure as a single parameter of XML. The parameter datatype is generally set as NText. For further details, please read the following:

http://en.csharp-online.net/XML_and_ADO.NET%E2%80%94OPENXML

After using this option, when you start your profiler trace, you should be satisfied that there is only a single Update statement being executed.

Are you happy now??

Functional Programming DataTypes F# .net

Functional Programming uses immutable data types. Those who are aware of the difference between String and StringBuilder in .net understand that the first is an immutable datatype but the other is mutable datatype. For those of you who are not familiar with the concept, immutable objects are not allowed to be updated. The updates that you make in the String are basically not the same object but each updated creates a new object and the earlier is presented to be collected and disposed by the runtime.

For compliance with .net, F# supports .net datatypes. But it considers them as mutable datatypes. It also introduces new datatypes, which are immutable ones. So with this we know that there are two categories of datatypes in F#, one is mutable and the other is immutable datatypes.

The immutable datatypes introduced by the language include tuples, records, discriminated unions and lists. A tuple is a collection which can hold more than one values. The number of values should be known at design time. Record is a specialized tuple in which each value may be named e.g. Age = 12. The list is a regular linked list. The discriminated union is like c style unions but it is typesafe. Like C, it defines a type whose instance may hold a value of any of the specified datatypes.

Though F# is a strongly typed language which used type inference. It deduces these datatypes during compilation.

Sunday, June 15, 2008

Some info about Project Velocity CTP-1

Named caches are universal across the cluster.

Regions are local to any cache host.It may limiti the scalibility to the cache cluster.

There are three ports.
1- Cluster Port
2- Aribitration port
3- Cache port

Your application must implement the Cache Aside pattern. i.e. it may support its operation even if data is not available in the cluster or even if any server is not available.It should be able to access data directly from database.

There are two types of clients.
1- Simple:
2- Routing

A simple client has no routing capabilities. It also can not track where each cached object is stored.It can request data from only one cache host. If that host does not hold the data. It gets data from other cache host (if available) and presents it to the client.


Each client also has the option to store cached data locally.This feature is called Local Cache.The type of client is configured in the configuration file.


The configuration in the application, so that clients may access the cluster, is maintained in Application Configuration file (app.config)

The configuration of cluster is maintained in ClusterConfig.xml file. This file presents a single point of failure in Velocity which is not yet taken care of (Till CTP1)


Objects are serialized before they are stored on cache host. Before it is used by the client, it must be deserialized. So it is recommended to have a local cache.

Concurrency Model:
Velocity supports the following concurrency models.
1- Optimistic
2- Pessimistic

Cache Expiration and Eviction:
The expiration is configured on named cache level in ClusterConfig.xml file. A TTL (Time to Live) may be associated with an object at the time of "Put".

Eviction is done by using LRU (Least Recently Used) algorithm.

Tuesday, June 10, 2008

Sample code for FTP client using System.net (FTPWebRequest)


Imports System.Text
Imports System.Net
Imports System.IO

Public Class FTPClient
Private UserID As String
Private Password As String

Public Sub New(ByVal UserID As String, ByVal Password As String)
Me.UserID = UserID
Me.Password = Password
End Sub

Public Sub uploadFile(ByVal URI As String, ByVal UploadFileName As
String, ByVal LocalPath As String, ByVal LocalFileName As String, Optional
ByVal FTPUserID As String = "", Optional ByVal FTPPassword As String = "")
Dim completePath = LocalPath + "/" + LocalFileName
Dim fileInf As FileInfo = New FileInfo(completePath)

If UploadFileName = "" Then
UploadFileName = LocalFileName
End If

If FTPUserID = "" Then
FTPUserID = Me.UserID
End If

If FTPPassword = "" Then
FTPPassword = Me.Password
End If

Dim MyURI As String = URI + "/" + UploadFileName



Dim reqFTP As FtpWebRequest


Dim buffLength As Integer = 2048
Dim buff(buffLength) As Byte
Dim contentLen As Integer

Dim response As FtpWebResponse = Nothing

Dim fs As FileStream = fileInf.OpenRead()
Dim strm As Stream = Nothing

Try
reqFTP = CType(FtpWebRequest.Create(New Uri(MyURI)),
FtpWebRequest)
reqFTP.Credentials = New NetworkCredential(FTPUserID,
FTPPassword)
reqFTP.KeepAlive = False
reqFTP.Method = WebRequestMethods.Ftp.UploadFile
reqFTP.UseBinary = True
reqFTP.ContentLength = fileInf.Length
reqFTP.UsePassive = True

response = CType(reqFTP.GetResponse(), FtpWebResponse)

strm = reqFTP.GetRequestStream()
contentLen = fs.Read(buff, 0, buffLength)

While (contentLen <> 0)
strm.Write(buff, 0, contentLen)
contentLen = fs.Read(buff, 0, buffLength)
End While
Finally
strm.Close()
fs.Close()
response.Close()
End Try
End Sub


Public Function GetFileList(ByVal URI As String, Optional ByVal
FTPUserID As String = "", Optional ByVal FTPPassword As String = "") As
String()
Dim downloadFiles() As String
Dim result As StringBuilder = New StringBuilder()
Dim reqFTP As FtpWebRequest = Nothing
Dim response As WebResponse = Nothing
Dim reader As StreamReader = Nothing

If FTPUserID = "" Then
FTPUserID = Me.UserID
End If

If FTPPassword = "" Then
FTPPassword = Me.Password
End If

Try
reqFTP = CType(FtpWebRequest.Create(URI), FtpWebRequest)
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential(FTPUserID,
FTPPassword)
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory

response = reqFTP.GetResponse()

reader = New StreamReader(response.GetResponseStream())

Dim line As String = reader.ReadLine()

While Not line Is Nothing
result.Append(line)
result.Append("\n")
line = reader.ReadLine()
End While

result.Remove(result.ToString().LastIndexOf("\n"), 1)

downloadFiles = result.ToString().Split("\n")
Catch ex As Exception
downloadFiles = Nothing
Finally
reader.Close()
response.Close()
End Try

Return downloadFiles
End Function


Public Sub downloadFile(ByVal Uri As String, ByVal ToDownLoadFileName
As String, ByVal LocalPath As String, Optional ByVal LocalFileName As
String = "", Optional ByVal FTPUserID As String = "", Optional ByVal
FTPPassword As String = "")
Dim result As StringBuilder = New StringBuilder()
Dim reqFTP As FtpWebRequest = Nothing
Dim response As FtpWebResponse = Nothing
Dim reader As StreamReader = Nothing

Dim ftpStream As Stream = Nothing
Dim outputStream As FileStream = Nothing

If FTPUserID = "" Then
FTPUserID = Me.UserID
End If

If FTPPassword = "" Then
FTPPassword = Me.Password
End If

If LocalFileName = "" Then
LocalFileName = ToDownLoadFileName
End If

Try
outputStream = New FileStream(LocalPath + "\\" + LocalFileName,
FileMode.Create)
reqFTP = CType(FtpWebRequest.Create(Uri + "/" +
ToDownLoadFileName), FtpWebRequest)
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential(FTPUserID,
FTPPassword)
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile


response = CType(reqFTP.GetResponse(), FtpWebResponse)
ftpStream = response.GetResponseStream()

Dim cl As Long = response.ContentLength
Dim bufferSize As Integer = 2048

Dim readCount As Integer
Dim buffer(bufferSize) As Byte
readCount = ftpStream.Read(buffer, 0, bufferSize)

While readCount > 0
outputStream.Write(buffer, 0, readCount)
readCount = ftpStream.Read(buffer, 0, bufferSize)
End While
Finally
ftpStream.Close()
outputStream.Close()
response.Close()
End Try
End Sub
End Class

Monday, May 26, 2008

Sample Code Word 11.0 Object Library

Just add the reference of Microsoft Word 11.0 Object library and play with the following code by putting in your method:


Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();

ApplicationClass myWordApp = new ApplicationClass(); // our application


object nothing = System.Reflection.Missing.Value; // our 'void' value

object filename = "C:/TestDoc/TestDot.dot"; // our word template

object destination = "C:/TestDoc/MyNewDocument.doc"; // our target filename

object notTrue = false; // our boolean false


myWordApp.Visible = false;

doc = this.myWordApp.Documents.Add(ref filename, ref nothing, ref nothing, ref nothing);


doc.WebPagePreview();


doc.SaveAs(

ref destination,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing,

ref nothing);