Wednesday, July 14, 2010

SVN CHANGE FINDER

Everyone knows how cool of a software svn is.Along with tools like visualsvn, tortoisesvn,ankh svn,svn monitor it makes you feel happy all day as with out being worried about your data.Like everyone else programmer/developers uses svn a lot in their daily routine for keeping revisions of their source files alongs with any other documentaion.When you want to find a change a colleague made in a file or wonder when that change is made, you have to almost reap through all the revisions of the file and use the diff tools/viewers open each revision and see if change is there.It is hectic time consuming when there are many revisions on a file and if there are lot of changes per revision.So I created this small utility to find when the text/change you are looking is made in a file.

Set SvnExeLocation and TortoiseExeLocation in the config.xml before using the application.




Get the code and binaries from the link below.


Keywords:
svn subversion changes revisions head diff diffs log author message datetime
cvs repo repository file branch trunk tag history commit check-in check-out rev,svn changelist,svn changelog,svn change log message,svn changeset,svn change commit message,svn changes in revision,svn changes between revisions,svn changes since revision date,svn changes report.
svn changelist svn blame svn changelog

Saturday, July 3, 2010

Crystal Reports Windows Application - Failed to open the connection

Failed to open the connection.
Details: [Database Vendor Code: 4060 ]
Failed to open the connection.
temp_62a7065e-b077-44f0-8593-7dca04303f6a {7498BCDB-812A-4D53-B04E-9BD3E45EC6B6}.rpt
Details: [Database Vendor Code: 4060 ]
Stack Trace:
at CrystalDecisions.ReportAppServer.Controllers.RowsetControllerClass.CreateCursor(ISCRGroupPath GroupPath, RowsetMetaData MetaData, Int32 Reserved)
at CrystalDecisions.ReportAppServer.CrystalReportDataView.EnsureDataTableIsFilled()
at CrystalDecisions.ReportAppServer.CrystalReportDataView.get_DataView()
at CrystalDecisions.ReportAppServer.CrystalReportDataView.get_InternalCollection()
at CrystalDecisions.ReportAppServer.CrystalReportDataView.get_Count()


OK, the error above appeared out of no where and we had to spend hours and hours to figure out what is going on.

Let's get some info about the environment.

Dev database - where developers write code against and is used to design new reports.

QA database - where qa staff run the test cases in the app against.

Both databases are on the same server.

-Code sequence before issue
1.Change ReportDocument TableLogOnInfo using the app connection string.
2.Then load Report Viewer

Our requirement changed and wants to display report viewer if there are any records.
--Code sequence after issue happened
1.Check ReportDocument Rows Count and display message saying no records, and skip step2 and 3.
2.Change ReportDocument TableLogOnInfo using the app connection string.
3.Then load Report Viewer.

Problem here is step1 where row count is checked, when the check is done data is fetched from the database to which report is pointed at the design time as the connection is not updated until step2.

When QA staff runs the report at step1 database context changes to dev database where QA staff has no access to the data, for that matter they dont even have a login in the database which is why "Failed to open the connection." error is given.

GIST HERE IS UPDATE THE TABLELOGONINFO FOR REPORTS and SUBREPORTS WITH THE APPLiCATION INSTANCE CONNECTION STRING BEFORE QUERYING THE ROW COUNT ON THE REPORT DOCUMENT.

--SAMPLE CODE TO CHANGE THE CONNECTION INFO
Dim LogonInfo As New TableLogOnInfo

'-- Set the connection info
LogonInfo.ConnectionInfo.ServerName = GetServerName(connectionString)
LogonInfo.ConnectionInfo.DatabaseName = GetDatabaseName(connectionString)
If UsesIntegratedSecurity(connectionString) Then
LogonInfo.ConnectionInfo.IntegratedSecurity = True
Else
LogonInfo.ConnectionInfo.UserID = GetUserName(connectionString)
LogonInfo.ConnectionInfo.Password = GetUserPassword(connectionString)
End If

'--- Apply the connection info to each database table
For Each Table As Table In report.Database.Tables
Table.ApplyLogOnInfo(LogonInfo)
Next

'--- Also set connection info in the subreports
For Each subReport As ReportDocument In report.Subreports
For Each Table As Table In subReport.Database.Tables
Table.ApplyLogOnInfo(LogonInfo)
Next
Next

svnadmin dump - never finishes

Ok, here I am trying to separate a repository into two following svn documentation.I got to create a dump file then use svndumpfilter to create separate dump files for the projects I want and create repo's using those individual files.

