This is the third part of a four-part series on automating workflow execution within Citrix Workflow Studio. In the first two parts of the series, I discussed how you can create Powershell scripts to execute workflows. Part 1 provided a high-level overview of creating Powershell scripts for automating workflow execution and Part 2 expanded on those scripts to discuss how to pass parameters into the workflow. In this blog, I will discuss how you can automate workflow execution with a custom Windows application. The sample .NET application I built is shown below. I am providing both the executable and full source code to allow you to expand upon this solution to meet the needs of your environment.
When would I need to use a custom application for executing workflows?
A lot of you might be asking the question - "If we can use the Workflow Studio Console to execute workflows, why would I need a custom application to do that for me?". The answer really comes down to how you need to execute certain workflows in your environment. If you need to execute workflows "on-demand" or "on a schedule", the Workflow Studio Console would meet those needs. Just open the Workflow Studio Console and schedule a job to run immediately or on a pre-determined schedule. However, if you need "event-driven" automation where a third-party application kicks off the execution of a workflow based on an event happening, that is where you need to be able to hook into Workflow Studio with a custom solution to perform that type of automation.
The custom application provided in the Downloads section below provides a sample for how you can tie any .NET windows application to Workflow Studio for executing workflows. Feel free to try out the sample application on your Workflow Studio machine. The full source code is also provided to allow you to customize and extend the application further based on what you need to do.
Downloads:
Download the application executable here
Download the application source code here
Preparing your Workflow Studio environment to use the custom application:
The custom application needs to run on a machine that contains Workflow Studio since it ties into Powershell and calls the Workflow Studio cmdlets for performing various actions on Workflow Studio. In your Workflow Studio Console, you will need to pre-deploy the workflow that you want to automate (see Part 1 for more information on pre-deploying workflows). The workflow that you want to automate can include parameters as well. Parameters for a workflow are defined in the Workflow Studio Designer under the Global Properties section (see Part 2 for more information on defining workflow parameters).
This custom application functions as any typical Windows application in that it runs under the context of the logged-on user account. The logged-on account needs to have permissions in Workflow Studio to execute workflows. These permissions are defined in the Security section of the Workflow Studio Console. For simplicity, I typically add the user accounts as a "Workflow-Admin", but you can play with the security roles here to determine what roles are actually needed.
Using the custom application:
To use the custom application, log onto your Workflow Studio machine with an account that has permissions to execute workflows within Workflow Studio. Place WFSWorkflowExecute.exe on your Workflow Studio machine. When you launch the application, the initial view is shown below.
Click the Get Runtimes button to get the Workflow Studio runtimes that are installed on the local machine. The runtimes are listed within the combo-box below and the name of the runtime specifies which account the runtime is running under.
When a runtime is selected, all of the workflows that are deployed on that runtime are listed as well. To execute a certain workflow, you need to know which runtime you deployed the workflow on. This sample application also provides the version of the workflow as you may have deployed two different versions of the same workflow to the same runtime. Using the version numbers helps you keep them straight.
When you want to execute a workflow, you need to know if that workflow requires any parameters. The workflow parameters are defined in the Workflow Studio Designer in the Global Properties section of the workflow. As mentioned above, Part 2 of this blog series goes into detail on how to define and use parameters inside a workflow.
When specifying workflow parameters inside the custom application, the parameter name is case sensitive. (Notice how I kept the parameter name as "gMessage"). If you mistype the parameter name or use the wrong case, you will get an error message when executing the workflow stating that the parameter name is not recognized. Just keep this in mind as you type the name of the parameters into the application.
Click the Execute Workflow button to execute the workflow. If the workflow was successfully executed, you'll get a pop-up message indicating success.
To verify the workflow was executed, you can open the Workflow Studio Console and check out the Jobs section.
Understanding the source code:
A lot of you out there will want to customize this application in your own environment. I developed this application with C# using Visual Studio 2008 and the Powershell SDK. Your development machine will also need Powershell 1.0 and Citrix Workflow Studio. For advice on setting up your Visual Studio environment, check out this article. If you follow the steps in that article, you'll just need to add the Powershell SDK and you should be all set.
The Powershell SDK is included as part of the Windows Software Development Kit. You can get information on the Poweshell SDK here. I downloaded the full ISO and it took me quite a while to get it. When you are ready to install, you don't need everything in the setup wizard. The Powershell SDK link provided above actually tells you what you specifically need to install to just get the Powershell SDK. To use the Powershell SDK inside your Visual Studio project, the project will need to reference System.Management.Automation.dll.
Once you get your development machine set up, you can open the solution that I provided above inside Visual Studio. Essentially all this custom application does is use the Powershell SDK APIs to execute cmdlets on Powershell. Since Workflow Studio provides Powershell cmdlets to automate various tasks, we can use the Powershell SDK to automate many Workflow Studio functions.
From my personal experience, using the Powershell SDK takes a little time getting used to. What I found to be helpful is to first write out the Powershell commands in Notepad and test them within Powershell to make sure they are functioning as expected. If you are working with Powershell variables, use the echo statement frequently to understand the current value of the variable. Then when you are ready to use the Powershell SDK in your Visual Studio project, you can convert each of your Powershell statements to the equivalent Powershell SDK code. In the source code that I provided for this custom application, I put comments into the code to explain what Powershell command I was trying to execute within that code block. Reviewing those comments should help you to get started with understanding how to use the Powershell SDK. For example, here is the ExecuteWorkflow() function that is used by the custom application. Stepping through this code inside Visual Studio and watching the variables is another great way to learn this code.
public string ExecuteWorkflow(Hashtable objFunctionParameters, Hashtable objWorkflowParameters) { try { //Declare local variables string l_strReturn = "Executing workflow"; string l_strWorkflowName = objFunctionParameters["WorkflowName"].ToString(); string l_strRuntimeName = objFunctionParameters["RuntimeName"].ToString(); Hashtable l_objWorkflowParameters = objWorkflowParameters; //Create a runspace containing the Workflow Studio snap-ins RunspaceConfiguration l_objRSConfiguration = RunspaceConfiguration.Create(); PSSnapInException l_objSnapInException = null; l_objRSConfiguration.AddPSSnapIn("Citrix.WorkflowStudio.Azman", out l_objSnapInException); l_objRSConfiguration.AddPSSnapIn("Citrix.WorkflowStudio.Core", out l_objSnapInException); l_objRSConfiguration.AddPSSnapIn("Citrix.WorkflowStudio.DataStore", out l_objSnapInException); l_objRSConfiguration.AddPSSnapIn("Citrix.WorkflowStudio.Installer", out l_objSnapInException); Runspace l_objRunspace = RunspaceFactory.CreateRunspace(l_objRSConfiguration); l_objRunspace.Open(); //Get reference to the Workflow Studio runtime that was passed in. //We are executing the Powershell command below: //$rt = Get-WorkflowRuntime -ServiceName $ServiceName Pipeline l_objPipeLine = l_objRunspace.CreatePipeline(); Command l_objCommand = new Command("get-workflowruntime"); l_objCommand.Parameters.Add("ServiceName", l_strRuntimeName); l_objPipeLine.Commands.Add(l_objCommand); Collection<PSObject> l_objCommandResults = l_objPipeLine.Invoke(); PSObject l_objRuntime = l_objCommandResults[0]; l_objPipeLine = null; //Get reference to the deployed workflow that was passed in. //We are executing the Powershell command below: //$workflow = get-deployedworkflow -workflowruntime $rt -workflowname $strWorkflowName -includeschedule l_objPipeLine = l_objRunspace.CreatePipeline(); l_objCommand = new Command("get-deployedworkflow"); l_objCommand.Parameters.Add("workflowruntime", l_objRuntime); l_objCommand.Parameters.Add("workflowname", l_strWorkflowName); l_objCommand.Parameters.Add("includeschedule"); l_objPipeLine.Commands.Add(l_objCommand); l_objCommandResults = l_objPipeLine.Invoke(); PSObject l_objWorkflow = l_objCommandResults[0]; l_objPipeLine = null; //Schedule the workflow to run immediately. //We are executing the Powershell command below: //schedule-workflow -workflowruntime $rt -workflowstrongname $workflow.WorkflowStrongName -workflowparameters $wfparameters -runimmediately l_objPipeLine = l_objRunspace.CreatePipeline(); l_objCommand = new Command("schedule-workflow"); l_objCommand.Parameters.Add("workflowruntime", l_objRuntime); l_objCommand.Parameters.Add("workflowstrongname", l_objWorkflow.Properties["WorkflowStrongName"].Value.ToString()); l_objCommand.Parameters.Add("workflowparameters", l_objWorkflowParameters); l_objCommand.Parameters.Add("runimmediately"); l_objPipeLine.Commands.Add(l_objCommand); l_objCommandResults = l_objPipeLine.Invoke(); l_objPipeLine = null; //Close the runspace l_objRunspace.Close(); //Return success l_strReturn = "Job completed!"; return l_strReturn; } catch (Exception objException) { //Initialize error message string l_strError = ""; l_strError = "An error has occurred. The error is \"" + objException.Message.ToString() + "\". "; return l_strError; } }
Blogs in this series:
Using Powershell to automate workflow execution within Citrix Workflow Studio
Passing parameters into a workflow within Citrix Workflow Studio
Automating workflow execution for Citrix Workflow Studio using a .NET windows application (this one)
Automating workflow execution for Citrix Workflow Studio using an ASP.NET web application
Virtualize your servers, desktops, applications; the benefits are clear, it's a question of when not if - sure get that. Virtualization is not an end point, but an enabler of a more flexible and efficient compute environment - ok get that too. Ultimately virtualization must enable IT to contribute to better business results. What about other parts of the IT infrastructure beyond servers, clients and applications? Are we evolving to having islands of virtual clients and servers connected via a static network infrastructure? See this post in Archimedius for more on this theme.
Not to be left behind in the dust of server virtualization, network interconnects are also marching toward being enabled in dynamic virtual environments. Case in point is HP's recent introduction of its Virtual Connect Flex-10 technology, a new component in HP's Virtual Connect architecture. Flex-10 enables you to add 4x more NICs to each server blade without more hardware. In addition to supporting oodles of connections and NICS, Flex-10 provides the ability to dynamically adjust bandwidth for each network connection on the fly. With HP Flex-10 technology, you choose how many NICs are on each server and can adjust the bandwidth of each NIC in increments of 100 Mb.
This HP Flex-10 product is an example of how it is not just servers that can be virtualized and illustrates how the days of static infrastructure will soon be over. HP product details are posted here. Seems those HP hardware folks have some cool few new virtualization solutions to share beyond their XenServer based virtualization solutions. I'm now wondering how long before those virtualized server workloads are able to talk intelligently with the network infrastructure to automate and optimize the cloud ....?

The first question that most people ask me after seeing Workflow Studio in action is:
"Wow! That's cool, but what can I do with that?
I would like to use this post to try to explain why I think you should be doing automation in your data center today and then look at some different processes that are good candidates for automation with Workflow Studio.
Why should you automate?
The IT data center of today often includes products from many different vendors and consists of both hardware devices and software. Often, the SDKs that are available for all of these devices and software are quite inconsistent and some of your processes may have been developed by a consultant who is no longer around. Stop and ask yourself this question:
Are all of my processes consistently repeatable by anyone on the team?
If you can't answer 'yes' to that question then you should be looking into IT Process Automation. And if you want an easy way to automate tasks across multiple products/components without the need for complex scripting, then take a look at Workflow Studio.
Here are some broad categories for types of automation you might want to have in your data center:
- On-Demand Automation - Being able to launch a process that combines several tasks, possibly with some simple user input, in response to something that has happened in your environment (e.g. A call or email comes in that a new user needs to be setup, a new application installed, or permissions modified for a user.)
- Schedule-Based Automation - Schedule a task to be performed at a set time each day (e.g. Restart your servers every night at midnight.)
- Event-Driven Automation - Automate a set of tasks based on system events (e.g. When load is increasing bring more servers online and when load decreases take servers offline)
If you download the Tech Preview of Workflow Studio (free download here) you can look at some of the sample templates we include with the product and get a look at some On-Demand Automation out of the box. The Tech Preview doesn't really provide any help with scheduling or event management, but this type of functionality is being added to the product.
Next, let's look at what I think are the 3 key categories of use cases for Workflow Studio and some examples that you could put in action today:
- Server Resource Management = Dynamic Delivery Center - Transform your data center into a delivery center by creating workflows that tie together your server provisioning process (both physical and virtual) with your web, desktop, and application delivery processes.
- Power Management = Green Data Center - Being able to power on/off both physical and virtual servers automatically provides the ability to better manage your resources and, ultimately, save $$ by having your power-hungry servers off when they are not needed.
- User Management = Automated User Provisioning - Every organization has a process for provisioning and de-provisioning user accounts, but often these processes involve multiple manual steps. Automating the process end-to-end ensures that best practices are followed in exactly the same way each time.
I hope this encourages everyone to think about what kinds of tasks you could automate in your environment. Let me know in the comments what kinds of things you would like to automate or you can find my email address in my profile if you want to email me directly.