Welcome to K2 Underground Sign In | Join | Help

Using the Archiving functionality throught API

The archiving functionality is available in the Workspace but that is a manual that can automated using the API.

Here is a sample c# console application code that does that :

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using SourceCode.Workflow.Management;

namespace archiving
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 5 )
            {
                Console.WriteLine("Argument required usage is : archiving.exe connectionstring LogDB archiveDB FromDate ToDate");
                Console.WriteLine("server=BLACKPEARL;database=K2ServerLog;Integrated Security=SSPI");
                Console.WriteLine("LogDB = K2ServerLog");
                Console.WriteLine("archiveDB = MyarchiveDB");
                Console.WriteLine("FromDate = 8/20/2008");
                Console.WriteLine("ToDate = 8/25/2008");
                return;
            }
            string connectionstring = args[0];
            string LogDB = args[1];
            string archiveDB = args[2];
            DateTime from = DateTime.Parse(args[3]);
            DateTime to = DateTime.Parse(args[4]);

            WorkflowArchiving MyarchivingClass = new WorkflowArchiving();

            //try
            //{
            Console.WriteLine("executing archive command with parameters = " + connectionstring + " // " + LogDB + " // " + archiveDB + " // " + from.ToString() + " // " + to.ToStrin());
                MyarchivingClass.Archive(connectionstring, LogDB, archiveDB, from, to);   
            //}catch (Exception e) {
            //    FileStream file = new FileStream("execption.txt",FileMode.OpenOrCreate, FileAccess.ReadWrite);
            //    StreamWriter sw = new StreamWriter(file);
            //    sw.WriteLine("Message = " + e.Message);
            //    sw.WriteLine("stack trace = "  + e.StackTrace);
            //    sw.Close();
            //}
        }
    }
}

 

Here is a vbscript that does acheive the same thing (note that you will need to run “rgasm” on the SourceCode.Workspace.Management.dll ) :

 Option Explicit
msgbox "Start Archiving"

Dim objShell
Set objShell = CreateObject("SourceCode.Workflow.Management.WorkflowArchiving")

if err.number <> 0 then
    msgbox "Error " & Err.number & " Creating Customer: " & Err.description
else
objshell.Archive "server=BLACKPEARL;database=K2ServerLog;Integrated Security=SSPI", "K2ServerLog", "Myarchive", "8/20/2008", "8/24/2008"
 msgbox "Done"
end if

 

Posted by chalama | 0 Comments
Filed under:

Looping through an Activity for each SmartObject List item

Today I discovered a feature within K2 [blackpearl], the ability to loop through a list of items and execute a set of Events for each item – without having to write a line of code!

A simple Order Processing example would illustrate my business case. For demonstration purposes I will assume an Order has multiple Order Items. A K2 Process (Process Order) instance has been started for an individual order. Whilst running this process we need to spawn a sub-process (Process Order Item) for each Order Item.

I have created a SmartObject (SmartBox) called “OrderItems” which has a List Method returning all Items for a given Order.

"Process Order" & "Process Order Item" processes

K2 Processes 

Process Order Process has one Process Data Field

·         OrderId (Number)

The Process Order Item process has two

·         OrderId (Number)

·         OrderItemId (String) – Note this has to be a String as K2 will pass this value into the Process

We are going to start an instance of “Process Order Item” for each Item returned by our SmartObject. Within the “Process Order Items” set the “Destination Rule Option” to be “Plan per Slot (no destinations)”.

Select the “Id” field from the “OrderItems” SmartObject’s List method.

Important: The field you select here will be used to identifying each loop instance.

Pass the OrderId (Process Data Field) as an Input for the SmartObject.

Click Finish.

Now when we configure the IPC Event we are able to get the OrderItem’s Id Field by access the “Activity Destination Instance/Instance Data” (String).

We then Map the required fields

A final step would be to configure the “Process Order Items” Activity Succeeding Rule to ensure all instances have completed.

 

Russell Forster

 

Posted by russforster | 2 Comments
Filed under: , ,

Writing K2 Wizard Projects in VS2008

Recently I have found a requirement to build a new Wizard for a client, in order to allow business analysts to build processes whilst also meeting the specific technical requirements of the project.

One of the drawbacks of building a custom wizard is that in VS2005 the wpf designer was only ever released as a CTP, making the development experience much trickier than it needs to be. A much better experience would be had if we could build the wizard project in VS2008, but blackpearl does not yet support 2008, so we’re a bit stuck.

