Ejemplo n.º 1
0
        public static void AssociateWorflow(SPWeb web, string workflowTemplateBaseGuid, string workflowAssociationName)
        {
            //string workflowTemplateBaseGuid = "0b5d7c6b-2764-45dc-8fc1-33fa98145d1c";
            //string workflowAssociationName = "Odchudzanie bazy danych";

            SPWorkflowTemplateCollection workflowTemplates = web.WorkflowTemplates;
            SPWorkflowTemplate           workflowTemplate  = workflowTemplates.GetTemplateByBaseID(new Guid(workflowTemplateBaseGuid));

            if (workflowTemplate != null)
            {
                // Create the workflow association
                SPList taskList    = EnsureListExist(web, workflowTaskListName);
                SPList historyList = EnsureListExist(web, workflowHistoryListName);

                SPWorkflowAssociation workflowAssociation = web.WorkflowAssociations.GetAssociationByName(workflowAssociationName, CultureInfo.InvariantCulture);

                if (workflowAssociation == null)
                {
                    workflowAssociation             = SPWorkflowAssociation.CreateWebAssociation(workflowTemplate, workflowAssociationName, taskList, historyList);
                    workflowAssociation.AllowManual = true;
                    //workflowAssociation.Enabled = true;  - nie wiem dlaczego ale ta pozycja wywala błąd.
                    web.WorkflowAssociations.Add(workflowAssociation);
                }
            }
        }
Ejemplo n.º 2
0
        public static SPWorkflowAssociation CreateWorkflowAssociation(this SPWeb web,
                                                                      SPWorkflowTemplate workflowTemplate, string assocName,
                                                                      SPList workflowTasksList, SPList workflowHistoryList,
                                                                      bool overwrite = false, Action <SPWorkflowAssociation> action = null)
        {
            if (workflowTemplate == null)
            {
                throw new ArgumentNullException("workflowTemplate");
            }

            SPWorkflowAssociation workflowAssociation = null;
            // create the association
            SPWorkflowAssociation assoc =
                SPWorkflowAssociation.CreateWebAssociation(
                    workflowTemplate, assocName,
                    workflowTasksList, workflowHistoryList);

            if (action != null)
            {
                action(assoc);
            }

            //apply the association to the list
            if (web != null)
            {
                if (overwrite)
                {
                    SPWorkflowAssociation dupWfAssoc =
                        web.WorkflowAssociations.GetAssociationByName(assocName, web.Locale);

                    if (dupWfAssoc != null)
                    {
                        if (dupWfAssoc.BaseId == workflowTemplate.Id)
                        {
                            web.WorkflowAssociations.Remove(dupWfAssoc);
                        }
                        else
                        {
                            throw new SPException(string.Format("Duplicate workflow name \"{0}\" is detected.", assocName));
                        }
                    }
                }

                workflowAssociation = web.WorkflowAssociations.Add(assoc);
            }

            return(workflowAssociation);
        }
Ejemplo n.º 3
0
        public static void AssociateSiteWorkflow(SPWeb web, string workflowTemplateBaseGuid, string workflowAssociationName, string workFlowTaskListName, string workFlowHistoryListName)
        {
            SPWorkflowTemplateCollection workflowTemplates = web.WorkflowTemplates;
            SPWorkflowTemplate           workflowTemplate  = workflowTemplates.GetTemplateByBaseID(new Guid(workflowTemplateBaseGuid));

            if (workflowTemplate != null)
            {
                // Create the workflow association
                SPList taskList    = web.Lists[workFlowTaskListName];
                SPList historyList = web.Lists[workFlowHistoryListName];
                SPWorkflowAssociation workflowAssociation = web.WorkflowAssociations.GetAssociationByName(workflowAssociationName, CultureInfo.InvariantCulture);

                if (workflowAssociation == null)
                {
                    workflowAssociation             = SPWorkflowAssociation.CreateWebAssociation(workflowTemplate, workflowAssociationName, taskList, historyList);
                    workflowAssociation.AllowManual = true;
                    //workflowAssociation.Enabled = true;
                    web.WorkflowAssociations.Add(workflowAssociation);
                }
            }
        }
Ejemplo n.º 4
0
 private void AssociateSiteWorkflow()
 {
     if (this.associationParams.AssociationGuid == Guid.Empty)
     {
         SPWorkflowAssociation association = SPWorkflowAssociation.CreateWebAssociation(
             Web.WorkflowTemplates[new Guid(this.associationParams.BaseTemplate)],
             this.associationParams.AssociationName,
             Web.Lists[this.associationParams.TaskListGuid],
             Web.Lists[this.associationParams.HistoryListGuid]);
         PopulateAssociationParams(association);
         Web.WorkflowAssociations.Add(association);
     }
     else
     {
         SPWorkflowAssociation association = Web.WorkflowAssociations[this.associationParams.AssociationGuid];
         association.SetTaskList(Web.Lists[this.associationParams.TaskListGuid]);
         association.SetHistoryList(Web.Lists[this.associationParams.HistoryListGuid]);
         PopulateAssociationParams(association);
         Web.WorkflowAssociations.Update(association);
     }
 }
        public SPWorkflowAssociationInstance CreateWebAssociation(SPWorkflowTemplateInstance template, string name, SPListInstance taskList, SPListInstance historyList)
        {
            if (template == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A workflow template must be supplied as the first argument.");
            }

            if (taskList == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A task list must be supplied as the third argument.");
            }

            if (historyList == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A history list must be supplied as the fourth argument.");
            }

            var result = SPWorkflowAssociation.CreateWebAssociation(template.SPWorkflowTemplate, name, taskList.List,
                                                                    historyList.List);

            return(result == null
                ? null
                : new SPWorkflowAssociationInstance(this.Engine.Object.InstancePrototype, result));
        }