Monday, February 9, 2009

When IE Zoom Feature does not zoom in the silverlight plugin Islands.

A silverlight pluggin area won't grow/shrink while zoom-IN/OUT the Internet Explorer window. This functionality can be achieved as follows



This is a straight forward approach and pretty simple



1. Register your Class



2. Create the Method to be called from IE Javascript with the ScriptableMember attribute




public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
HtmlPage.RegisterScriptableObject("page", this);

}
[ScriptableMember]
public void ResizePage(double Height, double Width)
{
LayoutRoot.Height = Height;
LayoutRoot.Width = Width;
}
}



3.Create a javascript function in the html page where in the silverlight pluggin is used




function onResize(sender, args) {
var slControl = document.getElementById("slControl");
var height, width;
height = slControl.Content.ActualHeight;
width = slControl.Content.ActualWidth;
slControl.Content.page.ResizePage(height, width);
}



4.Call this method in the onresize method of the html object tag as




<object id="slControl" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="50%" height="50%">
<param name="source" value="ClientBin/SilverlightNet.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="autoUpgrade" value="true" />
<param name="onresize" value="onResize" />
<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>



You are done. Now the Silverlight content will Grow/Shrink with the zoom in/out



Reference : http://www.microsoft.com/Web/content.aspx?id=browser-resize-zoom



Friday, February 6, 2009

Password Encryption and Decryption in SQL Server 2005

Encryption of column data in SQL 2005 is a good approach while we think of some one tampering our database through some sql injection and methods like that

Here are the steps involved

1. Create a MASTER KEY ENCRYPTION for your database

CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<Give a Password Here>'





2.Create a Certificate




CREATE CERTIFICATE SampleCertificate  
WITH SUBJECT = '<Give some Description about the certificate>'





3.Create the symmetric Key (You'll use the certificate created above while creating a symmetric key)




CREATE SYMMETRIC KEY SamplePassword    
WITH ALGORITHM = AES_256 ENCRYPTION BY CERTIFICATE SampleCertificate



You can select an encryption algorithm of your choice while creating a Symmetric key.





Your keys for the Encryption and Decryption are ready now. Open your keys and do the encryption or decryption as follows



Encrypting the Password




OPEN SYMMETRIC KEY IMCPSPassword   
DECRYPTION BY CERTIFICATE IMCPSCert;

UPDATE [dbo].[Users]
SET [Password] = EncryptByKey(Key_GUID('IMCPSPassword'),Password)





Decrypting the Password




SELECT 
[UserID],
CONVERT(varchar, DecryptByKey(Password)) as Decryptedpassword
FROM [dbo].[Users]

Simple Colour Animation in Silverlight 2.0 using inline XAML

If you do not want your Silverlight pluggin to look for the xap file in its relative path ..go for the inline XAML concept. Its pretty simple and easy

A sample code which do the colour animation is as follows

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>BugRepro</title>
<SCRIPT type="text/xaml" id="xaml1">
   1:  
   2:     <Canvas
   3:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   4:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   5:     <Canvas.Triggers>
   6:       <EventTrigger  RoutedEvent="Canvas.Loaded" >
   7:       <BeginStoryboard >
   8:     <Storyboard x:Name="myAnimation" RepeatBehavior='Forever'>
   9:     <ColorAnimation    
  10:               Storyboard.TargetName="myRectangle"     
  11:               Storyboard.TargetProperty='(Shape.Fill).(SolidColorBrush.Color)'    
  12:               From="Red"    
  13:               To="Green"                  
  14:               Duration="0:0:0.5"    
  15:               AutoReverse="True"/>  
  16:     </Storyboard>
  17:       </BeginStoryboard>
  18:       </EventTrigger>
  19:     </Canvas.Triggers>
  20:     <Canvas Background="White" Width="100" Height="100">
  21:     <Rectangle x:Name="myRectangle" Fill='Red' Height='100' Width='100'/>
  22:     </Canvas>
  23:     </Canvas>
  24:     
</SCRIPT>
</head>
<body>
<div>
<object data=data:application/x-silverlight, type=application/x-silverlight-2
width="100" height="100" id="Ag1">
<param name="Source" value="#xaml1" />
</object></div>
</body>
</html>