Ejemplo n.º 1
0
        private void LoadInvokedWorkflowsFromReader(SqlDataReader reader, object parameter)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            DateTime tmpMin = SqlDateTime.MinValue.Value;

            while (reader.Read())
            {
                SqlTrackingWorkflowInstance inst = SqlTrackingQuery.BuildInstance(reader, _connectionString);

                if (inst.Initialized > tmpMin)
                {
                    tmpMin = inst.Initialized;
                }

                _invoked.Add(inst);
            }
            //
            // set the min for the next query to the most recently invoked instance from this query
            // Don't overwrite the previous min if nothing came back for this query
            if (tmpMin > SqlDateTime.MinValue.Value)
            {
                _invMinDT = tmpMin;
            }
        }
Ejemplo n.º 2
0
 public HomeController(
     WorkflowRuntime runtime, 
     SqlTrackingQuery trackingQuery,
     ICreditCardProvider creditCardProvider)
 {
     string t = typeof (SqlTrackingQuery).Assembly.FullName;
     this.runtime = runtime;
     this.trackingQuery = trackingQuery;
     this.creditCardProvider = creditCardProvider;
 }
Ejemplo n.º 3
0
        static void GetInstanceTrackingEvents(Guid instanceId)
        {
            SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);

            SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
            sqlTrackingQuery.TryGetWorkflow(instanceId, out sqlTrackingWorkflowInstance);
            if (sqlTrackingWorkflowInstance != null)
            {
                Console.WriteLine("\nInstance Level Events:\n");

                foreach (WorkflowTrackingRecord workflowTrackingRecord in sqlTrackingWorkflowInstance.WorkflowEvents)
                {
                    Console.WriteLine("EventDescription : {0}  DateTime : {1}", workflowTrackingRecord.TrackingWorkflowEvent, workflowTrackingRecord.EventDateTime);
                }
            }
        }
Ejemplo n.º 4
0
 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);
                }
           }
      }
 }
Ejemplo n.º 5
0
        private void LoadInvokedWorkflowsFromReader(SqlDataReader reader, object parameter)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            DateTime initialized = SqlDateTime.MinValue.Value;

            while (reader.Read())
            {
                SqlTrackingWorkflowInstance item = SqlTrackingQuery.BuildInstance(reader, this._connectionString);
                if (item.Initialized > initialized)
                {
                    initialized = item.Initialized;
                }
                this._invoked.Add(item);
            }
            if (initialized > SqlDateTime.MinValue.Value)
            {
                this._invMinDT = initialized;
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 internal bool TryGetWorkflow(Guid workflowInstanceId, out SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance)
 {
     SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);
     return sqlTrackingQuery.TryGetWorkflow(workflowInstanceId, out sqlTrackingWorkflowInstance);
 }
Ejemplo n.º 8
0
 private SqlTrackingWorkflowInstance BuildInstance(SqlDataReader reader)
 {
     return(SqlTrackingQuery.BuildInstance(reader, _connectionString));
 }
Ejemplo n.º 9
0
        private static void OutputActivityTrackingEvents(Guid instanceId)
        {
            SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);

            SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
            if (sqlTrackingQuery.TryGetWorkflow(instanceId, out sqlTrackingWorkflowInstance))
            {
                Console.WriteLine("\nActivity Tracking Events:\n");

                foreach (ActivityTrackingRecord activityTrackingRecord in sqlTrackingWorkflowInstance.ActivityEvents)
                {
                    Console.WriteLine("StatusDescription : {0}  DateTime : {1} Activity Qualified Name : {2}", activityTrackingRecord.ExecutionStatus, activityTrackingRecord.EventDateTime, activityTrackingRecord.QualifiedName);
                }
            }
        }
Ejemplo n.º 10
0
        private static void OutputTrackedData(Guid instanceId)
        {
            SqlTrackingQuery sqlDataTrackingQuery = new SqlTrackingQuery(connectionString);

            SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
            if (sqlDataTrackingQuery.TryGetWorkflow(instanceId, out sqlTrackingWorkflowInstance))
            {
                Console.WriteLine("\nOutputting data tracked from the workflow:\n");

                foreach (ActivityTrackingRecord activityDataTrackingRecord in sqlTrackingWorkflowInstance.ActivityEvents)
                {
                    foreach (TrackingDataItem dataItem in activityDataTrackingRecord.Body)
                    {
                        // Output data queried from TrackingDataItem table in the database.
                        Console.WriteLine("At the {0} event for the {1}:\n{2} = {3}",
                        activityDataTrackingRecord.ExecutionStatus, activityDataTrackingRecord.QualifiedName,
                        dataItem.FieldName, dataItem.Data);
                    }
                }
            }
            else
            {
                Console.WriteLine("Could not retrieve data for workflow with instance id {0}", instanceId);
            }
        }
