Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Web.UI.WebControls
Imports System.Workflow.ComponentModel
Imports Microsoft.IdentityManagement.WebUI.Controls
Imports Microsoft.ResourceManagement.Workflow.Activities
Imports FIM.CustomWorkflowsActivityLibrary
Public Class CustomUpdateUI
Inherits ActivitySettingsPart
Public Overrides Function GenerateActivityOnWorkflow(ByVal workflow As SequentialWorkflow) As Activity
If Not Me.ValidateInputs() Then
Return Nothing
End If
Dim CustomUpdate As New CustomUpdate()
CustomUpdate.Attribute = Me.GetText("txtAttribute")
CustomUpdate.Value = Me.GetText("txtValue")
CustomUpdate.AuthZAfterAction = Me.GetIsChecked("bAuthZAfterAction")
Return CustomUpdate
End Function
'''
''' Called when editing the workflow activity settings.
'''
Public Overrides Sub LoadActivitySettings(ByVal activity As Activity)
Dim CustomUpdate As CustomUpdate = TryCast(activity, CustomUpdate)
If CustomUpdate IsNot Nothing Then
Me.SetText("txtAttribute", CustomUpdate.Attribute)
Me.SetText("txtValue", CustomUpdate.Value)
Me.SetIsChecked("bAuthZAfterAction", CustomUpdate.AuthZAfterAction)
End If
End Sub
'''
''' Saves the activity settings.
'''
Public Overrides Function PersistSettings() As ActivitySettingsPartData
Dim data As New ActivitySettingsPartData()
data("Attribute") = Me.GetText("txtAttribute")
data("Value") = Me.GetText("txtValue")
data("AuthZAfterAction") = Me.GetIsChecked("bAuthZAfterAction")
Return data
End Function
'''
''' Restores the activity settings in the UI
'''
Public Overrides Sub RestoreSettings(ByVal data As ActivitySettingsPartData)
If data IsNot Nothing Then
Me.SetText("txtAttribute", DirectCast(data("Attribute"), String))
Me.SetText("txtValue", DirectCast(data("Value"), String))
Me.SetIsChecked("bAuthZAfterAction", DirectCast(data("AuthZAfterAction"), Boolean))
End If
End Sub
'''
''' Switches the activity between read only and read/write mode
'''
Public Overrides Sub SwitchMode(ByVal mode As ActivitySettingsPartMode)
Dim [readOnly] As Boolean = (mode = ActivitySettingsPartMode.View)
Me.SetTextBoxReadOnlyOption("txtAttribute", [readOnly])
Me.SetTextBoxReadOnlyOption("txtValue", [readOnly])
Me.SetCheckBoxReadOnlyOption("bAuthZAfterAction", [readOnly])
End Sub
'''
''' Returns the activity naMe.
'''
Public Overrides ReadOnly Property Title() As String
Get
Return "Custom Update"
End Get
End Property
'''
''' In general, this method should be used to validate information entered
''' by the user when the activity is added to a workflow in the Workflow
''' Designer.
''' We could add code to verify that the log file path already exists on
''' the server that is hosting the FIM Portal and check that the activity
''' has permission to write to that location. However, the code
''' would only check if the log file path exists when the
''' activity is added to a workflow in the workflow designer. This class
''' will not be used when the activity is actually run.
''' For this activity we will just return true.
'''
Public Overrides Function ValidateInputs() As Boolean
Return True
End Function
'''
''' Creates a Table that contains the controls used by the activity UI
''' in the Workflow Designer of the FIM portal. Adds that Table to the
''' collection of Controls that defines each activity that can be selected
''' in the Workflow Designer of the FIM Portal. Calls the base class of
''' ActivitySettingsPart to render the controls in the UI.
'''
Protected Overrides Sub CreateChildControls()
Dim controlLayoutTable As Table
controlLayoutTable = New Table()
'Width is set to 100% of the control size
controlLayoutTable.Width = Unit.Percentage(100.0)
controlLayoutTable.BorderWidth = 0
controlLayoutTable.CellPadding = 2
'Add a TableRow for each textbox in the UI
Dim loggingOptions As String() = {"Normal", "Verbose"}
controlLayoutTable.Rows.Add(Me.AddTableRowTextBox("Target Attribute:", "txtAttribute", 400, 100, False, "The target attribute.", False))
controlLayoutTable.Rows.Add(Me.AddTableRowTextBox("New Value:", "txtValue", 400, 100, False, "The new value of the attribute.", False))
controlLayoutTable.Rows.Add(Me.AddTableRowCheckBox("Allow Authorization:", "bAuthZAfterAction", False))
Me.Controls.Add(controlLayoutTable)
MyBase.CreateChildControls()
End Sub
#Region "WebUI Functions"
#Region "SubHeading"
Private Function AddSubHeading(ByVal labelText As [String]) As TableHeaderRow
Dim hrow As New TableHeaderRow()
Dim labelCell As New TableCell()
Dim oLabel As New Label()
oLabel.Text = labelText
oLabel.CssClass = MyBase.LabelCssClass
oLabel.Font.Bold = True
labelCell.Controls.Add(oLabel)
hrow.Cells.Add(labelCell)
Return hrow
End Function
#End Region
#Region "TextBox"
'Create a TableRow that contains a label and a textbox.
Private Function AddTableRowTextBox(ByVal labelText As [String], ByVal controlID As [String], ByVal width As Integer, _
ByVal maxLength As Integer, ByVal multiLine As [Boolean], ByVal defaultValue As [String], _
Optional ByVal hideText As Boolean = False) As TableRow
Dim row As New TableRow()
Dim labelCell As New TableCell()
Dim controlCell As New TableCell()
Dim oLabel As New Label()
Dim oText As New TextBox()
oLabel.Text = labelText
oLabel.CssClass = MyBase.LabelCssClass
labelCell.Controls.Add(oLabel)
oText.ID = controlID
oText.CssClass = MyBase.TextBoxCssClass
oText.Text = defaultValue
oText.MaxLength = maxLength
oText.Width = width
If multiLine Then
oText.TextMode = TextBoxMode.MultiLine
oText.Rows = System.Math.Min(6, (maxLength + 60) \ 60)
oText.Wrap = True
End If
If hideText Then
oText.TextMode = TextBoxMode.Password
End If
controlCell.Controls.Add(oText)
row.Cells.Add(labelCell)
row.Cells.Add(controlCell)
Return row
End Function
Private Function GetText(ByVal textBoxID As String) As String
Dim textBox As TextBox = DirectCast(Me.FindControl(textBoxID), TextBox)
Return If(textBox.Text, [String].Empty)
End Function
Private Sub SetText(ByVal textBoxID As String, ByVal text As String, Optional ByVal hideText As Boolean = False)
Dim textBox As TextBox = DirectCast(Me.FindControl(textBoxID), TextBox)
If hideText Then textBox.TextMode = TextBoxMode.Password
If textBox IsNot Nothing Then
textBox.Text = text
Else
textBox.Text = ""
End If
End Sub
Private Sub SetTextBoxReadOnlyOption(ByVal textBoxID As String, ByVal [readOnly] As Boolean)
Dim textBox As TextBox = DirectCast(Me.FindControl(textBoxID), TextBox)
textBox.[ReadOnly] = [readOnly]
End Sub
#End Region
#Region "CheckBox"
Private Function AddTableRowCheckBox(ByVal labelText As [String], ByVal controlID As [String], _
ByVal defaultValue As [Boolean]) As TableRow
Dim row As New TableRow()
Dim labelCell As New TableCell()
Dim controlCell As New TableCell()
Dim label As New Label()
Dim checkbox As New CheckBox()
label.Text = labelText
label.CssClass = MyBase.LabelCssClass
labelCell.Controls.Add(label)
checkbox.ID = controlID
checkbox.Checked = defaultValue
controlCell.Controls.Add(checkbox)
row.Cells.Add(labelCell)
row.Cells.Add(controlCell)
Return row
End Function
Private Function GetIsChecked(ByVal checkBoxID As String) As Boolean
Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)
Return checkBox.Checked
End Function
Private Sub SetIsChecked(ByVal checkBoxID As String, ByVal isChecked As Boolean)
Dim checkBox As CheckBox = DirectCast(Me.FindControl(checkBoxID), CheckBox)
If checkBox IsNot Nothing Then
checkBox.Checked = isChecked
Else
checkBox.Checked = True
End If
End Sub
Private Sub SetCheckBoxReadOnlyOption(ByVal textBoxID As String, ByVal [readOnly] As Boolean)
Dim checkBox As CheckBox = DirectCast(Me.FindControl(textBoxID), CheckBox)
checkBox.Enabled = Not [readOnly]
End Sub
#End Region
#Region "Radio"
Private Function AddTableRowRadioList(ByVal labelText As [String], ByVal controlID As [String], _
ByVal radioOptions As String(), _
ByVal defaultValue As [String]) As TableRow
Dim row As New TableRow()
Dim labelCell As New TableCell()
Dim controlCell As New TableCell()
Dim label As New Label()
Dim radioList As New RadioButtonList()
Dim item As String
label.Text = labelText
label.CssClass = MyBase.LabelCssClass
labelCell.Controls.Add(label)
radioList.ID = controlID
For Each item In radioOptions
radioList.Items.Add(New ListItem(item, item))
Next
radioList.SelectedValue = defaultValue
radioList.RepeatDirection = RepeatDirection.Horizontal
controlCell.Controls.Add(radioList)
row.Cells.Add(labelCell)
row.Cells.Add(controlCell)
Return row
End Function
Private Function GetRadioSelection(ByVal radioListID As String) As String
Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)
Return radioList.SelectedValue
End Function
Private Sub SetRadioSelection(ByVal radioListID As String, ByVal radioSelection As String)
Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)
If radioList IsNot Nothing Then
radioList.SelectedValue = radioSelection
Else
radioList.SelectedValue = radioList.Items.Item(0).Text
End If
End Sub
Private Sub SetRadioListReadOnlyOption(ByVal radioListID As String, ByVal [readOnly] As Boolean)
Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)
radioList.Enabled = Not [readOnly]
End Sub
#End Region
#End Region
End Class