Upgrading or Redeploying SharePoint 2010 Workflows

While creating several State Machine SharePoint 2010 workflows using visual studio for a client I had some concerns related to upgrading and redeploying those workflows because as we all know, changes are inevitable!

Where following are the concerns and my solution to them

1- How can we redeploy or upgrade workflow?

I found a nice article which goes in details of upgrading workflow approaches, and as per my analysis Versioning workflows seems to be the only feasible solution.

2- When it’s required to version my workflows and how can I minimized it?

Versioning is required only when UI changes are done on workflow e.g. modification in state, activities etc. as this will break running instance of workflows due to failure in deserialization.

As a strategy we chose multi-layer architecture, which means whole logic in a separate Class library (business) and workflows in separate Library where workflow only defines flow as shown below.

image001.png

This means for code level changes or bug fixes, we only redeploy business solution wsp not affecting workflows wsp.

3- How to Version Workflow solution and any step by step instructions?

While goggling I could not found comprehensive step by step instructions.

Where following contain the step by step instruction how I implemented it.

Step 1: Upgrade Assemble

· Go to Workflow Solution -> AssemblyInfo Class and update assembly version and file version as shown below.

image003.png image004.png

Step 2: Upgrade Workflow Element.xml

Go to modified workflows and Open their Element.xml files then

· Update 'CodeBesideAssembly' attribute assembly version.

· Update ‘Name’ with Version number at end e.g. xyz version 1.0.0.1 (for your convenience).

· Update 'ID' attribute with a new GUID (Tools->Create GUID).

image007.jpg

Step 3: Workflow Feature Update

· Remove any existing feature that deploy workflows from solution

· Add a new Site Scope Feature with 'Name' e.g. PrjectNameWorkflowsVersionX.X.X.X

· Add only modified Workflows inside this feature (Step 2 modified ones only)

Step 4: Upgrade Solution Package

   Double Click Package and then

· Update the 'SolutionId' with a new GUID.

· Update 'Name' with modified version.

Step 5: Deployment

· Build and deploy the new workflow wsp solution and IIS Reset.

     Note: this will register a new version of the workflow assembly in the GAC.

Step 6: Association and No New instance

· Associate newly deployed workflow e.g. xyz version 1.0.0.1

· Go to Associated list Workflow Settings -> Remove workflow and Put the old version workflows as "No New instance".

image008.png

Note:  As my solution contains several workflows so I created a utility for Programmatically performing step 6 operation, here are some methods that I created that might be helpful.

''' <summary>

''' To Programmatically associate workflow with a List or library

''' </summary>

Public Shared Sub AssociateWorkflow(ByVal web As SPWeb, _

ByVal WorkflowGUID As String, _

ByVal WorkflowName As String, _

ByVal ListName As String, _

ByVal TaskListName As String, _

ByVal HistoryListName As String, _

ByVal AllowManual As Boolean, _

ByVal AutoStartChange As Boolean, _

ByVal AutoStartCreate As Boolean)

'Bind to lists.

Dim ListToAssociate As SPList = web.Lists(ListName)

Dim TasksListToAssociate As SPList = web.Lists(TaskListName)

Dim workflowHistoryList As SPList = web.Lists(HistoryListName)

'Get workflow Template

Dim workflowTemplate As SPWorkflowTemplate = web.WorkflowTemplates(New Guid(WorkflowGUID))

If ListToAssociate.WorkflowAssociations.Count > 0 Then

Throw New Exception(String.Format("List '{0}' is already associated with Workflow '{1}', Please Disassociate this workflow first.", ListToAssociate.Title, ListToAssociate.WorkflowAssociations(0).Name))

End If

'Create workflow association.

Dim workflowAssociation As SPWorkflowAssociation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate, WorkflowName, TasksListToAssociate, workflowHistoryList)

'Set workflow options.

        workflowAssociation.AllowManual = AllowManual

        workflowAssociation.AutoStartChange = AutoStartChange

        workflowAssociation.AutoStartCreate = AutoStartCreate

       ' Hint: WorkflowAssociation.Enabled = false means 'No new instantace'

'Add workflow association.

ListToAssociate.WorkflowAssociations.Add(workflowAssociation)

End Sub

''' <summary>

''' To programmatically start workflow already associated with a List or library

''' </summary>

Public Shared Sub ManuallyStartWorkflow(ByVal objWeb As SPWeb, ByVal listTitle As String, ByVal itemID As Integer)

Using elevatedSite = New SPSite(objWeb.Url, SiteHelper.GetSystemUserSecruityToken(objWeb))

Using web = elevatedSite.OpenWeb()

                web.AllowUnsafeUpdates = True

Dim elevatedList As SPList = web.Lists(listTitle)

'Get Associated Workflow

Dim item As SPListItem = elevatedList.GetItemById(itemID)

If item.Workflows.Count = 0 Then

Dim myAssociation As SPWorkflowAssociation = GetWorkflowAssociation(elevatedList.WorkflowAssociations)

elevatedSite.WorkflowManager.StartWorkflow(item, myAssociation, myAssociation.AssociationData)

End If

End If

                web.AllowUnsafeUpdates = False

End Using

End Using

End Sub

Where even after reading this article you don’t like any of the solution and you want to develop few workflows that are not complex, then go with Event Receivers you can build your logic by code resulting in better performance and you don’t have to worry about versioning or anything J

转载于:https://www.cnblogs.com/frankzye/p/3275257.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值