Ejemplo n.º 1
0
        public void Process(WorkflowPipelineArgs args)
        {
            Item   contentItem     = args.DataItem;
            string workflowComment = (!string.IsNullOrEmpty(args.CommentFields[Constants.Comments])) ? args.CommentFields[Constants.Comments] : Constants.NoComment;

            try
            {
                using (new SecurityDisabler())
                {
                    Item notifyStepItem      = args.ProcessorItem.InnerItem;
                    Item currentWorkflowStep = WorkflowHelper.GetCurrentState(args); // Current workflow state
                    Item nextWorkflowStep    = WorkflowHelper.GetNextState(args);    // Next workflow state

                    var from = notifyStepItem.Fields[Templates.NotifyNextStepUser.Fields.From].Value;
                    var emailTemplateItem = notifyStepItem.TargetItem(Templates.NotifyNextStepUser.Fields.EmailTemplate);
                    var receivers         = GetReceivers(contentItem, currentWorkflowStep.ID, nextWorkflowStep.ID);

                    _workflowNotifyService.SendEmailNotifications(receivers, from, contentItem, workflowComment, emailTemplateItem);
                }
            }
            catch (Exception ex)
            {
                Log.Error($"NotifyNextStepUser: {ex}", this);
            }
        }
Ejemplo n.º 2
0
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var processorItem = args.ProcessorItem;
            if (processorItem == null)
            {
                return;
            }
            var actionItem = processorItem.InnerItem;

            var dataItem = args.DataItem;

            if (string.IsNullOrEmpty(actionItem[ScriptItemFieldNames.Script]))
            {
                return;
            }

            var scriptItem = actionItem.Database.GetItem(new ID(actionItem[ScriptItemFieldNames.Script]));

            if (RulesUtils.EvaluateRules(actionItem[ScriptItemFieldNames.EnableRule], dataItem) &&
                RulesUtils.EvaluateRules(scriptItem[ScriptItemFieldNames.EnableRule], dataItem))
            {
                var str = new UrlString(UIUtil.GetUri("control:PowerShellRunner"));
                str.Append("id", dataItem.ID.ToString());
                str.Append("db", dataItem.Database.Name);
                str.Append("lang", dataItem.Language.Name);
                str.Append("ver", dataItem.Version.Number.ToString(CultureInfo.InvariantCulture));
                str.Append("scriptId", scriptItem.ID.ToString());
                str.Append("scriptDb", scriptItem.Database.Name);
                Context.ClientPage.ClientResponse.Broadcast(
                    SheerResponse.ShowModalDialog(str.ToString(), "400", "220", "PowerShell Script Results", false),
                    "Shell");
            }
        }
        public void Process(WorkflowPipelineArgs args)
        {
            Item item = args.DataItem;

             ProcessorItem workflowItem = args.ProcessorItem;
             string commandToExecute = workflowItem.InnerItem["CommandToExecute"];
             if(commandToExecute == "" || item.Database.Items[commandToExecute] == null || item.Database.Items[commandToExecute]["Next state"] == "")
             {
            Log.Error("Action SetStateByLanguage is failed: 'CommandToExecute' field is not set properly", this);
            return;
             }
             foreach (Language language in item.Languages)
             {
            if (language.Name == item.Language.Name)
            {
               continue;
            }

            Item langItem = item.Database.Items[item.Paths.FullPath, language, item.Version];
            if (GetIsAllowToChangeState(langItem, workflowItem))
            {
               using (new EditContext(langItem))
               {
                  CommandExecuter.Execute(commandToExecute, langItem, "", true);
               }
            }
             }
        }