Ejemplo n.º 11
0
        // Reading Data from Tracking Database
        static void QueryAndWriteTrackingInformationToConsole(Guid instanceId, TrackingWorkflowEvent workflowEventToFind)
        {
            SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);

            SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
            if (sqlTrackingQuery.TryGetWorkflow(instanceId, out sqlTrackingWorkflowInstance))
            {
                foreach (WorkflowTrackingRecord workflowTrackingRecord in sqlTrackingWorkflowInstance.WorkflowEvents)
                {
                    if (workflowTrackingRecord.TrackingWorkflowEvent == workflowEventToFind)
                    {
                        WriteEventDescriptionAndArgs(workflowTrackingRecord.TrackingWorkflowEvent.ToString(), workflowTrackingRecord.EventArgs, workflowTrackingRecord.EventDateTime);
                        break;
                    }
                }
            }
        }
        private ReadOnlyCollection<string> GetStateHistory()
        {
            if (_sqlTrackingService == null)
            {
                _sqlTrackingService = _runtime.GetService<SqlTrackingService>();
                if (_sqlTrackingService == null)
                    throw new InvalidOperationException(SR.GetSqlTrackingServiceRequired());
            }

            if (_sqlTrackingQuery == null)
                _sqlTrackingQuery = new SqlTrackingQuery(_sqlTrackingService.ConnectionString);

            StateMachineWorkflowActivity stateMachineWorkflow;
            Stack<string> stateHistory = new Stack<string>();

            try
            {
                stateMachineWorkflow = this.StateMachineWorkflow;
            }
            catch (InvalidOperationException)
            {
                return new ReadOnlyCollection<string>(stateHistory.ToArray());
            }

            if (_sqlTrackingWorkflowInstance == null)
            {
                bool result = _sqlTrackingQuery.TryGetWorkflow(_instanceId, out _sqlTrackingWorkflowInstance);
                if (!result)
                {
                    // Workflow has not started yet, so we just return an
                    // empty collection
                    return new ReadOnlyCollection<string>(stateHistory.ToArray());
                }
            }

            _sqlTrackingWorkflowInstance.Refresh();
            IList<UserTrackingRecord> events = _sqlTrackingWorkflowInstance.UserEvents;
            foreach (UserTrackingRecord record in events)
            {
                if (record.UserDataKey != StateActivity.StateChangeTrackingDataKey)
                    continue;

                string stateQualifiedName = record.UserData as string;
                if (stateQualifiedName == null)
                    throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());

                StateActivity state = StateMachineHelpers.FindStateByName(stateMachineWorkflow, record.QualifiedName);
                if (state == null)
                    throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());

                if (StateMachineHelpers.IsLeafState(state))
                    stateHistory.Push(stateQualifiedName);
            }

            ReadOnlyCollection<string> history = new ReadOnlyCollection<string>(stateHistory.ToArray());
            return history;
        }
Ejemplo n.º 13
0
        private static void GetUserTrackingEvents(Guid workflowInstanceId)
        {
            SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(connectionString);

            SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance;
            if (sqlTrackingQuery.TryGetWorkflow(workflowInstanceId, out sqlTrackingWorkflowInstance))
            {
                foreach (UserTrackingRecord userTrackingRecord in sqlTrackingWorkflowInstance.UserEvents)
                {
                    Console.WriteLine("\nUser Tracking Event : Event Date Time : {0}, Event Data : {1}\n", userTrackingRecord.EventDateTime.ToString(), userTrackingRecord.UserData.ToString());
                }
            }
            else
            {
                throw new Exception("\nFailed to retrieve workflow instance\n");
            }
        }
Ejemplo n.º 14
0
 //
 // Private Methods
 //
 private void RefreshData()
 {
     SqlTrackingQuery query = new SqlTrackingQuery(_connString);
      SqlTrackingQueryOptions options = new SqlTrackingQueryOptions();
      trackingBindingSource.DataSource = query.GetWorkflows(options);
 }
 private ReadOnlyCollection<string> GetStateHistory()
 {
     StateMachineWorkflowActivity stateMachineWorkflow;
     if (this._sqlTrackingService == null)
     {
         this._sqlTrackingService = this._runtime.GetService<SqlTrackingService>();
         if (this._sqlTrackingService == null)
         {
             throw new InvalidOperationException(SR.GetSqlTrackingServiceRequired());
         }
     }
     if (this._sqlTrackingQuery == null)
     {
         this._sqlTrackingQuery = new SqlTrackingQuery(this._sqlTrackingService.ConnectionString);
     }
     Stack<string> stack = new Stack<string>();
     try
     {
         stateMachineWorkflow = this.StateMachineWorkflow;
     }
     catch (InvalidOperationException)
     {
         return new ReadOnlyCollection<string>(stack.ToArray());
     }
     if ((this._sqlTrackingWorkflowInstance != null) || this._sqlTrackingQuery.TryGetWorkflow(this._instanceId, out this._sqlTrackingWorkflowInstance))
     {
         this._sqlTrackingWorkflowInstance.Refresh();
         foreach (UserTrackingRecord record in this._sqlTrackingWorkflowInstance.UserEvents)
         {
             if (record.UserDataKey == "StateActivity.StateChange")
             {
                 string userData = record.UserData as string;
                 if (userData == null)
                 {
                     throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                 }
                 StateActivity state = StateMachineHelpers.FindStateByName(stateMachineWorkflow, record.QualifiedName);
                 if (state == null)
                 {
                     throw new InvalidOperationException(SR.GetInvalidUserDataInStateChangeTrackingRecord());
                 }
                 if (StateMachineHelpers.IsLeafState(state))
                 {
                     stack.Push(userData);
                 }
             }
         }
     }
     return new ReadOnlyCollection<string>(stack.ToArray());
 }