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 EnsureWorkflowAssociation(SPWorkflowAssociationCollection collection, Guid workflowBaseId, SPWorkflowAssociationCreator createDelegate, out bool associationUpdated)
        {
            CommonHelper.ConfirmNotNull(collection, "collection");
            CommonHelper.ConfirmNotNull(createDelegate, "createDelegate");
            associationUpdated = false;

            SPWeb targetWeb = collection.ParentWeb;
            SPWorkflowAssociation wfAssoc = collection.GetAssociationByBaseIDSafe(workflowBaseId);

            if (wfAssoc == null)
            {
                SPWorkflowTemplate wfTemplate = targetWeb.WorkflowTemplates[workflowBaseId];
                if (wfTemplate == null)
                {
                    throw new ArgumentOutOfRangeException("workflowBaseId", "Workflow template with the specified base ID does not exist in this site");
                }
                SPList taskList    = EnsureList(targetWeb, SPListTemplateType.Tasks, SPResource.GetString("DefaultWorkflowTaskListName", new object[0]));
                SPList historyList = EnsureList(targetWeb, SPListTemplateType.WorkflowHistory, SPResource.GetString("DefaultWorkflowHistoryListName", new object[0]));
                wfAssoc = createDelegate(wfTemplate, wfTemplate.Name, taskList, historyList);
                collection.Add(wfAssoc);
                associationUpdated = true;
            }
            if (!wfAssoc.Enabled)
            {
                wfAssoc.Enabled = true;
                collection.Update(wfAssoc);
                associationUpdated = true;
            }
            return(wfAssoc);
        }
Ejemplo n.º 3
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            IConfigManager hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IConfigManager>();

            hierarchicalConfig.SetInPropertyBag(Constants.SubSiteCreationConfigSiteKey, web.Url, SPFarm.Local);

            SPList taskList    = web.Lists[taskListName];
            SPList historyList = web.Lists[workflowHistoryName];
            SPList subSiteCreationRequestList = web.Lists[subSiteRequestsListName];

            var existingAssociation = subSiteCreationRequestList.WorkflowAssociations.GetAssociationByName(workflowTemplateName, CultureInfo.CurrentCulture);

            if (existingAssociation == null)
            {
                SPWorkflowManager            workflowManager = web.Site.WorkflowManager;
                SPWorkflowTemplateCollection templates       = workflowManager.GetWorkflowTemplatesByCategory(web, null);
                SPWorkflowTemplate           template        = templates.GetTemplateByBaseID(workflowTemplateId);
                SPWorkflowAssociation        association     = SPWorkflowAssociation.CreateListAssociation(template, template.Name, taskList, historyList);
                association.AllowManual     = true;
                association.AutoStartCreate = true;
                subSiteCreationRequestList.AddWorkflowAssociation(association);
                subSiteCreationRequestList.Update();
                association.Enabled = true;
            }

            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IBusinessEventTypeConfigurationRepository, BusinessEventTypeConfigurationRepository>();
            typeMappings.RegisterTypeMapping <ISubSiteCreationRequestRepository, SubSiteCreationRequestsRepository>();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Bind workflow
        /// </summary>
        /// <param name="web"></param>
        /// <param name="contentTypeName"></param>
        /// <param name="workflowName"></param>
        public static void BindWorkflow(SPWeb web, string contentTypeName, string workflowName)
        {
            SPContentType         siteContentType  = web.ContentTypes[contentTypeName];
            string                taskListTitle    = ApplicationConfig.TaskListName;
            string                historyListTitle = ApplicationConfig.HistoryListName;
            SPWorkflowAssociation wfAssoc          = null;

            // Get a template.
            SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates.Cast <SPWorkflowTemplate>().FirstOrDefault(wft => wft.Name == workflowName);


            // Add the association to the content type or update it if it already exists.
            if ((wfAssoc = siteContentType.WorkflowAssociations.GetAssociationByName(workflowName, web.Locale)) == null)
            {
                wfAssoc = SPWorkflowAssociation.CreateWebContentTypeAssociation(workflowTemplate,
                                                                                workflowName,
                                                                                taskListTitle,
                                                                                historyListTitle);
                siteContentType.WorkflowAssociations.Add(wfAssoc);
            }
            else
            {
                siteContentType.WorkflowAssociations.Update(wfAssoc);
            }

            // Propagate to children of this content type.
            siteContentType.UpdateWorkflowAssociationsOnChildren(false,              // Do not generate full change list
                                                                 true,               // Push down to derived content types
                                                                 true,               // Push down to list content types
                                                                 false);             // Do not throw exception if sealed or readonly
        }
