Monday, March 21, 2005

Close All for VS 2003

Imports EnvDTE
Imports System.Diagnostics

Public Module CloseAll
Private maxTries As Integer = 3
Sub CloseAll()
Dim currentTries As Integer = 0
While (Not exeClose()) And currentTries < maxTries
currentTries += 1
End While
End Sub

Function exeClose() As Boolean
Try
For Each d As Document In DTE.Documents()
d.Close(vsSaveChanges.vsSaveChangesPrompt)
Next
Catch
Return False
End Try

Return True
End Function

End Module

Saturday, March 19, 2005

AccessorsCreator for VS

Imports EnvDTE
Imports System.Diagnostics

Public Module AccessorsCreator
Sub createAccessor()
Dim selected As String = DTE.ActiveDocument().Selection.text()
If (selected Is Nothing Or selected.Length = 0) Then
Exit Sub
End If

selected = selected.Replace(",", "")
selected = selected.Replace(";", "")
Dim parts() As String = selected.Split(" ")
Dim memberCount As Integer = parts.Length - 2

Dim basicOutput As String = "public $TYPE$ $PROP_NAME$ {" & vbCrLf _
& vbTab & "get { return $MEMBER_NAME$; }" & vbCrLf _
& vbTab & "set { $MEMBER_NAME$ = value; }" & vbCrLf _
& "}" & vbCrLf & vbCrLf

Dim results(memberCount) As String
For i As Integer = 2 To parts.Length - 1
Dim propName As String
propName = parts(i).Substring(0, 1).ToUpper() & parts(i).Substring(1)
results(i - 2) = basicOutput.Replace("$MEMBER_NAME$", parts(i))
results(i - 2) = results(i - 2).Replace("$PROP_NAME$", propName)
results(i - 2) = results(i - 2).Replace("$TYPE$", parts(1))
Next

Dim entryLine As Integer = DTE.ActiveDocument().Selection.BottomLine + 1
DTE.ActiveDocument().Selection.GotoLine(entryLine)

For i As Integer = 0 To results.Length - 1
DTE.ActiveDocument().Selection.Insert(results(i))
Next
End Sub
End Module

Wednesday, March 02, 2005

SYSTEM: DMA

Delete these four properties to force XP to reevaluate IDE
devices DMA capabilities on next boot.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E96A-E325-11CE-BFC1-08002BE10318}\0001]
"MasterIdDataCheckSum"=dword:0
"SlaveIdDataCheckSum"=dword:0

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E96A-E325-11CE-BFC1-08002BE10318}\0002]
"MasterIdDataCheckSum"=dword:0
"SlaveIdDataCheckSum"=dword:0

Tuesday, March 01, 2005

C#: Hebrew Date

public static string GetHebrewJewishDateString(DateTime anyDate, bool addDayOfWeek)
{
System.Text.StringBuilder hebrewFormatedString = new System.Text.StringBuilder();

// Create the hebrew culture to use hebrew (Jewish) calendar
CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");
jewishCulture.DateTimeFormat.Calendar = new HebrewCalendar();

#region Format the date into a Jewish format

if (addDayOfWeek)
{
// Day of the week in the format " "
hebrewFormatedString.Append(anyDate.ToString("dddd", jewishCulture) + " ");
}

// Day of the month in the format "'"
hebrewFormatedString.Append(anyDate.ToString("dd", jewishCulture) + " ");

// Month and year in the format " "
hebrewFormatedString.Append("" + anyDate.ToString("y", jewishCulture));

#endregion

return hebrewFormatedString.ToString();
}