public WorkflowNode(object parent, SPWorkflow workflow) { this.Tag = workflow; this.SPParent = parent; Setup(); }
/// <summary> /// 工作流已完成. /// </summary> public override void WorkflowCompleted(SPWorkflowEventProperties properties) { base.WorkflowCompleted(properties); if (properties.CompletionType != SPWorkflowEventCompletionType.Completed) return; SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite(properties.WebUrl)) { string title=""; try { using (SPWeb web = site.OpenWeb()) { SPWorkflow wf = new SPWorkflow(web, properties.InstanceId); SPList list = web.Lists[wf.ListId]; if (list.Title == "请假单") { SPListItem item = list.Items.GetItemById(wf.ItemId); title = item.Title; if (!Records.IsRecord(item)) { Records.DeclareItemAsRecord(item); log(site, "请假单流程结束", "消息", "请假单【" + title + "】流程结束,已经声明为记录。"); if (item["请假单审批流程"].ToString() == "16") // 通过了才扣年假,对吧。 { if (item["假别"].ToString() == "年假") { SPList annual_list = web.Lists["年假汇总"]; SPQuery query = new SPQuery(); DateTime date = DateTime.Parse(item["开始日期"].ToString()); string user_id = item["创建者"].ToString().Split(new char[] { ';', '#' })[0]; query.Query = "<Where><And><Eq><FieldRef Name='_x5e74__x4efd_'/><Value Type='Integer'>" + date.Year + "</Value></Eq><Eq><FieldRef Name='_x4eba__x5458_' LookupId='TRUE'/><Value Type='User'>" + user_id + "</Value></Eq></And></Where>"; SPListItemCollection annual_items = annual_list.GetItems(query); if (annual_items.Count > 0) { SPListItem annual_item = annual_items[0]; int annual_days_left = int.Parse(annual_item["剩余年假天数"].ToString()); int leave_days = int.Parse(item["请假天数"].ToString()); annual_item["剩余年假天数"] = annual_days_left - leave_days; annual_item.Update(); log(site, "年假汇总更新", "消息", "请假单【" + title + "】流程结束,对应的年假剩余天数已经更新。"); } } } } } } } catch (Exception ex) { log(site, "请假单流程结束", "错误", "请假单【" + title + "】流程结束,声明为记录时出错。" + ex.ToString()); } } }); }
public static void StartWorkflow(SPListItem listItem, string workflowName) { try { SPWorkflowManager manager = listItem.Web.Site.WorkflowManager; SPWorkflowAssociationCollection objWorkflowAssociationCollection = listItem.ParentList.WorkflowAssociations; foreach (SPWorkflowAssociation objWorkflowAssociation in objWorkflowAssociationCollection) { if (String.Compare(objWorkflowAssociation.Name, workflowName, true) == 0) { try { SPWorkflowCollection wfc = manager.GetItemActiveWorkflows(listItem); bool isActive = false; foreach (SPWorkflow wf in wfc) { // wf.IsCompleted nie używać - blokuje kolejne uruchomienie procesu jeżęli status jest "Ukończono" if (wf.IsLocked && objWorkflowAssociation.Id.Equals(wf.AssociationId)) { isActive = true; break; } } if (!isActive) { //manager.StartWorkflow(listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, true); SPWorkflow wf = manager.StartWorkflow(listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, SPWorkflowRunOptions.SynchronousAllowPostpone); Debug.WriteLine("Workflow InternalState:" + wf.InternalState.ToString()); //The above line will start the workflow... } else { Debug.WriteLine("WF aktualnie uruchomiony - kolejna aktywacja procesu przerwana"); //ElasticEmail.EmailGenerator.SendMail("wf aktualnie uruchomiony" + listItem.ID.ToString(), string.Empty); } } catch (Exception) { } break; } } } catch (Exception) { } }
/// <summary> /// Reads the workflow tasks. This method /// is implemented because the Tasks property /// of the SPWorkflow instance takes a /// while to be populated. /// </summary> public static SPWorkflowTaskCollection GetWorkflowTasks(SPWorkflow workflowInstance) { SPWorkflowTaskCollection taskCollection = null; bool tasksPopulated = false; while (!tasksPopulated) { try { taskCollection = workflowInstance.Tasks; tasksPopulated = true; } catch { } } return taskCollection; }
private void Execute(SPItemEventProperties properties) { this.EventFiringEnabled = false; try { SPWorkflow wf = BLL.Workflows.StartWorkflow(properties.ListItem, "tabZadaniaWF"); Debug.WriteLine("StartWorkflow: tabZadaniaWF " + wf.InternalState.ToString()); } catch (Exception ex) { BLL.Logger.LogEvent(properties.WebUrl, ex.ToString()); var result = ElasticEmail.EmailGenerator.ReportError(ex, properties.WebUrl.ToString()); } this.EventFiringEnabled = true; }
/// <summary> /// Overrides base class event and adds custom code to remove items from /// My Submitted Documents list. /// Note. The protected OnClick_HtmlAnchorEnd() method is not virtual thus it won’t get called /// by the framework even if overriden. /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); // Detect cancellation event if (Request.Form[EVENT_TARGET] != null && Request.Form[EVENT_TARGET].Contains("HtmlAnchorEnd")) { Guid guid = new Guid(base.StrGuidWorkflow); SPWorkflow workflow = new SPWorkflow(base.Web, guid); using (DisabledItemEventsScope scope = new DisabledItemEventsScope()) { SPList ObjList = SPContext.Current.Web.Lists[new Guid(Request.QueryString["List"].ToString())]; SPListItem ObjItem = ObjList.Items.GetItemById(workflow.ItemId); ObjItem["Publishable Status"] = ""; ObjItem.Update(); } } }
private static void Create_New_GFR_K(Microsoft.SharePoint.SPListItem item, string mask, SPList list, SPListItem klientItem) { string ct = "Generowanie formatek rozliczeniowych dla klienta"; int okresId = BLL.Tools.Get_LookupId(item, "selOkres"); SPListItem newItem = list.AddItem(); newItem["ContentType"] = ct; newItem["selKlient"] = klientItem.ID; newItem["selOkres"] = okresId; newItem["colMaskaSerwisu"] = mask; newItem.SystemUpdate(); SPWorkflow wf = BLL.Workflows.StartWorkflow(newItem, "Generuj formatki rozliczeniowe dla klienta"); Debug.WriteLine("StartWorkflow: Generuj formatki rozliczeniowe dla klienta " + wf.InternalState.ToString()); }
internal static void Execute(SPListItem item) { BLL.Logger.LogEvent("Obsłga wiadomomości", item.ID.ToString()); SPList list = item.Web.Lists.TryGetList(targetList); list.Items.Cast <SPListItem>() .Where(i => (bool)i["colCzyWyslana"] != true) .Where(i => i["colPlanowanaDataNadania"] == null || (i["colPlanowanaDataNadania"] != null && (DateTime)i["colPlanowanaDataNadania"] <= DateTime.Now)) .ToList() .ForEach(i => { SPWorkflow wf = BLL.Workflows.StartWorkflow(i, "Obsługa wiadomości"); Debug.WriteLine("StartWorkflow: Obsługa wiadomości " + wf.InternalState.ToString()); BLL.Logger.LogEvent(BLL.Tools.Get_LookupValue(i, "selKlient_NazwaSkrocona").ToString(), i.ID.ToString()); }); }
public static SPWorkflow StartWorkflow(SPListItem listItem, string workflowName) { SPWorkflow wf = null; try { SPWorkflowManager manager = listItem.Web.Site.WorkflowManager; SPWorkflowAssociationCollection objWorkflowAssociationCollection = listItem.ParentList.WorkflowAssociations; foreach (SPWorkflowAssociation objWorkflowAssociation in objWorkflowAssociationCollection) { if (String.Compare(objWorkflowAssociation.Name, workflowName, true) == 0) { //We found our workflow association that we want to trigger. //Replace the workflow_GUID with the GUID of the workflow feature that you //have deployed. try { //result = manager.StartWorkflow(listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, SPWorkflowRunOptions.SynchronousAllowPostpone); wf = manager.StartWorkflow(listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, true); //ElasticEmail.EmailGenerator.SendMail("StartWorkflow: " + workflowName + " " + wf.InternalState.ToString(), ""); //manager.StartWorkflow(listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, true); //The above line will start the workflow... } catch (Exception) { } break; } } } catch (Exception) { } return(wf); }
public static void CancelWorkflowAppropriately(SPWorkflow workflow, SPSite site) { bool flag = false; try { //E43856D2-1BB4-40ef-B08B-016D89A0 Guid objB = new Guid("a938eabe-8db1-45b9-87cb-b930728afe10"); foreach (SPWorkflowModification modification in workflow.Modifications) { if (object.Equals(modification.TypeId, objB)) { site.WorkflowManager.ModifyWorkflow(workflow, modification, null); flag = true; break; } } //ULS.SendTraceTag(0x38747333, ULSCat.msoulscat_CMS_Publishing, ULSTraceLevel.Verbose, "Simple cancellation on workflow: {0} for item: {1} ", new object[] { workflow.AssociationId.ToString(), workflow.ParentItem.Url }); } catch (ArgumentNullException) { flag = false; } catch (ArgumentException) { flag = false; } catch (SPException) { flag = false; } if (!flag) { SPWorkflowManager.CancelWorkflow(workflow); //ULS.SendTraceTag(0x38747334, ULSCat.msoulscat_CMS_Publishing, ULSTraceLevel.Verbose, "SPWorkflowManager.CancelWorkflow(), full cancellation on workflow: {0} for item: {1} ", new object[] { workflow.AssociationId.ToString(), workflow.ParentItem.Url }); } }
private void TerminateWF(SPListItem taskItem) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite osite = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb oweb = osite.OpenWeb("WorkflowCenter")) { oweb.AllowUnsafeUpdates = true; SPWorkflow workflow = new SPWorkflow(oweb, new Guid(taskItem[SPBuiltInFieldId.WorkflowInstanceID].AsString())); foreach (SPWorkflowTask wfTask in workflow.Tasks) { wfTask["Status"] = "Canceled"; wfTask.SystemUpdate(); } SPWorkflowManager.CancelWorkflow(workflow); oweb.AllowUnsafeUpdates = false; } } }); }
/// <summary> /// Logging function that enters updates to the Workflow History list /// </summary> /// <param name="logMessage"></param> public void LogWFHistoryComment(string logMessage, SPWorkflowActivationProperties workflowProperties, Guid WorkflowInstanceId) { SPWorkflow.CreateHistoryEvent(workflowProperties.Web, WorkflowInstanceId, 0, workflowProperties.Web.CurrentUser, new TimeSpan(), "Update", logMessage, string.Empty); }
public XmlDocument GetWFTasks(string sSiteURL, string sDocLibName, string sFolder, string sDocName, string sUser) { //temp debugging code: if (sUser.ToLower() == @"basexp\admin") { sUser = @"mossrtm\administrator"; } sUser = @"mossrtm\administrator"; //end temp debugging code string sTaskName = string.Empty; string sTaskURL = string.Empty; XmlDocument xDoc = new XmlDocument(); XmlElement xElem = null; XmlText xText = null; XmlNode xNode = null; //SPUser usr = new SPUser( //this.User. SPSite site = new SPSite(sSiteURL); SPWeb web = site.OpenWeb(); SPDocumentLibrary doclib = (SPDocumentLibrary)web.Lists[sDocLibName]; SPListItem item = null; foreach (SPListItem itemTemp in doclib.Items) { if (sFolder == string.Empty) { if (itemTemp.File.Name.ToLower() == sDocName.ToLower()) { item = itemTemp; break; } } else { if ((itemTemp.Folder.Name == sFolder) && (itemTemp.File.Name.ToLower() == sDocName.ToLower()) ) { item = itemTemp; break; } } } //string sCurrentUser = this.User.Identity.Name.ToLower(); string sTaskAssignedTo = string.Empty; for (int i = 0; i < item.Workflows.Count; i++) { SPWorkflow wf = item.Workflows[i]; if (!wf.IsCompleted) { wf.TaskFilter = new SPWorkflowFilter(SPWorkflowState.Running, SPWorkflowState.None); for (int j = 0; j < wf.Tasks.Count; j++) { SPWorkflowTask task = item.Workflows[i].Tasks[j]; sTaskAssignedTo = task["AssignedTo"].ToString(); sTaskAssignedTo = sTaskAssignedTo.Substring(sTaskAssignedTo.IndexOf('#') + 1); if (sUser.ToLower() == sTaskAssignedTo.ToLower()) { sTaskName = task.DisplayName; sTaskURL = sSiteURL.TrimEnd('/') + "/Lists/" + wf.TaskList.Title + "/DispForm.aspx?ID=" + task.ID.ToString(); break; } } } } xNode = xDoc.CreateNode(XmlNodeType.XmlDeclaration, string.Empty, string.Empty); xDoc.AppendChild(xNode); xElem = xDoc.CreateElement("WorkFlowTask"); xDoc.AppendChild(xElem); xElem = xDoc.CreateElement("TaskName"); xText = xDoc.CreateTextNode(sTaskName); xElem.AppendChild(xText); xDoc.ChildNodes.Item(1).AppendChild(xElem); xElem = xDoc.CreateElement("TaskURL"); xText = xDoc.CreateTextNode(sTaskURL); xElem.AppendChild(xText); xDoc.ChildNodes.Item(1).AppendChild(xElem); return(xDoc); }
public override void CallEventHandler(Type eventType, string eventName, object[] eventData, SPWorkflow workflow, string identity, System.Workflow.Runtime.IPendingWork workHandler, object workItem) { string correlationToken = (string)eventData[0]; string data = (string)eventData[1]; if (correlationToken == String.Empty) { correlationToken = null; } ExternalEventArgs extData = new ExternalEventArgs(workflow.InstanceId, correlationToken, data); extData.Identity = identity; extData.WorkHandler = workHandler; extData.WorkItem = workItem; if (eventName == "OnExternalEvent" && OnExternalEvent != null) { OnExternalEvent(null, extData); } }
protected void Page_Load(object sender, EventArgs e) { ListId = Request.QueryString["List"]; TaskList = Web.Lists[new Guid(ListId)]; TaskItem = TaskList.GetItemById((Convert.ToInt32(Request.Params["ID"]))); WorkflowInstanceId = new Guid((string)TaskItem["WorkflowInstanceID"]); WorkflowInstance = new SPWorkflow(Web, WorkflowInstanceId); ItemList = WorkflowInstance.ParentList; Item = ItemList.GetItemById(WorkflowInstance.ItemId); string urlToItem = Web.Site.MakeFullUrl(string.Format("{0}?ID={1}", ItemList.DefaultDisplayFormUrl, Item.ID.ToString())); string ItemName; if (Item.File != null) { ItemName = Item.File.Name; } else { ItemName = Item.Title; } lnkItem.Text = ItemName; lnkItem.NavigateUrl = urlToItem; lblListName.Text = ItemList.Title; lblSiteUrl.Text = Web.Url; if (TaskItem[SPBuiltInFieldId.TaskStatus].ToString() .Equals(SPUtility.GetLocalizedString("$Resources:Completed;", "core", SPContext.Current.Web.Language))) { btnApprove.Visible = false; btnReject.Visible = false; txtComments.Text = TaskItem["Comments"].ToString(); txtComments.Enabled = false; } }
internal static bool DoesWorkflowCancelWhenItemEdited(SPWorkflow wf) { return(DoesWorkflowCancelWhenItemEdited(wf.ParentAssociation)); }