This example walks you through creating a simple Forward Path scenario and task script.
This creates a new scenario and opens it in the Editor. The new scenario script is as follows:
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 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.
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.)
The values in the RAG column reflect the actual RAG values.
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).
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.
For example, you can use the Output.Display property to control the width and visibility of the standard columns in reports, like this:
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:
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.
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.
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.
This creates a new task script and opens it in the Editor. The new task script is as follows:
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.
Imports System.Net.Mail Imports System.Net
' This informs the controller that it can abort if the user cancels controller.AbortOnCancel() Dim myClient As New SmtpClient("<validsmtpserver>") myClient.Credentials = New NetworkCredential("<emailaccountusername>", "<emailaccountpassword>") Dim MainMessage As String = "" Dim Message As New MailMessage() Dim Address As New MailAddress("<fromaddress>", "AppDNA Notification") Dim ToAddress As New MailAddress("<recipientemailaddress>") MainMessage = MainMessage + "<html>" MainMessage = MainMessage + "<head>" MainMessage = MainMessage + "<title>AppDNA Notification</title>" MainMessage = MainMessage + "</head>" MainMessage = MainMessage + "<body>" MainMessage = MainMessage + "Hello," MainMessage = MainMessage + "<br />" MainMessage = MainMessage + "<br />" MainMessage = MainMessage + "Application needs redevelopment." MainMessage = MainMessage + "<br />" MainMessage = MainMessage + "Application Name: " + controller.Application.Name MainMessage = MainMessage + "<br />" MainMessage = MainMessage + "Source Path: " + controller.Application.SourcePath MainMessage = MainMessage + "<br />" MainMessage = MainMessage + "Goodbye." MainMessage = MainMessage + "<br />" MainMessage = MainMessage + "</body>" MainMessage = MainMessage + "</html>" Message.Body = MainMessage Message.IsBodyHtml = True Message.From = Address Message.To.Add(ToAddress) Message.Subject = "AppDNA Notification" myClient.Send(Message)
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.
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).