With this in mind I started to work on it.Our repo is about 5 gigs in size.Command prompt in which I started the command says not responding after a while and never finishes dumping.I thougt it needed more time so let it go for the entire night with no success.After all these hours I
found out that dump is written to the console window.Changing that to output to file fixed the problem

Wrong
svadmin dump e:\repo e\repodump

Correct(if you want the dump file)
svadmin dump e:\repo >e\repodump

Finding the Owner( Launching Form)

Sometimes it is very useful to have reference to the form that launches another form.This is easily done by passing the owner in the form show method.But what if you have to change a lot in the existing code to get that.You can use windows api to get the owner.Lets say you have form1 and form2 in your app and form2 is launched from form1 and if we want to find the launcher of form2 which in our case is form1.This is what you do in form2.


<dllimport("user32", charset:="CharSet.Auto," exactspelling:="True)" setlasterror:="True,">_
Public Shared Function GetWindow(ByVal hwnd As IntPtr, ByVal uCmd As Integer) As Integer
End Function


--get the window now
Dim i As Integer
i = GetWindow(Me.Handle, 4)
Dim ctrl As Control = Form.FromHandle(i)

Friday, March 5, 2010

Linq Remove Duplicates and Merge Two Collections using Union and Distinct

Linq is a boon from Microsoft to all .net developers; it makes things really easy and simple and also gives the ability to perform several tasks that you do using sql (many more).I had to remove duplicates based on some columns from two different collections, it was done using for loops in the past, as linq is available I thought of giving it a shot.

Union and distinct is used to obtain the desired results; also notice a custom IEqualityComparer is passed to distinct instead of the default equality comparer to compare values. In custom equality comparer you can ignore the columns or properties you don’t want to consider when deciding the uniqueness. If you don’t have a custom IEqualityComparer then linq distinct wont work as expected and might return duplicates.

Let’s dive into some code here.
''define lists
Dim list1 As New List(Of Item)
Dim list2 As New List(Of Item)

''add two items to list 1
Dim item1 As New Item
item1.ItemID = Guid.Empty
item1.ItemName = "item1"

list1.Add(item1)

Dim item2 As New Item
item2.ItemID = Guid.Empty
item2.ItemName = "item2"

list1.Add(item2)


''add same item(item 2 from list1) to list 2
Dim item3 As New Item
item3.ItemID = Guid.Empty
item3.ItemName = "item1"

list2.Add(item3)

''get thee distinct of the two lists
Dim aaaaa = (From l1i In list1 Select l1i).Union _
(From l2i In list2 Select l2i).Distinct(New ItemComparer)

''a simple item class
Public Class Item
Public ItemID As Guid
Public ItemName As String
End Class

''custom IEqualityComparer for our item class
Public Class ItemComparer
Implements IEqualityComparer(Of Item)

Public Function Equals1(ByVal x As Item, ByVal y As Item) As Boolean _
Implements IEqualityComparer(Of Item).Equals

If x Is y Then Return True

If x Is Nothing OrElse y Is Nothing Then Return False

Return (x.ItemID = y.ItemID) AndAlso (x.ItemName = y.ItemName)

End Function

Public Function GetHashCode1(ByVal item As Item) As Integer _
Implements IEqualityComparer(Of Item).GetHashCode

If item Is Nothing Then Return 0

Dim hashname = _
If(item.ItemName Is Nothing, 0, item.ItemName.GetHashCode())

Dim hashid = item.ItemID.GetHashCode()

Return hashname Xor hashid
End Function
End Class

Complex and a special three state (tri state) Treeview Control

As we all know treeview is used to show hierarchy of items easily. Microsoft tree is readily available for you if your needs are simple. But if you want to have the tree do more than two states it might not be possible with the treeview control as it is. You might have seen several treeview .net controls out there that have three states but the treeview in this post here might be little different than those. A parent can have its own state and can depict its child check state when stateless, also all the children under a parent are not affected when check state on the parent changes.

States:
Checked – Green Check
Unchecked – No Check
AtLeastOneChild Checked (only for Parent) – Light Gray Check

State Determination:

Node when checked a green check is shown regardless of whether any child nodes have been checked
Node when unchecked but has checked child, gray check is shown for the node.
Node when unchecked and has no children or all children unchecked, an empty check is shown

State Images:






What it can do:

Bind to Any Type of DataSource
Bind to a Single Datasource (With node definition and its check state)
Bind to Two Datasources(One that has node definition and other that has check state of the nodes)
Select All
Deselect All
Expand All
Collapse All
Read-only
Undo
Redo
Escape on a node gets previous check state back
Enter Select the node
Node color change on editing
Configurable coloring scheme for read-only and edited nodes

Using It:

For the treeview to properly work you have to set the members(columns in your binding objects)

ParentIDMember - Column to determine heirarchy
ValueMember – Column that holds the ID of the node
DisplayMember – Column that holds the Node Text
DefinitionValueRelationshipMember – Column that is common in the definition object and value object
DefinitionEntityCheckValueMember – Column that determines the check state of the node in the definition
ValueEntityCheckValueMember - Column that determines the check state of the node in the value object
CheckBoxEnabledMember – Column to enable/disable the node

Loading Nodes And Values

a)With no node values in the definition
TriStateTreeView1.DefinitionHasValue = False
TriStateTreeView1.DisplayMember = "Name"
TriStateTreeView1.ValueMember = "ID"
TriStateTreeView1.ParentIDMember = "ParentID"
TriStateTreeView1.CheckBoxEnabledMember = "CheckBoxEnabled"

