Esempio n. 1
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);

            var q = dc.QueueInstances
                    .Where(x => x.CurrentSubQueueID != null &&
                           (QueueName.Get(context) == "" ||
                            x.SubQueue.Queue.QueueName == QueueName.Get(context)))
                    .GroupBy(x => x.SubQueue.Queue.QueueName + "|" +
                             x.SubQueue.SubQueueName + "|" +
                             x.QC.ToString());

            // Build the result array
            if (q.Count() > 0)
            {
                QueueDetail[] queueStats = new QueueDetail[q.Count()];
                int           i          = 0;
                foreach (var group in q)
                {
                    // Split the key into the queue name and QC value
                    string   s         = group.Key;
                    char[]   delimiter = { '|' };
                    string[] values    = s.Split(delimiter, 3);

                    // Add a new queue to the stats array
                    QueueDetail det = new QueueDetail();
                    det.Key          = group.Key;
                    det.QueueName    = values[0];
                    det.SubQueueName = values[1];
                    det.QC           = bool.Parse(values[2]);
                    det.Count        = group.Count();
                    det.Oldest       = group.Min(x => x.CreateDate);
                    queueStats[i++]  = det;
                }

                // Store the results in the output arguments
                QueueStats.Set(context, queueStats);
            }
        }
Esempio n. 2
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Lookup the QueueInstance
            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);

            dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
            QueueInstance qi = dc.QueueInstances.SingleOrDefault(x => x.QueueInstanceKey == QueueInstanceKey.Get(context));

            if (qi == null)
            {
                throw new InvalidProgramException("The specified request (" + QueueInstanceKey.Get(context) + ") was not found");
            }

            if (qi.AssignedOperatorID != null)
            {
                qi.AssignedOperatorID = null;
                qi.AssignedDate       = null;

                // Update the QueueInstance record
                PersistQueueInstance persist = context.GetExtension <PersistQueueInstance>();
                persist.AddQueueInstance(qi);
            }

            // Add a custom track record
            CustomTrackingRecord userRecord = new CustomTrackingRecord("UnAssign")
            {
                Data =
                {
                    { "QueueInstanceKey", qi.QueueInstanceKey  },
                    { "SubQueueID",       qi.CurrentSubQueueID },
                    { "QC",               qi.QC                }
                }
            };

            // Emit the custom tracking record
            context.Track(userRecord);
        }
Esempio n. 3
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);

            // Lookup the QueueInstance
            dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
            QueueInstance qi = dc.QueueInstances.SingleOrDefault(x => x.QueueInstanceKey == QueueInstanceKey.Get(context));

            if (qi == null)
            {
                throw new InvalidProgramException("The specified request (" + QueueInstanceKey.Get(context) + ") was not found");
            }

            QueueInstance.Set(context, qi);
            ConnectionString.Set(context, ext.ConnectionString);
        }
Esempio n. 4
0
        protected override void Track(TrackingRecord record, TimeSpan timeout)
        {
            CustomTrackingRecord customTrackingRecord =
                record as CustomTrackingRecord;

            if (customTrackingRecord != null)
            {
                if (customTrackingRecord.Name == "Start" ||
                    customTrackingRecord.Name == "Route" ||
                    customTrackingRecord.Name == "Assign" ||
                    customTrackingRecord.Name == "UnAssign" ||
                    customTrackingRecord.Name == "QC")
                {
                    QueueTrack t = new QueueTrack();

                    // Extract all the user data
                    if ((customTrackingRecord != null) &&
                        (customTrackingRecord.Data.Count > 0))
                    {
                        foreach (string key in customTrackingRecord.Data.Keys)
                        {
                            switch (key)
                            {
                            case "QueueInstanceKey":
                                if (customTrackingRecord.Data[key] != null)
                                {
                                    t.QueueInstanceKey = (Guid)customTrackingRecord.Data[key];
                                }
                                break;

                            case "SubQueueID":
                                if (customTrackingRecord.Data[key] != null)
                                {
                                    t.SubQueueID = (int)customTrackingRecord.Data[key];
                                }
                                break;

                            case "QC":
                                if (customTrackingRecord.Data[key] != null)
                                {
                                    t.QC = (bool)customTrackingRecord.Data[key];
                                }
                                break;

                            case "OperatorKey":
                                if (customTrackingRecord.Data[key] != null)
                                {
                                    t.OperatorKey = (Guid)customTrackingRecord.Data[key];
                                }
                                break;
                            }
                        }
                    }

                    if (t.SubQueueID != null && t.QC == null)
                    {
                        t.QC = false;
                    }

                    t.EventType = customTrackingRecord.Name;
                    t.EventDate = DateTime.UtcNow;

                    // Insert a record into the TrackUser table
                    UserTasksDataContext dc =
                        new UserTasksDataContext(_connectionString);
                    dc.QueueTracks.InsertOnSubmit(t);
                    dc.SubmitChanges();
                }
            }
        }
