Sunday, July 25, 2010

Saturday, June 26, 2010

UML Sequence Diagrams - Activation Blocks - steps

Here are the steps for making a sequence diagram with activations


Start by drawing the actor initiating the activity and the participating classes and objects

















Start the first activation block. An activation block representation of C# is any set of open and closed braces{}, such as for a method, try catch, if, foreach, etc


























Next, add in the next message. Any place an arrow will terminate, before drawing in the arrow head, start the next activation block, then draw in the arrowhead pointing to that activation block(See Fig 4 and 5)









Once you have added all of the messages you want to show, finish off your activation blocks. Waiting until the end is easier, because you know how long they need to be.





Monday, June 21, 2010

UML Sequence Diagrams - Activation blocks - foreach statements


As I mentioned in a previous post, you can use an activation block to show the contents of a foreach loop, with "foreach" as the message and (Company company in Companies) as parameters ( use whatever type an name you are actually looping through ).

UML Sequence Diagrams - Activation blocks

Activation blocks tend to confuse people when learning UML Sequence Diagrams. I have to admit, if I haven't sequenced something for awhile, I forget how and especially why, too.


Activation blocks are usually only necessary once you start sequencing multiple calls within the same object or class.






If a sequence starts in an asp.net web page, such as Page_Load(...), and then a call is made to a method called InitializeVariables(), and then one to GetLogonUser(), as in Fig 1. Did Page_Load(...) call GetLogonUser(), or did InitializeVariables()?


We don't know unless we use activation blocks (See Fig 2 and Fig 3, showing each way).

Fig 2 shows that InitializeVariables() called GetLogonUser(),









Fig 3 shows that Page_Load(...) did.

Sunday, June 20, 2010

Sequence Diagram - If statement


While UML 2.0 has syntax for blocks like if -else and loops in Sequence Diagrams, I prefere to use pseudo - c#. I use the if, else, for, foreach, etc as the message, and an activation block to show what happens inside the block. I know this is not standard UML, but I find it much more readable, especially for reverse engineering

Friday, June 18, 2010

Sequence Diagrams Static vs Instance Methods

To show that a Method call is static - Underline it
Speeding up RadGrids

If you can, turn viewstate off

HierarchyLoadMode="ServerOnDemand"

Do your data load for the top level parent table in The NeedDataSource Event
if (!e.IsFromDetailTable)
{
grd.DataSource = DAL.Practice.Catalog.GetMasterCatalogSuppliers();
}

Load the child table data in the _OnDetailTableDataBind event
//Get the id of the parent item
GridDataItem gridParentDataItem = e.DetailTableView.ParentItem as GridDataItem;
int brandID = gridParentDataItem.GetColumnInt32("BrandID");
//Note that the GetColumnInt32 is an Extension Method I wrote, you won't have it

// bind the detail grid
grd.MasterTableView.DetailTables[0].DataSource = Get...(brandID);

Friday, June 11, 2010

UML on June 18

Tuesday, June 8, 2010

How can I make query to find "ClientID = 2660" in all tables in The Database?

Quick and Dirty


in Sql , set Results to Text

Run this query

SELECT 'Select * from ' + dbo.sysobjects.Name + ' where ClientID = 2660' FROM dbo.syscolumns

INNER JOIN dbo.sysobjects ON dbo.syscolumns.id = dbo.sysobjects.ID

WHERE dbo.syscolumns.Name = 'ClientID'



Then copy the queries it makes, past them into a query window, and run them

Clean Asp.net temp directory iis

A better Property Macro Snippet

Private Function MakePropertyGet(ByVal line As String) As String
'Make sure we are dealing with selected text in the form of:
'Variable_Name Type Default_Value
Dim Words() As String = line.Trim().Split()

If Words.Length < 2 Then
Return "Input in invalid format! Use PropName Type Default_Value"
Else


Return "public " & Words(0) & " " & Words(1) & Words(0) & vbNewLine & _
vbTab & vbTab & "{" & vbNewLine & _
vbTab & vbTab & vbTab & "get { return " & Words(1) & "; }" & vbNewLine & _
vbTab & vbTab & "}"

End If

End Function

Public Sub CreateSimplePropertyVB()
Dim TS As TextSelection = DTE.ActiveDocument.Selection
Dim Insertion As String, Line As String
Dim Lines() As String = TS.Text.Split(vbNewLine)

For Each Line In Lines
Insertion &= MakePropertyGet(Line)
Next

TS.Delete()
TS.Insert(Insertion)
End Sub

Shared View Desktop monitor sharing

Get the screen Sharing Program SharedView from Microsoft hereEdit

https://connect.microsoft.com/site/sitehome.aspx?SiteID=94&wa=wsignin1.0

Snippet Public Properties for Controls

To add public properties for controls

xml version="1.0" encoding="utf-8" ?>

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

<CodeSnippet Format="1.0.0">

<Header>

<Title>propGetControlTitle>

<Shortcut>propGetControlShortcut>

<Description>Code snippet for propGetControlDescription>

<Author>Mike SneenAuthor>

<SnippetTypes>

<SnippetType>ExpansionSnippetType>

