コード例 #1
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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public Response MakeRequest(WorkflowType selection)
        {
            string section = "Add Order(s)";

            Console.Clear();
            Console.Title = $"{Utilities.ProgramTitle} - {section}";
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Green);
            Console.SetCursorPosition((Console.WindowWidth - section.Length) / 2, Console.CursorTop);
            Console.WriteLine(section.Color("White"));
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Green);

            var request = new Request
            {
                Type     = WorkflowType.Add,
                Date     = Utilities.GetDate("Order Date", true),
                Customer = Utilities.GetString("Company Name", new Regex(@"^[\w ,.]{2,20}$"), false).Trim().ToTitle(),
                Product  = Utilities.GetString("Product Name", new Regex(@"^[\w ,.]{2,20}$"), false).Trim().ToTitle(),
                State    = Utilities.GetString("State", new Regex(@"^[A-Za-z]{2}$"), false).ToUpper(),
                Area     = Utilities.GetNumber <decimal>("Area of Material in Sq. Ft. (minimum: 100)", new Regex(@"^\d{3,7}(\.\d+)?$"))
            };

            IWorkflow flow     = WorkflowFactory.Create(selection);
            Response  response = flow.Execute(request);

            return(response);
        }
コード例 #3
0
ファイル: WorkflowInvoker.cs プロジェクト: richardhopton/Flux
 public static IDictionary<String, Object> Execute(IWorkflow workflow, IDictionary<String, Object> inputs)
 {
     using (var context = new Context(workflow))
     {
         foreach (var argument in workflow.Arguments)
         {
             if (((argument.Direction == Direction.In) ||
                  (argument.Direction == Direction.InOut)) &&
                 inputs.ContainsKey(argument.Name))
             {
                 context.SetValue(argument, inputs[argument.Name]);
             }
         }
         workflow.Execute(context);
         var outputs = new Dictionary<String, Object>();
         foreach (var argument in workflow.Arguments)
         {
             if ((argument.Direction == Direction.Out) ||
                 (argument.Direction == Direction.InOut))
             {
                 outputs[argument.Name] = context.GetValue(argument);
             }
         }
         return outputs;
     }
 }
コード例 #4
0
        public Response MakeRequest(WorkflowType selection)
        {
            string section = "Remove Order(s)";

            Console.Clear();
            Console.Title = $"{Utilities.ProgramTitle} - {section}";
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Red);
            Console.SetCursorPosition((Console.WindowWidth - section.Length) / 2, Console.CursorTop);
            Console.WriteLine(section.Color("White"));
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Red);

            var request = new Request
            {
                Type        = WorkflowType.Remove,
                Date        = Utilities.GetDate("Order Date", false),
                OrderNumber = Utilities.GetNumber <int>("Order Number", new Regex(@"^\d{1,5}$"))
            };

            IWorkflow flow     = WorkflowFactory.Create(WorkflowType.Find);
            Response  response = flow.Execute(request);

            if (response.Success)
            {
                Order removalTarget = response.Order;

                Utilities.PrintOrderDetails(removalTarget, WorkflowType.Remove);
                Console.WriteLine("Please confirm that you want to remove this order.");

                string polarOption = Utilities.GetString("(Y)es or (N)o",
                                                         new Regex(@"^Y(es)?$|^N(o)?$", RegexOptions.IgnoreCase), false).ToUpper();

                if (polarOption == "Y" || polarOption == "YES")
                {
                    flow     = WorkflowFactory.Create(selection);
                    response = flow.Execute(request);
                }
                else
                {
                    response.Success = false;
                    response.Message = $"Order #{removalTarget.OrderNumber} removal cancelled. Ending workflow...";
                    return(response);
                }
            }
            return(response);
        }
コード例 #5
0
 public void Execute(Document document)
 {
     if (IsMatchingWorkflow(document))
     {
         DoWorkflowExecute(document);
     }
     else if (_nextWorkflow != null)
     {
         _nextWorkflow.Execute(document);
     }
 }
