Wednesday, September 10, 2008

Migrating Visual Studio.NET project from VisualSourceSafe to ClearCase while retaining history

This article by IBM has a complete description of migrating the .NET project which is currently under the VSS to ClearCase with history. But still it doesn't much explain about exporting the project / solution from VSS and importing back to the ClearCase by using the clearexport_ssafe and clearimport. The below given section explains them better.

To export the project's / solution's information along with history we need to use the clearexport_ssafe command in the DOS prompt. This article explains about the same, but still it doesn't have any sample to explain. The below given sample batch file explains it better.

This is the batch file commands, which I used when migrating one of my .net project from VSS to ClearCase.

SET PATH=%PATH%;C:\Program Files\Microsoft Visual SourceSafe;(The loaction of the SS.exe in the machine)
SET SSDIR=\\NetwrokVSSDatabaseLocation\VSS DatabaseName (eg., \\TestLocation\TestDatabaseName)
SET SSUSER= VSS User Name (This user should be created in VSS database with blank password)
SS CP $/VSSProjectLocation (eg., $/TestProject)
clearexport_ssafe -r

Running the above batch file, will generate a file in the same folder with the name "cvt_data". This is the file having the complete VSS project data with history.

Then while importing the data back to ClearCase, the command used is

clearimport -pcase "cvt_data file location"

This command should be executed in DOS prompt in the location of VOB where you need to move your data. Consider your project's VOB is mapped to Z: directory in your machine and your project's VOB name is TestVOB. Then you chould first change the directory to "Z:\TestVOB\FolderName". Then execute the above command with the correct CVT_Data file location.

In the above command the switch -pcase is used to tell import utility to preserve the case of the files while importing. If this attribute is missed, by default clearimport will import the files with all lowercase letters.

If you are not the VOB owner, then running the above command will give you a "Permission Denied" error. To avoid this run the command with the switch -nsetevent, like shown below

clearimport -nsetevent -pcase "cvt_data file location"

This will import the files exported using the "clearexport_ssafe" command. Now your VOB would be having the complete VSS project's data along with history.

References:

http://www-01.ibm.com/support/docview.wss?rs=0&uid=swg21222507
http://publib.boulder.ibm.com/infocenter/cchelp/v7r0m0/index.jsp?topic=/com.ibm.rational.clearcase.books.cc_admin.doc/import-export.htm
http://www.astrainfotech.com/rsdc-2006-dilip.pdf


Tuesday, July 29, 2008

Label Chart Widget for blogger - Using Google Charts API

Are you interested in showing your blogs label count as a chart, like the one available in my blog? Then follow the below and you can achieve it by some scripts and the Google Chart API.

If you are not familiar with Google Chart API, then check it here.

Then the script for the Widget is as follows.


<b:widget id='LabelChart' locked='false' title='Label Chart' type='Label'>
<b:includable id='main'>
<b:if cond='data:title'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content'>
<div id='LabelChartDiv'/>
<script type='text/javascript'>
var LabelArray = new Object;
var i=0;
<b:loop values='data:labels' var='label'>
var LabelName = "<data:label.name/>";
LabelArray[LabelName] = <data:label.count/>;
i++
</b:loop>
var LabelChartDivObj = document.getElementById('LabelChartDiv');
var ChartLocation = 'http://chart.apis.google.com/chart?chs=230x75&chd=t:';
var j=0;
for (LabelCount in LabelArray)
{
j++;
if(j<i)
{
ChartLocation = ChartLocation + LabelArray[LabelCount] + ',';
}
else
{
ChartLocation = ChartLocation + LabelArray[LabelCount];
}
}
ChartLocation = ChartLocation + '&cht=p&chl=';
j=0;
for (LabelCount1 in LabelArray)
{
j++;
if(j<i)
{
ChartLocation = ChartLocation + escape(LabelCount1) + '['+ LabelArray[LabelCount1] + ']|';
}
else
{
ChartLocation = ChartLocation + escape(LabelCount1) + '['+ LabelArray[LabelCount1] + ']';
}
}
LabelChartDivObj.innerHTML = '<img src=' + ChartLocation + '>';
</script>
</div>
</b:includable>
</b:widget>

To add the above widget script, you need to go to your blogger 'Dashboard'. Then go for 'Layout' and 'Edit HTML' as shown in the below image.


Then go for 'Edit Template' section and check the '

