Ejemplo n.º 1
0
        public void Process(PopulateScribanMailActionModelArgs args)
        {
            var dataItem = args.WorkflowPipelineArgs.DataItem;
            var workflow = dataItem.State.GetWorkflow();

            var events = new WorkflowEvent[0];

            if (workflow != null)
            {
                events = workflow.GetHistory(dataItem);
            }

            args.AddModel(ModelKey, events);
        }
Ejemplo n.º 2
0
        public TableCell GetCell(ArticleItemWrapper articleItemWrapper)
        {
            Database masterDb = Factory.GetDatabase("master");

            ArticleItem article   = articleItemWrapper.InnerItem;
            Item        item      = article.InnerItem;
            var         cell      = new TableCell();
            string      text      = "";
            ItemState   itemState = item.State;

            if (itemState == null)
            {
                cell.Text = "N/E";
                return(cell);
            }
            WorkflowState workflowState = itemState.GetWorkflowState();

            if (workflowState == null)
            {
                cell.Text = "N/E";
                return(cell);
            }
            text += workflowState.DisplayName;
            if (workflowState.FinalState)
            {
                //TODO I took this from EmailUtil, need to refactor a bit so that code is not in two places
                List <WorkflowEvent> history = GetWorkflowHistory(masterDb, item);

                if (history.Count == 0)
                {
                    cell.Text = "N/E";
                    return(cell);
                }
                else
                {
                    WorkflowEvent latest = history.Last();
                    text += "<br />Signed off: " + latest.Date.ToServerTimeZone();
                    string user = latest.User;
                    text += "<br />By: " + user.Substring(user.LastIndexOf(@"\") + 1);
                }
            }
            cell.Text = text;
            return(cell);
        }
        public override WorkflowEvent[] GetHistory(Sitecore.Data.Items.Item item)
        {
            var query = Query.And(
                Query.EQ("Id", item.ID.Guid),
                Query.EQ("Language", item.Language.ToString()),
                Query.EQ("Version", item.Version.ToInt32())
                );

            var results = WorkflowHistories.Find(query);

            List <WorkflowEvent> list = new List <WorkflowEvent>();

            foreach (var result in results)
            {
                WorkflowEvent workflow = new WorkflowEvent(result.OldState, result.NewState, result.Text, result.User, result.Now);
                list.Add(workflow);
            }
            return(list.ToArray());
        }
 private string GetHistory(IWorkflow workflow, Item item)
 {
     WorkflowEvent[] history = workflow.GetHistory(item);
     if (history.Length > 0)
     {
         WorkflowEvent event2 = history[history.Length - 1];
         string        user   = event2.User;
         string        name   = Context.Domain.Name;
         if (user.StartsWith(name + @"\", StringComparison.OrdinalIgnoreCase))
         {
             user = StringUtil.Mid(user, name.Length + 1);
         }
         user = StringUtil.GetString(new string[] { user, Translate.Text("Unknown") });
         string stateName = this.GetStateName(workflow, event2.OldState);
         string str5      = this.GetStateName(workflow, event2.NewState);
         return(string.Format(Translate.Text("{0} changed from <b>{1}</b> to <b>{2}</b> on {3}."), new object[] { user, stateName, str5, DateUtil.FormatDateTime(event2.Date, "D", Context.User.Profile.Culture) }));
     }
     return(Translate.Text("No changes have been made."));
 }
Ejemplo n.º 5
0
 public WorkflowContext(IServerConnection conn, IReadOnlyItem item)
 {
   _conn = conn;
   _activity = new Activity(item);
   _result = conn.AmlContext.Result();
   switch (item.Property("WorkflowEvent").Value)
   {
     case "on_activate":
       _event = WorkflowEvent.OnActivate;
       break;
     case "on_assign":
       _event = WorkflowEvent.OnAssign;
       break;
     case "on_close":
       _event = WorkflowEvent.OnClose;
       break;
     case "on_delegate":
       _event = WorkflowEvent.OnDelegate;
       break;
     case "on_due":
       _event = WorkflowEvent.OnDue;
       break;
     case "on_escalate":
       _event = WorkflowEvent.OnEscalate;
       break;
     case "on_refuse":
       _event = WorkflowEvent.OnRefuse;
       break;
     case "on_remind":
       _event = WorkflowEvent.OnRemind;
       break;
     case "on_vote":
       _event = WorkflowEvent.OnVote;
       break;
     default:
       _event = WorkflowEvent.Other;
       break;
   }
 }
        private WorkflowEvent[] AddItemHistory(Mock <Item> item, ID[] workflowStates)
        {
            WorkflowEvent[] events = null;

            if (workflowStates.Length == 0)
            {
                events = new WorkflowEvent[0];
            }
            else
            {
                events = new WorkflowEvent[workflowStates.Length - 1];
                for (var i = 0; i < workflowStates.Length - 1; i++)
                {
                    events[i] = new WorkflowEvent(workflowStates[i].ToString(), workflowStates[i + 1].ToString(), "comment", "user", DateTime.UtcNow);
                }
            }

            var workflow = Mock.Of <IWorkflow>(x =>
                                               x.GetHistory(item.Object) == events
                                               );

            var initialStateId = ID.NewID.ToString();

            if (workflowStates.Length > 0)
            {
                initialStateId = workflowStates[workflowStates.Length - 1].ToString();
            }

            var workflowState = new WorkflowState(initialStateId, "state", "icon", true);

            var itemState = new Mock <ItemState>(item.Object);

            itemState.Setup(x => x.GetWorkflow()).Returns(workflow);
            itemState.Setup(x => x.GetWorkflowState()).Returns(workflowState);

            item.Setup(x => x.State).Returns(itemState.Object);

            return(events);
        }
Ejemplo n.º 7
0
        public bool Invoke(Tr tr, Tt tt)
        {
            //find the transitions available for current state
            var t = GetPossibleTransitions()
                    .Where(x => x.Trigger.GetHashCode() == tt.GetHashCode())
                    .Where(x => x.AllowRoles.Contains(tr))
                    .FirstOrDefault();

            if (t != null)
            {
                var newWorkflowState = t.Invoke(tr, tt);

                //invoke state events onexit/onentry
                if (CurrentState.State.GetHashCode() != newWorkflowState.State.GetHashCode())
                {
                    var oldState = States.FirstOrDefault(x => x.InnerState.GetHashCode() == CurrentState.State.GetHashCode());
                    oldState.InvokeOnExit();

                    var newState = States.FirstOrDefault(x => x.InnerState.GetHashCode() == newWorkflowState.State.GetHashCode());
                    newState.InvokeOnEntry();
                }



                var workflowEvent = new WorkflowEvent()
                {
                    FromState = CurrentState.State, ToState = newWorkflowState.State, Action = tt, PerformedBy = tr, When = DateTime.Now
                };
                _onTransitioned?.Invoke(workflowEvent);


                CurrentState = newWorkflowState;

                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        public static void RunExample(Configuration confgiration)
        {
            string location = "http://location-testing";

            WorkflowEvent workflow = new WorkflowEvent("cycle_count_finished", location, DateTime.Now, null, 10, new List <string>()
            {
                "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
            });

            try
            {
                // capture
                WorkflowApi workflowApi = new WorkflowApi(confgiration);
                Console.WriteLine("------------- Capture workflow event");
                workflowApi.CaptureWorkflowEvent(workflow);
                Console.WriteLine("captured workflow events");
            }
            catch (ApiException e)
            {
                Console.WriteLine(e);
            }

            Console.ReadKey();
        }
 public WorkflowEventCustom(Item item, WorkflowEvent wEvent)
 {
     Item = item;
     WorkflowEvent = wEvent;
 }
Ejemplo n.º 10
0
        public override WorkflowEvent[] GetHistory(Sitecore.Data.Items.Item item)
        {
            var query = Query.And(
                   Query.EQ("Id", item.ID.Guid),
                   Query.EQ("Language", item.Language.ToString()),
                   Query.EQ("Version", item.Version.ToInt32())
               );

            var results = WorkflowHistories.Find(query);

            List<WorkflowEvent> list = new List<WorkflowEvent>();

            foreach (var result in results)
            {
                WorkflowEvent workflow = new WorkflowEvent(result.OldState, result.NewState, result.Text, result.User, result.Now);
                list.Add(workflow);
            }
            return list.ToArray();
        }
Ejemplo n.º 11
0
 public void TestMethod(WorkflowEvent testArgument)
 {
     InvokedWith = testArgument;
 }
        /// <summary>
        /// Fills out the report information section of the report
        /// </summary>
        private void SetTestInformation()
        {
            if (TestDefinitionItem.IsNull())
            {
                return;
            }

            TestDefinitionItem testDefinition = new TestDefinitionItem(TestDefinitionItem);
            IWorkflow          workflow       = TestDefinitionItem.State.GetWorkflow();
            DateTime           testStartDate  = DateTime.MinValue;
            DateTime           testFinishDate = DateTime.MinValue;

            if (workflow != null)
            {
                WorkflowEvent testStartEvent = workflow.GetHistory(TestDefinitionItem).LastOrDefault <WorkflowEvent>(w => w.NewState == Sitecore.Analytics.Data.Items.TestDefinitionItem.StateIDs.Deployed);
                if (testStartEvent != null)
                {
                    testStartDate = testStartEvent.Date;
                }

                WorkflowEvent testFinishEvent = workflow.GetHistory(TestDefinitionItem).LastOrDefault <WorkflowEvent>(w => w.NewState == Sitecore.Analytics.Data.Items.TestDefinitionItem.StateIDs.Completed);
                if (testFinishEvent != null)
                {
                    testFinishDate = testFinishEvent.Date;
                }
            }

            //start date
            litTestStarted.Text = "Test has not started";
            if (testStartDate != DateTime.MinValue && testStartDate != DateTime.MaxValue)
            {
                litTestStarted.Text = testStartDate.ToString("MMMM dd, yyyy");
            }

            //end date
            litTestEnded.Text = "Test has not completed";
            if (testFinishDate != DateTime.MinValue && testFinishDate != DateTime.MaxValue)
            {
                litTestEnded.Text = testFinishDate.ToString("MMMM dd, yyyy");
            }

            if (testDefinition.IsRunning)
            {
                litProgress.Text = "Running";
            }
            else if (testDefinition.IsFinished)
            {
                litProgress.Text = "Finished";
            }
            else if (testDefinition.IsDraft)
            {
                litProgress.Text = "Draft";
            }
            else if (testDefinition.IsDeployed)
            {
                litProgress.Text = "Deployed";
            }
            else
            {
                litProgress.Text = "N/A";
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// An internal workflow to facilitate downloading the XAP file
        /// </summary>
        /// <param name="xapName">The name of the XAP</param>
        /// <param name="xapLoaded">The action to call once it is loaded</param>
        /// <param name="xapProgress">Action to call to report download progress</param>
        /// <returns>A list of <see cref="IWorkflow"/> items to execute</returns>
        private IEnumerable <IWorkflow> DownloadWorkflow(
            string xapName,
            Action <Exception> xapLoaded,
            Action <long, int, long> xapProgress)
        {
            var xap = xapName.Trim().ToLower();

            Logger.LogFormat(LogSeverity.Verbose, GetType().FullName, "{0}::{1}", MethodBase.GetCurrentMethod().Name, xapName);

            var uri = new Uri(xap, UriKind.Relative);

            if (_loaded.Contains(uri))
            {
                if (xapLoaded != null)
                {
                    xapLoaded(null);
                }
                yield break;
            }

            var deploymentCatalog = new DeploymentCatalog(uri);

            EventHandler <DownloadProgressChangedEventArgs> eventHandler = null;

            if (xapProgress != null)
            {
                eventHandler = (o, args) => xapProgress(
                    args.BytesReceived,
                    args.ProgressPercentage,
                    args.TotalBytesToReceive);
                deploymentCatalog.DownloadProgressChanged += eventHandler;
            }

            var downloadAction = new WorkflowEvent <AsyncCompletedEventArgs>(deploymentCatalog.DownloadAsync,
                                                                             h => deploymentCatalog.DownloadCompleted += h,
                                                                             h => deploymentCatalog.DownloadCompleted -= h);

            Catalog.Catalogs.Add(deploymentCatalog);

            EventAggregator.Publish(Constants.BEGIN_BUSY);

            yield return(downloadAction);

            if (xapProgress != null)
            {
                deploymentCatalog.DownloadProgressChanged -= eventHandler;
            }

            InitModules();

            EventAggregator.Publish(Constants.END_BUSY);

            Logger.LogFormat(LogSeverity.Verbose, GetType().FullName, "{0}::{1}", MethodBase.GetCurrentMethod().Name, deploymentCatalog.Uri);

            var e = downloadAction.Result;

            if (e.Error != null)
            {
                var exception = new DeploymentCatalogDownloadException(e.Error);

                Logger.Log(LogSeverity.Critical, string.Format("{0}::{1}", GetType().FullName,
                                                               MethodBase.GetCurrentMethod().Name), exception);

                if (xapLoaded == null)
                {
                    throw exception;
                }
            }
            else
            {
                _loaded.Add(deploymentCatalog.Uri);
                Logger.LogFormat(LogSeverity.Verbose, string.Format("{0}::{1}", GetType().FullName,
                                                                    MethodBase.GetCurrentMethod().Name),
                                 Resources.DeploymentService_DeploymentCatalogDownloadCompleted_Finished, deploymentCatalog.Uri);

                if (xapLoaded != null)
                {
                    xapLoaded(null);
                }
            }
        }
Ejemplo n.º 14
0
 private void ApplyWorkflowEvent(WorkflowEvent workflowEvent)
 {
     clientWorkflow.ApplyEvent(workflowEvent);
 }
Ejemplo n.º 15
0
        /// <summary>
        ///     Ensures a record exists for a user before adding to the list of issues they worked
        /// </summary>
        /// <param name="data"></param>
        /// <param name="lastHistoryItem"></param>
        private static void UpdateDataForUser(List<WorkflowUserRecords> data, WorkflowEvent lastHistoryItem)
        {
            //Retrieve the user that made the update from our return data, or null if no entry exist.
            //This acts similarly to a dictionary but gives us control of more information to be added later
            var person = data.FirstOrDefault(dataItem => dataItem.UserName == lastHistoryItem.User);

            //If the user that made the change to the current item has no previous entry make one
            if (person == null)
            {
                //Create entry for the user and add them to the return data
                person = new WorkflowUserRecords
                {
                    UserName = lastHistoryItem.User,
                    IssuesUpdated = 0
                };
                data.Add(person);
            }
            //Update the number of issues updated for the returned user
            person.IssuesUpdated++;
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     Retrieves the latest history entry and determines if its latest modify date is within the date range
        /// </summary>
        /// <param name="workflowProvider"></param>
        /// <param name="item"></param>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="lastHistoryItem"></param>
        /// <returns></returns>
        private static bool GetLatestWorkflowHistoryEntry(IWorkflowProvider workflowProvider, Item item, DateTime begin,
            DateTime end, out WorkflowEvent lastHistoryItem)
        {
            lastHistoryItem = null;

            //Get the workflow for the current item
            var itemWorkflow = workflowProvider.GetWorkflow(item);

            //If the workflow for the item is null then move to the next item
            if (itemWorkflow == null) return true;
            //Grab the history of the items workflow
            var itemHistory = itemWorkflow.GetHistory(item);

            //If the history of the item is null or has no entries then move to the next item
            if (itemHistory == null || itemHistory.Length <= 0) return true;

            //Grab the latest history update to an item
            lastHistoryItem = itemHistory[itemHistory.Length -1];

            //Ensure that the latest history update exist in the specified date range
            return lastHistoryItem.Date <= begin || lastHistoryItem.Date >= end;
        }
 public WorkflowEventCustom(Item item, WorkflowEvent wEvent)
 {
     Item          = item;
     WorkflowEvent = wEvent;
 }