Esempio n. 5
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Lookup the Queue
            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);
            Queue q = dc.Queues.SingleOrDefault(x => x.QueueName == QueueName.Get(context));

            if (q == null)
            {
                throw new InvalidProgramException("The specified queue (" + QueueName.Get(context) + ") was not found");
            }

            SubQueue s = dc.SubQueues
                         .SingleOrDefault(x => x.QueueID == q.QueueID &&
                                          x.SubQueueName == SubQueueName.Get(context));

            if (s == null)
            {
                throw new InvalidProgramException("The specified sub-queue (" + SubQueueName.Get(context) + ") was not found");
            }

            // Create and initialize a QueueInstance object
            QueueInstance qi = new QueueInstance();

            qi.QueueInstanceKey  = Guid.NewGuid();
            qi.CurrentSubQueueID = s.SubQueueID;
            qi.CreateDate        = DateTime.UtcNow;
            qi.InstanceID        = context.WorkflowInstanceId;

            // Setup the initial values
            qi.AssignedDate       = null;
            qi.AssignedOperatorID = null;
            qi.QC       = false;
            qi.Priority = null;

            // Insert the Request record
            PersistQueueInstance persist = context.GetExtension <PersistQueueInstance>();

            persist.AddQueueInstance(qi);

            // Return the QueueInstance object
            QueueInstanceKey.Set(context, qi.QueueInstanceKey);

            CustomTrackingRecord userRecord = new CustomTrackingRecord("Start")
            {
                Data =
                {
                    { "QueueInstanceKey", qi.QueueInstanceKey  },
                    { "SubQueueID",       qi.CurrentSubQueueID }
                }
            };

            // Emit the custom tracking record
            context.Track(userRecord);
        }
Esempio n. 6
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);

            Queue    q          = null;
            SubQueue sq         = null;
            int      queueID    = 0;
            int      subQueueID = 0;

            if (QueueName.Get(context) != "" && SubQueueName.Get(context) != "None")
            {
                // Lookup the queue and subqueue
                q = dc.Queues.SingleOrDefault(x => x.QueueName == QueueName.Get(context));
                if (q == null)
                {
                    throw new InvalidProgramException("The specified queue (" + QueueName.Get(context) + ") was not found");
                }

                sq = dc.SubQueues.SingleOrDefault(x => x.QueueID == q.QueueID &&
                                                  x.SubQueueName == SubQueueName.Get(context));
                if (sq == null)
                {
                    throw new InvalidProgramException("The specified subqueue (" +
                                                      QueueName.Get(context) + " - " +
                                                      SubQueueName.Get(context) + ") was not found");
                }

                queueID    = q.QueueID;
                subQueueID = sq.SubQueueID;
            }

            // Lookup the QueueInstance
            dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
            QueueInstance qi = dc.QueueInstances.SingleOrDefault(x => x.QueueInstanceKey == QueueInstanceKey.Get(context));

            if (qi == null)
            {
                throw new InvalidProgramException("The specified request (" + QueueInstanceKey.Get(context) + ") was not found");
            }

            // Assign the QueueInstance to this subqueue
            if (sq != null)
            {
                qi.CurrentSubQueueID = sq.SubQueueID;
            }
            else
            {
                qi.CurrentSubQueueID = null;
            }

            qi.AssignedDate       = null;
            qi.AssignedOperatorID = null;
            qi.QC       = false;
            qi.Priority = null;

            // Update the QueueInstance record
            PersistQueueInstance persist = context.GetExtension <PersistQueueInstance>();

            persist.AddQueueInstance(qi);

            // Add a custom track record
            CustomTrackingRecord userRecord = new CustomTrackingRecord("Route")
            {
                Data =
                {
                    { "QueueInstanceKey", qi.QueueInstanceKey  },
                    { "SubQueueID",       qi.CurrentSubQueueID }
                }
            };

            // Emit the custom tracking record
            context.Track(userRecord);
        }
