Forward Path example
Aug 14, 2017
This example walks you through creating a simple Forward Path scenario and task script.
Create the scenario
From the AppDNA menus, choose Configure > Forward Path.
On the toolbar in the Forward Path Logic Editor, click New Scenario.
In the Forward Path Script Name dialog box, enter a name and description for the new scenario, and then click OK.
This creates a new scenario and opens it in the Editor. The new scenario script is as follows:
pre codeblock 1 Public Function ForwardPath(ByVal currentApplication As Application) As Output 2 ' TODO: Your new Forward Path Logic definition must be defined here. 3 ' Refer to the sample Forward Path scripts which have been provided. 4 Dim myForwardpathresult As New Output() 5 6 myForwardpathresult.Outcome = "Sample Outcome" 7 myForwardpathresult.Cost = 100 8 myForwardpathresult.RAG = RAG.Green 9 10 ForwardPath = myForwardpathresult 11 12 End Function
This is a functional scenario script, although it is not of any practical use. To understand how it works, click Test on the Editor toolbar.
This evaluates the scenario against the applications that are currently selected in the Application List and opens the results on the Output tab.
Notice that the value in the Outcome column is “Sample Outcome” for each application, and similarly the value in the RAG and Cost columns are “Green” and 100 for all of the selected applications. This is because the values for these columns are “hard-coded” in the script in lines 6-8.
Notice that the Description and Customfield columns are empty because the scenario does not provide values for these columns.
Change the value of the RAG column to reflect the application’s actual RAG for the Windows 7 report. Change line 8 in the scenario script as follows:
pre codeblock myForwardpathresult.RAG = currentApplication.Modules.Windows7.RAG
This sets the value in the RAG column to the application’s Windows 7 RAG status. (This assumes that the application has already been analyzed for the Windows 7 report. If this report is not available, choose another report that is available. Use the Property Explorer to discover how to refer to the other reports.)
Click Test to see the results.
The values in the RAG column reflect the actual RAG values.
Next make the value in the Outcome column depend on the Windows 7 RAG status. To do this, replace line 6 with an If statement, like this:
pre codeblock If (currentApplication.Modules.Windows7.RAG = RAG.Green) Then myForwardpathresult.Outcome = "OK for Windows 7" Else If (currentApplication.Modules.Windows7.RAG = RAG.Amber) Then myForwardpathresult.Outcome = "Remediation required" Else myForwardpathresult.Outcome = "Redevelopment required" End If End If
This statement tests whether the application’s Windows 7 RAG status is green. If it is, the script writes “OK for Windows 7” in the Outcome column and if not, it tests whether the Windows 7 RAG status is amber. If it is amber, the script writes “Remediation required” into the Outcome column and otherwise writes “Redevelopment required” to the Outcome column – because if the RAG status is not green or amber, it must be red (assuming the application has been analyzed and unlocked).
Click Test to see the results.
Notice that now the values in the Outcome column reflect the logic in the If statement.
This is a deliberately trivial example that is designed to introduce how Forward Path works. To see some more realistic examples, use the Scenarios Explorer to browse the sample scenarios that come with AppDNA and use the Property Explorer to explore the properties that are available to the scenario scripts.
Note: The Output object is shown as ForwardPathReportOutput in the Property Explorer.
For example, you can use the Output.Display property to control the width and visibility of the standard columns in reports, like this:
``` pre codeblock myForwardpathresult.Display.Application.Width = 250 myForwardpathresult.Display.Manufacturer.Width = 100 myForwardpathresult.Display.Version.Width = 50 myForwardpathresult.Display.SourcePath.Visible = false myForwardpathresult.Display.Outcome.Width = 400
Similarly you can use the Output.CustomFieldn.Display properties to control the width and visibility of the custom field columns: ``` pre codeblock myForwardpathresult.CustomField1.Display.Width = 50 myForwardpathresult.CustomField2.Display.Width = 100
These properties control the display of the columns when you run the report. They do not control the columns on the Output tab in the Forward Path Logic Editor.
Create a task script
We will now create a task script that is associated with the “Redevelopment required” value in the Outcome column created by our example scenario script.
Open the example script we created in the previous step in the Editor.
On the main toolbar, click New Task Script.
This opens the Forward Path Task Script dialog box, which lists the possible values in the Outcome column for the scenario that is open in the Editor.
From the drop-down list, select Redevelopment required, enter a description, and click OK.
This creates a new task script and opens it in the Editor. The new task script is as follows:
pre codeblock 1 ' This sample script kicks off an Install Capture of the given file 2 ' as well as interacts with the gui 3 LoadAssembly System.Windows.Forms.dll 4 5 Imports AppDNA.AppTitude.Scripting 6 Imports System.Collections.Generic 7 8 Public Class ScriptClass 9 10 Public Function Start(controller As IActionController) As TaskStatusEnum 11 ' If you need to override or provide replaceable to the 12 ' execution profiles add then to this dictionary 13 14 Dim replaceables As Dictionary(Of String, String) 15 ' replaceables.Add( "replaceablename", "value") 16 17 ' This informs the controller that it can abort if the user cancels 18 controller.AbortOnCancel() 19 20 ' This lets you run the execution profile for a given app using a given VM 21 ProductionManager.RunExecutionProfile(controller, "Snapshot", replaceables, "Default VM Configuration") 22 23 ' Add you own actions 24 controller.GUI.ProgressPercent = 100 25 Start = TaskStatusEnum.Complete 26 End Function 27 28 End Class
This is a skeleton task script that starts an Install Capture.
We will change the lines that relate to Install Capture (lines 11 – 21) with code that will send an email. However, first we will add the following lines after line 6 to import the namespaces we need to send an email:
pre codeblock Imports System.Net.Mail Imports System.Net
Now replace the Install Capture code (now lines 13 – 23) with the following:
``` pre codeblock ‘ This informs the controller that it can abort if the user cancels controller.AbortOnCancel()
Dim myClient As New SmtpClient(“
") myClient.Credentials = New NetworkCredential(" ", " ")
Dim MainMessage As String = “”
Dim Message As New MailMessage() Dim Address As New MailAddress(“
", "AppDNA Notification") Dim ToAddress As New MailAddress(" ")
MainMessage = MainMessage + “<html>” MainMessage = MainMessage + “<head>” MainMessage = MainMessage + “
MainMessage = MainMessage + “</head>” MainMessage = MainMessage + “<body>”
MainMessage = MainMessage + “Hello,” MainMessage = MainMessage + “
” MainMessage = MainMessage + “
” MainMessage = MainMessage + “Application needs redevelopment.” MainMessage = MainMessage + “
” MainMessage = MainMessage + “Application Name: “ + controller.Application.Name MainMessage = MainMessage + “
” MainMessage = MainMessage + “Source Path: “ + controller.Application.SourcePath MainMessage = MainMessage + “
” MainMessage = MainMessage + “Goodbye.” MainMessage = MainMessage + “
” MainMessage = MainMessage + “</body>” MainMessage = MainMessage + “</html>”
Message.Body = MainMessage Message.IsBodyHtml = True Message.From = Address Message.To.Add(ToAddress)
Message.Subject = “AppDNA Notification”
Replace <validsmtpserver>, <emailaccountusername>, <emailaccountpassword>, <fromaddress> and <recipientemailaddress> with appropriate values for your environment.
Click Save to preserve your changes.
Now let’s run the task script:
- From the AppDNA side bar, choose Reports: Applications > Forward Path.
- In the Forward Path report viewer, select the Forward Path scenario we created earlier.
- Click Evaluate Tasks.
This opens the Forward Path Task Sequencing screen, which lists the applications that have been processed by the Forward Path scenario and shows whether they have a task script associated with them.
Select an application that has a task script associated and click Start on the toolbar.
This runs the task script for that application. The Status column shows whether the script was run successfully. When an error occurs, it is shown in the lower part of the screen. In this example, the script fails if you have not entered appropriate mail parameters for your environment (step 6 above).
- To see some more examples, use the Task Scripts Explorer to browse the sample task scripts that come with AppDNA.
- For information about running an execution profile from a task script, see Run an execution profile.