Thursday, May 29, 2008

Structures in C#

Structures:

 

Points:

1. Its a value type so if we assign a value to another struct then it is stored at two different point in the stack.

2. We cannot have a explicit empty constructor in a structure.

3. Structure cannot have constructors that do not completely initialize all the variables in it.

4. There is a 16 byte size limit to structure's instance. All value types are 16 bytes or shorter.

5. It is logically a single value.

6. It will not be cast to a reference type.

7. If a copy of a structure is passed to another procedure or function then the original will not change after the call. This is because a copy is passed to that procedure or function.

8. Value types are far more efficient then reference types however there is a instance size limit.

Strategy Pattern Part-2.

Tried to create the strategy pattern example as a vehicle that can fly or a drive on the road.
Intreastingly the go method that is implemented in each of the vehicle sub classes is not hard coded into the subclass itself.
That means that a car go method is not very different from a helicopter go method. And here is the kicker: The method is not implemented in the car and vehicle classes.

The go method is instead created in an interface.
So whats the big idea? We could as well create an interface and then implement it there.

ah but the interface is implemented in two classes GoDriving class and GoFlying class.

The abstract Vehicle class has a method that takes in an interface and decides what function to call. And then takes that interface and decides what go method to call.

Its easy to understand because an interface in the Vehicle class is replced by the actual class(goFlying or goDriving is used) that implements that interface in the car class. Then the go method of

And all that is there in the car class is a call to GoDriving class to intantiate a variable.
The helicopter class therefore has only a call to GoFlying. This ensures that the go method can be modified without modifying the Car and Helicopter classes.

The advantage becomes apparent when there is a huge number of classes and they may keep changing over time.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

public interface goInterface
{
void goMethod();

}

class goDriving : goInterface
{

#region goInterface Members

void goInterface.goMethod()
{
System.Console.WriteLine("Go Driving");
}

#endregion
}

class goFlying : goInterface
{
#region goInterface Members

public void goMethod()
{
System.Console.WriteLine("Go Flying");
}

#endregion
}

public abstract class Vehicle : goInterface
{
public goInterface travelMode;
public void setTravelMode(goInterface x)
{
travelMode = x;
}
public void goMethod()
{
travelMode.goMethod();
}


}

public class Car : Vehicle
{
public Car()
{
goDriving drx = new goDriving();
setTravelMode(drx);
}


}

public class AeroPlane : Vehicle
{


}



class Program
{
static void Main(string[] args)
{
Car x = new Car();
x.goMethod();
System.Console.ReadLine();
}

}
}

Why use design patterns

1. they are a quick and easy way to benefit from the knowledge of others.
2. There is no point in reinventing the wheel.

Have been reading some books to increase my awareness of the subject.
Design Pattern in C# by Steven John
and Design Patterns for dummies.
The dummies book is in java so that is fine.

Strategy Design Pattern

Strategy Design Pattern:
Have been reading Strategy design pattern from various books including Design Patterns in C# and Design Pattern for dummies.

Use when there is a section of code that will change frequently.
1. Instead of modelling is a relationship

like Class Vehicle
then Class car:Vehicle
        Class plane:Vehicle,

        We do class Vehicle:IDriving;
                so car:Vehicle, IDriving
                and plane:Vehicle, IDriving
           which is not so good because if something changes then it has
           to be changed in each class file.


                               so

1. Create a n interface that the subclasses will use
        in this case

 public Interface Igo{
                        public void  go();
                                              
                        }


2  public class goDriving: Igo
  {

   go(){
   System.Console.Writeline("Driving");
   }

  }
3.
  public class goFlying: Igo
  {

   go(){
   System.Console.Writeline("Flying");
   }

  }


4.
  public abstract class Vehicle
  {
     private Igo goMethod;
          
  }


Database Access in ADO.NET

Database Access in ADO.NET

Data providers:  Set of classes that allows us to
access a particular database, execute commands and
retrieve/update data.

Data providers generally have the following classes
1. Connection   : use to connect
2. Command      : used to execute commands or stored procs
3. DataReader   :Object that provides read only,forward
only access
4. DataAdapter  :Object that is used to populate the
dataset(disconnected tables). Or used to apply changes
to  a database.

There are four providers
1. SQL Server Provider  : Access to sql server
2. OLE DB Provider      :Access to data sources which
provide ole db drivers
3. Oracle provider              : Optimized access to Oracle
database.
4. ODBC provider                :access to an odbc data source.


Try Catch Throw

Throw Catch Exceptions
1. Try the block
2. Catch the exception.
3. Cleanup any remaining issues within the finally section.

Filtering Exceptions: We can use multiple catch for a single try section.
Only the first catch will be executed and then it will switch to finally.

The finally section cannot access variables declare in the try section.

If we want to create a variable declaration and make sure that it is cleaned
up even if an error occurs, then use the "using" keyword.

Tuesday, May 13, 2008

Asp.Net

Say wonder what is the need of the reusable property in i http
handler? It enables sharing of the instance with other requests so
what? Whats the advantage in using that?

--
Sent from Gmail for mobile | mobile.google.com

Wednesday, April 30, 2008

Trying to join a group.

--
Sent from Gmail for mobile | mobile.google.com

Storm aftermath

After the storm last night, the power is back up again. Its amazing
how fast things moved.

--
Sent from Gmail for mobile | mobile.google.com

Tuesday, April 29, 2008

Newspapers

Is the print media dead? Has everyone moved to online tools and online news?

--
Sent from Gmail for mobile | mobile.google.com

Travel