Ejemplo n.º 5
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            if (web != null)
            {
                SPList taskList         = web.Lists[Lists.RegistrationApprovalTasks];
                SPList historyList      = web.Lists[Lists.WorkflowHistory];
                SPList registrationList = web.Lists[Lists.Registrations];

                SPWorkflowAssociation existingAssociation = null;
                existingAssociation = registrationList.WorkflowAssociations.GetAssociationByName(WorkflowTemplates.RegistrationApprovalNameV2, CultureInfo.CurrentCulture);
                if (existingAssociation == null)
                {
                    //Create a worklow manager and associate the Course Registration Approval Workflow template
                    //to our Registrations list.
                    SPWorkflowManager            workflowManager = web.Site.WorkflowManager;
                    SPWorkflowTemplateCollection templates       = workflowManager.GetWorkflowTemplatesByCategory(web, null);
                    SPWorkflowTemplate           template        = templates.GetTemplateByBaseID(new Guid(WorkflowTemplates.RegistrationApprovalBaseIdV2));
                    SPWorkflowAssociation        association     = SPWorkflowAssociation.CreateListAssociation(template, template.Name, taskList, historyList);
                    association.AllowManual     = true;
                    association.AutoStartCreate = true;
                    registrationList.AddWorkflowAssociation(association);
                    registrationList.Update();
                    association.Enabled = true;
                }
            }
        }
        public SPWorkflowTemplateInstance(ObjectInstance prototype, SPWorkflowTemplate workflowTemplate)
            : this(prototype)
        {
            if (workflowTemplate == null)
            {
                throw new ArgumentNullException("workflowTemplate");
            }

            m_workflowTemplate = workflowTemplate;
        }
Ejemplo n.º 7
0
        public static SPWorkflowAssociation CreateListWorkflowAssociation(this SPWeb web, string listUrl, string workflowName, string assocName,
                                                                          string workflowTasksListName, string workflowHistoryListName,
                                                                          bool allowManual, bool autoStartCreate, bool autoStartChange, bool overwrite = false)
        {
            // Get the workflow template.
            SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates.GetTemplateByName(workflowName, web.Locale);

            return(web.CreateListWorkflowAssociation(listUrl, workflowTemplate, assocName, workflowTasksListName,
                                                     workflowHistoryListName, allowManual, autoStartCreate, autoStartChange, overwrite));
        }
Ejemplo n.º 8
0
        public static SPWorkflowAssociation CreateWorkflowAssociation(this SPWeb web, string listUrl, Guid workflowId, string assocName,
                                                                      string workflowTasksListName, string workflowHistoryListName,
                                                                      bool allowManual, bool autoStartCreate, bool autoStartChange)
        {
            // Get the workflow template.
            SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates.GetTemplateByBaseID(workflowId);

            return(web.CreateWorkflowAssociation(listUrl, workflowTemplate, assocName, workflowTasksListName,
                                                 workflowHistoryListName, allowManual, autoStartCreate, autoStartChange));
        }
        public bool IsCategoryApplicable(string strAllCategs, ArrayInstance rgReqCateg)
        {
            if (rgReqCateg == null)
            {
                throw new JavaScriptException(Engine, "Errr", "An array of requred categories is required");
            }

            var strs = rgReqCateg.ElementValues.Select(TypeConverter.ToString).ToArray();

            return(SPWorkflowTemplate.IsCategoryApplicable(strAllCategs, strs));
        }
Ejemplo n.º 10
0
        public static SPWorkflowAssociation CreateWorkflowAssociation(this SPWeb web, string listUrl, string workflowName, string assocName,
                                                                      string workflowTasksListName, string workflowHistoryListName,
                                                                      bool allowManual, bool autoStartCreate, bool autoStartChange)
        {
            // Get the workflow template.
            SPWorkflowTemplate workflowTemplate =
                web.WorkflowTemplates.GetTemplateByName(workflowName, CultureInfo.CurrentCulture);

            return(web.CreateWorkflowAssociation(listUrl, workflowTemplate, assocName, workflowTasksListName,
                                                 workflowHistoryListName, allowManual, autoStartCreate, autoStartChange));
        }
Ejemplo n.º 11
0
        private void FetchAssociationInfo()
        {
            SPWorkflowAssociationCollection wac;

            m_baseTemplate  = Web.WorkflowTemplates[new Guid(Request.Params["WorkflowDefinition"])];
            m_assocTemplate = null;

            // figure out whether or not this is associating with a content type or a list,
            // and get the association collection.  Also set the return page values.
            if (m_ct != null) // associating w/ a content type
            {
                wac                  = m_ct.WorkflowAssociations;
                hlReturn.Text        = m_ct.Name;
                hlReturn.NavigateUrl = "ManageContentType.aspx" + m_strQueryParams;
            }
            else   // associating w/ a list
            {
                List.Permissions.CheckPermissions(SPRights.ManageListPermissions);
                wac                  = List.WorkflowAssociations;
                hlReturn.Text        = List.Title;
                hlReturn.NavigateUrl = List.DefaultViewUrl;
            }
            if (wac == null || wac.Count < 0)
            {
                throw new SPException("No Associations Found");
            }
            //Set the general workflow properties
            m_autoStartCreate = (Request.Params["AutoStartCreate"] == "ON");
            m_autoStartChange = (Request.Params["AutoStartChange"] == "ON");
            m_allowManual     = (Request.Params["AllowManual"] == "ON");
            m_bLockItem       = (Request.Params["LockItem"] == "ON");
            m_setDefault      = (Request.Params["SetDefault"] == "ON");
            m_updateLists     = (Request.Params["UpdateLists"] == "TRUE");
            // check if workflow association already exists.
            string strGuidAssoc = Request.Params["GuidAssoc"];

            if (strGuidAssoc != string.Empty)
            {
                m_assocTemplate = wac[new Guid(strGuidAssoc)];
            }

            // Check for a duplicate name. Note that we do this both on initial load and on
            // postback. The reason we do it on postback is that some other user may have
            // added a workflow by this name since the last time we checked.
            SPWorkflowAssociation dupTemplate = wac.GetAssociationByName(m_workflowName, Web.Locale);

            if (dupTemplate != null && (m_assocTemplate == null || m_assocTemplate.Id != dupTemplate.Id))
            {
                // throw an exception if there is a template with the same name already
                throw new SPException("Duplicate workflow name is detected.");
            }
        }