コード例 #6
0
        private void SendSelected(Message message)
        {
            IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider;

            if (workflowProvider != null)
            {
                string    workflowID = message["wf"];
                string    str2       = message["ws"];
                IWorkflow workflow   = workflowProvider.GetWorkflow(workflowID);
                if (workflow != null)
                {
                    int  num  = 0;
                    bool flag = false;
                    foreach (string str3 in Context.ClientPage.ClientRequest.Form.Keys)
                    {
                        if ((str3 != null) && str3.StartsWith("check_"))
                        {
                            string   str4     = "hidden_" + str3.Substring(6);
                            string[] strArray = Context.ClientPage.ClientRequest.Form[str4].Split(new char[] { ',' });
                            Item     item     = Context.ContentDatabase.Items[strArray[0], Language.Parse(strArray[1]), Version.Parse(strArray[2])];
                            if (item != null)
                            {
                                WorkflowState state = workflow.GetState(item);
                                if (state.StateID == str2)
                                {
                                    try
                                    {
                                        workflow.Execute(message["command"], item, state.DisplayName, true, new object[0]);
                                    }
                                    catch (WorkflowStateMissingException)
                                    {
                                        flag = true;
                                    }
                                    num++;
                                }
                            }
                        }
                    }
                    if (flag)
                    {
                        SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]);
                    }
                    if (num == 0)
                    {
                        Context.ClientPage.ClientResponse.Alert("There are no selected items.");
                    }
                    else
                    {
                        Context.ClientPage.ClientResponse.SetLocation(string.Empty);
                    }
                }
            }
        }
コード例 #7
0
        [TestCase("1/1/2020", 99, false)] // order number not found
        public void CanRemoveOrderIfRequestDataCorrect(string date, int orderNumber, bool expectedResult)
        {
            IWorkflow workflow = WorkflowFactory.Create(WorkflowType.Find);

            var request = new Request
            {
                Type        = WorkflowType.Find,
                Date        = DateTime.Parse(date),
                OrderNumber = orderNumber
            };

            Response response = workflow.Execute(request);

            if (response.Success)
            {
                request.Type = WorkflowType.Remove;
                response     = workflow.Execute(request);

                Assert.AreEqual(expectedResult, response.Success);
            }
        }
コード例 #8
0
        private void AdvanceWorkflow(WorkflowPipelineArgs args, Item relatedItem, IWorkflow itemWorkflow)
        {
            try
            {
                itemWorkflow.Execute(args.CommandItem.ID.ToString(), 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);
            }
        }
コード例 #9
0
        [TestCase("2/2/2020", 9)] // unknown order number
        public void OrderNotFoundReturnsNull(string date, int orderNumber)
        {
            IWorkflow workflow = WorkflowFactory.Create(WorkflowType.Find);

            var request = new Request
            {
                Type        = WorkflowType.Find,
                Date        = DateTime.Parse(date),
                OrderNumber = orderNumber
            };

            Response response = workflow.Execute(request);

            Assert.IsNull(response.Order);
            Assert.IsFalse(response.Success);
        }
コード例 #10
0
        public void CanFindExistingOrder(string date, int orderNumber)
        {
            IWorkflow workflow = WorkflowFactory.Create(WorkflowType.Find);

            var request = new Request
            {
                Type        = WorkflowType.Find,
                Date        = DateTime.Parse(date),
                OrderNumber = orderNumber
            };

            Response response = workflow.Execute(request);

            Assert.IsNotNull(response.Order);
            Assert.IsTrue(response.Success);
            Assert.AreEqual(orderNumber, response.Order.OrderNumber);
        }
