public IList <SqlTrackingWorkflowInstance> GetWorkflows(SqlTrackingQueryOptions options) { if (null == options) { throw new ArgumentNullException("options"); } if (null != options.TrackingDataItems) { foreach (TrackingDataItemValue val in options.TrackingDataItems) { if (null == val.QualifiedName) { throw new ArgumentNullException("options.TrackingDataItems.QualifiedName"); } if (null == val.FieldName) { throw new ArgumentNullException("options.TrackingDataItems.FieldName"); } } } SqlCommand cmd = BuildCommand(options); SqlDataReader reader = null; List <SqlTrackingWorkflowInstance> inst = new List <SqlTrackingWorkflowInstance>(); try { cmd.Connection = GetConnection(); reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); // // There will only be 1 row while (reader.Read()) { inst.Add(BuildInstance(reader)); } } finally { if (null != reader) { reader.Close(); } if (null != cmd && null != cmd.Connection && ConnectionState.Closed != cmd.Connection.State) { cmd.Connection.Close(); } } return(inst); }
public IList <SqlTrackingWorkflowInstance> GetWorkflows(SqlTrackingQueryOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (options.TrackingDataItems != null) { foreach (TrackingDataItemValue value2 in options.TrackingDataItems) { if (value2.QualifiedName == null) { throw new ArgumentNullException("options.TrackingDataItems.QualifiedName"); } if (value2.FieldName == null) { throw new ArgumentNullException("options.TrackingDataItems.FieldName"); } } } SqlCommand command = this.BuildCommand(options); SqlDataReader reader = null; List <SqlTrackingWorkflowInstance> list = new List <SqlTrackingWorkflowInstance>(); try { command.Connection = this.GetConnection(); reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { list.Add(this.BuildInstance(reader)); } } finally { if (reader != null) { reader.Close(); } if (((command != null) && (command.Connection != null)) && (command.Connection.State != ConnectionState.Closed)) { command.Connection.Close(); } } return(list); }
protected void Page_Load(object sender, EventArgs e) { SqlTrackingQueryOptions options = new SqlTrackingQueryOptions(); options.WorkflowStatus = WorkflowStatus.Running; SqlTrackingQuery query = new SqlTrackingQuery(ConfigurationManager.ConnectionStrings["workflows"].ConnectionString); IList<SqlTrackingWorkflowInstance> workflows = query.GetWorkflows(options); foreach (SqlTrackingWorkflowInstance workflow in workflows) { foreach (WorkflowTrackingRecord workflowEvent in workflow.WorkflowEvents) { TrackingWorkflowTerminatedEventArgs args = workflowEvent.EventArgs as TrackingWorkflowTerminatedEventArgs; if (args != null) { Response.Write(workflow.WorkflowInstanceId + ": " + args.Exception.Message); } } } }
public IList<SqlTrackingWorkflowInstance> GetWorkflows(SqlTrackingQueryOptions options) { if (null == options) throw new ArgumentNullException("options"); if (null != options.TrackingDataItems) { foreach (TrackingDataItemValue val in options.TrackingDataItems) { if (null == val.QualifiedName) throw new ArgumentNullException("options.TrackingDataItems.QualifiedName"); if (null == val.FieldName) throw new ArgumentNullException("options.TrackingDataItems.FieldName"); } } SqlCommand cmd = BuildCommand(options); SqlDataReader reader = null; List<SqlTrackingWorkflowInstance> inst = new List<SqlTrackingWorkflowInstance>(); try { cmd.Connection = GetConnection(); reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); // // There will only be 1 row while (reader.Read()) { inst.Add(BuildInstance(reader)); } } finally { if (null != reader) reader.Close(); if (null != cmd && null != cmd.Connection && ConnectionState.Closed != cmd.Connection.State) cmd.Connection.Close(); } return inst; }
private SqlCommand BuildCommand(SqlTrackingQueryOptions opt) { SqlCommand cmd = new SqlCommand("[dbo].[GetWorkflows]") { CommandType = CommandType.StoredProcedure }; SqlParameter parameter = new SqlParameter(); if (opt.WorkflowStatus.HasValue) { parameter.ParameterName = "@WorkflowStatusId"; parameter.SqlDbType = SqlDbType.TinyInt; parameter.Value = opt.WorkflowStatus.Value; cmd.Parameters.Add(parameter); if ((DateTime.MinValue != opt.StatusMinDateTime) || (DateTime.MaxValue != opt.StatusMaxDateTime)) { parameter = new SqlParameter { ParameterName = "@StatusMinDateTime", SqlDbType = SqlDbType.DateTime }; if (opt.StatusMinDateTime < SqlDateTime.MinValue.Value) { parameter.Value = SqlDateTime.MinValue.Value; } else { parameter.Value = opt.StatusMinDateTime; } cmd.Parameters.Add(parameter); parameter = new SqlParameter { ParameterName = "@StatusMaxDateTime", SqlDbType = SqlDbType.DateTime }; if (opt.StatusMaxDateTime > SqlDateTime.MaxValue.Value) { parameter.Value = SqlDateTime.MaxValue.Value; } else { parameter.Value = opt.StatusMaxDateTime; } cmd.Parameters.Add(parameter); } } if (null != opt.WorkflowType) { parameter = new SqlParameter("@TypeFullName", opt.WorkflowType.FullName) { SqlDbType = SqlDbType.NVarChar, Size = 0x80 }; cmd.Parameters.Add(parameter); parameter = new SqlParameter("@AssemblyFullName", opt.WorkflowType.Assembly.FullName) { SqlDbType = SqlDbType.NVarChar, Size = 0x80 }; cmd.Parameters.Add(parameter); } if ((opt.TrackingDataItems != null) && (opt.TrackingDataItems.Count > 0)) { this.BuildArtifactParameters(cmd, opt.TrackingDataItems); } return cmd; }
public IList<SqlTrackingWorkflowInstance> GetWorkflows(SqlTrackingQueryOptions options) { if (options == null) { throw new ArgumentNullException("options"); } if (options.TrackingDataItems != null) { foreach (TrackingDataItemValue value2 in options.TrackingDataItems) { if (value2.QualifiedName == null) { throw new ArgumentNullException("options.TrackingDataItems.QualifiedName"); } if (value2.FieldName == null) { throw new ArgumentNullException("options.TrackingDataItems.FieldName"); } } } SqlCommand command = this.BuildCommand(options); SqlDataReader reader = null; List<SqlTrackingWorkflowInstance> list = new List<SqlTrackingWorkflowInstance>(); try { command.Connection = this.GetConnection(); reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { list.Add(this.BuildInstance(reader)); } } finally { if (reader != null) { reader.Close(); } if (((command != null) && (command.Connection != null)) && (command.Connection.State != ConnectionState.Closed)) { command.Connection.Close(); } } return list; }
internal List<SqlTrackingWorkflowInstance> GetWorkflows(string workflowEvent, DateTime from, DateTime until, TrackingDataItemValue trackingDataItemValue) { try { List<SqlTrackingWorkflowInstance> queriedWorkflows = new List<SqlTrackingWorkflowInstance>(); SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString); SqlTrackingQueryOptions sqlTrackingQueryOptions = new SqlTrackingQueryOptions(); sqlTrackingQueryOptions.StatusMinDateTime = from.ToUniversalTime(); sqlTrackingQueryOptions.StatusMaxDateTime = until.ToUniversalTime(); // If QualifiedName, FieldName, or DataValue is not supplied, we will not query since they are all required to match if (!((string.Empty == trackingDataItemValue.QualifiedName) || (string.Empty == trackingDataItemValue.FieldName) || ((string.Empty == trackingDataItemValue.DataValue)))) sqlTrackingQueryOptions.TrackingDataItems.Add(trackingDataItemValue); queriedWorkflows.Clear(); if ("created" == workflowEvent.ToLower(CultureInfo.InvariantCulture)) { sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Created; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); } else if ("completed" == workflowEvent.ToLower(CultureInfo.InvariantCulture)) { sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Completed; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); } else if ("running" == workflowEvent.ToLower(CultureInfo.InvariantCulture)) { sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Running; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); } else if ("suspended" == workflowEvent.ToLower(CultureInfo.InvariantCulture)) { sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Suspended; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); } else if ("terminated" == workflowEvent.ToLower(CultureInfo.InvariantCulture)) { sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Terminated; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); } else if (("all" == workflowEvent.ToLower(CultureInfo.InvariantCulture)) || (string.Empty == workflowEvent) || (null == workflowEvent)) { sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Created; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Completed; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Running; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Suspended; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); sqlTrackingQueryOptions.WorkflowStatus = WorkflowStatus.Terminated; queriedWorkflows.AddRange(sqlTrackingQuery.GetWorkflows(sqlTrackingQueryOptions)); } return queriedWorkflows; } catch (Exception exception) { throw new Exception("Exception in GetWorkflows", exception); } }
private SqlCommand BuildCommand(SqlTrackingQueryOptions opt) { SqlCommand cmd = new SqlCommand("[dbo].[GetWorkflows]"); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter(); if (opt.WorkflowStatus.HasValue) { param.ParameterName = "@WorkflowStatusId"; param.SqlDbType = SqlDbType.TinyInt; param.Value = opt.WorkflowStatus.Value; cmd.Parameters.Add(param); // // If one of the range values is set we have a date range constraint if (DateTime.MinValue != opt.StatusMinDateTime || DateTime.MaxValue != opt.StatusMaxDateTime) { param = new SqlParameter(); param.ParameterName = "@StatusMinDateTime"; param.SqlDbType = SqlDbType.DateTime; if (opt.StatusMinDateTime < SqlDateTime.MinValue.Value) { param.Value = SqlDateTime.MinValue.Value; } else { param.Value = opt.StatusMinDateTime; } cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@StatusMaxDateTime"; param.SqlDbType = SqlDbType.DateTime; if (opt.StatusMaxDateTime > SqlDateTime.MaxValue.Value) { param.Value = SqlDateTime.MaxValue.Value; } else { param.Value = opt.StatusMaxDateTime; } cmd.Parameters.Add(param); } } if (null != opt.WorkflowType) { param = new SqlParameter("@TypeFullName", opt.WorkflowType.FullName); param.SqlDbType = SqlDbType.NVarChar; param.Size = 128; cmd.Parameters.Add(param); param = new SqlParameter("@AssemblyFullName", opt.WorkflowType.Assembly.FullName); param.SqlDbType = SqlDbType.NVarChar; param.Size = 128; cmd.Parameters.Add(param); } if (null != opt.TrackingDataItems && opt.TrackingDataItems.Count > 0) { BuildArtifactParameters(cmd, opt.TrackingDataItems); } return(cmd); }
private SqlCommand BuildCommand(SqlTrackingQueryOptions opt) { SqlCommand cmd = new SqlCommand("[dbo].[GetWorkflows]") { CommandType = CommandType.StoredProcedure }; SqlParameter parameter = new SqlParameter(); if (opt.WorkflowStatus.HasValue) { parameter.ParameterName = "@WorkflowStatusId"; parameter.SqlDbType = SqlDbType.TinyInt; parameter.Value = opt.WorkflowStatus.Value; cmd.Parameters.Add(parameter); if ((DateTime.MinValue != opt.StatusMinDateTime) || (DateTime.MaxValue != opt.StatusMaxDateTime)) { parameter = new SqlParameter { ParameterName = "@StatusMinDateTime", SqlDbType = SqlDbType.DateTime }; if (opt.StatusMinDateTime < SqlDateTime.MinValue.Value) { parameter.Value = SqlDateTime.MinValue.Value; } else { parameter.Value = opt.StatusMinDateTime; } cmd.Parameters.Add(parameter); parameter = new SqlParameter { ParameterName = "@StatusMaxDateTime", SqlDbType = SqlDbType.DateTime }; if (opt.StatusMaxDateTime > SqlDateTime.MaxValue.Value) { parameter.Value = SqlDateTime.MaxValue.Value; } else { parameter.Value = opt.StatusMaxDateTime; } cmd.Parameters.Add(parameter); } } if (null != opt.WorkflowType) { parameter = new SqlParameter("@TypeFullName", opt.WorkflowType.FullName) { SqlDbType = SqlDbType.NVarChar, Size = 0x80 }; cmd.Parameters.Add(parameter); parameter = new SqlParameter("@AssemblyFullName", opt.WorkflowType.Assembly.FullName) { SqlDbType = SqlDbType.NVarChar, Size = 0x80 }; cmd.Parameters.Add(parameter); } if ((opt.TrackingDataItems != null) && (opt.TrackingDataItems.Count > 0)) { this.BuildArtifactParameters(cmd, opt.TrackingDataItems); } return(cmd); }
private SqlCommand BuildCommand(SqlTrackingQueryOptions opt) { SqlCommand cmd = new SqlCommand("[dbo].[GetWorkflows]"); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter(); if (opt.WorkflowStatus.HasValue) { param.ParameterName = "@WorkflowStatusId"; param.SqlDbType = SqlDbType.TinyInt; param.Value = opt.WorkflowStatus.Value; cmd.Parameters.Add(param); // // If one of the range values is set we have a date range constraint if (DateTime.MinValue != opt.StatusMinDateTime || DateTime.MaxValue != opt.StatusMaxDateTime) { param = new SqlParameter(); param.ParameterName = "@StatusMinDateTime"; param.SqlDbType = SqlDbType.DateTime; if (opt.StatusMinDateTime < SqlDateTime.MinValue.Value) param.Value = SqlDateTime.MinValue.Value; else param.Value = opt.StatusMinDateTime; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@StatusMaxDateTime"; param.SqlDbType = SqlDbType.DateTime; if (opt.StatusMaxDateTime > SqlDateTime.MaxValue.Value) param.Value = SqlDateTime.MaxValue.Value; else param.Value = opt.StatusMaxDateTime; cmd.Parameters.Add(param); } } if (null != opt.WorkflowType) { param = new SqlParameter("@TypeFullName", opt.WorkflowType.FullName); param.SqlDbType = SqlDbType.NVarChar; param.Size = 128; cmd.Parameters.Add(param); param = new SqlParameter("@AssemblyFullName", opt.WorkflowType.Assembly.FullName); param.SqlDbType = SqlDbType.NVarChar; param.Size = 128; cmd.Parameters.Add(param); } if (null != opt.TrackingDataItems && opt.TrackingDataItems.Count > 0) BuildArtifactParameters(cmd, opt.TrackingDataItems); return cmd; }
// // Private Methods // private void RefreshData() { SqlTrackingQuery query = new SqlTrackingQuery(_connString); SqlTrackingQueryOptions options = new SqlTrackingQueryOptions(); trackingBindingSource.DataSource = query.GetWorkflows(options); }