Advertuse

Search This Blog

Your Ad Here

Friday, 26 September 2008

.NET 3.0

.net 3.0 is nothing but the extension of .net 2.0 with following features
  • WWF - ( Window Work Foundation)
  • WCF - ( Window communication Foundation)
  • WPF - ( Window Presentation Foundation)
  • Silverlight( WPF/E)
  • Window Cardspace

  1. WWF ( Window Work Foundation)
WWF stand for Window Work Foundation. It is also know as workflow. It is a set of activities that stored as model that describes a real-word process. It is further divide as follow.
  • Activity Model
  • Workflow Designer
  • Workflow Runtime
  • Rules Engine
Activity Model
Activities are the building blocks of workflow, They are added to a workflow programmatically in a manner similar to adding XML DOM child nodes to a root node. When all the activities in a given flow path are finished running, the workflow instance is completed.
An activity can perform a single action, such as writing a value to a database, or it can be a composite activity and consist of a set of activities. Activities have two types of behavior: runtime and design time. The runtime behavior specifies the actions upon execution. The design time behavior controls the appearance of the activity and its interaction while being displayed within the designer

  • Workflow Designer: This is the design surface that you see within Visual Studio, and it allows for the graphical composition of workflows, by placing activities within the workflow model. You can find a screenshot of designing a sequential workflow here. One interesting feature of the designer is that it can be re-hosted within any Windows Forms application. Check out this article on MSDN to see how you can do this.
  • Workflow Runtime: Our runtime is a light-weight and extensible engine that executes the activites which make up a workflow. The runtime is hosted within any .NET process, enabling developers to bring workflow to anything from a Windows Forms application to an ASP.NET web site or a Windows Service.
  • Rules Engine: Windows Workflow Foundation has a rules engine which enables declarative, rule-based development for workflows and any .NET application to use. Here is an article which outlines the capabilities of the rules engine.

Wednesday, 30 July 2008

How to Download Embedded SWF files using Firefox

Hi Friends,


fllowing are the few steps to download embedded swf files using Firefox.



Step 1 : open the site which has embedded swf file





Step 2 : click on tool --> Page Info


.

Step:3 In Page Info click on media tab, and select embeed file and click on save as button.


Tuesday, 29 July 2008

Style button

hi friends,


Here i have develop a style button for winform in C#.net 2.0.


it is look like below images












to download it dll click below link
stylebutton.dll
and I will give full detail in next post

Tuesday, 27 May 2008

OOPS in Javascript for C#.NET developer

There three basic concept we found in OOPs
  1. Encapsulation (प्रावरण) (સંપુટીકરણ )
  2. Inheritance (धरोहर) (ધરોહર)
  3. Polymorphism (बहुरूपता ) (બહુરુપતા)
  • Encapsulation

Encapsulation conceals the functional details of a class from objects that send messages to it.
e.g. the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private in C#. Because JavaScript is not a statically typed language, it does not provide a keyword for defining a class or object-type definition. Additionally, because JavaScript is not compiled, there would be no way to enforce the proper use of such types. However, it is still possible to define custom objects in JavaScript that behave, in many ways, like classes in C# .

// C# Pet class
public class Pet
{ private string name;
public Pet(string name)
{
this.name = name;
}
public string GetName()
{
return name;
}
}

consume the C# code

Pet p = new Pet("Max");
System.Console.WriteLine(p.GetName());

// JavaScript Pet class
function Pet(name)
{
this._name = name;
}
Pet.prototype._name;
Pet.prototype.getName = function()
{
return this._name;
}

consume javascript class

var p = new Pet("Max");
alert(p.getName());

  • Inheritance
    Inheritance in object-oriented programming allows developers to define an "is a" relationship between classes. For example, we might want to extend our object model to define slightly more specialized versions of the Pet class: Dog and Cat. The base class, Pet, will contain any properties or methods shared by all Pets, but Dog and Cat may define additional properties or methods applicable only to instances of those classes. For example, our Dog class will provide a wag tail method, and the Cat class will provide a purr method.

// C# Dog class
public class Dog : Pet
{
public Dog(string name) : base(name)
{
}
public void WagTail()
{
// Wagging
}
}
// C# Cat class
public class Cat : Pet
{
public Cat(string name) : base(name)
{
}
public void Purr()
{
// Purring
}
}

consume C# code