<SnippetType>SurroundsWithSnippetType>

SnippetTypes>

Header>

<Snippet>

<Declarations>

<Literal>

<ID>typeID>

<Default>LabelDefault>

Literal>

Declarations>

<Code Language="csharp">

public $type$ $end$$type$

{

get{ return $selected$; }

}]]>

Code>

Snippet>

CodeSnippet>

CodeSnippets>


Monday, June 7, 2010

Visual Studio 2008 app_offline.htm

To get rid of the annoying autogenerated app_offline.htm, do 2 steps

1. Make an external tool definition
Tools... External Tools...
Add...
Title - 'Delete
App_Offline'
Command -
'cmd.exe'
Arguments - '/K "del
app_offline.htm'
Initial directory -
'$(ProjectDir)'
Use Output Window =
checked

2. put an entry on the toolbar to call it
Click on the down arrow of the toolbar... Add or
Remove Buttons... Customize
Categories - 'Tools'
Commands - External Tools 3
(Instead of 3, the 1 based index of your External Tool above)
Drag the command to the toolbar
Click on it and rename it

general db search

Declare @Search varchar(255)
set @Search = 'IsThirdPartyProduct' --Set the search text here
DECLARE @SearchTxt varchar(255)
SET @SearchTxt = '%' + @Search + '%'
SELECT o.[name],
CASE
o.xtype
WHEN 'TR' THEN 'Trigger'
WHEN
'U' THEN 'User Table'
WHEN 'F' THEN 'Foreign Key'
WHEN 'C' THEN
'Check
Constraint
'
WHEN 'UQ' THEN
'Index'
WHEN 'S' THEN 'System
Table'
WHEN 'D' THEN 'User Defined Data
Type'
WHEN 'PK' THEN 'Primary
Key'
WHEN 'FN' THEN 'Function'
WHEN 'TF' THEN
'Table Function'
WHEN 'V' THEN
'View'
WHEN 'P' THEN 'Stored
Procedure'
ELSE 'Other'
END
ObjType,
(SELECT TOP 1 SUBSTRING([Text],PATINDEX(@SearchTxt,
[Text]) - 25, 100) + '...'
FROM dbo.syscomments

WHERE [id] = c.[id]
AND
PATINDEX(@SearchTxt, [Text]) > 0) ObjText
FROM dbo.sysobjects
o
INNER JOIN dbo.syscomments c
ON o.[id] =
c.[id]
WHERE c.encrypted = 0
AND c.colid =
1
AND EXISTS( SELECT [id]
FROM dbo.syscomments
WHERE [text] LIKE
@SearchTxt
AND [id] =
c.[id])
ORDER BY ObjType, o.[name]

Search for a column name in sql db


SELECT dbo.sysobjects.Name FROM dbo.syscolumns
INNER JOIN dbo.sysobjects ON dbo.syscolumns.id = dbo.sysobjects.ID
WHERE dbo.syscolumns.Name = 'UserID' --and dbo.syscolumns.xtype = 175
--AND dbo.sysobjects.type = 'U'

Update 2 tables in a transaction

Yuiko was writing a query the other day to update 2 tables at the same time.

ALTER PROCEDURE [dbo].[usp_PracticeBillingAddress_Update]

(

@PracticeID INT

, @AddressID INT

, @AttentionOf VARCHAR(50)

, @AddressLine1 VARCHAR(50)

, @AddressLine2 VARCHAR(50)

, @City VARCHAR(50)

, @State CHAR(2)

, @ZipCode CHAR(5)

, @ZipCodePlus4 CHAR(4)

, @ModifiedUserID INT

)

AS

BEGIN

DECLARE @TransactionCountOnEntry INT -- Transaction Count before the transaction begins

, @Err INT -- holds the @@Error code returned by SQL Server

SELECT @Err = @@ERROR

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

IF @Err = 0

BEGIN

SELECT @TransactionCountOnEntry = @@TRANCOUNT

BEGIN TRANSACTION

END

IF @Err = 0

BEGIN

UPDATE dbo.Address

SET

AddressLine1 = @AddressLine1

, AddressLine2 = @AddressLine2

, City = @City

, State = @State

, ZipCode = @ZipCode

, ZipCodePlus4 = @ZipCodePlus4

, ModifiedUserID = @ModifiedUserID

, ModifiedDate = GETDATE()

WHERE

AddressID = @AddressID

SET @Err = @@ERROR

END

IF @Err = 0

BEGIN

UPDATE dbo.PracticeBillingAddress

SET

AttentionOf = @AttentionOf

, ModifiedUserID = @ModifiedUserID

, ModifiedDate = GETDATE()

WHERE

PracticeID = @PracticeID

AND AddressID = @AddressID

SET @Err = @@ERROR

END

Exec usp_PracticeBillingAddress_UpdateCentralDecentral @practiceID, @ModifiedUserID

IF @@TranCount > @TransactionCountOnEntry

BEGIN

IF @Err = 0

COMMIT TRANSACTION

ELSE

ROLLBACK TRANSACTION

-- Add any database logging here

END

RETURN @Err

END