private void m_sendEmail1_MethodInvoking(object sender, EventArgs e) { try { POLibraryWorkflowAssociationData _activationData = POLibraryWorkflowAssociationData.Deserialize(m_WorkflowProperties.InitiationData); IPurchaseOrderTemplate _emailBodyObject = null; using (EntitiesDataContext _EDC = new EntitiesDataContext(m_WorkflowProperties.SiteUrl)) { if (_activationData.Carrier) { _emailBodyObject = FreightPurchaseOrderTemplate.CreateEmailMessage(m_WorkflowProperties.Item, _EDC); } else { _emailBodyObject = SecurityEscortPurchaseOrderTemplate.CreateEmailMessage(m_WorkflowProperties.Item, _EDC); } m_sendEmail1_CC = DistributionList.GetEmail(ShepherdRole.Coordinator, _EDC); } m_sendEmail1_From = m_WorkflowProperties.OriginatorEmail; m_sendEmail1_Subject = _activationData.Name; m_sendEmail1_To = _emailBodyObject.EmaiAddressTo; m_sendEmail1_Body = _emailBodyObject.TransformText(); } catch (Exception ex) { string _frmt = "Worflow aborted in TransformText because of the error: {0}"; throw new ApplicationException(String.Format(_frmt, ex.Message)); } }
/// <summary> /// Occurs after a Feature is activated. /// </summary> /// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"/> object that represents the properties of the event.</param> public override void FeatureActivated(SPFeatureReceiverProperties properties) { string _state = default(string); try { SPSite _siteCollection = (SPSite)properties.Feature.Parent; _state = "Feature.Parent"; //This best practice addresses the issue identified by the SharePoint Dispose Checker Tool as SPDisposeCheckID_140. { //More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_140 SPWeb _web = _siteCollection.RootWeb; // obtain referecnes to lists SPList _taskList = _web.Lists[CommonDefinition.SendNotificationWorkflowTasks]; SPList _historyList = _web.Lists[CommonDefinition.SendNotificationWorkflowHistory]; _taskList.UseFormsForDisplay = false; _state = "Update"; _taskList.Update(); _state = "FreightPOLibraryTitle"; NewSendEmailAssociation(CommonDefinition.FreightPOLibraryTitle, _web, _taskList, _historyList, POLibraryWorkflowAssociationData.FreightPOAssociationData()); _state = "EscortPOLibraryTitle"; NewSendEmailAssociation(CommonDefinition.EscortPOLibraryTitle, _web, _taskList, _historyList, POLibraryWorkflowAssociationData.SecurityPOAssociationData()); _state = "CreatePO"; NewCreatePOAssociation(CreatePO.CreatePO.WorkflowDescription, _web, _taskList, _historyList, false); _state = "CreateSecurityPO1"; NewCreatePOAssociation(CreateSecurityPO1.CreateSecurityPO1.WorkflowDescription, _web, _taskList, _historyList, false); _state = "CreateSealProtocol"; NewCreatePOAssociation(CreateSealProtocol.CreateSealProtocol.WorkflowDescription, _web, _taskList, _historyList, false); _state = "ShippingStateMachine"; NewCreatePOAssociation(ShippingStateMachine.ShippingStateMachine.WorkflowDescription, _web, _taskList, _historyList, true); _state = "ScheduleTemplateListTitle"; NewWorkflowAssociation(CommonDefinition.ScheduleTemplateListTitle, AddTimeSlots.Definitions.WorkflowDescription, _web, _taskList, _historyList); _state = "DataImportLibraryTitle"; NewWorkflowAssociation(CommonDefinition.DataImportLibraryTitle, ImportDictionaries.Definitions.WorkflowDescription, _web, _taskList, _historyList); } } catch (Exception _ex) { string _frmt = "ActivationContext failed in the {0} state because of the error {1}"; throw new ApplicationException(String.Format(_frmt, _state, _ex.Message)); } }
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); }