Ejemplo n.º 12
0
        private void AssociateWithWorkFlows(string[] workFlows, SPSite curSite, SPWeb curWeb)
        {
            List <SPList>      docLibs              = new List <SPList>();
            SPWorkflowTemplate baseTemplate         = null;
            SPWorkflowTemplate wfTemplate           = null; // our template we store in PropertyBag
            SPList             caseDocs             = curWeb.GetListByInternalName(eCaseConstants.ListInternalNames.REFERRAL_DOCUMENTS);
            SPList             relatedDocs          = curWeb.GetListByInternalName(eCaseConstants.ListInternalNames.INVESTIGATION_DOCUMENTS);
            SPList             finishedWorkProducts = curWeb.GetListByInternalName(eCaseConstants.ListInternalNames.SDO_DOCUMENTS);

            docLibs.Add(caseDocs);
            docLibs.Add(relatedDocs);
            docLibs.Add(finishedWorkProducts);

            var taskList    = curWeb.GetListByInternalName("Tasks List");
            var historyList = curWeb.GetListByInternalName("Workflow History List");


            if (historyList == null)
            {
                var hlGuid = curWeb.Lists.Add("Workflow History List", string.Empty, SPListTemplateType.WorkflowHistory);
                historyList = curWeb.Lists.GetList(hlGuid, false);
            }

            if (taskList == null)
            {
                var tlGuid = curWeb.Lists.Add("Tasks List", string.Empty, SPListTemplateType.Tasks);
                taskList = curWeb.Lists.GetList(tlGuid, false);
            }

            foreach (string wfName in workFlows)
            {
                wfTemplate = curWeb.WorkflowTemplates.GetTemplateByName(wfName, CultureInfo.CurrentCulture);
                if (wfTemplate != null)
                {
                    baseTemplate = wfTemplate;
                    baseTemplate.StatusColumn = false;
                    foreach (SPList docLib in docLibs)
                    {
                        if (docLib.WorkflowAssociations.GetAssociationByBaseID(baseTemplate.Id) == null)
                        {
                            SPWorkflowAssociation assoc = SPWorkflowAssociation.CreateListContentTypeAssociation(baseTemplate, baseTemplate.Name, taskList, historyList);
                            assoc.AllowManual     = true;
                            assoc.AutoStartCreate = false;
                            docLib.WorkflowAssociations.Add(assoc);
                            assoc.Enabled = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private static void EnsureWorkflowAssociationCT(SPContentType ct, string workflowTemplateName, string associationName)
        {
            SPSite site           = ct.ParentWeb.Site;
            SPWeb  web            = site.OpenWeb();
            var    lcid           = (int)web.Language;
            var    defaultCulture = new CultureInfo(lcid);

            // Create the workflow association
            SPList taskList    = EnsureListExist(web, workflowTaskListName);
            SPList historyList = EnsureListExist(web, workflowHistoryListName);

            // Get a template
            SPWorkflowTemplate workflowTemplate = null;

            foreach (SPWorkflowTemplate template in web.WorkflowTemplates)
            {
                workflowTemplate = template;
                if (workflowTemplate.Name.Equals(workflowTemplateName))
                {
                    break;
                }
            }

            SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateWebContentTypeAssociation(workflowTemplate, associationName, workflowTaskListName, workflowHistoryListName);

            //ElasticEmail.EmailGenerator.SendMail("wartość zmiennej", ct.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, web.Locale).Name);

            // Add the association to the content type or update it if it already exists.
            if (ct.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, web.Locale) == null)
            {
                //ElasticEmail.EmailGenerator.SendMail("ct:add", "");
                ct.WorkflowAssociations.Add(workflowAssociation);
            }
            else
            {
                //ElasticEmail.EmailGenerator.SendMail("ct:update", "");
                //ct.WorkflowAssociations.Update(workflowAssociation);
                ct.WorkflowAssociations.UpdateAssociationsToLatestVersion();
            }

            // Propagate to children of this content type.
            ct.UpdateWorkflowAssociationsOnChildren(false,  // Do not generate full change list
                                                    true,   // Push down to derived content types
                                                    true,   // Push down to list content types
                                                    false); // Do not throw exception if sealed or readonly

            web.Dispose();
            site.Dispose();
        }
Ejemplo n.º 14
0
        public static SPWorkflowAssociation CreateListWorkflowAssociation(this SPContentType contentType,
                                                                          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.CreateListContentTypeAssociation(
                    workflowTemplate, assocName,
                    workflowTasksList, workflowHistoryList);

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

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

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

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

            return(workflowAssociation);
        }
 public static SPWorkflowAssociation CreateListWorkflowAssociation(this SPContentType contentType,
   SPWorkflowTemplate workflowTemplate, string assocName,
   SPList workflowTasksList, SPList workflowHistoryList,
   bool allowManual, bool autoStartCreate, bool autoStartChange, bool overwrite = false)
 {
     SPWorkflowAssociation workflowAssociation =
          contentType.CreateListWorkflowAssociation(workflowTemplate, assocName, workflowTasksList, workflowHistoryList,
                                         overwrite,
                                         assoc =>
                                         {
                                             assoc.AllowManual = allowManual;
                                             assoc.AutoStartCreate = autoStartCreate;
                                             assoc.AutoStartChange = autoStartChange;
                                         });
     return workflowAssociation;
 }
Ejemplo n.º 16
0
        public static SPWorkflowAssociation CreateListWorkflowAssociation(this SPContentType contentType,
                                                                          SPWorkflowTemplate workflowTemplate, string assocName,
                                                                          SPList workflowTasksList, SPList workflowHistoryList,
                                                                          bool allowManual, bool autoStartCreate, bool autoStartChange, bool overwrite = false)
        {
            SPWorkflowAssociation workflowAssociation =
                contentType.CreateListWorkflowAssociation(workflowTemplate, assocName, workflowTasksList, workflowHistoryList,
                                                          overwrite,
                                                          assoc =>
            {
                assoc.AllowManual     = allowManual;
                assoc.AutoStartCreate = autoStartCreate;
                assoc.AutoStartChange = autoStartChange;
            });

            return(workflowAssociation);
        }
        public static SPWorkflowAssociation CreateListWorkflowAssociation(this SPContentType contentType,
         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.CreateListContentTypeAssociation(
                    workflowTemplate, assocName,
                    workflowTasksList, workflowHistoryList);

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

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

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

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

            return workflowAssociation;
        }
        private static void NewCreatePOAssociation(WorkflowDescription _dsc, SPWeb _web, SPList _taskList, SPList _historyList, bool _autoStartCreate)
        {
            SPWorkflowTemplate _workflowTemplate = _web.WorkflowTemplates[_dsc.WorkflowId];
            // create workflow association
            SPWorkflowAssociation _freightPOLibraryWorkflowAssociation =
                SPWorkflowAssociation.CreateListAssociation(
                    _workflowTemplate,
                    _dsc.Name,
                    _taskList,
                    _historyList);

            // configure workflow association and add to WorkflowAssociations collection
            _freightPOLibraryWorkflowAssociation.Description     = _dsc.Description;
            _freightPOLibraryWorkflowAssociation.AllowManual     = true;
            _freightPOLibraryWorkflowAssociation.AutoStartCreate = _autoStartCreate;
            _freightPOLibraryWorkflowAssociation.AutoStartChange = false;
            _freightPOLibraryWorkflowAssociation.AssociationData = _dsc.Name;
            _web.Lists[CommonDefinition.ShippingListTitle].WorkflowAssociations.Add(_freightPOLibraryWorkflowAssociation);
        }
        private static void NewSendEmailAssociation(string _targetList, SPWeb _web, SPList _taskList, SPList _historyList, POLibraryWorkflowAssociationData _wfData)
        {
            SPWorkflowTemplate _workflowTemplate = _web.WorkflowTemplates[SendEmail.SendEmail.WorkflowId];
            // create workflow association
            SPWorkflowAssociation _wa = SPWorkflowAssociation.CreateListAssociation(
                _workflowTemplate,
                _wfData.Name,
                _taskList,
                _historyList);

            // configure workflow association and add to WorkflowAssociations collection
            _wa.Description     = "Send PO by email";
            _wa.AllowManual     = true;
            _wa.AutoStartCreate = true;
            _wa.AutoStartChange = false;
            // add workflow association data
            _wa.AssociationData = _wfData.Serialize(_wa);
            _web.Lists[_targetList].WorkflowAssociations.Add(_wa);
        }
Ejemplo n.º 20
0
        public static void AssociateWokflow(this SPContentType ctype, string wokflowTemplateName, string workflowName, string association)
        {
            SPWorkflowTemplate    workflowTemplate    = null;         // Workflow template
            SPWorkflowAssociation workflowAssociation = null;         //Workflow association
            SPList historyList = null;                                // Workflow history list
            SPList taskList    = null;                                // Workflow tasks list
            SPList list        = null;                                //Sharepoint List


            workflowTemplate = ctype.ParentWeb.Site.RootWeb.WorkflowTemplates.GetTemplateByName(wokflowTemplateName, System.Globalization.CultureInfo.CurrentCulture);

            //List which we is going to associate the workflow
            historyList = ctype.ParentWeb.Lists["Workflow History"]; //The list to which to log workflow history events.

            taskList = ctype.ParentWeb.Lists["Workflow Task"];       //The task list on which to create workflow tasks for this workflow


            try
            {
                ctype.ParentWeb.AllowUnsafeUpdates = false;
                // Create workflow association
                workflowAssociation = SPWorkflowAssociation.CreateWebContentTypeAssociation(workflowTemplate, workflowName, "Workflow Task", "Workflow History");

                // Set workflow parameters
                workflowAssociation.AllowManual     = false;
                workflowAssociation.AutoStartCreate = true;
                workflowAssociation.AutoStartChange = false;

                workflowAssociation.AssociationData = association;

                // Add workflow association to my list
                //list.AddWorkflowAssociation(workflowAssociation);
                ctype.WorkflowAssociations.Add(workflowAssociation);
                // Enable workflow
                workflowAssociation.Enabled = true;
            }
            finally
            {
                ctype.ParentWeb.AllowUnsafeUpdates = false;
            }
        }
Ejemplo n.º 21
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);
                }
            }
        }
        private void GetAssociationInfo()
        {
            Guid associationTemplateId = new Guid(Request.Params["TemplateID"]);

            associationTemplate = list.WorkflowAssociations[associationTemplateId];

            if (associationTemplate == null)
            {
                SPContentTypeId contentTypeId = (SPContentTypeId)listItem["ContentTypeId"];
                SPContentType contentType = list.ContentTypes[contentTypeId];
                associationTemplate = contentType.WorkflowAssociations[associationTemplateId];
            }

            if (associationTemplate == null)
                throw new SPException("The requested workflow could not be found.");

            baseTemplate = Web.WorkflowTemplates[associationTemplate.BaseId];

            workflowName = associationTemplate.Name;

            string m_formData = (string)associationTemplate.AssociationData;
        }
        private static void NewWorkflowAssociation(string _targetList, WorkflowDescription _dsc, SPWeb _web, SPList _taskList, SPList _historyList)
        {
            if (string.IsNullOrEmpty(_targetList))
            {
                throw new ApplicationException("The parameter _targetList of the NewWorkflowAssociation cannot be null or empty");
            }
            SPWorkflowTemplate _workflowTemplate = _web.WorkflowTemplates[_dsc.WorkflowId];
            // create workflow association
            SPWorkflowAssociation _workflowAssociation =
                SPWorkflowAssociation.CreateListAssociation(
                    _workflowTemplate,
                    _dsc.Name,
                    _taskList,
                    _historyList);

            // configure workflow association and add to WorkflowAssociations collection
            _workflowAssociation.Description     = _dsc.Description;
            _workflowAssociation.AllowManual     = true;
            _workflowAssociation.AutoStartCreate = false;
            _workflowAssociation.AutoStartChange = false;
            _workflowAssociation.AssociationData = _dsc.Name;
            _web.Lists[_targetList].WorkflowAssociations.Add(_workflowAssociation);
        }
