Silverlight 2.0 MEDIA PLAYER

April 8, 2008 by sunilmallya

Silverlight 2.0 has finally arrived and provides us with a cool option of coding in any language of our choice ( MANAGED CODE )..!! thank god.. javascript is really yucky !! but i know will end up using it quite sooner than later… itz like this yucky gum stuck on to your boot!

Comming to the real funda here abt Silverlight 2.0. After the Presentation @ Microsoft Student Partners South India BootCAMP .. Lotz of people requested me to blog about how to create a Silverlight Application .. more specifically creating a Simple video Library !. which indeed is simple ;) )

So tools i recommend you people to have are BLEND 2.5 March Preview , Visual Studio 2008 (Needed) and silverlight 2.0 runtime.

Start a new project in blend -> Choose Silverlight 2.0 Website

Now Lets add a media element by double clicking on the media we just added ! ( page.Xaml File )


Create 3 buttons name them Play / pause /Stop : try using in intellisense in VS 2008 !! :) –> Add click events to thsese buttons

 

Create a nice media holder back ground as shown ( better than Shoddy one i have done !!!)
 

Goto Page.xaml.cs file and add some logic to u’r newly create events
(check the code file to get more info ).
 

If you want to change video on some event ..add this code

(YourmediaelementName).Source = new Uri(“frisbee.wmv”, UriKind.Relative);
Just Remember here Source doesn’t take a string but takes a  URI instead !!

DOWNLOAD the code for the media player here !!!!

http://cid-7c189d3ffb9ce13c.skydrive.live.com/self.aspx/My%20Presentations/SLBootCampMediaPlayer_SunilMallya.zip

Writing CLR Triggers for SQL 2005

April 2, 2008 by sunilmallya

Here is a small Example of How to Write CLR Triggers in SQL 2005 .

First Open a ClassLibrary Project in Visual Studio and go to the Program.cs File and edit as Required

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Data;

namespace ClassLibrary1
{
    public partial class Triggers
 {
 //In my CLR Method i have Opened the connection like below

        [Microsoft.SqlServer.Server.SqlTrigger(Name = @"FuncName",
  Target = "[dbo].[Table_NAME]“, Event = “FOR INSERT”)]
     
   
       
public static void FuncName()
{
    SqlTriggerContext triggContext = SqlContext.TriggerContext;

    String userType = “” ;
    SqlCommand command1;
    SqlCommand command2;
  

   
 SqlConnection connection
            = new SqlConnection(@”context connection=true”);

        connection.Open();

     command1 = new SqlCommand(@”SELECT * FROM TableName;”,connection);
 // Select all from Table

 command1.ExecuteScalar();
  // Returns First Row , First Column of the

  command2 = new SqlCommand(@”insert into [dbo].[docs2](docname) values(1)”, connection);
       
 int rows = command2.ExecuteNonQuery();
     

}
}
}

Now Build the DLL and Store it in Some Location.

I have stored it under this location -
 C:\ClassLibrary1\bin\Debug\ClassLibrary1.dll’

-> After this open the SQL management studio to run the Query , Make sure the Query is run on the Database you want the trigger to be on !

sp_configure  ‘clr_enabled’, 1
go
RECONFIGURE with override
go

reconfigure

create assembly ClassLibrary1
from ‘C:\ClassLibrary1\bin\Debug\ClassLibrary1.dll’
with Permission_Set =safe
go
create trigger tr_TriggerName
on  AllDocs
for INSERT
as
external name ClassLibrary1.[ClassLibrary1.Triggers].FuncName
go

Now when  you Insert the Trigger will be Exectuted .
You can specify Triggers similarly for Update , Delete as well

Measuring Execution Time in C#

March 30, 2008 by sunilmallya

DateTime startTime = DateTime.Now;

Function(){}

DateTime EndTime = DateTime.Now;

TimeSpan TotalTime= EndTime – StartTime ;

 TotalTime.ToString();  // to display in some Label/ Textbox