Actually no - If we create a new Wizard Project in VS2005, it will generate 2 projects, both of which are of type .csproj. Therefore we can upgrade them into VS2008 without any detrimental side effects.....in theory!

In order to test the theory I downloaded the GotoActivity wizard project from blackmarket, since I do not yet have a working wizard of my own!

Open Wizard Project in VS2008 

Opening VS2008 and opening the GotoActivity solution will activate the upgrade wizard.

Project Conversion Wizard Welcome Screen 

I do not require a backup since I have the Zipped up source anyway

 Backup before Conversion

Finish will perform the upgrade

 Complete Conversion

Upgrade completes without any errors, so good so far.... checking the project properties, we can see that the projects still target the .Net 3.0 framework.

Run the installer, this will also compile the source code

Install the Wizard

You can now close VS2008, and open any K2 workflow project, once opened simply reset the toolbox, and you will then see the wizard appear.

Reset ToolboxToolbox after reset

NOTE: I have not yet tested this using a newly created Wizard Project, although that is my intention.  

Posted by Mike_H | 0 Comments

Keeping your Service GUIDs in sync

As some of you may know, when moving SmartObjects that are based on custom Services Instances between environments, you will hit an issue where the SmartObject won't deploy due to the Service Instance GUID on the environment you're deploying to matching the Service Instance GUID that your SmartObject definition is looking for.

 There are a few ways to overcome this problem.

1.Use the Blackmarket tool to update your SmartObject definitions.  This method works well but you will have to repeat the update each time you want to deploy to a different environment.

2.  Update the Service Instance GUIDs to match across all environments. This can be done in one of two ways.  The latter option being the preferred method.

 a. Update the database directly.

 b.  Use the Broker management tool to update the GUIDs

My preferred option is to use the Broker management tool when the Service Instances are first regisitered in each environment to ensure they are registered with a GUID that matches the other environments.  If this is the first environment then make a note of the GUID for later use.

 The Broker managment tool can be found in the default path of: C:\Program Files\K2 blackpearl\ServiceBroker\BrokerManagement.exe

After registering a new Service Type, right-click the type and select  Register New Service Instance.  The second screen of this wizard allows you to chose the GUID for the instance.  It's this GUID that you need to keep sync'd between environments.  The GUID of the Service Type does not matter.

 

Hacking the Work Folder (or, an alternative method of error repairing)

Sometimes, you can manually hack the Work folder for running process instances to, for example, replace a broken version of a referenced assembly with a fixed version. To begin, review Bob’s posting on the work folder and versioned assemblies:

http://www.k2underground.com/blogs/bobblog/archive/2008/01/14/custom-assembly-versioning-within-a-k2-process.aspx

 

During process execution, K2 server creates a folder inside Host Server\Bin\Work for each version of the process definition. Any referenced assemblies are also copied to this folder. This is important – even if the assembly is in die server’s bin folder, it will still be copied to the work folder – the only difference is that instead of the version of the assembly in the DB, the version from Host Server\Bin will be used.

 

Now, suppose you have a process in error state, and the error occurs because of a mistake in the version of the external assembly that the process definition uses. You want to update the assembly, but just copying the new version of the .dll to the Host Server\Bin folder does not do the trick, and you cannot export a new version of the process since the assembly version would then be bound to the process version. Aha - the key is that you need to copy the fixed .dll to the Host Server\Bin directory, and delete the Work folder for the specific version of the process definition.

So,  firstly you need to map the process in error state to the version of the process definition. If you open the K2Server.dbo._ErrorLog table, look for the process in question, and make a note of the ‘ProcID’ value. This is the process definition ID.

Now, head over to your K2 server, and locate the ProcNN folder in the Host Server\Bin\Work folder, where NN is the ProcID you just got from the DB. You can try to manually copy the assembly from Host Server\Bin to this folder, but chances are it will fail since the assembly is in use by Host Server. Fear not, just stop the Host server and delete the work folder. The next time you try to repair the error, K2 Server will realize that there is no Work folder for this specific process definition, and recreate the ProcNN folder, using the version of the assembly that lies in the Host Server\Bin directory. Hey presto!

 

Update: We have also proven another point - you can also directly fix errors in cs- and winwf- code behind in a workflow, by replacing the Context-xxxxxxx.dll and CSWinWF-xxxxxxxx.dll in the work folder or in the host server bin folder, and repairing the error. This is a slightly more complex process, and you really need to keep your wits about you, but it's a lifesaver if you cannot use studio to repair error on the server for whatever reason.


 