TriStateTreeView1. ValueEntityCheckValueMember = “NodeValue”
TriStateTreeView1. DefinitionValueRelationshipMember = “ID”
TriStateTreeView1.BindNodesDataSource(lst)
TriStateTreeView1.BindNodeValuesDataSource(lstValues)

b)With node values in the definition

TriStateTreeView1.DefinitionHasValue = True
TriStateTreeView1.DisplayMember = "Name"
TriStateTreeView1.ValueMember = "ID"
TriStateTreeView1.ParentIDMember = "ParentID"
TriStateTreeView1.CheckBoxEnabledMember = "CheckBoxEnabled"
TriStateTreeView1.DefinitionEntityCheckValueMember = “NodeValue”
TriStateTreeView1.BindNodesDataSource(lst)

Link below has the control and the sample code on how to use the control.

Tuesday, February 9, 2010

SQL SERVER Employee Scheduling System

Determining day based on the start time and end time can be trick especially in sql.Scenario like this is encountered when working on a employee or any other scheduling system.Sample below takes current time and gives back the employees that are available according to the employeeschedule table.Code is self explanatory and is why it is minimally commented.

If you need a nice formatted sql,get it from here.
http://code.google.com/p/sql-scheduling-availability-system/downloads/list


IF EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'Employees')
DROP TABLE [Employees]

GO

CREATE TABLE [dbo].[Employees] (
[EmpID] [INT],
[FirstName] [VARCHAR](50),
[LastName] [VARCHAR](50),
[PhoneNumber] [VARCHAR](15))

GO

IF EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'EmployeeSchedule')
DROP TABLE [EmployeeSchedule]

GO

CREATE TABLE [dbo].[EmployeeSchedule] (
[EmployeeScheduleID] [INT],
[WeekID] [INT],
[DayID] [INT],
[EmpID] [INT],
[StartTime] [SMALLDATETIME],
[EndTIme] [SMALLDATETIME] ,)

GO

--Create Test Employees
INSERT INTO [dbo].[Employees]
([EmpID],
[FirstName],
[LastName],
[PhoneNumber])
VALUES (1,
'Tester1',
'A1',
'111-111-1111')

GO

INSERT INTO [dbo].[Employees]
([EmpID],
[FirstName],
[LastName],
[PhoneNumber])
VALUES (2,
'Tester2',
'A2',
'112-112-1112')

GO

--Some Test scheduling data
--for the current week all days
INSERT INTO [dbo].[EmployeeSchedule]
([EmployeeScheduleID],
[WeekID],
[DayID],
[EmpID],
[StartTime],
[EndTIme])
VALUES (1,
Datepart(wk,Getdate()),
1,
1,
'1900-01-01 05:00:00',
'1900-01-01 17:00:00')

GO

INSERT INTO [dbo].[EmployeeSchedule]
([EmployeeScheduleID],
[WeekID],
[DayID],
[EmpID],
[StartTime],
[EndTIme])
VALUES (1,
Datepart(wk,Getdate()),
2,
1,
'1900-01-01 12:30:00',
'1900-01-01 00:30:00')

GO

INSERT INTO [dbo].[EmployeeSchedule]
([EmployeeScheduleID],
[WeekID],
[DayID],
[EmpID],
[StartTime],
[EndTIme])
VALUES (1,
Datepart(wk,Getdate()),
3,
1,
'1900-01-01 18:00:00',
'1900-01-01 03:00:00')

GO

INSERT INTO [dbo].[EmployeeSchedule]
([EmployeeScheduleID],
[WeekID],
[DayID],
[EmpID],
[StartTime],
[EndTIme])
VALUES (1,
Datepart(wk,Getdate()),
4,
1,
'1900-01-01 12:00:00',
'1900-01-01 8:00:00')