Travelled from bang to mad on the weekend. Took 350 for the taxi. It
was not too good. Temperature there was hot. The humidity gets you
when you are in the open. Wonder how the local people deal with the
heat. I guess they stay indoor in the afternoon.

--
Sent from Gmail for mobile | mobile.google.com

Pizza and power

There was a huge storm in the city today. As a result the power is
out. The more immediate reason is a huge part of a tree which fell on
a power line and took half of the cables with it. So no power and
without power there is no water too. Hmm so things dont look so rosy.
Its a nice thing my wife is not here right now. I wonder when will
they restore the power. Have drinking water that will last three days.
Not enough water to bath in though. Plus there are the mosquitoes to
be dealt with. Fun i guess.

--
Sent from Gmail for mobile | mobile.google.com

No power

No power in the house. There was a storm.

--
Sent from Gmail for mobile | mobile.google.com

Biog

Test

--
Sent from Gmail for mobile | mobile.google.com

Monday, July 03, 2006

my stuff

my stuff
The last post details how to send email without Outlook, using WEBDAV and Microsoft Exchange. The code is in C#.

my stuff

my stuff
using System.Diagnostics;using System.Net;using System.IO;using System;
namespace IndirectTimeFrontEnd{ /// /// Summary description for RamakantMailControl. ///
namespace RamakantMail { /// /// Summary description for Class1. /// class RamakantMailContro { public void sendMail() { // TODO: Replace with the name of the computer that is running Exchange 2000. string strServer = "server.com"; // TODO: Replace with the sender's alias. string strSenderAlias = "username"; // TODO: Replace with the sender's e-mail address. string strFrom = "sendercompleteEmail"; // TODO: Replace with the recipient's e-mail address. string strTo = "Reciever Complete Email";
string strSubject = "Send Using HttpWebRequest"; string strBody = "Hello World";
string sUri; sUri = "https://" + strServer + "/exchange/" + strSenderAlias; //sUri = sUri + "/%23%23DavMailSubmissionURI%23%23/"; sUri = sUri + "/Drafts/a.eml/test_file.zip";
System.Uri myUri = new System.Uri(sUri); HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);
string sQuery; DateTime mySentTime = new DateTime(); sQuery = "From: " + strFrom + "\n" + "To: " + strTo + "\n" + "Subject: " + strSubject + "\n" + "Date: " + DateTime.Now.ToString() + "\n" + "X-Mailer: My DAV mailer" + "\n" + "MIME-Version: 1.0" + "\n" + "Content-Type: application/zip;"+"\n" + "name=\"test_file.zip\"" + "\n" + //"Content-Type: text/plain;" + "\n" + "Charset = \"iso-8859-1\"" + "\n" + "Content-Transfer-Encoding: 7bit" + "\n" + "\n" + strBody + "."; Debug.WriteLine(myUri);
// Set the credentials. // TODO: Replace with the appropriate user credential. NetworkCredential myCred = new NetworkCredential(@"ramakant", "s56^"); CredentialCache myCredentialCache = new CredentialCache(); myCredentialCache.Add(myUri, "BASIC", myCred); HttpWRequest.Credentials = myCredentialCache;
// Set the headers. //HttpWRequest.Headers.Set("Translate", "f"); // HttpWRequest.ContentType = "message/rfc822"; HttpWRequest.ContentType = "application/zip"; HttpWRequest.ContentLength = sQuery.Length;
//Set the request timeout to 5 minutes. HttpWRequest.Timeout = 300000; // Set the request method. HttpWRequest.Method = "PUT"; HttpWebResponse HttpWResponse1 = (HttpWebResponse)HttpWRequest.GetResponse();
// Store the data in a byte array. byte[] ByteQuery = System.Text.Encoding.ASCII.GetBytes(sQuery); HttpWRequest.ContentLength = ByteQuery.Length; Stream QueryStream = HttpWRequest.GetRequestStream(); // write the data to be posted to the Request Stream QueryStream.Write(ByteQuery,0,ByteQuery.Length); QueryStream.Close();
// Send the request and get the response. HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
// Get the Status code. int iStatCode = (int)HttpWResponse.StatusCode; string sStatus = iStatCode.ToString(); Debug.WriteLine("Status Code: {0}", sStatus); // Get the request headers. string sReqHeaders = HttpWRequest.Headers.ToString(); Debug.WriteLine(sReqHeaders);
// Read the response stream. Stream strm = HttpWResponse.GetResponseStream(); StreamReader sr = new StreamReader(strm); string sText = sr.ReadToEnd(); Debug.WriteLine("Response: {0}", sText); //Debug.ReadLine();
// Close the stream. strm.Close();
// Clean up. myCred = null; myCredentialCache = null; HttpWRequest = null; HttpWResponse = null; QueryStream = null; strm = null; sr = null; } } } }

Wednesday, March 15, 2006

New Camera

got a new video cam, will post the webdav version of Email here soon.
Am also working on a CRM tool that can be customized and adapted to various users.

Monday, May 16, 2005

dataview as a datasource

DataView dv = new DataView();
//Dataview and the stuff
dv.Table=ds.Tables[0];
dv.RowFilter="age=20";
DataGrid1.DataSource=dv;

Wednesday, May 11, 2005

creating a pop up calendar control in ASP.net

the following links seems to be a viable option for a postback less date popup http://www.developer.com/net/asp/article.php/3327181

Sunday, March 27, 2005

new liks

here is a few things that i like on the net
its a link that contains an extended datagrid that allows custom controls in a grid.
http://dotnet.leadit.be/extendeddatagrid/

some c# faqs that i like
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q1075q