Ejemplo n.º 24
0
        private void GetAssociationInfo()
        {
            // get ID of the association template
            Guid assocTemplateId = new Guid(Request.Params["TemplateID"]);

            // fetch the association
            m_assocTemplate = List.WorkflowAssociations[assocTemplateId];
            if (m_assocTemplate == null) // its on a content type
            {
                SPContentTypeId ctid = (SPContentTypeId)m_listItem["ContentTypeId"];
                SPContentType   ct   = List.ContentTypes[ctid];
                m_assocTemplate = ct.WorkflowAssociations[assocTemplateId];
            }
            // make sure we found the association
            if (m_assocTemplate == null)
            {
                throw new SPException("The requested workflow could not be found.");
            }

            // get base template, workflow name, and form data
            m_baseTemplate = Web.WorkflowTemplates[m_assocTemplate.BaseId];
            m_workflowName = m_assocTemplate.Name;
            string m_formData = (string)m_assocTemplate.AssociationData;
        }
        private void FetchAssociationInfo()
        {
            SPWorkflowAssociationCollection wfAccociationCollection;
            baseTemplate = Web.WorkflowTemplates[new Guid(Request.Params["WorkflowDefinition"])];
            associationTemplate = null;

            if (contentType != null)
            {
                // Associating with a content type.
                wfAccociationCollection = contentType.WorkflowAssociations;
                hlReturn.Text = contentType.Name;
                hlReturn.NavigateUrl = "ManageContentType.aspx" + requestQueryString;
            }
            else
            {
                list.CheckPermissions(SPBasePermissions.ManageLists);

                wfAccociationCollection = list.WorkflowAssociations;
                hlReturn.Text = list.Title;
                hlReturn.NavigateUrl = list.DefaultViewUrl;
            }
            if (wfAccociationCollection == null || wfAccociationCollection.Count < 0)
            {
                throw new SPException("No Associations Found");
            }

            workflowOptions.autoStartCreate = (Request.Params["AutoStartCreate"] == "ON");
            workflowOptions.autoStartChange = (Request.Params["AutoStartChange"] == "ON");
            workflowOptions.allowManual = (Request.Params["AllowManual"] == "ON");
            workflowOptions.lockItem = (Request.Params["LockItem"] == "ON");
            workflowOptions.setDefault = (Request.Params["SetDefault"] == "ON");
            workflowOptions.updateLists = (Request.Params["UpdateLists"] == "TRUE");

            string associationGuid = Request.Params["GuidAssoc"];
            if (associationGuid != string.Empty)
            {
                associationTemplate = wfAccociationCollection[new Guid(associationGuid)];
            }

            SPWorkflowAssociation checkForDuplicateTemplate = wfAccociationCollection.GetAssociationByName(workflowName, Web.Locale);

            if (checkForDuplicateTemplate != null && (associationTemplate == null || associationTemplate.Id != checkForDuplicateTemplate.Id))
            {
                throw new SPException("Duplicate workflow name is detected.");
            }
        }