Now copy the above script and paste it in your template code near your normal label widget. You can find this by searching the below script.

<b:widget id="'Label1'" locked="'false'" title="'Labels'" type="'Label'">

Note: ID of the widget will not be same, it can be different.

The Label widget will be having some standard code and will be end with </b:widget>.

Now you paste the above copied code below this end line and save your template.

Thats all. You have made a colorful chart displaying your label counts.

Caution: Before editing your template, always take a copy of your old template. If some thing goes wrong while editing you can always revert back.

Monday, July 28, 2008

ASP .NET AJAX Timer control : Processing client script on Tick event

Timer Control is a very handy ASP.NET AJAX Extension control used to 'Performs asynchronous or synchronous Web page postbacks at a defined interval'.

This control has good set of features associated with it. But still i feel there is no option to process the client scripts on the Timer's Tick event.

The below given script explains a workaround to the above issue.


// Access the Timer control.
var TestTimer = $find('<%= TestTimer.ClientID %>');
/* Override the '_doPostback' (method called to fire the server Tick event)
method with your own function. */
TestTimer._doPostback = TimerTick;

// Overridden Timer Tick Function
function TimerTick()
{
// Here this is called on every timer tick event..
// So do your client processing here..
alert('Timer Client Click');
// Finally do the async postback..
var ClientTimerId = '<%= tAutoSave.ClientID %>';
// Now call the Asyncpost back method..
// Replace the client id's with the Unique Id..
__doAsyncPostBack(TestTimer, ClientTimerId.replace(/\_/g, '$'),'');
}

// Method to do async post back..
function __doAsyncPostBack(sourceElement, eventTarget, eventArgument)
{
// Here we need to do an async post back...
// Get the Form
var form = Sys.WebForms.PageRequestManager.getInstance()._form;
// Set Event target and the event arguments..
form.__EVENTTARGET.value = eventTarget;
form.__EVENTARGUMENT.value = eventArgument;
// Set the async post back as true..
Sys.WebForms.PageRequestManager.getInstance()._postBackSettings.async = true;
// Set source element..
Sys.WebForms.PageRequestManager.getInstance()._postBackSettings.sourceElement = sourceElement;
// Call the form submit..
Sys.WebForms.PageRequestManager.getInstance()._onFormSubmit();
}

Tuesday, April 8, 2008

Using CTE and Row_Number() to get the duplicate data in SQL Server 2005

This is the script to get the duplicate data from employee table, whose employee name is repeating.


With TestData as

(

Select

EmployeeId,

Row_Number() Over( Partition By EmployeeName Order By EmployeeName) AS Rowid

From

Employees

)

Select EmployeeId from TestData Where RowId > 1



If we need to get the duplicate records by two columns, those two columns should be in the Partition By column, and in the order by column.

Using CTE to write recursive query in SQL Server 2005

CTE (Common Table Expression) is newly introduced in SQL Server 2005. The below given link elaborates the CTE and its advantages.

http://www.4guysfromrolla.com/webtech/071906-1.shtml

http://searchwindevelopment.techtarget.com/tip/0,289483,sid8_gci1278207,00.html

Basically the requirement was, when an employee logs in he needs the list of employees reporting directly under him as well as the employees who are reporting under them.

The database structure was like:

  • Employee table containing the employee details like Employee Id, Name, etc.,
  • Supervisor table containing the mapping of employee and their supervisor

I tried out with the CTE to build a recursive function which will get the first level reporting employees and then their reporting employee. The script was given below


Declare@UserId Int

Set @UserId = 36332

-- This is the recursive function..

WITH EmployeeHierarchy (EmployeeID, EmployeeName, HierarchyLevel) AS

(

-- Base case

Select

E.EmployeeId,

E.Name As EmployeeName,

1 As HierarchyLevel

From


Employees E

Where

E.EmployeeId = @UserId


UNION ALL

-- Recursive step

select

E.EmployeeId,

E.Name As EmployeeName,

eh.HierarchyLevel + 1 AS HierarchyLevel

FROM

Supervisors ES

INNER Join Employees E On E.EmployeeId = ES.EmployeeId INNER JOIN EmployeeHierarchy eh ON ES.Supervisor1 = eh.EmployeeID

)

-- This is the final select

Select


E.EmployeeId,

E.EmployeeNumber As EmployeeNumber,


E.EmployeeName

From

EmployeeHierarchy E

Where

E.EmployeeId <> @UserId