Neil 'H@xx0r' and Conrad

Connecting InfoPath 2007 to WCF services

WCF Security and InfoPath 2007 have pretty poor integration, which means that it basically doesn’t work and some hacks have been necessary to get the forms to talk to the services. Below is a list of the required steps to ensure future services can be consumed by InfoPath forms.

WCF endpoints must implement the following in order to be consumed from within an InfoPath form:

Binding

 <service name="CustomerResponse.IssueService" behaviorConfiguration="CustomerResponse.IssueServiceBehavior">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="CustomerResponse.IIssueService" />
        </service>

 

Security

<security mode="TransportCredentialOnly">

<transport clientCredentialType="Windows" />

</security>

 

If the clientCredentialType is set to NTLM then forms services will work fine, but in InfoPath 2007 client you will be prompted continually to enter credentials. This is especially annoying when testing the form before publishing.

Within the InfoPath form, in order to consume this service, a Data Connection must be made to the service, and then converted to a .udcx file; storing the file in a Data Connection Library in the target SharePoint site. Once the udcx file has been created, the following security credentials must be inserted, otherwise the service will not authenticate and an error will occur.

<udc:Authentication>

                     <udc:UseExplicit CredentialType="NTLM">

                           <udc:UserId>a valid user</udc:UserId>

                           <udc:Password>password</udc:Password>

                     </udc:UseExplicit>

       </udc:Authentication>

 

Idiosyncrasies of WCF/Entity Framework

Connecting to Services exposing message entities generated by entity framework (EF) has also involved some strange behaviour. Due to the nature of the messages created by EF, I have not been able to find a way to call a create method from an InfoPath form – without inserting any code. To get round this, the solution was to insert a stub record into the database prior to opening the form; negating the need for an insert.
Posted by Mike_H | 0 Comments

Extending a K2 Report in Visual Studio

 

UPDATE:  A similar K2 Knowledge Base article on how to add a Chart to you reports also exists here - http://kb.k2workflow.com/articles/kb000189.aspx

Scenario: We have built a travel request process that stores the details of each travel request in SmartObjects.  Our business requests that they want reports to have column displaying the total duration of each travel request.  Of course the Workspace report designer makes it very easy for us to create the main report but doesn’t provide facility to do calculations. 

As you may know, K2 reporting leverages SQL Server Reporting Services (SSRS).  This makes it easier than ever to produce exactly the right report for the job.

For this post I’ll assume that you have already created a basic report on the Travel Request Details SmartObject that can use as a base.

First a task overview:

  •  <!--[endif]-->Create initial report
  • <!--[if !supportLists]--><!--[endif]-->Download report definition from SSRS
  • <!--[if !supportLists]--> <!--[endif]-->Add report to Visual Studio Report Server project
  • <!--[if !supportLists]-->Modify report
  • <!--[if !supportLists]-->Redeploy to SSRS
  • <!--[if !supportLists]--> <!--[endif]-->Use report
    • <!--[if !supportLists]--> <!--[endif]-->Either import to the Workspace,
    • <!--[if !supportLists]--><!--[endif]-->Reference on ASP.net pages with the Report Viewer control
    • <!--[if !supportLists]--><!--[endif]-->Or add to SharePoint pages with the Report Viewer webpart

As said above I’ve assumed that you have already created the initial report.  So, let’s jump straight to the second step and download our report definition (RDL file) from SSRS.