コード例 #11
0
        private void CopyPlan(Item item)
        {
            var eventItem = new Entities.EventItem(item);
            var planRoot  = (Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database).GetItem("{963678A4-869C-48AB-915B-D18C6D2AF357}");

            //TODO: Create more unike path
            var copiedPlanItem = eventItem.EventRoot.EngangementPlanItem.CopyTo(planRoot, item.Name);

            eventItem.PlanId = copiedPlanItem.ID.Guid;

            //Set the workflow state on the plan to deploy.
            // TODO: Move this to a deploy button instead!
            IWorkflow workflow = copiedPlanItem.State.GetWorkflow();

            Item workflowCommandItem = ItemUtil.GetContentItem(Guid.Parse("{4044A9C4-B583-4B57-B5FF-2791CB0351DF}"));

            if (workflow == null)
            {
                copiedPlanItem.Database.DataManager.SetWorkflowInfo(copiedPlanItem,
                                                                    new WorkflowInfo(workflowCommandItem.Parent.Parent.ID.ToString(), workflowCommandItem.Parent.ID.ToString()));

                workflow = copiedPlanItem.State.GetWorkflow();
            }

            WorkflowInfo workflowInfo = copiedPlanItem.Database.DataManager.GetWorkflowInfo(copiedPlanItem);

            if (workflowInfo == null || workflowInfo.StateID != workflowCommandItem.Parent.ID.ToString())
            {
                return;
            }

            WorkflowResult workflowResult = workflow.Execute("{4044A9C4-B583-4B57-B5FF-2791CB0351DF}", copiedPlanItem,
                                                             "Executed from Events save event", false, new object());


            PublishOptions options = new PublishOptions(copiedPlanItem.Database, Database.GetDatabase("web"), PublishMode.Smart, copiedPlanItem.Language, DateTime.Now)
            {
                Deep     = true,
                RootItem = copiedPlanItem
            };

            Publisher p = new Publisher(options);

            p.PublishAsync();
        }
コード例 #12
0
        [TestCase("2/2/2020", "Facebook", "Dirt", "PA", 200, false)] // product not found
        public void CanAddOrderIfRequestDataCorrect(string date, string customer, string product, string state,
            decimal area, bool expectedResult)
        {
            IWorkflow workflow = WorkflowFactory.Create(WorkflowType.Add);

            var request = new Request
            {
                Type     = WorkflowType.Add,
                Date     = DateTime.Parse(date),
                Customer = customer,
                Product  = product,
                State    = state,
                Area     = area
            };

            Response response = workflow.Execute(request);

            Assert.AreEqual(expectedResult, response.Success);
        }
コード例 #13
0
        [TestCase("9/9/2020", false, 0)] // unknown date
        public void CanDisplayOrderIfRequestDataCorrect(string date, bool expectedResult, int expectedOrderCount)
        {
            IWorkflow workflow = WorkflowFactory.Create(WorkflowType.Display);

            var request = new Request
            {
                Type = WorkflowType.Display,
                Date = DateTime.Parse(date)
            };

            Response response = workflow.Execute(request);

            Assert.AreEqual(expectedResult, response.Success);

            if (response.Success)
            {
                Assert.AreEqual(expectedOrderCount, response.Orders.Count);
            }
        }
コード例 #14
0
        public Response MakeRequest(WorkflowType selection)
        {
            string section = "Display Order(s)";

            Console.Clear();
            Console.Title = $"{Utilities.ProgramTitle} - {section}";
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Yellow);
            Console.SetCursorPosition((Console.WindowWidth - section.Length) / 2, Console.CursorTop);
            Console.WriteLine(section.Color("White"));
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Yellow);

            var request = new Request
            {
                Type = WorkflowType.Display,
                Date = Utilities.GetDate("Order Date", false)
            };

            IWorkflow flow     = WorkflowFactory.Create(selection);
            Response  response = flow.Execute(request);

            return(response);
        }
コード例 #15
0
        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;
        }