Ejemplo n.º 26
0
        public static void AssociateWorkflow(this SPList list, string workflowTemplateName, string workflowAssocName, string association, string wfTaskList)
        {
            SPWeb                 web                  = list.ParentWeb;
            SPList                historyList          = null;  // Workflow history list
            SPList                taskList             = null;  // Workflow tasks list
            string                workflowTemplateGuid = null;  // Workflow template Guid
            SPWorkflowTemplate    workflowTemplate     = null;  // Workflow template
            SPWorkflowAssociation workflowAssociation  = null;  // Workflow association

            try
            {
                // Workflow association name

                // Allow unsafe updates on web
                web.AllowUnsafeUpdates = true;

                //workflowTemplateGuid = "BAD855B1-32CE-4bf1-A29E-463678304E1A";
                //workflowTemplate = web.WorkflowTemplates[workflowTemplateName];

                workflowTemplate = web.WorkflowTemplates.GetTemplateByName(workflowTemplateName, System.Globalization.CultureInfo.CurrentCulture);
                if (workflowTemplate == null)
                {
                    return;
                }
                try
                {
                    historyList = web.Lists["Workflow History"];
                }
                catch (ArgumentException exc)
                {
                    // Create workflow history list
                    Guid listGuid = web.Lists.Add("Workflow History", "", SPListTemplateType.WorkflowHistory);
                    historyList        = web.Lists[listGuid];
                    historyList.Hidden = true;
                    historyList.Update();
                }

                try
                {
                    if (string.IsNullOrEmpty(wfTaskList))
                    {
                        wfTaskList = "Workflow Tasks";
                    }
                    taskList = web.Lists[wfTaskList];
                }
                catch (ArgumentException exc)
                {
                    // Create workflow tasks list
                    Guid listGuid = web.Lists.Add(wfTaskList, "", SPListTemplateType.Tasks);
                    taskList        = web.Lists[listGuid];
                    taskList.Hidden = true;
                    taskList.Update();
                }



                // Create workflow association
                workflowAssociation = SPWorkflowAssociation.CreateListAssociation(
                    workflowTemplate,
                    workflowAssocName, taskList, historyList);

                // Set workflow parameters
                workflowAssociation.AllowManual     = true;
                workflowAssociation.AutoStartCreate = false;
                workflowAssociation.AutoStartChange = false;
                workflowAssociation.AssociationData = association.ToString();

                // Add workflow association to my list
                list.WorkflowAssociations.Add(workflowAssociation);

                // Enable workflow
                workflowAssociation.Enabled = true;
            }
            catch (Exception ex)
            {
                Utility.LogError(ex);
            }
            finally
            {
                web.AllowUnsafeUpdates = false;
            }
        }