GO

INSERT INTO [dbo].[EmployeeSchedule]
([EmployeeScheduleID],
[WeekID],
[DayID],
[EmpID],
[StartTime],
[EndTIme])
VALUES (1,
Datepart(wk,Getdate()),
5,
1,
'1900-01-01 06:00:00',
'1900-01-01 15:00:00')

GO

INSERT INTO [dbo].[EmployeeSchedule]
([EmployeeScheduleID],
[WeekID],
[DayID],
[EmpID],
[StartTime],
[EndTIme])
VALUES (1,
Datepart(wk,Getdate()),
6,
1,
'1900-01-01 21:00:00',
'1900-01-01 05:00:00')

GO

INSERT INTO [dbo].[EmployeeSchedule]
([EmployeeScheduleID],
[WeekID],
[DayID],
[EmpID],
[StartTime],
[EndTIme])
VALUES (1,
Datepart(wk,Getdate()),
7,
1,
'1900-01-01 14:00:00',
'1900-01-01 21:00:00')

GO

DECLARE @weekday AS INTEGER

DECLARE @weekid AS INTEGER

DECLARE @InputTime DATETIME

SET @weekday = Datepart(dw,Getdate())

SET @weekid = Datepart(wk,Getdate())

SET @InputTime = '1900-01-02 ' + Convert(VARCHAR(10),Getdate(),108)

DECLARE @Schedule TABLE(
EMPID INT,
TodaysStart DATETIME,
TodaysEnd DATETIME,
YesterdaysStart DATETIME,
YesterdaysEnd DATETIME,
TodaysStartMins INT,
TodaysEndMins INT,
YesterdaysStartMins INT,
YesterdaysEndMins INT
)


--Get the start and end date time of today and yesterday
INSERT INTO @Schedule
(EMPID,
TodaysStart,
TodaysEnd,
YesterdaysStart,
YesterdaysEnd)
SELECT Isnull(todaysschedule.currempid,yesterdaysschedule.prevempid) AS empid,
Max(todaysschedule.todaysstart),
Max(todaysschedule.todaysend),
Max(yesterdaysschedule.yesterdaysstart),
Max(yesterdaysschedule.yesterdaysend)
FROM (SELECT empid AS prevempid,
starttime AS yesterdaysstart,
endtime AS yesterdaysend
FROM dbo.employeeschedule
WHERE WeekId = @weekid
AND dayid = CASE @weekday
WHEN 7
THEN 1
ELSE @weekday - 1
END
UNION
SELECT NULL,
NULL,
NULL) yesterdaysschedule,
(SELECT empid AS currempid,
starttime AS todaysstart,
endtime AS todaysend
FROM dbo.employeeschedule
WHERE WeekId = @weekid
AND dayid = @weekday
UNION
SELECT NULL,
NULL,
NULL) todaysschedule
WHERE Isnull(todaysschedule.currempid,yesterdaysschedule.prevempid) IS NOT NULL
GROUP BY Isnull(todaysschedule.currempid,yesterdaysschedule.prevempid)


--Increment today by 1 day
UPDATE @Schedule
SET TodaysStart = '1900-01-02 ' + Convert(VARCHAR(10),TodaysStart,108),
TodaysEnd = '1900-01-02 ' + Convert(VARCHAR(10),TodaysEnd,108),
YesterdaysStart = '1900-01-01 ' + Convert(VARCHAR(10),YesterdaysStart,108),
YesterdaysEnd = '1900-01-01 ' + Convert(VARCHAR(10),YesterdaysEnd,108)

--Populate minute columns which are used for determining if the end time falls into next day
UPDATE @Schedule
SET TodaysStartMins = Datepart(HOUR,TodaysStart) * 60 + Datepart(MINUTE,TodaysStart),
TodaysEndMins = Datepart(HOUR,TodaysEnd) * 60 + Datepart(MINUTE,TodaysEnd),
YesterdaysStartMins = Datepart(HOUR,YesterdaysStart) * 60 + Datepart(MINUTE,YesterdaysStart),
YesterdaysEndMins = Datepart(HOUR,YesterdaysEnd) * 60 + Datepart(MINUTE,YesterdaysEnd)