Dog d = new Dog("Max");
d.WagTail();
Cat c = new Cat("Fluffy");
c.Purr();

// JavaScript Dog class
function Dog(name)
{
Pet.call(this, name);
}
Dog.prototype = new Pet();
Dog.prototype.wagTail = function()
{ // Wagging
}
// JavaScript Cat class
function Cat(name)
{
Pet.call(this, name);
}
Cat.prototype = new Pet();
Cat.prototype.purr = function()
{ // Purring
}
consume javascript code
var d = new Dog("Max");
d.wagTail();
var c = new Cat("Fluffy");
c.purr();

call() is a built-in JavaScript function that is used to invoke a specific target function in the context of a specific object. In this case, we are invoking the Pet constructor function in the context of the Cat or Dog instance. In other words, when Pet() is called, the implicit JavaScript variable will refer to the instance of Cat or Dog that is being constructed.

  • Polymorphism

Polymorphism refers to the ability of a caller to invoke a particular method or set of methods on an object without regard to the object's type. For example, we might want to add a speak() method to our Pet class, to allow our Pets to answer the phone when we are not at home; the caller on the other end of the line will not necessarily know or care which Pet is answering the phone, as long as it is able to speak():

// C# Pet class
public class Pet
{
// ...
public virtual void Speak()
{
System.Console.WriteLine(GetName() + " says...");
}
}
// C# Dog class
public class Dog : Pet
{ // ...
public override void Speak()
{
base.Speak();
System.Console.WriteLine("woof");
}
}
// C# Cat class
public class Cat : Pet
{
// ...
public override void Speak()
{
base.Speak();
System.Console.WriteLine("meow");
}

}

Consume C# code
p = new Dog("Max");
p.Speak();
p = new Cat("Fluffy");
p.Speak();

// JavaScript Pet class
// ...

Pet.prototype.speak = function()
{
alert(this.getName() + " says...");
}


// JavaScript Dog class
// ...

Dog.prototype.speak = function()
{
Pet.prototype.speak.call(this);
alert("woof");}
// JavaScript Cat class
// ...
Cat.prototype.speak = function()
{
Pet.prototype.speak.call(this);
alert("meow");
}
Note that the same call() function used to invoke the base class constructor functions is also used to invoke method on the base class.

consume javascript code
p = new Dog("Max");
p.speak();
p = new Cat("Fluffy");
p.speak();

Tuesday, 2 October 2007

AJAX file upload

Introduction

File uploading thru HTTP is always big problem for websites. There are some restrictions from client and server sides. But with growing internet channels bandwidth one of major problem is file size. Sometimes it’s impossible to send 500MB file to webserver due to request length limit. One of the workaround is to increase maximal request length on webserver, but it may cause server restart when memory limit will be exceeded. For example: IIS APS.NET webserver. We increases maxRequestLength to 500MB, memoryLimit default value is 60% it means that process will be recycled when it use more than 60% of physical memory. If we have 1GB of physical memory in system and couple of users uploads simultaneously 400MB files webserver will be restarted with very high chance, because server wouldn’t have time to release memory from Requests objects.

Another big issue is file upload continuing, when process was interrupted by some reasons. Normally user needs to upload whole file once again

In this example I’ll describe how to implement file uploading method using AJAX and WebService technologies. Of course this method has its own restrictions, but it would be quite useful for intranet solutions and administrative areas in internet websites.

How it works

Main idea is quite simple. We should read file partially on send these parts to webserver.

Client Side

//Receive intial file information and init upload
function getFileParams()
{
//Convert file path to appropriate format
this.filePath = document.getElementById( "file").value.replace(/\\/g, "\\\\");

fso = new ActiveXObject( 'Scripting.FileSystemObject' );
if ( !fso.FileExists(this.filePath) )
{
alert("Can't open file.");
return;
}

f = fso.GetFile( this.filePath );
this.fileSize = f.size;
this.fileName = f.Name;
InitStatusForm();
InitUpload();
}

Allocate file on client, get file size. I use Scripting.FileSystemObject ActiveX object to get file size because this object will not load full file in memory.
Then init form Layout and upload process by InitStatusForm() and InitUpload functions.