コード例 #16
0
 // Methods
 public void Comment(ClientPipelineArgs args)
 {
     if (!args.IsPostBack)
     {
         Context.ClientPage.ClientResponse.Input("Enter a comment:", string.Empty);
         args.WaitForPostBack();
     }
     else if (args.Result.Length > 0x7d0)
     {
         Context.ClientPage.ClientResponse.ShowError(new Exception(string.Format("The comment is too long.\n\nYou have entered {0} characters.\nA comment cannot contain more than 2000 characters.", args.Result.Length)));
         Context.ClientPage.ClientResponse.Input("Enter a comment:", string.Empty);
         args.WaitForPostBack();
     }
     else if (((args.Result != null) && (args.Result != "null")) && (args.Result != "undefined"))
     {
         IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider;
         if (workflowProvider != null)
         {
             IWorkflow workflow = workflowProvider.GetWorkflow(Context.ClientPage.ServerProperties["workflowid"] as string);
             if (workflow != null)
             {
                 Item item = Context.ContentDatabase.Items[Context.ClientPage.ServerProperties["id"] as string, Language.Parse(Context.ClientPage.ServerProperties["language"] as string), Version.Parse(Context.ClientPage.ServerProperties["version"] as string)];
                 if (item != null)
                 {
                     try
                     {
                         workflow.Execute(Context.ClientPage.ServerProperties["command"] as string, item, args.Result, true, new object[0]);
                     }
                     catch (WorkflowStateMissingException)
                     {
                         SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]);
                     }
                     Context.ClientPage.ClientResponse.SetLocation(string.Empty);
                 }
             }
         }
     }
 }
コード例 #17
0
        private void SendAll(Message message)
        {
            IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider;

            if (workflowProvider != null)
            {
                string    workflowID = message["wf"];
                string    stateID    = message["ws"];
                IWorkflow workflow   = workflowProvider.GetWorkflow(workflowID);
                if (workflow != null)
                {
                    WorkflowState state    = workflow.GetState(stateID);
                    DataUri[]     items    = this.GetItems(state, workflow);
                    string        comments = (state != null) ? state.DisplayName : string.Empty;
                    bool          flag     = false;
                    foreach (DataUri uri in items)
                    {
                        Item item = Context.ContentDatabase.Items[uri];
                        if (item != null)
                        {
                            try
                            {
                                workflow.Execute(message["command"], item, comments, true, new object[0]);
                            }
                            catch (WorkflowStateMissingException)
                            {
                                flag = true;
                            }
                        }
                    }
                    if (flag)
                    {
                        SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]);
                    }
                    Context.ClientPage.ClientResponse.SetLocation(string.Empty);
                }
            }
        }
コード例 #18
0
        private void Send(Message message)
        {
            IWorkflowProvider workflowProvider = Context.ContentDatabase.WorkflowProvider;

            if (workflowProvider != null)
            {
                string    workflowID = message["wf"];
                IWorkflow workflow   = workflowProvider.GetWorkflow(workflowID);
                if (workflow != null)
                {
                    Item item = Context.ContentDatabase.Items[message["id"], Language.Parse(message["la"]), Version.Parse(message["vs"])];
                    if (item != null)
                    {
                        if ((message["ui"] != "1") && !(message["suppresscomment"] == "1"))
                        {
                            Context.ClientPage.ServerProperties["id"]         = message["id"];
                            Context.ClientPage.ServerProperties["language"]   = message["la"];
                            Context.ClientPage.ServerProperties["version"]    = message["vs"];
                            Context.ClientPage.ServerProperties["command"]    = message["command"];
                            Context.ClientPage.ServerProperties["workflowid"] = workflowID;
                            Context.ClientPage.Start(this, "Comment");
                        }
                        else
                        {
                            try
                            {
                                workflow.Execute(message["command"], item, string.Empty, true, new object[0]);
                            }
                            catch (WorkflowStateMissingException)
                            {
                                SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.", new string[0]);
                            }
                            Context.ClientPage.ClientResponse.SetLocation(string.Empty);
                        }
                    }
                }
            }
        }
コード例 #19
0
 public static State Execute(this IWorkflow workflow)
 {
     return(workflow.Execute(new State()));
 }
