private static void DetermineWorkflowStatus(WorkFlowTrackRecord workflowTrackingRecord, ref string workflowStatus) { //string workflowStatus = string.Empty; switch (workflowTrackingRecord.WfStatus) { case TrackingWorkflowEvent.Created: workflowStatus = TrackingWorkflowEvent.Created.ToString(); break; case TrackingWorkflowEvent.Completed: workflowStatus = TrackingWorkflowEvent.Completed.ToString(); break; case TrackingWorkflowEvent.Suspended: workflowStatus = TrackingWorkflowEvent.Suspended.ToString(); break; case TrackingWorkflowEvent.Terminated: workflowStatus = TrackingWorkflowEvent.Terminated.ToString(); break; case TrackingWorkflowEvent.Persisted: //return previous staus in case of persisted break; default: //Running workflowStatus = "Running"; break; } }
private static void GetTrackingData(XmlNode wfRecord, ref WorkFlowInfo wInfo) { foreach (XmlNode xmlNode in wfRecord.ChildNodes) { if (xmlNode.Name == WorkFlowTrackRecord.XMLTagName) { BaseTrackRecord wFTrackRecord = new WorkFlowTrackRecord(); foreach (XmlAttribute att in xmlNode.Attributes) { ConvertXmlNodeAttribValueToObjProp(att, ref wFTrackRecord); } //trackingData.WorkFlowRecords.Add((WorkFlowTrackRecord)wFTrackRecord); wInfo.TrackingRecords.Add(wFTrackRecord); } else if (xmlNode.Name == ActivityTrackRecord.XMLTagName) { BaseTrackRecord actTrackRecord = new ActivityTrackRecord(); foreach (XmlAttribute att in xmlNode.Attributes) { ConvertXmlNodeAttribValueToObjProp(att, ref actTrackRecord); } //trackingData.ActivityRecords.Add((ActivityTrackRecord)actTrackRecord); wInfo.TrackingRecords.Add(actTrackRecord); } } }
private static WorkFlowTrackRecord BuildSerializableWorkFlowTrackRecord(WorkflowTrackingRecord record) { WorkFlowTrackRecord wtr = new WorkFlowTrackRecord(); //utc date conversion to local wtr.DateTime = ConvertToLocalTime(record.EventDateTime); //record.EventDateTime.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours); wtr.WfHost = _wfHost; wtr.ThreadId = Thread.CurrentThread.ManagedThreadId; wtr.Order = record.EventOrder; wtr.WfStatus = record.TrackingWorkflowEvent; return(wtr); }
/// <summary> /// persist tracking records /// </summary> /// <param name="items">tracking records</param> public void PersistTrackingRecords(System.Collections.ICollection items) { if (_logFile == null) { if (File.Exists(_trackingFilePath)) { //Basanti //FileStream fstream = File.OpenWrite(_trackingFilePath); //Providing read access for other threads***** FileStream fstream = File.Open(_trackingFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); fstream.Position = fstream.Length - ("</" + WorkFlowInfo.XMLTagName + ">\n\r").Length; _logFile = new StreamWriter(fstream); //logfileExisted = true; } else { _logFile = File.CreateText(_trackingFilePath); _logFile.WriteLine(BuildWorkflowInfoString("Created", _wfPersistanceDB)); } } string workflowStatus = string.Empty; foreach (object itemToCommit in items) { WorkFlowTrackRecord workflowTrackingRecord = itemToCommit as WorkFlowTrackRecord; if (workflowTrackingRecord != null) { //Determine Workflow Status DetermineWorkflowStatus(workflowTrackingRecord, ref workflowStatus); _logFile.WriteLine(workflowTrackingRecord.ToString()); continue; } ActivityTrackRecord activityTrackingRecord = itemToCommit as ActivityTrackRecord; if (activityTrackingRecord != null) { //Reading ErrorCode, ErrorMessage value from AssociatedRequestedTaskStatusInfo object if (activityTrackingRecord.UpdateTaskStatusRequestedTaskStatusInfo != null) { Type underlyingType = activityTrackingRecord.UpdateTaskStatusRequestedTaskStatusInfo.GetType(); PropertyInfo pInfo = underlyingType.GetProperty("UserId"); if (pInfo != null) { object value = pInfo.GetValue(activityTrackingRecord.UpdateTaskStatusRequestedTaskStatusInfo, null); if (value != null) { activityTrackingRecord.User = value.ToString(); } } pInfo = underlyingType.GetProperty("TaskStatus"); if (pInfo != null) { object value = pInfo.GetValue(activityTrackingRecord.UpdateTaskStatusRequestedTaskStatusInfo, null); if (value != null) { activityTrackingRecord.ApexStatus = value.ToString().EscapeXML(); } } pInfo = underlyingType.GetProperty("ErrorCode"); if (pInfo != null) { object value = pInfo.GetValue(activityTrackingRecord.UpdateTaskStatusRequestedTaskStatusInfo, null); if (value != null) { activityTrackingRecord.ErrorCode = value.ToString().EscapeXML(); } } pInfo = underlyingType.GetProperty("ErrorMessage"); if (pInfo != null) { object value = pInfo.GetValue(activityTrackingRecord.UpdateTaskStatusRequestedTaskStatusInfo, null); if (value != null) { activityTrackingRecord.ErrorMessage = value.ToString().EscapeXML(); } } } //Reading UserId value from BaseActivityTask object if (activityTrackingRecord.BaseActivityTask != null) { Type underlyingType = activityTrackingRecord.BaseActivityTask.GetType(); PropertyInfo pInfo = underlyingType.GetProperty("UserId"); if (pInfo != null) { object value = pInfo.GetValue(activityTrackingRecord.BaseActivityTask, null); if (value != null) { activityTrackingRecord.User = value.ToString(); } } pInfo = underlyingType.GetProperty("DisplayName"); if (pInfo != null) { object value = pInfo.GetValue(activityTrackingRecord.BaseActivityTask, null); if (value != null) { activityTrackingRecord.DisplayName = value.ToString().EscapeXML(); } } // pInfo = underlyingType.GetProperty("Status"); // if (pInfo != null) // { // object value = pInfo.GetValue(activityTrackingRecord.AssociatedtaskDTO, null); // if (value != null) // activityTrackingRecord.ApexStatus = value.ToString().EscapeXML(); // } // pInfo = underlyingType.GetProperty("ErrorCode"); // if (pInfo != null) // { // object value = pInfo.GetValue(activityTrackingRecord.AssociatedtaskDTO, null); // if (value!=null) // activityTrackingRecord.ErrorCode = value.ToString().EscapeXML(); // } // pInfo = underlyingType.GetProperty("ErrorMessage"); // if (pInfo != null) // { // object value = pInfo.GetValue(activityTrackingRecord.AssociatedtaskDTO, null); // if (value != null) // activityTrackingRecord.ErrorMessage = value.ToString().EscapeXML(); // } // //pInfo = underlyingType.GetProperty("TaskType"); // //if (pInfo != null) // //{ // // object value = pInfo.GetValue(activityTrackingRecord.AssociatedtaskDTO, null); // // activityTrackingRecord.TaskType = (WorkflowTaskType)Enum.Parse(typeof(WorkflowTaskType), value.ToString()); // //} } _logFile.WriteLine(activityTrackingRecord.ToString()); continue; } UserTrackingRecord userTrackingRecord = itemToCommit as UserTrackingRecord; if (userTrackingRecord != null) { _logFile.WriteLine("<" + userTrackingRecord.UserDataKey + ":" + userTrackingRecord.UserData + "/>"); continue; } } _logFile.WriteLine("</" + WorkFlowInfo.XMLTagName + ">"); _logFile.Flush(); //Finally updating, workflow status & AllocationSetup id at the start of the log file if (!string.IsNullOrEmpty(workflowStatus)) { _logFile.BaseStream.Seek(0, SeekOrigin.Begin); _logFile.WriteLine(BuildWorkflowInfoString(workflowStatus, _wfPersistanceDB)); } //_logFile.BaseStream.Close(); _logFile.Close(); _logFile.Dispose(); _logFile = null; }