Example #1
0
        protected override void Execute()
        {
            ActivityInstanceData          activityInstance   = ActivityInstance;
            List <String>                 items              = new List <string>();
            TridionActivityDefinitionData activitydefinition = (TridionActivityDefinitionData)CoreServiceClient.Read(ActivityInstance.ActivityDefinition.IdRef, readoption);
            ProcessDefinitionData         processdefinition  = (ProcessDefinitionData)CoreServiceClient.Read(activitydefinition.ProcessDefinition.IdRef, readoption);

            Logger.Write(string.Format("ActivityInstance.Title : {0}", ActivityInstance.Title), "Workflow", LoggingCategory.General, TraceEventType.Information);

            foreach (WorkItemData wid in activityInstance.WorkItems)
            {
                items.Add(wid.Subject.Title);
            }

            try
            {
                SmtpClient  client = Utility.SMTPClientConfiguration();
                MailMessage mail   = Utility.WorkflowMailMessageConfiguration(ActivityInstance.Title.ToString(), items, null);
                client.Send(mail);
                Logger.Write(string.Format("Mail : {0}", mail.Body.ToString()), "Workflow", LoggingCategory.General, TraceEventType.Information);
                Logger.Write(string.Format("ActivityInstance.Title : {0}", "Mail Sent"), "Workflow", LoggingCategory.General, TraceEventType.Information);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("ActivityInstance.Title : {0}", ex.Message.ToString()), "Workflow", LoggingCategory.General, TraceEventType.Information);
            }
            finally
            {
                CoreServiceClient.FinishActivity(ActivityInstance.Id, new ActivityFinishData {
                    Message = "Mail Sent to Target Audience, Finished Activity"
                }, null);
                Logger.Write(string.Format("Message: {0}", "Auto Approved and Send for Next Activity , Finished Activity"), "Workflow", LoggingCategory.General, TraceEventType.Information);
            }
        }
        private UserData GetFirstManualActivityPerformer()
        {
            ReadOptions          readoption          = new ReadOptions();
            ActivityInstanceData firstManualActivity = GetFirstManualActivity();

            Logger.Write(string.Format("FirstManualActivity: {0}", firstManualActivity.Title), "Workflow", LoggingCategory.General, TraceEventType.Information);
            return((UserData)CoreServiceClient.Read(firstManualActivity.Performers.Last().IdRef, null));
        }
        /// <summary>
        /// Reload the <see cref="ActivityInstance" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.ActivityInstanceData" />
        /// </summary>
        /// <param name="activityInstanceData"><see cref="T:Tridion.ContentManager.CoreService.Client.ActivityInstanceData" /></param>
        protected void Reload(ActivityInstanceData activityInstanceData)
        {
            if (activityInstanceData == null)
                throw new ArgumentNullException("activityInstanceData");

            mActivityInstanceData = activityInstanceData;
            base.Reload(activityInstanceData);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivityInstance"/> class.
        /// </summary>
        /// <param name="client"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="activityInstanceData"><see cref="T:Tridion.ContentManager.CoreService.Client.ActivityInstanceData" /></param>
        protected ActivityInstance(Client client, ActivityInstanceData activityInstanceData)
            : base(client, activityInstanceData)
        {
            if (activityInstanceData == null)
                throw new ArgumentNullException("activityInstanceData");

            mActivityInstanceData = activityInstanceData;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivityInstance"/> class.
        /// </summary>
        /// <param name="client"><see cref="T:TcmCoreService.Client" /></param>
        /// <param name="activityInstanceData"><see cref="T:Tridion.ContentManager.CoreService.Client.ActivityInstanceData" /></param>
        protected ActivityInstance(Client client, ActivityInstanceData activityInstanceData) : base(client, activityInstanceData)
        {
            if (activityInstanceData == null)
            {
                throw new ArgumentNullException("activityInstanceData");
            }

            mActivityInstanceData = activityInstanceData;
        }
        protected override void Execute()
        {
            PublishInstructionData publishInstruction = new PublishInstructionData();

            publishInstruction.ResolveInstruction = new ResolveInstructionData();
            publishInstruction.RenderInstruction  = new RenderInstructionData();

            //Needed for publishing workflow revision/version
            publishInstruction.ResolveInstruction.IncludeWorkflow = true;
            TrusteeData          lastPerformer    = GetFirstManualActivityPerformer();
            ActivityInstanceData activityInstance = ActivityInstance;

            Logger.Write(string.Format("lastPerformer: {0}", lastPerformer.Title), "Workflow", LoggingCategory.General, TraceEventType.Information);

            if (Utility.IsMailSendOptionTrue(activityInstance.Title))
            {
                Logger.Write(string.Format("Mail Send Option: {0}", "True"), "Workflow", LoggingCategory.General, TraceEventType.Information);

                try
                {
                    SmtpClient  client = Utility.SMTPClientConfiguration();
                    MailMessage mail   = Utility.WorkflowMailMessageConfiguration(ActivityInstance.Title.ToString(), null, lastPerformer.Title);
                    client.Send(mail);
                    Logger.Write(string.Format("Mail : {0}", mail.Body.ToString()), "Workflow", LoggingCategory.General, TraceEventType.Information);
                    Logger.Write(string.Format("ActivityInstance.Title : {0}", "Mail Sent"), "Workflow", LoggingCategory.General, TraceEventType.Information);
                }
                catch (Exception ex)
                {
                    Logger.Write(string.Format("ActivityInstance.Title : {0}", ex.Message.ToString()), "Workflow", LoggingCategory.General, TraceEventType.Information);
                }
            }

            if (Utility.IsPublishedToPreviewTrue())
            {
                // Retrieving the Publication Target and Publish Transaction
                if (ProcessInstance.Variables.ContainsKey("PublishTransaction"))
                {
                    string publishTransactionId = ProcessInstance.Variables["PublishTransaction"];
                    // Undo Publish Transaction
                    CoreServiceClient.UndoPublishTransaction(publishTransactionId, QueueMessagePriority.Normal, null);
                }
            }


            // Finish the Activity
            ActivityFinishData finishData = new ActivityFinishData()
            {
                Message      = "The Item " + activityInstance.WorkItems.FirstOrDefault().ToString() + " has been rejected and reassigned to " + lastPerformer.Title,
                NextAssignee = new LinkToTrusteeData()
                {
                    IdRef = lastPerformer.Id
                }
            };

            CoreServiceClient.FinishActivity(activityInstance.Id, finishData, null);
        }
        /// <summary>
        /// This method is used to Publish Item to Preview environment
        /// </summary>
        protected override void Execute()
        {
            PublishInstructionData publishInstractionData = new PublishInstructionData();

            publishInstractionData.RenderInstruction  = new RenderInstructionData();
            publishInstractionData.ResolveInstruction = new ResolveInstructionData();
            publishInstractionData.ResolveInstruction.IncludeWorkflow          = true;
            publishInstractionData.ResolveInstruction.IncludeChildPublications = false;

            List <string> itemToPublish = new List <string>();

            String[] targets   = Utility.GetPublishingTarget("Preview Publication Target");
            String[] PublishTo = Utility.GetPublishingTo();
            int      length    = PublishTo.Length;

            Logger.Write(string.Format("length: {0}", length), "Workflow", LoggingCategory.General, TraceEventType.Information);

            ActivityInstanceData activityInstance = ActivityInstance;

            foreach (WorkItemData wid in activityInstance.WorkItems)
            {
                if (length != 0 && PublishTo[0].ToString() != "All")
                {
                    for (int counter = 0; counter < length; counter++)
                    {
                        string comp  = wid.Subject.IdRef;
                        int    index = comp.IndexOf('-');
                        string sub1  = comp.Substring(index, comp.Length - index);
                        comp = @"tcm:" + PublishTo[counter].ToString() + sub1;
                        Logger.Write(string.Format("component ID : {0}", comp), "Workflow", LoggingCategory.General, TraceEventType.Information);
                        itemToPublish.Add(comp);
                    }
                }
                else
                {
                    publishInstractionData.ResolveInstruction.IncludeChildPublications = true;
                    itemToPublish.Add(wid.Subject.IdRef);
                }
            }

            PublishTransactionData[] publishTransactionData = CoreServiceClient.Publish(itemToPublish.ToArray <String>(), publishInstractionData, targets, PublishPriority.High, null);

            if (ProcessInstance.Variables.ContainsKey("PublishTransaction"))
            {
                ProcessInstance.Variables["PublishTransaction"] = publishTransactionData[0].Id;
            }
            else
            {
                ProcessInstance.Variables.Add("PublishTransaction", publishTransactionData[0].Id);
            }

            CoreServiceClient.FinishActivity(ActivityInstance.Id, new ActivityFinishData {
                Message = "Publish to Preview Queued: Finished Activity"
            }, null);
            Logger.Write(string.Format("Message: {0}", "Publish to Preview Queued: Finished Activity"), "Workflow", LoggingCategory.General, TraceEventType.Information);
        }
        /// <summary>
        /// Reload the <see cref="ActivityInstance" /> with the specified <see cref="T:Tridion.ContentManager.CoreService.Client.ActivityInstanceData" />
        /// </summary>
        /// <param name="activityInstanceData"><see cref="T:Tridion.ContentManager.CoreService.Client.ActivityInstanceData" /></param>
        protected void Reload(ActivityInstanceData activityInstanceData)
        {
            if (activityInstanceData == null)
            {
                throw new ArgumentNullException("activityInstanceData");
            }

            mActivityInstanceData = activityInstanceData;
            base.Reload(activityInstanceData);
        }
Example #9
0
        protected override void Execute()
        {
            PublishInstructionData publishInstruction = new PublishInstructionData();

            publishInstruction.ResolveInstruction = new ResolveInstructionData();
            publishInstruction.RenderInstruction  = new RenderInstructionData();

            //Needed for publishing workflow revision/version
            publishInstruction.ResolveInstruction.IncludeWorkflow = true;
            ActivityInstanceData activityInstance   = ActivityInstance;
            IList <String>       itemsToPublishList = new List <String>();

            //Staging publication target URI
            String[] targets = Utility.GetPublishingTarget("Preview Publication Target");

            foreach (WorkItemData wid in activityInstance.WorkItems)
            {
                int value = Convert.ToInt32(Enum.Parse(typeof(ItemType), "VirtualFolder"));
                if (wid.Subject.IdRef.EndsWith(value.ToString()))
                {
                    itemsToPublishList.Add(wid.Subject.IdRef);
                }
            }

            //PublishTransactionData requires reference to System.ServiceModel
            PublishTransactionData[] publishTransactions = CoreServiceClient.Publish(itemsToPublishList.ToArray <String>(), publishInstruction, targets, PublishPriority.Normal, null);

            //Store the publish transaction id so that we can undo if needed!
            if (ProcessInstance.Variables.ContainsKey("PublishTransaction"))
            {
                ProcessInstance.Variables["PublishTransaction"] = publishTransactions[0].Id;
            }
            else
            {
                ProcessInstance.Variables.Add("PublishTransaction", publishTransactions[0].Id);
            }

            CoreServiceClient.FinishActivity(ActivityInstance.Id, new ActivityFinishData {
                Message = "Publish to Staging Queued: Finished Activity"
            }, null);
        }
Example #10
0
 public static ActivityInstanceData CreateActivityInstanceData(global::System.Guid ID, global::System.Guid activityInstanceId, string name)
 {
     ActivityInstanceData activityInstanceData = new ActivityInstanceData();
     activityInstanceData.Id = ID;
     activityInstanceData.ActivityInstanceId = activityInstanceId;
     activityInstanceData.Name = name;
     return activityInstanceData;
 }
Example #11
0
 public void AddToActivityInstanceData(ActivityInstanceData activityInstanceData)
 {
     base.AddObject("ActivityInstanceData", activityInstanceData);
 }
Example #12
0
        public string ViewWorkflow(GetParameter selectedItem)
        {
            ActivityInstanceData activityInstance = Client.Read(selectedItem.ActivityInstanceId, new ReadOptions()) as ActivityInstanceData;

            if (activityInstance != null)
            {
                string currentActivityId            = activityInstance.ActivityDefinition.IdRef;
                ProcessInstanceData processInstance = Client.Read(activityInstance.Process.IdRef, new ReadOptions()) as ProcessInstanceData;

                if (processInstance != null)
                {
                    ProcessDefinitionData processDefinition = Client.Read(processInstance.ProcessDefinition.IdRef, new ReadOptions()) as ProcessDefinitionData;

                    ProcessDefinitationDataModel processDefinitationDataModel = new ProcessDefinitationDataModel();
                    if (processDefinition != null)
                    {
                        processDefinitationDataModel.workflowTitle = processDefinition.Title;
                        processDefinitationDataModel.actions       = new List <ProcessInstancesDataModel>();
                        List <ActivityDefinitionData> listOfActivities = processDefinition.ActivityDefinitions.ToList();
                        ActivitySequence startActivitySequence         = new ActivitySequence {
                            sequenceNumber = 1
                        };
                        ProcessInstancesDataModel startProcessInstancesDataModel = new ProcessInstancesDataModel
                        {
                            actionTitle    = "",
                            actionType     = "Start",
                            actionSequence = 0,
                            actionTypeId   = 1,
                            nextSequences  = new List <ActivitySequence> {
                                startActivitySequence
                            }
                        };
                        processDefinitationDataModel.actions.Add(startProcessInstancesDataModel);
                        foreach (ActivityDefinitionData activityDefinitionData in processDefinition.ActivityDefinitions)
                        {
                            ProcessInstancesDataModel processInstancesDataModel =
                                new ProcessInstancesDataModel
                            {
                                actionTitle    = activityDefinitionData.Title,
                                isActive       = (activityDefinitionData.Id.Equals(currentActivityId)) ? true : false,
                                actionSequence =
                                    processDefinition.ActivityDefinitions.ToList().IndexOf(activityDefinitionData) +
                                    1
                            };
                            TridionActivityDefinitionData tridionActivityDefinitionData = Client.Read(activityDefinitionData.Id, new ReadOptions()) as TridionActivityDefinitionData;
                            processInstancesDataModel.nextSequences = new List <ActivitySequence>();
                            if (tridionActivityDefinitionData != null && tridionActivityDefinitionData.Script == "")
                            {
                                if (tridionActivityDefinitionData.NextActivityDefinitions.Count() > 1)
                                {
                                    processInstancesDataModel.actionType   = "Manual-Decision";
                                    processInstancesDataModel.actionTypeId = 4;
                                    foreach (var nextActivity in tridionActivityDefinitionData.NextActivityDefinitions)
                                    {
                                        foreach (ActivityDefinitionData item in listOfActivities)
                                        {
                                            if (item.Id.Equals(nextActivity.IdRef))
                                            {
                                                int findIndex = listOfActivities.IndexOf(item) + 1;
                                                ActivitySequence activitySequence =
                                                    new ActivitySequence {
                                                    sequenceNumber = findIndex
                                                };
                                                processInstancesDataModel.nextSequences.Add(activitySequence);
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    processInstancesDataModel.actionType   = "Manual";
                                    processInstancesDataModel.actionTypeId = 3;
                                    ActivitySequence activitySequence =
                                        new ActivitySequence
                                    {
                                        sequenceNumber = processInstancesDataModel.actionSequence + 1
                                    };
                                    processInstancesDataModel.nextSequences.Add(activitySequence);
                                }
                            }
                            else
                            {
                                if (tridionActivityDefinitionData != null && tridionActivityDefinitionData.NextActivityDefinitions.Count() > 1)
                                {
                                    processInstancesDataModel.actionType   = "Automatic-Decision";
                                    processInstancesDataModel.actionTypeId = 6;
                                    foreach (var nextActivity in tridionActivityDefinitionData.NextActivityDefinitions)
                                    {
                                        foreach (ActivityDefinitionData item in listOfActivities)
                                        {
                                            if (item.Id.Equals(nextActivity.IdRef))
                                            {
                                                int findIndex = listOfActivities.IndexOf(item) + 1;
                                                ActivitySequence activitySequence =
                                                    new ActivitySequence {
                                                    sequenceNumber = findIndex
                                                };
                                                processInstancesDataModel.nextSequences.Add(activitySequence);
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    processInstancesDataModel.actionType   = "Automatic";
                                    processInstancesDataModel.actionTypeId = 5;
                                    ActivitySequence activitySequence =
                                        new ActivitySequence {
                                        sequenceNumber = processInstancesDataModel.actionSequence + 1
                                    };
                                    processInstancesDataModel.nextSequences.Add(activitySequence);
                                }
                            }

                            processDefinitationDataModel.actions.Add(processInstancesDataModel);
                        }


                        ProcessInstancesDataModel sendProcessInstancesDataModel = new ProcessInstancesDataModel
                        {
                            actionTitle    = "",
                            actionType     = "Stop",
                            actionSequence = listOfActivities.Count() + 1,
                            actionTypeId   = 2,
                            nextSequences  = new List <ActivitySequence>()
                        };
                        processDefinitationDataModel.actions.Add(sendProcessInstancesDataModel);
                    }
                    var jsSerializer   = new JavaScriptSerializer();
                    var serializedJson = jsSerializer.Serialize(processDefinitationDataModel);
                    return(serializedJson);
                }
            }
            return(null);
        }