コード例 #20
0
        protected void Run(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull((object)args, "args");
            bool flag1 = args.IsPostBack;

            if (args.Parameters["checkmodified"] == "1")
            {
                if (!flag1)
                {
                    if (Context.ClientPage.Modified)
                    {
                        SheerResponse.CheckModified(true);
                        args.WaitForPostBack();
                        return;
                    }
                }
                else if (args.Result == "cancel")
                {
                    return;
                }
                args.Parameters["checkmodified"] = (string)null;
                flag1 = false;
            }
            string comments = string.Empty;
            bool   flag2    = StringUtil.GetString(new string[1]
            {
                args.Parameters["ui"]
            }) != "1";
            bool flag3 = StringUtil.GetString(new string[1]
            {
                args.Parameters["suppresscomment"]
            }) == "1";

            if (!flag1 && flag2 && !flag3)
            {
                SheerResponse.Input("Enter a comment:", "");
                args.WaitForPostBack();
            }
            else
            {
                if (flag1)
                {
                    if (args.Result == "null")
                    {
                        return;
                    }
                    comments = args.Result;
                }
                IWorkflowProvider workflowProvider = Sitecore.Client.ContentDatabase.WorkflowProvider;
                if (workflowProvider != null)
                {
                    IWorkflow workflow = workflowProvider.GetWorkflow(args.Parameters["workflowid"]);
                    if (workflow != null)
                    {
                        Item obj = Sitecore.Client.ContentDatabase.Items[args.Parameters["id"],
                                                                         Language.Parse(args.Parameters["language"]),
                                                                         Sitecore.Data.Version.Parse(args.Parameters["version"])];
                        if (obj != null)
                        {
                            var workflowState = workflow.GetState(obj);
                            var repository    = new WorxboxItemsRepository(workflow);
                            try
                            {
                                if (repository.IsWorxboxItem(workflowState, new DataUri(obj.Uri)) && repository.GetWorkflowCommandIDs().Any(x => x == ID.Parse(args.Parameters["commandid"])))
                                {
                                    var items =
                                        repository.GetWorxboxItems(
                                            repository.GetWorxboxWorkflowStates(workflow)
                                            .First(x => x.WorkflowCommands.Any(y => y.CommandID == args.Parameters["commandid"])), obj);
                                    foreach (var compositeItem in items)
                                    {
                                        var compositeWorkflowResult = workflow.Execute(args.Parameters["commandid"], compositeItem, comments, true);
                                        if (!compositeWorkflowResult.Succeeded)
                                        {
                                            if (!string.IsNullOrEmpty(compositeWorkflowResult.Message))
                                            {
                                                SheerResponse.Alert(compositeWorkflowResult.Message);
                                            }
                                        }
                                    }
                                }

                                WorkflowResult workflowResult = workflow.Execute(args.Parameters["commandid"], obj, comments, true);
                                if (!workflowResult.Succeeded)
                                {
                                    if (!string.IsNullOrEmpty(workflowResult.Message))
                                    {
                                        SheerResponse.Alert(workflowResult.Message);
                                    }
                                }
                            }
                            catch (WorkflowStateMissingException ex)
                            {
                                SheerResponse.Alert("One or more items could not be processed because their workflow state does not specify the next step.");
                            }
                        }
                    }
                }
                Context.ClientPage.SendMessage((object)this, "item:refresh");
                SheerResponse.Eval("window.top.location.reload();");
            }
        }
コード例 #21
0
 public void ShowWorkflow(IWorkflow step)
 {
     step.Execute();
 }
コード例 #22
0
 public static void Run(IWorkflow newWorkflows)
 {
     newWorkflows.Execute();
 }
コード例 #23
0
ファイル: Flowable.cs プロジェクト: xiaoxiongnpu/Enflow
 public static Flowable <U> Flow <T, U>(this Flowable <T> flowable, IWorkflow <T, U> workflow)
 {
     return(!flowable.HasValue ? Flowable <U> .Nothing : workflow.Execute(flowable.Value).AsFlowable());
 }
コード例 #24
0
 public void Run(IWorkflow workflow)
 {
     workflow.Execute();
 }
コード例 #25
0
 public static T Execute <T>(this IWorkflow workflow, T input)
 {
     return(workflow.Execute <T, T>(input));
 }