function InitUpload()
{
document.getElementById("uploadConsole").style.display = "none";
document.getElementById("statusConsole").style.display = "block";

xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
xmlhttp.onreadystatechange = HandleStateChange;

var parameters = "fileSize=" + encodeURI(this.fileSize) +
"&fileName=" + encodeURI(this.fileName)+
"&overwriteFile=" + encodeURI(document.getElementById("overwriteFile").checked);

xmlhttp.open("POST","http://localhost/AJAXUpload/Upload.asmx/InitUpload", true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.setRequestHeader("Content-length", parameters.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(parameters);
}

Init upload: Create XmlHttp object and send to webservice initial information such file size, file name and overwrite flag.

//XMLHTTPRequest change state callback function
function HandleStateChange() {
switch (xmlhttp.readyState) {
case 4:
response = xmlhttp.responseXML.documentElement;
id = response.getElementsByTagName('ID')[0].firstChild.data;
offset = esponse.getElementsByTagName('OffSet')[0].firstChild.data;
bufferLength = response.getElementsByTagName('BufferLength')[0].firstChild.data;

percentage = (offset/this.fileSize)*100;
if (offset<this.fileSize && !this.cancelUpload)
{
UpdateStatusConsole(percentage, "Uploading");
SendFilePart(offset, bufferLength);
}
else
{
SetButtonCloseState(false);
if (this.cancelUpload)
UpdateStatusConsole(percentage, "Canceled");
else
UpdateStatusConsole(percentage, "Complete");
}
break;
}
}

Asynchronous request from server-side handled by HandledStateChange() callback function.
Parse parameters from server: id – response-request identifier, offset – start position to read file part. bufferLength – file block size to read.
If requested start position not exceed file size and upload not canceled by user we send file part.

Collapse
//Read part of file and send it to webservice
function SendFilePart(offset, length)
{
// create SOAP XML document
var xmlSOAP = new ActiveXObject("MSXML2.DOMDocument");
xmlSOAP.loadXML('"1.0" encoding="utf-8"?>'+
'"http://www.w3.org/2001/XMLSchema-instance" '+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> '+
''+
'"http://tempuri.org/" >'+
''+this.fileName+''+
''+this.fileSize+''+
''+
'
'+
'
'+
'
');

// create a new node and set binary content
var fileNode = xmlSOAP.selectSingleNode("//file");
fileNode.dataType = "bin.base64";
// open stream object and read source file
if (adoStream.State != 1 )
{
adoStream.Type = 1; // 1=adTypeBinary
adoStream.Open();
adoStream.LoadFromFile(this.filePath);
}

adoStream.Position = offset;
// store file content into XML node
fileNode.nodeTypedValue = adoStream.Read(length);//adoStream.Read(-1); // -1=adReadAll
if (adoStream.EOS)
{
//Close Stream
adoStream.Close();
}

// send XML document to Web server
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = HandleStateChange;
xmlhttp.open("POST", "http://localhost/AJAXUpload/Upload.asmx", true);
xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/UploadData");
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.send(xmlSOAP);
}

In this function we create XmlSoap, read file part using ADODB.Stream ActiveX object and send it to WebServer with file name and filesize.
Server response from this operation would be handled by the same HandledStateChange() callback function.


Server Side

[WebMethod]
public XmlDocument InitUpload(int fileSize, string fileName, bool overwriteFile )
{
long offset = 0;
string filePath = GetFilePath(fileName);

if (File.Exists(filePath))
{
if (overwriteFile)
{
File.Delete(filePath);
}
else
{
using (FileStream fs = File.Open(filePath, FileMode.Append))
{
offset = fs.Length;
}
}
}

return GetXmlDocument(Guid.NewGuid(), string.Empty, offset,
(InitialBufferLength+offset)>fileSize?(int)(fileSize-offset):InitialBufferLength);
}

Init upload server-side function. If file with such name already exist and overwrite flag is false existed file will be appended otherwise file will be deleted. Then construct response by GetXmlDocument function.

[WebMethod]
public XmlDocument UploadData(string fileName, int fileSize, byte[] file)
{
if (fileName == null || fileName == string.Empty || file == null)
return GetXmlDocument(Guid.NewGuid(), "Incorrect UploadData Request", 0, 0);

string filePath = GetFilePath(fileName);

long offset=0;
using (FileStream fs = File.Open(filePath, FileMode.Append))
{
fs.Write(file, 0, file.Length);
offset = fs.Length;
}
return GetXmlDocument(Guid.NewGuid(), string.Empty, offset,
(InitialBufferLength+offset)>fileSize?(int)(fileSize-offset):InitialBufferLength);
}