--This is the heart of all the things we did so far
--if start time < end time and end time is before 12 am
--then it is today otherwise tommorow so adding a day to the end time.
SELECT e.EmpID,
FirstName,
LastName,
TodaysStart AS TodaysStartTime,
CASE
WHEN ((TodaysStartMins < TodaysEndMins)
AND (TodaysEndMins < 1440))
THEN TodaysEnd
ELSE Dateadd(d,1,TodaysEnd)
END AS TodaysEndTime,
YesterdaysStart AS YesterdaysStartTime,
CASE
WHEN (YesterdaysStartMins < YesterdaysEndMins)
AND (YesterdaysEndMins < 1440)
THEN YesterdaysEnd
ELSE Dateadd(d,1,YesterdaysEnd)
END AS YesterdaysEndTime
FROM @Schedule s
INNER JOIN dbo.Employees e
ON e.EMPID = s.EMPID
WHERE (@InputTime BETWEEN YesterdaysStart AND CASE
WHEN ((YesterdaysStartMins < YesterdaysEndMins)
AND (YesterdaysEndMins < 1440))
THEN YesterdaysEnd
ELSE Dateadd(d,1,YesterdaysEnd)
END)
OR (@InputTime BETWEEN TodaysStart AND CASE
WHEN ((TodaysStartMins < TodaysEndMins)
AND (TodaysEndMins < 1440))
THEN TodaysEnd
ELSE Dateadd(d,1,TodaysEnd)
END)

GO

--Author : Prashanth Vakati
--License : Freeware/OpenSource
--Feedback /Suggestions Welcome.

Sunday, January 24, 2010

Quality Assurance (QA) Tracking System - Access .Net(vb.net)

Any applications that are developed in no means are perfect hence need to be go through the QA process in every stage of the development.Quality Assurance seems to play a big role in all areas of manufacturing and product development.Tracking QA process can be tricky and complicated some times especially when tracking using word and excel documents.Database driven tracking system is very helpful as many people can help in tracking at the same time.

Big enterprise testing application provide the ability to maintain the QA process well but smaller companies and teams that dont have need or money to buy these enterprise products end up maintaining word and excel documents for Quality Assurance process.

I wrote this small application to track Quality Assurance process using vb.net and access database.Here is the link for it

http://code.google.com/p/quality-assurance-tracker/downloads/list



Feedback welcome,Thanks.

Saturday, January 23, 2010

DVR using a PC XBOX 360 and Silicon HDHomeRun

After wanting to create my own DVR setup for many days finally I got a chance to do it last night.I am really amazed by Microsoft Media Center and XBOX 360 capabilities.SiliconDust HDHomeRun is another amazing device that I came across.Using all these I was able to see my recordings and live tv on my PC.

Here are the components I used to make this
1.XBox 360 Pro 60gb HD
2.Windows 7 Ultimate Media Center PC
3.Linksys Router WTRG
4.Netgear WGR614v7
5.XBox Universal Remote
6.HDHome Run Dual Tuner Card
7.Terk HD Antenna

Lets start into going into details

1.Connect HDHome Run to the Router(1) that is connected to the Terk HD Antenna using a RF Splitter.

2.Download the HDHome Run setup software and let it discover the HDHomeRun on the network
(http://download.silicondust.com/hdhomerun/hdhomerun_windows_20100121.exe)

3.Run the Windows Media Center and Run the setup it will automatically connect to the Daul Tuners on the HDHomeRun which is on the network.

4.Look at the following pic which has the entire setup.As the media center pc is in a different room than xbox 360 and hdtv so I have to use Linksys WRTG in a clientbridge mode to connect to a wireless router in another room.


Saturday, January 2, 2010

Subversion pre-commit hook : Check Empty Log Message,Ignore File Extensions,Ignore Directories/Folders,Check For Lock Existance

Have you ever wondered a single svn/subversion pre-commit hook exists fow windows and can check for empty or no log message /messages ,ignore files and directories and check for lock existence(svn:needs-lock) on commiting binary files such as word documents, pdfs, exes,dlls,xls and others.

This small .net pre-commit hook can do it all for you, and is highly configurable to fit every ones need.Can easily maitain ignore list of files and folders, need lock files and turn off/on check using the configuration file.

Code can be used as a sample / example if you want to create a hook of your own.
You will get a Commit failed (details follow): Commit blocked by pre-commit hook (exit code xxxxxx) with output error if svnlook location is not defined in the xml configuration file.

here is the link for it.

http://code.google.com/p/prashanth-vakati-prj2/downloads/list

Config File:






Error Messages from the pre-commit hook:


IIS Manager Crashes on Load/Start Windows 7, IIS 7.5

IIS Manager Crashes on Start  Windows 7, IIS 7.5, Power Shell 5.1. Here is the error I got in the event viewer. IISMANAGER_CRASH IIS Ma...