Ejemplo n.º 4
0
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (args.DataItem == null)
            {
                return;
            }

            var context = new WorkflowRuleContext(args);

            var actionItem = args.ProcessorItem.InnerItem;

            if (actionItem == null)
            {
                return;
            }

            if (actionItem["execute global rules"] == "1")
            {
                RunGlobalRules(args.DataItem.Database, context);
            }

            var rules = RuleFactory.GetRules <WorkflowRuleContext>(actionItem.Fields["rules"]);

            rules.Run(context);
        }
        public void Process(WorkflowPipelineArgs args)
        {
            Item item = args.DataItem;

            ProcessorItem workflowItem     = args.ProcessorItem;
            string        commandToExecute = workflowItem.InnerItem["CommandToExecute"];

            if (commandToExecute == "" || item.Database.Items[commandToExecute] == null || item.Database.Items[commandToExecute]["Next state"] == "")
            {
                Log.Error("Action SetStateByLanguage is failed: 'CommandToExecute' field is not set properly", this);
                return;
            }
            foreach (Language language in item.Languages)
            {
                if (language.Name == item.Language.Name)
                {
                    continue;
                }

                Item langItem = item.Database.Items[item.Paths.FullPath, language, item.Version];
                if (GetIsAllowToChangeState(langItem, workflowItem))
                {
                    using (new EditContext(langItem))
                    {
                        CommandExecuter.Execute(commandToExecute, langItem, "", true);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        // Get all publishable items
        public List <Item> getAllPublishableItems(WorkflowPipelineArgs args)
        {
            UpdateWorkflowState update = new UpdateWorkflowState();
            List <Item>         getPublishableItems = new List <Item>();

            getPublishableItems.Add(args.DataItem);
            getPublishableItems.Add(args.DataItem.Children.Where(c => c.DisplayName.EndsWith("_Resources")).FirstOrDefault());

            // Find all controls on item
            foreach (string control in update.GetDatasourceValue(args, args.DataItem))
            {
                Item getControlMainDatasource = args.DataItem.Database.GetItem(control);
                if (getControlMainDatasource != null)
                {
                    getPublishableItems.Add(getControlMainDatasource);
                    List <Item> getAllChildren = getControlMainDatasource.Axes.GetDescendants().ToList();
                    // Get all main datasources' children
                    foreach (Item item in getAllChildren)
                    {
                        if (item != null)
                        {
                            getPublishableItems.Add(item);
                        }
                    }
                }
            }
            return(getPublishableItems);
        }
Ejemplo n.º 7
0
 public void Process(WorkflowPipelineArgs args)
 {
     if (args.DataItem != null)
     {
         ContentHelper.PublishItemAndRequiredAncestors(args.DataItem);
     }
 }
Ejemplo n.º 8
0
        // returns processorItem if WorkflowPipelineArgs input is valid
        public static ProcessorItem ValidateArgsProcessorItem(WorkflowPipelineArgs args)
        {
            // Check the condition before executing
            Assert.ArgumentNotNull((object)args, "args");

            ProcessorItem processorItem = args.ProcessorItem;

            if (processorItem == null)
            {
                return(null);
            }
            else // item in processor
            {
                LayoutItem layoutItem = args.DataItem.Visualization.GetLayout(Sitecore.Context.Device);
                if (layoutItem == null) // item does not have page layout
                {
                    string[] acceptablePaths = { "/sitecore/content/Data Components", "/sitecore/system/Modules/Wildcards/Routes" };
                    if (acceptablePaths.Any(args.DataItem.Paths.Path.Contains))
                    {
                        return(processorItem); // valid workflow item, although item has no page layout
                    }
                    else
                    {
                        return(null);
                    }                     // invalid workflow item
                }
                // item has page layout
                return(processorItem);
            }
        }
        public void Process(WorkflowPipelineArgs args)
        {
            Item          item         = args.DataItem;
            string        stateId      = item.State.GetWorkflowState().StateID;
            ProcessorItem workflowItem = args.ProcessorItem;
            string        langs        = workflowItem.InnerItem.Fields["LanguagesToWaitFor"].Value;
            string        commandID    = workflowItem.InnerItem.Fields["CommandToExecute"].Value;

            if (commandID == "")
            {
                Log.Error("WaitForLanguage action failed. The field 'CommandToExecute' value is not set.", this);
                return;
            }
            Item command = item.Database.Items[commandID];

            if (command["Next state"] == "")
            {
                Log.Error("WaitForLanguage action failed. The field 'Next State' value of the command is not set.", this);
                return;
            }
            bool result = true;

            foreach (Language lang in item.Languages)
            {
                if (langs != "")
                {
                    if (langs.IndexOf(lang.GetItem(item.Database).ID.ToString()) == -1)
                    {
                        continue;
                    }
                }
                if (lang.Name == item.Language.Name)
                {
                    continue;
                }

                Item          langItem      = item.Database.Items[item.Paths.FullPath, lang, item.Version];
                WorkflowState workflowState = langItem.State.GetWorkflowState();

                result = result && (workflowState.StateID == stateId || workflowState.FinalState);
            }
            if (result)
            {
                foreach (Language lang in item.Languages)
                {
                    Item langItem = item.Database.Items[item.Paths.FullPath, lang, item.Version];

                    WorkflowState state = langItem.State.GetWorkflowState();

                    if (workflowItem.InnerItem.Parent.ID.ToString() == state.StateID)
                    {
                        WorkflowResult execute = CommandExecuter.Execute(commandID, langItem, "", true);
                        if (!execute.Succeeded)
                        {
                            Log.Error("WaitForLanguage action failed: " + execute.Message, this);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void AdvanceWorkflow(WorkflowPipelineArgs args, WorkflowState dataItemWorkflowState, Item relatedItem, IWorkflow relatedItemWorkflow)
        {
            List <WorkflowCommand> commands = relatedItemWorkflow.GetCommands(relatedItem).ToList();

            if (commands.Any())
            {
                foreach (WorkflowCommand command in commands)
                {
                    Item commandItem = Sitecore.Context.ContentDatabase.GetItem(command.CommandID);

                    if (commandItem != null && commandItem.Fields["Next state"].Value == dataItemWorkflowState.StateID)
                    {
                        try
                        {
                            relatedItemWorkflow.Execute(command.CommandID, relatedItem, args.CommentFields, false, args.Parameters);

                            Log.Info("Item: " + relatedItem.DisplayName + " was successfully advanced to workflow", this);
                        }
                        catch (Exception ex)
                        {
                            Log.Error(relatedItem.DisplayName + " cannot be advanced to workflow", ex, this);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            ProcessorItem processorItem = args.ProcessorItem;
            if (processorItem != null)
            {
                Item innerItem = processorItem.InnerItem;
                string[] langsIDs = this.GetText(innerItem, "Languages", args).Split('|');

                foreach (string langID in langsIDs)
                {
                    Item langItm = Factory.GetDatabase("master").GetItem(langID);
                    if (langItm != null)
                    {
                        Item workFlowItem = args.DataItem;
                        Language language = Language.Parse(langItm.Name);
                        if (language != workFlowItem.Language)
                        {
                            Item langItem = workFlowItem.Database.GetItem(workFlowItem.ID, language);
                            langItem = langItem.Versions.AddVersion();
                        }
                    }
                }

            }
        }
Ejemplo n.º 12
0
        protected virtual Dictionary <string, object> CreateModel(WorkflowPipelineArgs args)
        {
            var modelArgs = new PopulateScribanMailActionModelArgs(args);

            PipelineManager.Run(PopulateModelPipelineName, modelArgs);
            return(modelArgs.GetModel());
        }
        public void Process(WorkflowPipelineArgs args)
        {
            string workflowComment = (!string.IsNullOrEmpty(args.CommentFields[Constants.Comments])) ? args.CommentFields[Constants.Comments] : Constants.NoComment;

            try
            {
                using (new SecurityDisabler())
                {
                    Item currentDataItem = args.DataItem;
                    if (currentDataItem.Fields[Multisite.Templates.MainSite.Fields.IsDisplayOnMainSite].IsChecked())
                    {
                        Item copiedItem     = _mallSiteWorkflowRepository.GetCopiedItemInMainSite(currentDataItem);
                        Item notifyStepItem = args.ProcessorItem.InnerItem;

                        var from = notifyStepItem.Fields[Templates.NotifyNextStepUser.Fields.From].Value;
                        var emailTemplateItem = notifyStepItem.TargetItem(Templates.NotifyNextStepUser.Fields.EmailTemplate);
                        var receivers         = WorkflowHelper.GetMainAdminsOf(copiedItem.GetSiteItem());

                        _workflowNotifyService.SendEmailNotifications(receivers, from, copiedItem, workflowComment, emailTemplateItem);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error($"NotifyNextStepUser: {ex}", this);
            }
        }
Ejemplo n.º 14
0
 //using System.Data;
 private string ReplaceVariables(string text, WorkflowPipelineArgs args)
 {
     text = text.Replace("$itemPath$", args.DataItem.Paths.FullPath);
     text = text.Replace("$itemLanguage$", args.DataItem.Language.ToString());
     text = text.Replace("$itemVersion$", args.DataItem.Version.ToString());
     return text;
 }
Ejemplo n.º 15
0
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var processorItem = args.ProcessorItem;

            if (processorItem == null)
            {
                return;
            }
            var actionItem = processorItem.InnerItem;

            var dataItem = args.DataItem;

            if (string.IsNullOrEmpty(actionItem[ScriptItemFieldNames.Script]))
            {
                return;
            }

            var scriptItem = actionItem.Database.GetItem(new ID(actionItem[ScriptItemFieldNames.Script]));

            if (RulesUtils.EvaluateRules(actionItem[ScriptItemFieldNames.EnableRule], dataItem) &&
                RulesUtils.EvaluateRules(scriptItem[ScriptItemFieldNames.EnableRule], dataItem))
            {
                var str = new UrlString(UIUtil.GetUri("control:PowerShellRunner"));
                str.Append("id", dataItem.ID.ToString());
                str.Append("db", dataItem.Database.Name);
                str.Append("lang", dataItem.Language.Name);
                str.Append("ver", dataItem.Version.Number.ToString(CultureInfo.InvariantCulture));
                str.Append("scriptId", scriptItem.ID.ToString());
                str.Append("scriptDb", scriptItem.Database.Name);
                Context.ClientPage.ClientResponse.Broadcast(
                    SheerResponse.ShowModalDialog(str.ToString(), "400", "220", "PowerShell Script Results", false),
                    "Shell");
            }
        }
 /// <summary>
 /// Main entry method of the workflow action.
 /// </summary>
 /// <param name="args">
 /// The workflow action arguments.
 /// </param>
 public void Process(WorkflowPipelineArgs args)
 {
     Assert.ArgumentNotNull(args, "args");
      var ruleContextArgs = new WorkflowRuleContext() { Arguments = args };
      var pipelineArgs = new WorkflowActionRuleContextArgs(ruleContextArgs);
      CorePipeline.Run("runWorkflowActionRules", pipelineArgs);
 }
Ejemplo n.º 17
0
        public void Process(WorkflowPipelineArgs args)
        {
            // Get item
            Item item = args.DataItem;
            // Get action item
            Item paramItem = args.ProcessorItem.InnerItem;

            // retrieving the publish tarets' IDs
            string targets = string.Empty;

            if (paramItem != null && paramItem["Targets"] != null)
            {
                targets = paramItem["Targets"];
            }

            // Get list of databases where you should publish
            Database[] publishDatabaseArray = GetPublishDatabases(targets);
            //Publish
            for (int i = 0; i < publishDatabaseArray.Length; i++)
            {
                Database       database = publishDatabaseArray[i];
                PublishOptions options  = new PublishOptions(PublishMode.SingleItem, item.Language, DateTime.Now);
                options.RootItem       = item;
                options.Deep           = IsDeepPublish(item);
                options.SourceDatabase = item.Database;
                options.TargetDatabase = database;
                Publisher publisher = new Publisher(options);
                publisher.PublishAsync();
            }
        }
Ejemplo n.º 18
0
        public void Process(WorkflowPipelineArgs args)
        {
            User editorUser = GetEditorUser(args);
            if (editorUser != null)
            {


                User reviewerUser = Sitecore.Context.User;
                Item innerItem = args.ProcessorItem.InnerItem;
                string subject = innerItem["subject"];
                string message = innerItem["message"];
                string comment = args.CommentFields["Comments"];
                message = message.Replace("$to$",
                editorUser.Profile.FullName)
                .Replace("$from$", reviewerUser.Profile.FullName)
                .Replace("$itempath$", args.DataItem.Paths.Path)
                .Replace("$itemlanguage$",
                args.DataItem.Language.Name)
                .Replace("$itemversion$",
                args.DataItem.Version.ToString())
                .Replace("$comments$", comment);
                SendEmail(reviewerUser.Profile.Email,
                editorUser.Profile.Email, subject, message);
            }
        }
        /// <summary>
        /// Move an item to a particular workflow state
        /// </summary>
        /// <param name="item">The item to go through workflow</param>
        /// <param name="workflowStateId">The ID of the workflow state</param>
        public void MoveToStateAndExecuteActions(Item item, ID workflowStateId)
        {
            IWorkflowProvider workflowProvider = item.Database.WorkflowProvider;
            IWorkflow workflow = workflowProvider.GetWorkflow(item);

            // if item is in any workflow
            if (workflow != null)
            {
                using (new EditContext(item))
                {
                    // update item's state to the new one
                    item[FieldIDs.WorkflowState] = workflowStateId.ToString();
                }

                Item stateItem = ItemManager.GetItem(workflowStateId, Language.Current, Version.Latest, item.Database, SecurityCheck.Disable);

                // if there are any actions for the new state
                if (!stateItem.HasChildren)
                    return;

                // TODO: Obsolete constructor
                var workflowPipelineArgs = new WorkflowPipelineArgs(item, string.Empty, null);

                // start executing the actions
                Pipeline pipeline = Pipeline.Start(stateItem, workflowPipelineArgs);
                if (pipeline == null)
                    return;

                // TODO: Obsolete class
                WorkflowCounters.ActionsExecuted.IncrementBy(pipeline.Processors.Count);
            }
        }
Ejemplo n.º 20
0
 private string ReplaceVariables(string text, WorkflowPipelineArgs args)//using System.Data;
 {
     text = text.Replace("$itemPath$", args.DataItem.Paths.FullPath);
     text = text.Replace("$itemLanguage$", args.DataItem.Language.ToString());
     text = text.Replace("$itemVersion$", args.DataItem.Version.ToString());
     return(text);
 }
Ejemplo n.º 21
0
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            ProcessorItem processorItem = args.ProcessorItem;

            if (processorItem != null)
            {
                Item     innerItem = processorItem.InnerItem;
                string[] langsIDs  = this.GetText(innerItem, "Languages", args).Split('|');

                foreach (string langID in langsIDs)
                {
                    Item langItm = Factory.GetDatabase("master").GetItem(langID);
                    if (langItm != null)
                    {
                        Item     workFlowItem = args.DataItem;
                        Language language     = Language.Parse(langItm.Name);
                        if (language != workFlowItem.Language)
                        {
                            Item langItem = workFlowItem.Database.GetItem(workFlowItem.ID, language);
                            langItem = langItem.Versions.AddVersion();
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>Runs the processor.</summary>
        /// <param name="args">The arguments.</param>
        public async Task Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull((object)args, nameof(args));

            var processorItem = args.ProcessorItem;

            if (processorItem == null)
            {
                return;
            }

            var item         = args.DataItem;
            var site         = _siteResolver.ResolveSite(item);
            var teamsMessage = new TeamsMessage
            {
                HostUrl  = $"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}",
                ItemId   = HttpUtility.UrlEncode(item.ID.ToString()),
                ItemName = item.DisplayName,
                ItemPath = item.Paths.FullPath,
                Language = item.Language.Name,
                ItemUrl  = GetItemUrl(item, site),
                Site     = site.Name,
                Command  = processorItem.InnerItem.Parent.Name,
                Comments = args.CommentFields["Comments"]
            };

            teamsMessage.FillTeamsMessage(item);

            await new FunctionService().DoPostAsync(teamsMessage);
        }
        public void Process(WorkflowPipelineArgs args)
        {
            Item      workflowItem = args.DataItem;
            IWorkflow itemwf       = this.master.WorkflowProvider.GetWorkflow(workflowItem);

            // Only run on project workflow
            if (itemwf.WorkflowID != Data.ProjectWorkflow.ToString())
            {
                return;
            }

            // Find other items that are in the same project
            var items = master.SelectItems("fast:/sitecore/content//*[@Project = '" + workflowItem.Fields[Data.ProjectFieldId].Value + "']");

            // Get the project defintion
            var       projectDefinition  = master.GetItem(workflowItem.Fields[Data.ProjectFieldId].Value);
            DateField projectReleaseDate = projectDefinition.Fields[Data.ProjectDetailsReleaseDate];

            // If there are no other items in the project, and it's after the project release date, continue the workflow.
            if (items == null && projectReleaseDate.DateTime < DateTime.Now)
            {
                // no other items using this so, send back
                RevertItemsWorkflowToOrigional(workflowItem);
                AutoPublish(args);
            }
            else
            {
                foreach (var item in items)
                {
                    // is the item in the same project
                    if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                    {
                        // is it not in the waiting state
                        if (item.Fields["__Workflow state"].Value != Data.ProjectWorkflowReadytoGoLiveState.ToString())
                        {
                            if (item.ID != workflowItem.ID) // ignore if same item
                            {
                                AllItemsReady = false;
                                break;
                            }
                        }
                    }
                }

                if (AllItemsReady && projectReleaseDate.DateTime < DateTime.Now)
                {
                    foreach (var item in items)
                    {
                        // is the item in the same project
                        if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                        {
                            RevertItemsWorkflowToOrigional(item);
                        }
                    }

                    AutoPublish(args);
                }
            }
        }
        public void AutoPublish(WorkflowPipelineArgs args)
        {
            Item dataItem  = args.DataItem;
            Item innerItem = args.ProcessorItem.InnerItem;

            Database[] targets = this.GetTargets(dataItem);
            PublishManager.PublishItem(dataItem, targets, new Language[] { dataItem.Language }, this.GetDeep(innerItem), false);
        }
 public void Process(WorkflowPipelineArgs args)
 {
     if (args.ProcessorItem == null)
     {
         return;
     }
     PublishPostItem(args.DataItem);
 }
Ejemplo n.º 26
0
 public void Process(WorkflowPipelineArgs args)
 {
     var item = args.DataItem;
     if (item != null)
     {
         item.Delete();
     }
 }
Ejemplo n.º 27
0
 //todo: implement workflow action support
 public void Process(WorkflowPipelineArgs args)
 {
     /*
     var workflowItem = args.DataItem;
     args.Abo
     ScriptSession.
     */
 }
        public void Process(WorkflowPipelineArgs args)
        {
            Item item = args.DataItem;
             string stateId = item.State.GetWorkflowState().StateID;
             ProcessorItem workflowItem = args.ProcessorItem;
               string langs = workflowItem.InnerItem.Fields["LanguagesToWaitFor"].Value;
             string commandID = workflowItem.InnerItem.Fields["CommandToExecute"].Value;
             if(commandID == "")
             {
            Log.Error("WaitForLanguage action failed. The field 'CommandToExecute' value is not set.", this);
            return;
             }
             Item command = item.Database.Items[commandID];
             if(command["Next state"] == "")
             {
            Log.Error("WaitForLanguage action failed. The field 'Next State' value of the command is not set.", this);
            return;
             }
               bool result = true;
               foreach(Language lang in item.Languages)
             {
            if(langs != "")
            {
               if(langs.IndexOf(lang.GetItem(item.Database).ID.ToString()) == -1)
               {
                  continue;
               }
            }
            if(lang.Name == item.Language.Name)
            {
               continue;
            }

            Item langItem = item.Database.Items[item.Paths.FullPath, lang, item.Version];
            WorkflowState workflowState = langItem.State.GetWorkflowState();

            result = result && (workflowState.StateID == stateId || workflowState.FinalState);
             }
             if(result)
             {
            foreach(Language lang in item.Languages)
            {
               Item langItem = item.Database.Items[item.Paths.FullPath, lang, item.Version];

               WorkflowState state = langItem.State.GetWorkflowState();

               if(workflowItem.InnerItem.Parent.ID.ToString() == state.StateID)
               {

                  WorkflowResult execute = CommandExecuter.Execute(commandID, langItem, "", true);
                  if(!execute.Succeeded)
                  {
                     Log.Error("WaitForLanguage action failed: " + execute.Message, this);
                  }
               }
            }
             }
        }
Ejemplo n.º 29
0
        // Access workflow process to get info
        public void Process(WorkflowPipelineArgs args)
        {
            ProcessorItem processorItem = args.ProcessorItem;

            // If item is not in processor and item doesn't have page layout, retrun
            if (processorItem == null)
            {
                return;
            }

            Item innerItem = processorItem.InnerItem;

            // Check the condition before excuting
            Assert.ArgumentNotNull((object)args, "args");

            string fullPath    = innerItem.Paths.FullPath;
            string fromAddress = "*****@*****.**";
            string toAddress   = User.Current.Profile.Email;

            if (String.IsNullOrEmpty(toAddress))
            {
                return;
            }

            string subject = this.GetText(innerItem, "subject", args);
            string message = this.GetText(innerItem, "message", args);

            Error.Assert(toAddress.Length > 0, "The 'To' field is not specified in the mail action item: " + fullPath);
            Error.Assert(subject.Length > 0, "The 'Subject' field is not specified in the mail action item: " + fullPath);
            Error.Assert(message.Length > 0, "The 'Message' field is not specified in the mail action item: " + fullPath);

            try
            {
                if (!String.IsNullOrEmpty(toAddress.Trim()) && !String.IsNullOrEmpty(fromAddress.Trim()))
                {
                    // Send email if no issue found
                    if (Util.sendEmail(toAddress, subject, message, fromAddress, "", "", true))
                    {
                        Sitecore.Diagnostics.Log.Info("Begin Blog info", this);
                        Sitecore.Diagnostics.Log.Info("fromAddress " + fromAddress, this);
                        Sitecore.Diagnostics.Log.Info("toAddress " + toAddress, this);
                        Sitecore.Diagnostics.Log.Info("subject " + subject, this);
                        Sitecore.Diagnostics.Log.Info("message " + message, this);
                        Sitecore.Diagnostics.Log.Info("End info", this);
                        Sitecore.Diagnostics.Log.Info("Email Successfully Sent!!", this);
                    }
                    else
                    {
                        SheerResponse.ShowError("Sending Email Failed. Please try to approve again", "");
                        args.AbortPipeline();
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("Sending Email Failed - Exception Error", ex, this);
            }
        }
Ejemplo n.º 30
0
        private void SentFailEmail(WorkflowPipelineArgs args, string e)
        {
            var editorUser   = GetEditorUser(args);
            var reviewerUser = Sitecore.Context.User;
            var subject      = "Can't Approve";
            var message      = "This content not approve because: " + e;

            SendMailConfig(reviewerUser.Profile.Email, editorUser.Profile.Email, subject, message);
        }
Ejemplo n.º 31
0
 private string GetText(Item commandItem, string field, WorkflowPipelineArgs args)
 {
     string text = commandItem[field];
     if (text.Length > 0)
     {
         return this.ReplaceVariables(text, args);
     }
     return string.Empty;
 }
Ejemplo n.º 32
0
        public void Process(WorkflowPipelineArgs args)
        {
            var item = args.DataItem;

            if (item != null)
            {
                item.Delete();
            }
        }
Ejemplo n.º 33
0
        // Replace special valuables in template
        public static string ReplaceVariables(string data, WorkflowPipelineArgs args)
        {
            data = data.Replace("$userFullName$", User.Current.Profile.FullName);
            data = data.Replace("$itemPath$", args.DataItem.Paths.FullPath);
            data = data.Replace("$itemVersion$", args.DataItem.Version.ToString());
            data = data.Replace("$itemUpdatedDate$", DateTime.Now.ToString("g"));
            data = data.Replace("$comment$", args.CommentFields["Comments"].ToString());

            return(data);
        }
Ejemplo n.º 34
0
        private static string scInternalUser = "******";   // for IS/IT dept internal users

        // Get special valuables and update with correct data
        public static string GetText(Item commandItem, string field, WorkflowPipelineArgs args)
        {
            string text = commandItem[field];

            if (text.Length > 0)
            {
                return(ReplaceVariables(text, args));
            }
            return(string.Empty);
        }
        /// <summary>
        /// Main entry method of the workflow action.
        /// </summary>
        /// <param name="args">
        /// The workflow action arguments.
        /// </param>
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var ruleContextArgs = new WorkflowRuleContext()
            {
                Arguments = args
            };
            var pipelineArgs = new WorkflowActionRuleContextArgs(ruleContextArgs);

            CorePipeline.Run("runWorkflowActionRules", pipelineArgs);
        }
Ejemplo n.º 36
0
 public void Process(WorkflowPipelineArgs args)
 {
     int addDays = Convert.ToInt32(args.ProcessorItem.InnerItem.Fields["AddDays"].Value);
      DateTime taskRunDate = DateTime.Now.AddDays(addDays);
      string isoDate = DateUtil.ToIsoDate(taskRunDate);
      isoDate = isoDate.Substring(0, 9) + "120000";
      using(new EditContext(args.DataItem))
      {
     args.DataItem.Fields["__Archive date"].Value = isoDate;
      }
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Create a new instance.
        /// </summary>
        /// <param name="workflowPipelineArgs">The <see cref="WorkflowPipelineArgs"/> for the workflow pipeline which is running.</param>
        public PopulateScribanMailActionModelArgs(WorkflowPipelineArgs workflowPipelineArgs)
        {
            if (workflowPipelineArgs == null)
            {
                throw new ArgumentNullException(nameof(workflowPipelineArgs));
            }

            WorkflowPipelineArgs = workflowPipelineArgs;

            _values = new Dictionary <string, object>();
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Populates the velocity template context. Only the objects that were
 /// added in this method will be accessible in the mail template.
 /// </summary>
 /// <remarks>Override this to add your own data to the context</remarks>
 protected virtual void PopulateContext(WorkflowPipelineArgs args)
 {
     velocityContext.Put("args", args);
     velocityContext.Put("item", args.DataItem);
     velocityContext.Put("processor", args.ProcessorItem);
     velocityContext.Put("user", Sitecore.Context.User);
     velocityContext.Put("history", args.DataItem.State.GetWorkflow().GetHistory(args.DataItem));
     velocityContext.Put("state", args.DataItem.State.GetWorkflowState());
     velocityContext.Put("nextState", GetNextState(args));
     velocityContext.Put("site", Sitecore.Context.Site);
     velocityContext.Put("time", DateTime.Now);
 }
        public void Process(WorkflowPipelineArgs args)
        {
            var itemLinks = args.DataItem.Axes.GetAncestors();

            foreach (var itm in itemLinks)
            {
                if (itm != null && itm.Paths.IsMediaItem)
                {
                    PublishItem(itm);
                }
            }
        }
Ejemplo n.º 40
0
        public virtual void Process(WorkflowPipelineArgs args)
        {
            ScribanMailActionItem actionItem = args.ProcessorItem.InnerItem;
            var mailTo = actionItem.To;

            if (string.IsNullOrWhiteSpace(mailTo))
            {
                Log.Error(GetType().FullName + " cannot be invoked with an empty 'To' field.", this);
                return;
            }

            var mailFrom = actionItem.From;

            if (string.IsNullOrWhiteSpace(mailFrom))
            {
                Log.Error(GetType().FullName + " cannot be invoked with an empty 'From' field.", this);
                return;
            }

            var mailSubject = actionItem.Subject;
            var mailBody    = actionItem.Message;

            var model = CreateModel(args);

            try
            {
                mailTo      = ProcessScribanTemplate(mailTo, model);
                mailFrom    = ProcessScribanTemplate(mailFrom, model);
                mailSubject = ProcessScribanTemplate(mailSubject, model);
                mailBody    = ProcessScribanTemplate(mailBody, model);
            }
            catch (Exception ex)
            {
                Log.Error("An error occurred whilst rendering a Scriban template in " + GetType().FullName, ex, this);
                return;
            }

            try
            {
                var message = new MailMessage(mailFrom, mailTo, mailSubject, mailBody);
                message.IsBodyHtml = true;

                using (var smtpClient = SmtpClientFactory.Invoke())
                {
                    smtpClient.Send(message);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception while sending workflow email", ex, this);
                args.AbortPipeline();
            }
        }
Ejemplo n.º 41
0
        public void Process(WorkflowPipelineArgs args)
        {
            int      addDays     = Convert.ToInt32(args.ProcessorItem.InnerItem.Fields["AddDays"].Value);
            DateTime taskRunDate = DateTime.Now.AddDays(addDays);
            string   isoDate     = DateUtil.ToIsoDate(taskRunDate);

            isoDate = isoDate.Substring(0, 9) + "120000";
            using (new EditContext(args.DataItem))
            {
                args.DataItem.Fields["__Archive date"].Value = isoDate;
            }
        }
        public void Process(WorkflowPipelineArgs args)
        {
            var itemLinks = args.DataItem.Axes.GetAncestors();

            foreach (var itm in itemLinks)
            {
                if (itm != null && itm.Paths.IsMediaItem)
                {
                    PublishItem(itm);
                }
            }
        }
        public void Process(WorkflowPipelineArgs args)
        {
            CreateFromMasterActionItem action = args.ProcessorItem.InnerItem;

             if (action.TargetMaster != string.Empty && action.TargetName != string.Empty)
             {
            Item parent = null;
            if (action.TargetParent != string.Empty)
            {
               parent = Sitecore.Context.ContentDatabase.Items[action.TargetParent];
            }

            if (parent == null)
            {
               parent = args.DataItem;
            }

            Sitecore.Data.ID id = Sitecore.Data.ID.Parse(action.TargetMaster);
            BranchItem branch = args.DataItem.Database.GetItem(id);
            Item target = parent.Add(this.GetTargetName(action.TargetName, parent), branch);

            if (target != null)
            {
               if (action.TargetWorkflow != string.Empty)
               {
                  using (new SecurityDisabler())
                  {
                     using (new EditContext(target))
                     {
                        target[FieldIDs.Workflow] = action.TargetWorkflow;
                     }
                  }
               }

               if (action.TargetState != string.Empty)
               {
                  using (new SecurityDisabler())
                  {
                     using (new EditContext(target))
                     {
                        target[FieldIDs.State] = action.TargetState;
                     }
                  }
               }
            }
             }
        }
Ejemplo n.º 44
0
        /// <summary>
        /// Processes the mail action, creates and sends the email
        /// </summary>
        public virtual void Process(WorkflowPipelineArgs args)
        {
            CreateContext(args);
             Item item = args.ProcessorItem.InnerItem;

             MailMessage message = new MailMessage();
             message.To = ProcessFieldValue("To", item);
             message.From = ProcessFieldValue("From", item);
             message.Subject = ProcessFieldValue("Subject", item);
             message.Body = ProcessFieldValue("Message", item);
             SmtpMail.SmtpServer = item["mail server"];

             Error.AssertString(message.To, "To", true);
             Error.AssertString(message.From, "From", true);
             Error.AssertString(message.Subject, "Subject", true);
             Error.AssertString(SmtpMail.SmtpServer, "Smtp Server", true);
             SmtpMail.Send(message);
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Processes the mail action, creates and sends the email
        /// </summary>
        public virtual void Process(WorkflowPipelineArgs args)
        {
            if (velocityContext==null)
            {
                return;
            }
            CreateContext(args);
            Item item = args.ProcessorItem.InnerItem;
            string to = ProcessFieldValue("To", item);
            string from = ProcessFieldValue("From", item);
            string subject = ProcessFieldValue("Subject", item);
            string body = ProcessFieldValue("Message", item);

            if (string.IsNullOrEmpty(to))
            {
                Logger.Error("No 'to' email available for Extended Email Action", this);
                return;
            }

            if (string.IsNullOrEmpty(from))
            {
                Logger.Error("No 'from' email available for Extended Email Action", this);
                return;
            }

            try
            {
                MailMessage message = new MailMessage(from, to, subject, body);
                string server = item["mail server"];
                if (string.IsNullOrEmpty(server))
                {
                    Sitecore.MainUtil.SendMail(message);
                }
                else
                {
                    SmtpClient smtp = new SmtpClient(server);
                    smtp.Send(message);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Exception while sending workflow email", e, this);
            }
        }
        public void Process(WorkflowPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (args.DataItem == null) return;

            var context = new WorkflowRuleContext(args);

            var actionItem = args.ProcessorItem.InnerItem;

            if (actionItem == null) return;

            if (actionItem["execute global rules"] == "1")
            {
                RunGlobalRules(args.DataItem.Database, context);
            }

            var rules = RuleFactory.GetRules<WorkflowRuleContext>(actionItem.Fields["rules"]);

            rules.Run(context);
        }
        public void Process(WorkflowPipelineArgs args)
        {       
            // Item being workflowed
            Item workflowItem = args.DataItem;
            IWorkflow wf = this.master.WorkflowProvider.GetWorkflow(workflowItem);

            
            if (workflowItem.IsProjectItem())
            {
                // Move item to the project workflow   
                using (new SecurityDisabler())
                {
                    workflowItem.Editing.BeginEdit();
                    workflowItem["__Workflow"] = Data.ProjectWorkflow.ToString(); 
                    workflowItem["__Workflow state"] = Data.ProjectWorkflowReadytoGoLiveState.ToString();
                    workflowItem["OrigionalWorkflow"] = wf.WorkflowID;
                    workflowItem.Editing.EndEdit();
                }

                wf = this.master.WorkflowProvider.GetWorkflow(Data.ProjectWorkflow.ToString());
                wf.Start(workflowItem);
            }
            else
            {
                // get current state
                var state = wf.GetState(workflowItem);
                var cmds = wf.GetCommands(state.StateID);

                foreach(var cmd in cmds)
                {
                    if (cmd.SuppressComment)
                    {
                        wf.Execute(cmd.CommandID, workflowItem, "", false);
                        return;
                    }
                }
            }            
            return; 
        }
 public void AutoPublish(WorkflowPipelineArgs args)
 {
     Item dataItem = args.DataItem;
     Item innerItem = args.ProcessorItem.InnerItem;
     Database[] targets = this.GetTargets(dataItem);
     PublishManager.PublishItem(dataItem, targets, new Language[] { dataItem.Language }, this.GetDeep(innerItem), false);
 }
Ejemplo n.º 49
0
        private string GetNextState(WorkflowPipelineArgs args)
        {
            Item command = args.ProcessorItem.InnerItem.Parent;
            string nextStateID = command["Next State"];
            if (nextStateID.Length == 0)
            {
                return string.Empty;
            }

            Item nextState = args.DataItem.Database.Items[ID.Parse(nextStateID)];
            if (nextState != null)
            {
                return nextState.Name;
            }
            return string.Empty;
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Populates the velocity template context. Only the objects that were
        /// added in this method will be accessible in the mail template.
        /// </summary>
        /// <remarks>Override this to add your own data to the context</remarks>
        protected virtual void PopulateContext(WorkflowPipelineArgs args)
        {
            velocityContext.Put("args", args);
            velocityContext.Put("item", args.DataItem);
            velocityContext.Put("processor", args.ProcessorItem);
            velocityContext.Put("user", Sitecore.Context.User);
            velocityContext.Put("history", args.DataItem.State.GetWorkflow().GetHistory(args.DataItem));
            velocityContext.Put("state", args.DataItem.State.GetWorkflowState());
            velocityContext.Put("nextState", GetNextState(args));
            velocityContext.Put("site", Sitecore.Context.Site);
            velocityContext.Put("time", DateTime.Now);

            EntryItem entryItem = null;
            if (args.DataItem.TemplateIsOrBasedOn(Settings.EntryTemplateID))
            {
                entryItem = new EntryItem(args.DataItem);
            }
            else if (args.DataItem.TemplateIsOrBasedOn(Settings.CommentTemplateID))
            {
                CommentItem commentItem = new CommentItem(args.DataItem);
                entryItem = ManagerFactory.EntryManagerInstance.GetBlogEntryByComment(commentItem);
                velocityContext.Put("comment", commentItem);
            }

            if (entryItem != null)
            {
                velocityContext.Put("entry", entryItem);
                if (!string.IsNullOrEmpty(entryItem.InnerItem.Statistics.CreatedBy))
                {
                    UserProfile createdBy = User.FromName(entryItem.InnerItem.Statistics.CreatedBy, false).Profile;
                    velocityContext.Put("entryCreatedBy", createdBy);
                }
                if (!string.IsNullOrEmpty(entryItem.InnerItem.Statistics.UpdatedBy))
                {
                    UserProfile updatedBy = User.FromName(entryItem.InnerItem.Statistics.UpdatedBy, false).Profile;
                    velocityContext.Put("entryUpdatedBy", updatedBy);
                }

                BlogHomeItem blog = ManagerFactory.BlogManagerInstance.GetCurrentBlog(entryItem);
                velocityContext.Put("blog", blog);
            }
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Creates velocity context.
 /// </summary>
 /// <remarks>To add your own data to the context, you should
 /// override the <c>PopulateContext</c> method</remarks>
 protected virtual void CreateContext(WorkflowPipelineArgs args)
 {
     velocityContext = new VelocityContext();
     PopulateContext(args);
 }
 public void Process(WorkflowPipelineArgs args)
 {
     Item item = args.DataItem;
      item.Recycle();
 }
 public WorkflowRuleContext(WorkflowPipelineArgs args)
 {
     WorkflowArgs = args;
     Item = args.DataItem;
 }
Ejemplo n.º 54
0
 /// <summary>
 /// Populates the velocity template context. Only the objects that were
 /// added in this method will be accessible in the mail template.
 /// </summary>
 /// <remarks>Override this to add your own data to the context</remarks>
 protected virtual void PopulateContext(WorkflowPipelineArgs args)
 {
     velocityContext.Put("args", args);
      velocityContext.Put("item", args.DataItem);
      velocityContext.Put("processor", args.ProcessorItem);
      velocityContext.Put("user", Sitecore.Context.User);
      velocityContext.Put("history", args.DataItem.State.GetWorkflow().GetHistory(args.DataItem));
      velocityContext.Put("state", args.DataItem.State.GetWorkflowState());
      velocityContext.Put("nextState", GetNextState(args));
      velocityContext.Put("site", Sitecore.Context.Site);
      velocityContext.Put("time", DateTime.Now);
 }
 public void Process(WorkflowPipelineArgs args)
 {
     if(args.DataItem != null)
         ContentHelper.PublishItemAndRequiredAncestors(args.DataItem);
 }
        public void Process(WorkflowPipelineArgs args)
        {
            Item workflowItem = args.DataItem;
            IWorkflow itemwf = this.master.WorkflowProvider.GetWorkflow(workflowItem);

            // Only run on project workflow
            if (itemwf.WorkflowID != Data.ProjectWorkflow.ToString())
            {
                return;
            }

            // Find other items that are in the same project
            var items = master.SelectItems("fast:/sitecore/content//*[@Project = '" + workflowItem.Fields[Data.ProjectFieldId].Value + "']");

            // Get the project defintion
            var projectDefinition = master.GetItem(workflowItem.Fields[Data.ProjectFieldId].Value);
            DateField projectReleaseDate = projectDefinition.Fields[Data.ProjectDetailsReleaseDate];            

            // If there are no other items in the project, and it's after the project release date, continue the workflow.
            if (items == null && projectReleaseDate.DateTime < DateTime.Now)
            {
                // no other items using this so, send back
                RevertItemsWorkflowToOrigional(workflowItem);
                AutoPublish(args);
            }
            else
            {
                foreach (var item in items)
                {
                    // is the item in the same project
                    if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                    {
                        // is it not in the waiting state
                        if (item.Fields["__Workflow state"].Value != Data.ProjectWorkflowReadytoGoLiveState.ToString())
                        {
                            if (item.ID != workflowItem.ID) // ignore if same item
                            {
                                AllItemsReady = false;
                                break;
                            }
                        }
                    }
                }

                if (AllItemsReady && projectReleaseDate.DateTime < DateTime.Now)
                {
                    foreach (var item in items)
                    {
                        // is the item in the same project
                        if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                        {
                            RevertItemsWorkflowToOrigional(item);
                        }
                    }

                    AutoPublish(args);
                }

            }
    
        }