コード例 #1
0
        public void UpdateFields(ArticleWorkflowState state, ArticleStruct articleStruct)
        {
            if (_staff == null)
            {
                _staff = SitecoreClient.GetStaffAndGroups();
            }

            uxNotifyPicker.DataSource    = _staff;
            uxNotifyPicker.DisplayMember = "Name";
            uxNotifyPicker.ValueMember   = "ID";
            if (state == null)
            {
                return;
            }
            _ArticleStruct = articleStruct;
            uxCurrentWorkflowValue.Text = state.DisplayName;
            Commands = new List <ArticleWorkflowCommand>();
            Commands.Insert(0, new ArticleWorkflowCommand {
                DisplayName = "Move in Workflow...", StringID = Guid.Empty.ToString()
            });
            if (state.Commands != null)
            {
                Commands.AddRange(state.Commands);
            }
            else
            {
                Globals.SitecoreAddin.Log("No workflow actions were available.");
                uxWorkflowActions.Enabled = false;
            }
            uxWorkflowActions.DataSource    = Commands;
            uxWorkflowActions.DisplayMember = "DisplayName";
            uxWorkflowActions.ValueMember   = "StringID";
            uxUnlockOnSave.Checked          = false;
            subjectLbl.Text = "Subject :";
        }
コード例 #2
0
        public ArticleWorkflowState GetWorkFlowState(Guid articleId)
        {
            var item = _sitecoreMasterService.GetItem <Item>(articleId);

            if (item?.State?.GetWorkflowState() == null)
            {
                return(null);
            }
            var currentState = item.State.GetWorkflowState();

            Sitecore.Workflows.IWorkflow workflow = item.State.GetWorkflow();
            var workFlowState = new ArticleWorkflowState();

            workFlowState.IsFinal     = currentState.FinalState;
            workFlowState.DisplayName = currentState.DisplayName;
            var commands = new List <ArticleWorkflowCommand>();

            foreach (Sitecore.Workflows.WorkflowCommand command in workflow.GetCommands(item))
            {
                var wfCommand = new ArticleWorkflowCommand();
                wfCommand.DisplayName = command.DisplayName;
                wfCommand.StringID    = command.CommandID;
                ICommand commandItem   = _sitecoreMasterService.GetItem <ICommand>(new Guid(command.CommandID));
                IState   nextStateItem = _sitecoreMasterService.GetItem <IState>(commandItem.Next_State);

                if (nextStateItem != null)
                {
                    wfCommand.SendsToFinal     = nextStateItem.Final;
                    wfCommand.GlobalNotifyList = new List <StaffStruct>();
                    foreach (var staff in nextStateItem.Staffs)
                    {
                        var staffItem = _sitecoreMasterService.GetItem <IStaff_Item>(staff._Id);
                        if (staffItem.Inactive)
                        {
                            continue;
                        }
                        var staffMember = new StaffStruct
                        {
                            ID   = staffItem._Id,
                            Name = staffItem.Last_Name + " , " + staffItem.First_Name
                        };
                        //   staffMember.Publications = staff  //TODO :Check if this field if we need this field.
                        wfCommand.GlobalNotifyList.Add(staffMember);
                    }
                    commands.Add(wfCommand);
                }
            }
            workFlowState.Commands = commands;

            return(workFlowState);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        /// <param name="commandID">Optional: if included, the command will be executed</param>
        /// <returns>The workflow state of the item (after workflow command has executed, if given one)</returns>
        public ArticleWorkflowState ExecuteCommandAndGetWorkflowState(Item i, string commandID)
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                IWorkflow workflow = i.State.GetWorkflow();

                if (workflow == null)
                {
                    //uh oh
                    return(new ArticleWorkflowState());
                }

                if (commandID != null)
                {
                    //var oldWorkflow = workflow.WorkflowID;
                    // This line will cause the workflow field to be set to null... sometimes
                    workflow.Execute(commandID, i, "comments", false);
                    //var info = new WorkflowInfo(oldWorkflow, i.Fields[Sitecore.FieldIDs.WorkflowState].Value);
                    //i.Database.DataManager.SetWorkflowInfo(i, info);
                    //i.Fields[Sitecore.FieldIDs.Workflow].Value = oldWorkflow;
                }
                var state = new ArticleWorkflowState();

                var currentState = workflow.GetState(i);
                state.DisplayName = currentState.DisplayName;
                state.IsFinal     = currentState.FinalState;

                var commands = new List <ArticleWorkflowCommand>();
                foreach (Sitecore.Workflows.WorkflowCommand command in workflow.GetCommands(i))
                {
                    var wfCommand = new PluginModels.ArticleWorkflowCommand();
                    wfCommand.DisplayName = command.DisplayName;
                    wfCommand.StringID    = command.CommandID;

                    ICommand commandItem = _sitecoreMasterService.GetItem <ICommand>(new Guid(command.CommandID));

                    IState stateItem = _sitecoreMasterService.GetItem <IState>(commandItem.Next_State);

                    if (stateItem == null)
                    {
                        //_logger.Warn("WorkflowController.ExecuteCommandAndGetWorkflowState: Next state for command [" + command.CommandID + "] is null!");
                    }
                    else
                    {
                        wfCommand.SendsToFinal     = stateItem.Final;
                        wfCommand.GlobalNotifyList = new List <StaffStruct>();

                        foreach (var x in stateItem.Staffs)
                        {
                            var staffItem = _sitecoreMasterService.GetItem <IStaff_Item>(x._Id);
                            if (staffItem.Inactive)
                            {
                                continue;
                            }

                            var staffMember = new StaffStruct {
                                ID = staffItem._Id
                            };
                            //staffMember.Name = x.GetFullName();
                            //staffMember.Publications = x.Publications.ListItems.Select(p => p.ID.ToGuid()).ToArray();
                            wfCommand.GlobalNotifyList.Add(staffMember);
                        }

                        commands.Add(wfCommand);
                    }
                }

                state.Commands = commands;

                return(state);
            }
        }