protected override void Execute(CodeActivityContext context)
        {
            string queueName      = QueueName.Get(context);
            long   priorityTicket = context.GetExtension <CriticalSectionQueueExtension>()
                                    .GetPriorityTicket(queueName);

            PriorityTicket.Set(context, priorityTicket);
        }
 private void OnBodyFaulted(NativeActivityFaultContext faultcontext, Exception propagatedexception,
                            ActivityInstance propagatedfrom)
 {
     faultcontext.GetExtension <CriticalSectionQueueExtension>()
     .Exit(_resumeBookmark.Get(faultcontext), QueueName.Get(faultcontext));
     _bodyError.Set(faultcontext, propagatedexception);
     faultcontext.RemoveAllBookmarks();
 }
 private void OnBodyComplete(NativeActivityContext context, ActivityInstance completedinstance)
 {
     if (_bodyError.Get(context) == null)
     {
         context.GetExtension <CriticalSectionQueueExtension>()
         .Exit(_resumeBookmark.Get(context), QueueName.Get(context));
     }
     context.RemoveAllBookmarks();
 }
 protected override void Cancel(NativeActivityContext context)
 {
     base.Cancel(context);
     context.CancelChildren();
     if (_bodyError.Get(context) == null)
     {
         context.GetExtension <CriticalSectionQueueExtension>()
         .Exit(_resumeBookmark.Get(context), QueueName.Get(context));
     }
 }
        protected override void Execute(NativeActivityContext context)
        {
            var taskCanceledWithComment = new TaskCanceledWithCommentEntry()
            {
                Id          = Guid.NewGuid(),
                Caption     = Caption.Get(context),
                QueueName   = QueueName.Get(context),
                TextComment = InputComment.Get(context),
            };

            var db = context.GetExtension <Db>();

            db.TaskCanceledWithComment.Add(taskCanceledWithComment);

            TaskCanceledId.Set(context, taskCanceledWithComment.Id);
        }
Exemple #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);

            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);
            }
        }
Exemple #7
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService             trace          = executionContext.GetExtension <ITracingService>();
            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            var queueName = QueueName.Get <string>(executionContext);
            var caseId    = Case.Get <EntityReference>(executionContext);

            var queueIdentifierService = new QueueIdentifierService();

            if (!string.IsNullOrWhiteSpace(queueName))
            {
                trace.Trace("getting queue by queue name.");
                var response = queueIdentifierService.GetQueueBy(queueName, service, trace);
                if (response != null)
                {
                    executionContext.SetValue <EntityReference>(Queue, response);
                }
                else
                {
                    trace.Trace("response is null");
                }

                return;
            }

            trace.Trace("getting queue by case id.");
            if (caseId != null)
            {
                var response = queueIdentifierService.GetQueueFor(caseId, service, trace);
                if (response != null)
                {
                    executionContext.SetValue <EntityReference>(Queue, response);
                }
                else
                {
                    trace.Trace("response is null");
                }

                return;
            }

            trace.Trace("queueName and caseId inputs - both are null;");
        }
        protected override void Execute(NativeActivityContext context)
        {
            string bookmarkName = Guid.NewGuid().ToString();

            _resumeBookmark.Set(context, bookmarkName);

            context.CreateBookmark(bookmarkName, OnResumeBody, BookmarkOptions.None);
            bool resumeImmediately = context.GetExtension <CriticalSectionQueueExtension>()
                                     .Enter(bookmarkName, QueueName.Get(context), PriorityTicket.Get(context));

            if (!resumeImmediately && WorkItem.Get(context) != null)
            {
                context.Track(
                    new CustomTrackingRecord(WorkItemStatus.Waiting)
                {
                    Data =
                    {
                        { CustomProgressTrackingDataKey.Target,  WorkItem.Get(context) },
                        { CustomProgressTrackingDataKey.Message,
                          String.Format(Resources.WaitingInTheQueue, QueueName.Get(context)) }
                    }
                });
            }
        }
Exemple #9
0
        protected override void Execute(NativeActivityContext context)
        {
            var task = new UserTaskEntry()
            {
                Id             = Guid.NewGuid(),
                Caption        = Caption.Get(context),
                QueueName      = QueueName.Get(context),
                ViewName       = ViewName.Get(context),
                ViewInputModel = JsonConvert.SerializeObject(ViewInputModel.Get(context) ?? new object()
                                                             , Formatting.None
                                                             , new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver(), DateFormatString = "dd.MM.yyyy"
                }),
                WWFId = context.WorkflowInstanceId
            };

            var db = context.GetExtension <Db>();

            db.UserTasks.Add(task);

            UserTaskId.Set(context, task.Id);

            context.ScheduleFunc(Wizard, task.Id, OnChildComplete);
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
0
        protected override void Execute(CodeActivityContext context)
        {
            // Open the config file and get the connection string
            Configuration            config = WebConfigurationManager.OpenWebConfiguration("/RequestWeb");
            ConnectionStringsSection css    =
                (ConnectionStringsSection)config.GetSection("connectionStrings");
            string connectionString = css.ConnectionStrings["Request"].ConnectionString;

            // Lookup the Queue
            RequestDataContext dc = new RequestDataContext(connectionString);

            Queue queue = dc.Queues.SingleOrDefault(x => x.QueueName == QueueName.Get(context));

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

            if (queue.AllowSelection)
            {
                IEnumerable <Request> q = dc.Requests
                                          .Where(x => x.Queue.QueueName == QueueName.Get(context) &&
                                                 x.QC == QC.Get(context) &&
                                                 (x.AssignedOperator == null ||
                                                  x.AssignedOperator == OperatorID.Get(context)))
                                          .OrderBy(x => x.AssignedDate);

                if (q.Count() > 0)
                {
                    Request[] reqList = new Request[q.Count()];
                    int       i       = 0;
                    foreach (Request r in q)
                    {
                        reqList[i++] = r;
                    }

                    RequestList.Set(context, reqList);
                }
            }
            else
            {
                IEnumerable <Request> q = dc.Requests
                                          .Where(x => x.Queue.QueueName == QueueName.Get(context) &&
                                                 x.QC == QC.Get(context) &&
                                                 (x.AssignedOperator == null ||
                                                  x.AssignedOperator == OperatorID.Get(context)))
                                          .OrderBy(x => x.AssignedDate)
                                          .Take(1);

                if (q.Count() > 0)
                {
                    Request r = q.First <Request>();
                    r.AssignedOperator = OperatorID.Get(context);
                    dc.SubmitChanges();

                    Request[] reqList = new Request[1];
                    reqList[0] = r;

                    RequestList.Set(context, reqList);
                }
            }
        }