Downloading the report is easy, just choose the Edit option from the properties of your report on the SSRS web-site.  K2 reports are deployed to a folder called “Reporting” by default.  Our SSRS URL will be (http://blackpearl/reports). 

Save the file in a convenient location:

 

Next Open a new Visual Studio Report Server project from the Business Intelligence section,and then add the downloaded report file to the project.


 


Next modify the report by adding a new “Duration” column to the table.  Do this by selecting the end column then right-clicking the grey block at the top of the table.

 

Next right-click the new cell and select “Expression” then build an expression of:

=Fields!TravelRequestDetails_EndDate.Value-Fields!TravelRequestDetails_StartDate.Value

This assumes that your SmartObject is called TravelRequestDetails.  You can select your SmartObject fields from the Fields section of this dialog.

 

Finally, OK this expression.  Then add a header such as Duration in the table cell just above the new expression.

You can now preview the report by selecting preview in Visual Studio

Note our new Duration column.

You can now redeploy the report to SSRS by modifying the Project properties and adding the Report Server web-service URL (http://blackpearl/ReportServer).  Then just right-click the project and Deploy.


 

 

After deployment you can import to the K2 Workspace using the Reports section of the Workspace and the Import from Reporting Services feature, or use the report in another manner.

 

The report will be deployed to a folder on the Reports Server website named the same as your Report Server project.

Of course SSRS provide many more advanced features but this should serve as a base to get you started.

Good luck!

 Ashley
 

Reporting Services Woes

SQL Server Reporting Services 2005 can at times be a nightmare to get working, so here are some tips to get your Reporting Services running using host headers and a couple of little things to watch out for.

 

Host Headers

If you are using a host header for your reporting services web site but each time you browse to the report manager you get presented with an error, then follow these steps.

 

Run through the “Reporting Services Configuration” tool as per Microsoft’s instructions http://technet.microsoft.com/en-gb/library/ms159868.aspx

 

After running successfully through the Reporting Services configuration we now need to edit the 2 following configuration files;

 

RSWebApplication.config” located in the ReportManager directory, for example;

C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting

Services\ReportManager\RSWebApplication.config

 

Reportserver.config” located in the ReportServer directory, for example;

C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\Reportserver.config

 

In “RSWebApplication.config” locate the 2 lines;

<ReportServerUrl> </ReportServerUrl>

<ReportServerVirtualDirectory>ReportServer</ReportServerVirtualDirectory>

 

Comment out the “<ReportServerVirtualDirectory>” node and place your host header value with the virtual directory for your report server web service path in the “<ReportServerUrl>”, for example;

 

<ReportServerUrl>http://MySSRS.k2.com/ReportServer</ReportServerUrl>

<!--<ReportServerVirtualDirectory>ReportServer</ReportServerVirtualDirectory>-->

 

In “Reportserver.config” locate the line;

<UrlRoot>http://blackpearl/reportserver</UrlRoot>

 

Replace the value with your host header and report server web service path, for example;

<UrlRoot>http://MySSRS.k2.com/reportserver</UrlRoot>

 

Something to watch out for, if you are running multiple instances of Reporting Services on one server make sure that in your “Reportserver.config” file the instance node points to the right instance path.

<InstanceId>MSSQL.9</InstanceId>

 

Mark Green

Posted by Mark_SCUK | 0 Comments

Using the K2 Workspace Archive facility

As your K2 workflow processes are run the K2ServerLog is used to log information about your workflow processes. This database will grow in size over time and you will no doubt have to do some archiving on this database. Out of the box the K2 Workspace provides an Archive facility that can be leveraged to enable an archive to be run on the database specifying a given date range.

Before I go into the steps that can be followed to use this feature remember the K2ServerLog database is used for your out of the box and probably custom reports. Therefore you need to take this into account when choosing the date range for your archive.

To implement your archive you will need to carry out two steps:

  1. Create a blank database to be used as the archive database
  2. Use the workspace to start the archive.

Create a new blank database
I appreciate there are many ways to do this, below is one

  • Open Microsoft SQL Server Management Studio
  • Right Click Databases and select New Database

  • Enter your preferred values

  • Click OK

Use the K2 workspace to carry out the archive

  • Open the K2 workspace
  • Navigate to Workflow Server -> Archiving
  • Choose your authentication method

  • Select the K2ServerLog Database as the Log Database

  • Enter the date range to archive
  • Select the blank database as the archive database

  • Close the dialog and that’s it! K2 will create the required tables if they do not exist in the selected database and carry out the archive.

Posted by Murphy | 0 Comments

How to implement a Custom Security Provider for K2 blackpearl

 

I recently implemented a Custom Security provider that is used in a production environment. I had a few enquiries surrounding the implementation and thought it would be good to share an example implementation. Attached is a derived version of the provider I created but with a  SQL Server Implementation.

 

PLEASE NOTE: The example source code for this blog can be found by clicking on the "File List" tab on the link below. You have to be logged into K2Underground to access this link!

http://www.k2underground.com/k2/ProjectHome.aspx?ProjectID=59

 

1.       Unzip the example files to a favorite temp location on a K2 BP VPC with all the standard K2 development and runtime artifacts installed

2.       Crack open SQL Server Management Studio and create a new empty database. Call it “EmpSec”. Execute the “SecSQLScript.txt” located in the Security Provider Implementation Folder. Make sure all the Tables, Test Data and Sprocs deploy.

3.       Compile the Security Implementation Project and copy the output “ArnIT.K2SecurityProviderLibrary.Implementations.dll” Assembly to the “C:\Program Files\K2 blackpearl\Host Server\Bin\securityproviders” folder after you stopped K2 Host Server.

4.       Start K2 Host Server and crack open another Query Window in SQL Man Studio. Run the following Script. Make sure K2 Host Server starts up before running the script!:

 

use [HostServer]

declare @id uniqueidentifier, @a_newid uniqueidentifier;

set @a_newid =  newid()

 

select @id = SecurityProviderID from SecurityProviders where ProviderClassName = 'ArnIT.K2SecurityProviderLibrary.Implementations.SqlMembershipProviderProxy'

insert into SecurityLabels values (@a_newid, 'ArnIT Security', @id, null, @id, null, '0')

 

5.       Stop K2 Host Server again and open up the “K2HostServer.config” located in “C:\Program Files\K2 blackpearl\Host Server\Bin”. Delete the < connectionStrings> node and its contents after learning the replacement settings. An example of the unencrypted settings is in the section above the connectionStrings node. By commenting that back, K2 Host Server will consume and encrypt it again upon startup, hence we can safely delete the original encrypted version. The idea is to register the SQL Connectionstring the Security Provider uses.

 

Deleting the Encrypted connectionStrings:

 

 

Recreating the connectionStrings section:  

Add the connectionstring below and start K2 Host Server after saving the file.

 

<add name="ArnITEmpSecurityProvider.Connectionstring" connectionString="Data Source=BLACKPEARL;Database=EmpSec; Integrated Security=True" />

 

 

As mentioned, K2 Host Server will consume your settings and encrypt it. The “green” section should be deleted for production environments.

 

Encrypted connectionStrings section:

 

6.       Restart K2 Host Server. Your provider will be registered after 4. above and you should be good to test it. The easiest way to verify registration completed successfully is to do a user lookup in workspace in any of the permissions sections

 

 

 

 

The next section will test the Security Provider Implementation. An example Expense Claim K2 Process is included in the zip file and needs to be exported to your environment.

 

7.       You need to create the following Roles in workspace. These are used as destinations for the Claims Process:

 

Add the following DYNAMIC K2 Roles

                1. “ArnIT EmpSys Administrator “ (Group "ArnIT Security:Administrator")              [Claim Approval Activity Destination]

                2. “ArnIT EmpSys Clerk” (Group "ArnIT Security:Worker")                                             [Claim Processing Activity Destination]

               

It should look like the below:

 

 

and

 

 

8.       Export the process and assign Start Permissions to all the “ArnIT” Groups. Ensure  you save the permissions.

 

 

You should be good to test the process. I included a test application that basically starts a new instance of the claims process and approves it by actioning the worklist items. You should be able to plug any front end into this and point your UI Security Provider to your Custom Security Provider datastore.

 

9.       Start the process and inspect the Worklist and Process Instance

 

 

 

 

 

 

 

 

10.   Finish the Worklist items for the “Claim Approval” Activity and inspect the Worklist and Process Instance

 

 

 

 

 

 

11.   Finish off the “Claim Processing” tasks by adding a “WL Item” finish code section for Paul.

 

 

This example is tested and works on K2 Sp1 with KB234. Dynamic Roles also works fine. The Filter Criteria for the Search is not implemented, but this should not be a too big a job to implement. The password sections should also be encrypted as per normal security patterns.

 

 

Posted by punkas | 4 Comments

Automatic Deployment of K2 Process and K2 SmartObject artefacts using theSourceCode Deployment Framework and MSBuild Assemblies

Introduction

Continuous Integration is a deployment concept that ensures changes to your code base results in an automatic build and deployment to their target environments. This article explains how to automatically deploy K2 Process and K2 SmartObject artefacts using the SourceCode Deployment Framework and the MSBuild Assemblies. The example code can be used to create a custom MSBuild task that can be included in a MSBuild file. CCNet, TFS and FinalBuilder are typically used to automatically build and deploy applications using MSBuild files as deployment directives.

K2 and MSBuild

The K2 Deployment Framework takes advantage of the MSBuild Libraries to build and deploy K2 Projects. This K2 deployment process is transparent to Developers using VS 2005 to compile and deploy K2 processes. The K2 Deployment API is used by VS 2005 under the covers to achieve this. This article will explain how to used this API and automate this build and deployment process.

Implementation Example

This example will create a Deployment Class called LibK2Deploy that will be referenced by a Console Application that calls a static method called Execute to deploy the K2 Processes or K2 SmartObjects. 

Let’s Start

Open VS 2005 and create a new Solution. Add a new Class Library project called LibK2Build to the solution. Add a new class to the project called LibK2Deploy. Add References to the following Assemblies

·         Microsoft.Build.Engine

·         Microsoft.Build.Framework

·         SourceCode.EnvironmentSettings.Client

·         SourceCode.Framework

·         SourceCode.Workflow.Design

Add the following code in your using directives

using SourceCode.EnvironmentSettings.Client;

using SourceCode.Framework.Deployment;

using SourceCode.ProjectSystem;

using SourceCode.Workflow.Design.EnvironmentSettings;

The class will contain a public Execute method and two helper methods GetEnvironmentManager and GetDeploymentPackage. Execute will use the EnvironmentSettingsManager and DeploymentPackage returned from the respective helper methods to build and deploy the K2 Project.

Add the following code into LibK2Deploy your class:

The method below is a standard way to return the Environment Manager.

private static EnvironmentSettingsManager GetEnvironmentManager()

        {

            EnvironmentSettingsManager environmentManager = new EnvironmentSettingsManager(false, false);

 

            // This is weird but the only way I could get it to work!

            environmentManager.ConnectToServer(GetConnectionString());

            environmentManager.InitializeSettingsManager();

            environmentManager.ConnectToServer(GetConnectionString());

 

            if (_environment != null)

                environmentManager.ChangeEnvironment(_environment);

            environmentManager.InitializeSettingsManager();

            environmentManager.GetEnvironmentFields(environmentManager.CurrentEnvironment);

 

            return environmentManager

}

 

The method below is particularly useful because you can intercept and change the Environment Field Values based on your configuration. You also specify your Deployment Label and Description in this method. These are the same Label and Description you would specify in VS 2005 when you deploy your K2 Artefacts. Note there are separate sections of code that deals with K2 Workflow and K2 SmartObject objects.

private static DeploymentPackage GetDeploymentPackage(Project project, EnvironmentSettingsManager environmentManager)

        {

            DeploymentPackage package;

 

            package = project.CreateDeploymentPackage();

 

            // Populate Environment Fields

            foreach (EnvironmentInstance env in environmentManager.CurrentTemplate.Environments)

            {

                DeploymentEnvironment depEnv = package.AddEnvironment(env.EnvironmentName);

                foreach (EnvironmentField field in env.EnvironmentFields)

                {

                    depEnv.Properties[field.FieldName] = field.Value;

                }

            }

 

            package.SelectedEnvironment = environmentManager.CurrentEnvironment.EnvironmentName;

            package.DeploymentLabelName = DateTime.Now.ToString();

            package.DeploymentLabelDescription = string.Empty;

            package.TestOnly = false;

 

            // Get the Default SmartObject Server in the Environment

            // The prefix "$Field=" is when the value of the SmartObject server is registered in the environment fields collection.

            // this will do a lookup in the environment with the display name of the field, and use the value.

            // If you set the value directly, no lookups will be performed.

            EnvironmentField smartObjectServerField =

                environmentManager.CurrentEnvironment.GetDefaultField(typeof(SmartObjectField));

            package.SmartObjectConnectionString = "$Field=" + smartObjectServerField.DisplayName;

 

            // Get the Default Workflow Management Server in the Environment

            EnvironmentField workflowServerField =

                environmentManager.CurrentEnvironment.GetDefaultField(typeof(WorkflowManagementServerField));

            package.WorkflowManagementConnectionString = "$Field=" + workflowServerField.DisplayName;

 

            return package;

}

 

This method creates a K2 Connection String that is used by the methods above.

 

private static string GetConnectionString()

{

            return string.Format("Integrated=True;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;Host={0};Port={1}", _server, _port);

}

The helper methods use the private variables below that are populated with the K2HostServer, Port and Environment Name. Add these to your class:

static string _server;

static int _port;

static string _environment;

 

Add the Execute method to the code. This public method’s signature accepts the K2 Host Server name (eg. “BLACKPEARL”), the Environment Name (typically “Development”, “Production”), the ProjectPath the location of the “.k2proj” that needs deploying and OuputPath the location of the MSBuild files that are consumed by MSBuild during deployment.

public static bool Execute(string K2HostServer, string EnvironmentName, string ProjectPath, string OutputPath)

        {

            _environment = EnvironmentName;

            _port = 5555;

            _server = K2HostServer;