Ejemplo n.º 27
0
        protected void associateCustomWorkflows()
        {
            AddWorklfowTemplate();

            try
            {
                foreach (SiteCollInfo siteCollInfo in Owner.WorkingSiteCollections)
                {
                    using (SPSite siteColl = new SPSite(siteCollInfo.URL))
                    {
                        foreach (SiteInfo siteInfo in siteCollInfo.Sites)
                        {
                            using (SPWeb web = siteColl.OpenWeb(siteInfo.ID))
                            {
                                if (web.Features[new Guid("00bfea71-f600-43f6-a895-40c0de7b0117")] == null)
                                {
                                    web.Features.Add(new Guid("00bfea71-f600-43f6-a895-40c0de7b0117"));
                                }
                                else
                                {
                                    Owner.IncrementCurrentTaskProgress("", siteInfo.Lists.Count);
                                }

                                SPWorkflowTemplateCollection wfTemplates = web.WorkflowTemplates;
                                int templateIndex = -1;

                                for (int i = 0; i < wfTemplates.Count; i++)
                                {
                                    SPWorkflowTemplate wfTemplate = wfTemplates[i];
                                    if (wfTemplate.Name == "SPDG Workflow")
                                    {
                                        templateIndex = i;
                                    }
                                }

                                if (templateIndex == -1)
                                {
                                    Log.Write("Declarative Workflow 'SPDG Workflow' not found.");
                                    return;
                                }


                                foreach (ListInfo listInfo in siteInfo.Lists)
                                {
                                    try
                                    {
                                        SPList             list             = web.Lists[listInfo.Name];
                                        SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates[templateIndex];

                                        SPList wftasks = web.Lists.TryGetList("Workflow Tasks");
                                        if (wftasks == null)
                                        {
                                            //Check if Workflow List exists
                                            Guid listGuid = web.Lists.Add(
                                                "Workflow Tasks",
                                                string.Empty,
                                                SPListTemplateType.Tasks);
                                            wftasks = web.Lists.GetList(listGuid, false);
                                        }

                                        SPList wfhistory = web.Lists.TryGetList("Workflow History");
                                        if (wfhistory == null)
                                        {
                                            //Check if Workflow List exists
                                            Guid listGuid = web.Lists.Add(
                                                "Workflow History",
                                                string.Empty,
                                                SPListTemplateType.WorkflowHistory);
                                            wfhistory        = web.Lists.GetList(listGuid, false);
                                            wfhistory.Hidden = true;
                                            wfhistory.Update();
                                        }


                                        // create the association
                                        SPWorkflowAssociation assoc =
                                            SPWorkflowAssociation.CreateListAssociation(
                                                workflowTemplate, workflowTemplate.Name,
                                                wftasks, wfhistory
                                                );
                                        assoc.AllowManual = true;

                                        //apply the association to the list
                                        list.WorkflowAssociations.Add(assoc);
                                        Owner.IncrementCurrentTaskProgress(string.Format("Added declarative workflow to {0} on subsite{1}", listInfo.Name, web.Url));
                                    }
                                    catch (Exception ex)
                                    {
                                        Errors.Log(ex);
                                        Owner.IncrementCurrentTaskProgress(string.Format("Error while adding declarative workflow to {0} on subsite{1}", listInfo.Name, web.Url));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Errors.Log(ex);
            }
        }
Ejemplo n.º 28
0
        void associateWorkflows()
        {
            try
            {
                foreach (SiteCollInfo siteCollInfo in Owner.WorkingSiteCollections)
                {
                    using (SPSite siteColl = new SPSite(siteCollInfo.URL))
                    {
                        // Activating out-of-the-box workflows
                        if (siteColl.Features[new Guid("0af5989a-3aea-4519-8ab0-85d91abe39ff")] == null)
                        {
                            siteColl.Features.Add(new Guid("0af5989a-3aea-4519-8ab0-85d91abe39ff"));
                        }

                        foreach (SiteInfo siteInfo in siteCollInfo.Sites)
                        {
                            using (SPWeb web = siteColl.OpenWeb(siteInfo.ID))
                            {
                                int workflowCount = web.WorkflowTemplates.Count;

                                foreach (ListInfo listInfo in siteInfo.Lists)
                                {
                                    try
                                    {
                                        SPList     list             = web.Lists[listInfo.Name];
                                        int        randomNumberOfWF = SampleData.GetRandomNumber(1, 2);
                                        List <int> addedTemplates   = new List <int>();

                                        for (int i = 0; i < randomNumberOfWF; i++)
                                        {
                                            Owner.IncrementCurrentTaskProgress("Adding Workflow Association to list '" + web.Url + "/" + list.RootFolder.Url + "'");
                                            int templateIndex = SampleData.GetRandomNumber(0, 5);

                                            if (addedTemplates.Any(x => x == templateIndex))
                                            {
                                                continue;
                                            }

                                            SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates[templateIndex];

                                            SPList wftasks = web.Lists.TryGetList("Workflow Tasks");
                                            if (wftasks == null)
                                            {
                                                //Check if Workflow List exists
                                                Guid listGuid = web.Lists.Add(
                                                    "Workflow Tasks",
                                                    string.Empty,
                                                    SPListTemplateType.Tasks);
                                                wftasks = web.Lists.GetList(listGuid, false);
                                            }

                                            SPList wfhistory = web.Lists.TryGetList("Workflow History");
                                            if (wfhistory == null)
                                            {
                                                //Check if Workflow List exists
                                                Guid listGuid = web.Lists.Add(
                                                    "Workflow History",
                                                    string.Empty,
                                                    SPListTemplateType.WorkflowHistory);
                                                wfhistory        = web.Lists.GetList(listGuid, false);
                                                wfhistory.Hidden = true;
                                                wfhistory.Update();
                                            }


                                            // create the association
                                            SPWorkflowAssociation assoc =
                                                SPWorkflowAssociation.CreateListAssociation(
                                                    workflowTemplate, workflowTemplate.Name,
                                                    wftasks, wfhistory
                                                    );
                                            assoc.AllowManual = true;

                                            //apply the association to the list
                                            list.WorkflowAssociations.Add(assoc);

                                            addedTemplates.Add(templateIndex);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Errors.Log(ex);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Errors.Log(ex);
            }
        }
Ejemplo n.º 29
0
        public static SPWorkflowAssociation CreateWorkflowAssociation(this SPWeb web, string listUrl, SPWorkflowTemplate workflowTemplate, string assocName,
                                                                      string workflowTasksListName, string workflowHistoryListName,
                                                                      bool allowManual, bool autoStartCreate, bool autoStartChange)
        {
            SPList workflowTasksList = web.Lists.TryGetList(workflowTasksListName) ??
                                       web.Lists[web.Lists.Add(workflowTasksListName,
                                                               /*"This is workflow tasks list."*/ "", SPListTemplateType.Tasks)];

            SPList workflowHistoryList = web.Lists.TryGetList(workflowHistoryListName) ??
                                         web.Lists[web.Lists.Add(workflowHistoryListName,
                                                                 /*"This is workflow history list."*/ "", SPListTemplateType.WorkflowHistory)];

            return(web.CreateWorkflowAssociation(workflowTemplate, assocName, workflowTasksList,
                                                 workflowHistoryList, allowManual, autoStartCreate, autoStartChange));
        }
Ejemplo n.º 30
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Declare Fields

            var site = SPContext.Current.Site;
            var web  = site.RootWeb;
            // Get the SPFieldCollection for the root web.
            var fields = web.Fields;
            // Add a new date field.
            var fieldExpiryDate = new SPFieldDateTime(fields, SPFieldType.DateTime.ToString(), "Expiry Date")
            {
                StaticName    = "ExpiryDate",
                DisplayFormat = SPDateTimeFieldFormatType.DateOnly,
                Group         = "Contoso Columns",
                Required      = true
            };

            fieldExpiryDate.Update();
            fields.Add(fieldExpiryDate);

            // Add a new choice field.
            var fieldProductionType = new SPFieldChoice(fields, SPFieldType.Choice.ToString(), "Production Type")
            {
                StaticName = "ProductionType"
            };

            fieldProductionType.Choices.Add("Research");
            fieldProductionType.Choices.Add("Prototype");
            fieldProductionType.Choices.Add("Trial");
            fieldProductionType.Choices.Add("Release");
            fieldProductionType.Group    = "Contoso Columns";
            fieldProductionType.Required = true;
            fieldProductionType.Update();
            fields.Add(fieldProductionType);

            // Declare Content Types

            // Get the ID of the parent content type.
            var parentId = SPBuiltInContentTypeId.Document;
            // Create the Invoice content type.
            var ctInvoice = new SPContentType(parentId, web.ContentTypes, "Invoice");
            // Create field links.
            var fldClientName         = fields.GetField("ClientName");
            var fldPaymentDueDate     = fields.GetField("PaymentDueDate");
            var fldAmount             = fields.GetField("Amount");
            var fldLinkClientName     = new SPFieldLink(fldClientName);
            var fldLinkPaymentDueDate = new SPFieldLink(fldPaymentDueDate);
            var fldLinkAmount         = new SPFieldLink(fldAmount);

            // Add the field links to the content type.
            ctInvoice.FieldLinks.Add(fldLinkClientName);
            ctInvoice.FieldLinks.Add(fldLinkPaymentDueDate);
            ctInvoice.FieldLinks.Add(fldLinkAmount);
            // Persist the changes to the content database.
            ctInvoice.Update();
            // Add the content type to the collection.
            web.ContentTypes.Add(ctInvoice);
            web.Dispose();

            // Bind Content Type

            // Get the list.
            var list = web.GetList("Invoices");
            // Get the site content type.
            var ct = web.AvailableContentTypes["Invoice"];

            // Enable content types on the list.
            list.ContentTypesEnabled = true;
            // Add the content type to the list.
            list.ContentTypes.Add(ct);
            // Persist the changes to the database.
            list.Update();

            //Set Document Template

            ct.DocumentTemplate = "SiteAssets/MyTemplate.dotx";
            ct.Update();

            //Set Workflow Template

            SPWorkflowTemplate template = web.WorkflowTemplates.GetTemplateByName("InvoiceWorkflow", web.Locale);

            // Create a new workflow association.
            SPWorkflowAssociation association = SPWorkflowAssociation.CreateWebContentTypeAssociation(template, "Process Invoice", "Invoice Tasks", "Process Invoice History");

            if (ct.WorkflowAssociations.GetAssociationByName("Process Invoice", web.Locale) == null)
            {
                ct.WorkflowAssociations.Add(association);
                ct.UpdateWorkflowAssociationsOnChildren(false, true, true, false);
            }
        }