コード例 #26
0
        public Response MakeRequest(WorkflowType selection)
        {
            string section = "Edit Order(s)";

            Console.Clear();
            Console.Title = $"{Utilities.ProgramTitle} - {section}";
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Blue);
            Console.SetCursorPosition((Console.WindowWidth - section.Length) / 2, Console.CursorTop);
            Console.WriteLine(section.Color("White"));
            Utilities.GenerateSeparator('=', Console.WindowWidth, ConsoleColor.Blue);

            var request = new Request
            {
                Type        = WorkflowType.Find,
                Date        = Utilities.GetDate("Order Date", false),
                OrderNumber = Utilities.GetNumber <int>("Order Number", new Regex(@"^\d{1,5}$"))
            };

            IWorkflow flow     = WorkflowFactory.Create(request.Type);
            Response  response = flow.Execute(request);

            if (response.Success)
            {
                Order editTarget = response.Order;
                Utilities.PrintOrderDetails(editTarget, WorkflowType.Edit);

                string newCustomer = Utilities.GetString("New Company Name", new Regex(@"^$|^[\w ,.]{2,20}$"), false).Trim().ToTitle(); // ?? editTarget.Customer;
                string newProduct  = Utilities.GetString("New Product Name", new Regex(@"^$|^[\w ,.]{2,20}$"), false).Trim().ToTitle(); // ?? editTarget.Product.ToString();
                string newState    = Utilities.GetString("New State", new Regex(@"^$|^[A-Za-z]{2}$"), false).ToUpper();                 // ?? editTarget.StateTax.StateAbbreviation).ToUpper();
                string newArea     = Utilities.GetString("New Area of Material (sq. ft.)", new Regex(@"^$|^\d{3,7}(\.\d+)?$"), false);

                request = new Request
                {
                    Type        = WorkflowType.Edit,
                    Date        = request.Date,
                    OrderNumber = request.OrderNumber,
                    Customer    = string.IsNullOrEmpty(newCustomer) ? editTarget.Customer : newCustomer,
                    Product     = string.IsNullOrEmpty(newProduct) ? editTarget.Product.ProductType : newProduct,
                    State       = string.IsNullOrEmpty(newState) ? editTarget.StateTax.StateAbbreviation : newState,
                    Area        = string.IsNullOrEmpty(newArea) ? editTarget.Area : decimal.Parse(newArea)
                };

                flow     = WorkflowFactory.Create(WorkflowType.Find);
                response = flow.Execute(request);

                Order updatedSample = new Order()
                {
                    OrderNumber = request.OrderNumber,
                    Customer    = request.Customer,
                    Area        = request.Area,
                    Product     = new Product()
                    {
                        ProductType = request.Product
                    },
                    StateTax = new StateTax()
                    {
                        StateAbbreviation = request.State
                    },
                    Total = (response.Order.Product.CostPerSquareFoot
                             + response.Order.Product.LaborCostPerSquareFoot)
                            * request.Area
                            * (1 + (response.Order.StateTax.TaxRate / 100))
                };

                Utilities.PrintOrderDetails(updatedSample, WorkflowType.Edit);

                Console.WriteLine("\nPlease confirm to keep these changes.");

                string polarOption = Utilities.GetString("(Y)es or (N)o",
                                                         new Regex(@"^Y(es)?$|^N(o)?$", RegexOptions.IgnoreCase), false).ToUpper();

                if (polarOption == "Y" || polarOption == "YES")
                {
                    flow     = WorkflowFactory.Create(selection);
                    response = flow.Execute(request);
                }
                else
                {
                    response.Success = false;
                    response.Message = $"Order #{editTarget.OrderNumber} editing cancelled. Ending workflow...";
                    return(response);
                }
            }
            return(response);
        }
コード例 #27
0
 /// <summary>Passes this object through the input workflow.</summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="candidate"></param>
 /// <param name="workflow"></param>
 /// <returns></returns>
 public static T Flow <T>(this T candidate, IWorkflow <T> workflow) where T : IModel <T>
 {
     workflow.Execute(candidate);
     return(candidate);
 }