Esempio n. 7
0
        protected override void Execute(CodeActivityContext context)
        {
            // Get the connection string
            DBConnection ext = context.GetExtension <DBConnection>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Lookup the operator
            UserTasksDataContext dc = new UserTasksDataContext(ext.ConnectionString);
            OperatorConfig       oc = dc.OperatorConfigs.SingleOrDefault(x => x.OperatorKey == OperatorKey.Get(context));

            if (oc == null)
            {
                oc                     = new OperatorConfig();
                oc.OperatorKey         = OperatorKey.Get(context);
                oc.UnderEvaluation     = false;
                oc.Frequency           = 5;
                oc.NumberSinceLastEval = 0;

                dc.OperatorConfigs.InsertOnSubmit(oc);
                dc.SubmitChanges();
            }

            // Determine the Queue info
            char[]   delimiter = { '|' };
            string[] values    = QueueKey.Get(context).Split(delimiter, 3);

            // Lookup the queue and subqueue
            Queue q = dc.Queues.SingleOrDefault(x => x.QueueName == values[0]);

            if (q == null)
            {
                throw new InvalidProgramException("The specified queue (" + values[0] + ") was not found");
            }

            SubQueue sq = dc.SubQueues.SingleOrDefault(x => x.QueueID == q.QueueID &&
                                                       x.SubQueueName == values[1]);

            if (sq == null)
            {
                throw new InvalidProgramException("The specified subqueue (" +
                                                  values[0] + " - " +
                                                  values[1] + ") was not found");
            }

            bool bQC = bool.Parse(values[2]);

            if (sq.AllowSelection)
            {
                // Return all the available instances
                IEnumerable <QueueInstance> instances;

                if (bQC)
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => x.Priority.Value)
                                .OrderBy(x => x.CreateDate);
                }
                else
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => x.CreateDate);
                }

                if (instances.Count() > 0)
                {
                    QueueInstance[] qiList = new QueueInstance[instances.Count()];
                    int             i      = 0;
                    foreach (QueueInstance r in instances)
                    {
                        qiList[i++] = r;
                    }

                    QueueInstanceList.Set(context, qiList);
                }
            }
            else
            {
                // Return the oldest instance
                IEnumerable <QueueInstance> instances;
                if (bQC)
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => x.Priority.Value)
                                .OrderBy(x => x.CreateDate)
                                .Take(1);
                }
                else
                {
                    instances = dc.QueueInstances
                                .Where(x => x.CurrentSubQueueID == sq.SubQueueID &&
                                       x.QC == bQC &&
                                       (x.AssignedOperatorID == null ||
                                        x.AssignedOperatorID == oc.OperatorConfigID))
                                .OrderBy(x => (x.Priority.HasValue ? 1 : 0) * x.Priority.Value * (bQC ? 1 : 0))
                                .OrderBy(x => x.CreateDate)
                                .Take(1);
                }

                if (instances.Count() > 0)
                {
                    QueueInstance qi = instances.First <QueueInstance>();
                    qi.AssignedOperatorID = oc.OperatorConfigID;
                    dc.SubmitChanges();

                    QueueInstance[] qiList = new QueueInstance[1];
                    qiList[0] = qi;

                    QueueInstanceList.Set(context, qiList);
                }
            }
        }
Esempio n. 8
0
        protected override void CollectValues
            (out IDictionary <XName, object> readWriteValues,
            out IDictionary <XName, object> writeOnlyValues)
        {
            // We're not actually providing data to the caller
            readWriteValues = null;
            writeOnlyValues = null;

            //_actions.Clear();

            // See if there is any work to do...
            if (_actions.Count > 0)
            {
                // Get the current transaction
                Transaction t = System.Transactions.Transaction.Current;

                // Setup the DataContext
                UserTasksDataContext dc = new UserTasksDataContext(_connectionString);

                // Open the connection, if necessary
                if (dc.Connection.State == System.Data.ConnectionState.Closed)
                {
                    dc.Connection.Open();
                }

                if (t != null)
                {
                    dc.Connection.EnlistTransaction(t);
                }

                // Process each object in our work queue
                foreach (KeyValuePair <string, QueueInstance> kvp in _actions)
                {
                    QueueInstance qi = kvp.Value as QueueInstance;

                    // Perform the insert
                    if (kvp.Key == "")
                    {
                        dc.QueueInstances.InsertOnSubmit(qi);
                    }

                    // Perform the update
                    else
                    {
                        dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.QueueInstances);
                        QueueInstance qiTmp = dc.QueueInstances.SingleOrDefault <QueueInstance>
                                                  (x => x.QueueInstanceID == qi.QueueInstanceID);

                        if (qiTmp != null)
                        {
                            qiTmp.InstanceID         = qi.InstanceID;
                            qiTmp.AssignedDate       = qi.AssignedDate;
                            qiTmp.AssignedOperatorID = qi.AssignedOperatorID;
                            qiTmp.CurrentSubQueueID  = qi.CurrentSubQueueID;
                            qiTmp.QC = qi.QC;
                        }
                    }
                }

                // Submit all the changes to the database
                dc.SubmitChanges();

                // Remove all objects since the changes have been submitted
                _actions.Clear();
            }
        }