/// <summary> /// Gets the WorkflowTemplate /// </summary> /// <returns>the workflowTemplate</returns> /// <exception cref="ElementsMigrationException">if there is no workflowTemplate</exception> private WorkflowTemplate GetTemplate() { WorkflowTemplateCollection sourceWorkflowTemplateCollection = SourceClientContext.Web.WorkflowTemplates; WorkflowTemplateCollection targetWorkflowTemplateCollection = TargetClientContext.Web.WorkflowTemplates; try { SourceClientContext.ExecuteQuery(); TargetClientContext.ExecuteQuery(); if (targetWorkflowTemplateCollection == null || targetWorkflowTemplateCollection.Count == 0) { Logger.AddMessage("No templates for Workflow found!"); throw new ElementsMigrationException("No templates for Workflow found!"); } if (sourceWorkflowTemplateCollection == null || sourceWorkflowTemplateCollection.Count == 0) { //// nothing to search return target->first return(targetWorkflowTemplateCollection.First()); } foreach (var targetWorkflowTemplate in targetWorkflowTemplateCollection) { foreach (var sourceWorkflowTemplate in sourceWorkflowTemplateCollection) { if (targetWorkflowTemplate.Name == sourceWorkflowTemplate.Name) { return(targetWorkflowTemplate); } } } Logger.AddMessage("No templates for Workflow found!"); throw new ElementsMigrationException("No templates for Workflow found!"); } catch (Exception e) { Console.WriteLine("Exception during fetching the template of the Workflow.", e); Logger.AddMessage("Exception during fetching the template of the Workflow. Error = " + e.Message); throw new ElementsMigrationException("Exception during fetching the WorkflowTemplates.", e); } }
public static WorkflowTemplate GetWorkflowTemplate(Web oWeb, string cTemplateName) { try { WorkflowTemplateCollection wts = oWeb.WorkflowTemplates; oWeb.Context.Load(wts); oWeb.Context.ExecuteQuery(); foreach (WorkflowTemplate wt in wts) { System.Diagnostics.Trace.WriteLine(wt.Name); if (wt.Name.ToLower() == cTemplateName.ToLower()) { return(wt); } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } return(null); }