Thursday, May 20, 2010

HEX to Color in Silverlight GridView

Recently i need to use colors in my grid cells, for that i have written code in RadGridView_RowLoaded to set the colors. But i had trouble setting color as background to cells. I could able to achieve this way.

 // Setting backgrounds to cells 
        private void RadGridView1_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            string strPirority = "";
            string strStage = "";
            if (e.Row.Item != null)
            {
                strPirority = ((TelerikOrderSilverlight.ServiceReference1.v_order_mgmt)(((Telerik.Windows.Controls.RadRowItem)(((Telerik.Windows.Controls.GridView.GridViewRowItemEventArgs)(e)).Row)).Item)).priority.ToString();
                if (((TelerikOrderSilverlight.ServiceReference1.v_order_mgmt)(((Telerik.Windows.Controls.RadRowItem)(((Telerik.Windows.Controls.GridView.GridViewRowItemEventArgs)(e)).Row)).Item)).stage != null)
                {
                    strStage = ((TelerikOrderSilverlight.ServiceReference1.v_order_mgmt)(((Telerik.Windows.Controls.RadRowItem)(((Telerik.Windows.Controls.GridView.GridViewRowItemEventArgs)(e)).Row)).Item)).stage.ToString();
                }               
                for (int i = 0; i < e.Row.Cells.Count; i++)
                {
                    if (e.Row.Cells[i].Column.UniqueName == "priority")
                    {
                        if (strPirority == "Critical")
                        {
                            // Can set this way using solid
                            e.Row.Cells[i].Background = new System.Windows.Media.SolidColorBrush(Colors.Red);
                        }
                    }
                    if (e.Row.Cells[i].Column.UniqueName == "MileStone")
                    {
                        if (strStage.Length > 0)
                        {
                            // You can set this way using Hexa codes.
                            if (strStage.Substring(0, 4) == "Bill")
                            {
                                e.Row.Cells[i].Background = new System.Windows.Media.SolidColorBrush(GetColorFromHexa("#FF000000"));
                            }
                        }
                    }
                }
            }
        }
        private Color GetColorFromHexa(string hexaColor)
        {
            return Color.FromArgb(
                    Convert.ToByte(hexaColor.Substring(1, 2), 16),
                    Convert.ToByte(hexaColor.Substring(3, 2), 16),
                    Convert.ToByte(hexaColor.Substring(5, 2), 16),
                    Convert.ToByte(hexaColor.Substring(7, 2), 16));
        }


Here is the list of all predefined SolidColorBrush objects.

Thursday, May 13, 2010

Configuring IIS for Silverlight Applications

Recently i want to deploy my Silverlight application Window 2003 Server. I have copied all the files and thought it will work as in development machine. But i am not able to run on Window 2003 server, so for that i need to configure my server to support silverlight.

Here is the URL that found helpful.

How to Create Hidden folders using c#

using System.IO; 
// folder path that you want to create
string path = @"c:\createfolder\NewFolder"; 
if (!Directory.Exists(path)) 
{ 
  // Creating folder 
  DirectoryInfo di = Directory.CreateDirectory(path); 
  // setting attributes
  di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; 
}

Friday, April 30, 2010

Handling large sets of data from WCF service in Silverlight application

I had the problem of handling data which is coming from my WCF web service to Silverlight application. When data is huge i got communication exception. I have googled on this and found a great article to handle huge amount of data.

Here is a great article by Syed Mehroz Alam. I found it very helpful.

Thursday, April 29, 2010

What is WCF?

 

A WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world.

A Client is a program that exchanges messages with one or more Endpoints. A Client may also expose an Endpoint to receive Messages from a Service in a duplex message exchange pattern.

Service Endpoint:

A Service Endpoint has an Address, a Binding, and a Contract.

The Endpoint's Address is a network address where the Endpoint resides. The EndpointAddress class represents a WCF Endpoint Address.

The Endpoint's Binding specifies how the Endpoint communicates with the world including things like transport protocol (e.g., TCP, HTTP), encoding (e.g., text, binary), and security requirements (e.g., SSL, SOAP message security). The Binding class represents a WCF Binding.

The Endpoint's Contract specifies what the Endpoint communicates and is essentially a collection of messages organized in operations that have basic Message Exchange Patterns (MEPs) such as one-way, duplex, and request/reply. The ContractDescription class represents a WCF Contract.

The ServiceEndpoint class represents an Endpoint and has an EndpointAddress, a Binding, and a ContractDescription corresponding to the Endpoint's Address, Binding, and Contract, respectively

An EndpointAddress is basically a URI, an Identity, and a collection of optional headers.

An Endpoint's security identity is normally its URI; however, in advanced scenarios the identity can be explicitly set independent of the URI using the Identity address property.

The optional headers are used to provide additional addressing information beyond the Endpoint's URI. For example, address headers are useful for differentiating between multiple Endpoints that share the same address URI.

A Binding has a name, a namespace, and a collection of composable binding elements.
The presence of each binding element describes part of the how of communicating with the Endpoint. The TcpTransportBindingElement indicates that the Endpoint will communicate with the world using TCP as the transport protocol. ReliableSessionBindingElement indicates that the Endpoint uses reliable messaging to provide message delivery assurances. SecurityBindingElement indicates that the Endpoint uses SOAP message security.

For example, the ReliableSessionBindingElement has an Assurances property that specifies the required message delivery assurances, such as none, at least once, at most once, or exactly once.

A WCF Contract is a collection of Operations that specifies what the Endpoint communicates to the outside world. Each operation is a simple message exchange, for example one-way or request/reply message exchange.

The ContractDescription class is used to describe WCF Contracts and their operations. Within a ContractDescription, each Contract operation has a corresponding OperationDescription that describes aspects of the operation such as whether the operation is one-way or request/reply. Each OperationDescription also describes the messages that make up the operation using a collection of MessageDescriptions.

A ContractDescription is usually created from an interface or class that defines the Contract using the WCF programming model. This type is annotated with ServiceContractAttribute and its methods that correspond to Endpoint Operations are annotated with OperationContractAttribute. You can also build a ContractDescription by hand without starting with a CLR type annotated with attributes.

A duplex Contract defines two logical sets of operations: A set that the Service exposes for the Client to call and a set that the Client exposes for the Service to call. The programming model for defining a duplex Contract is to split each set in a separate type (each type must be a class or an interface) and annotate the contract that represents the service's operations with ServiceContractAttribute, referencing the contract that defines the client (or callback) operations. In addition, ContractDescription contains a reference to each of the types thereby grouping them into one duplex Contract.

Similar to Bindings, each Contract has a Name and Namespace that uniquely identify it in the Service's metadata.

Each Contract also has a collection of ContractBehaviors that are modules that modify or extend the contract's behavior. The next section covers behaviors in more detail.

For more details, visit this link at MSDN.