示例#1
0
        public void SetNewDiagram()
        {
            var contract = new EditorContract()
            {
                Id        = "contract",
                Name      = "Contract",
                Processes = new ContractProcesses()
                {
                }
            };

            contract.ReplaceSafely(BPMNProcessDiagram.FromXml(GetExampleBPMN()));
            contract.Processes.Main.UserActivities.First().Form = new ContractForm()
            {
                Id = "XXX"
            };
            contract.Processes.Main.BusinessActivities.First().Diagram = DMNProcessDiagram.FromXml("YYY");
            contract.Processes.Main.ScriptActivities.First().Script    = "ZZZ";
            contract.Processes.Main.StartEvents.First().StartForm      = new ContractForm()
            {
                Id = "XXXX"
            };

            contract.Processes.Diagram = BPMNProcessDiagram.FromXml(GetExampleBPMN());

            //Check
            Assert.AreEqual("XXXX", contract.Processes.Main.StartEvents.First().StartForm.Id);
            Assert.AreEqual("XXX", contract.Processes.Main.UserActivities.First().Form.Id);
            Assert.AreEqual("YYY", contract.Processes.Main.BusinessActivities.First().Diagram.DiagramXML);
            Assert.AreEqual("ZZZ", contract.Processes.Main.ScriptActivities.First().Script);
            AssertExampleProcess(contract.Processes.Main);
        }
示例#2
0
 public void ValidatePotencialDiagram_NoEndEvents()
 {
     try
     {
         contract.ValidatePotentialDiagram(BPMNProcessDiagram.FromXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?> <bpmn:definitions xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:bpmn=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\" xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\" id=\"Definitions_0eb01sb\" targetNamespace=\"http://bpmn.io/schema/bpmn\" exporter=\"bpmn-js (https://demo.bpmn.io)\" exporterVersion=\"6.3.0\"> <bpmn:process id=\"Process_1sge6c9\" isExecutable=\"false\"> <bpmn:startEvent id=\"StartEvent_0p6bth7\" /> </bpmn:process> <bpmndi:BPMNDiagram id=\"BPMNDiagram_1\"> <bpmndi:BPMNPlane id=\"BPMNPlane_1\" bpmnElement=\"Process_1sge6c9\"> <bpmndi:BPMNShape id=\"_BPMNShape_StartEvent_2\" bpmnElement=\"StartEvent_0p6bth7\"> <dc:Bounds x=\"156\" y=\"81\" width=\"36\" height=\"36\" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id=\"Event_0n2mpqp_di\" bpmnElement=\"Event_0n2mpqp\"> <dc:Bounds x=\"272\" y=\"81\" width=\"36\" height=\"36\" /> </bpmndi:BPMNShape> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn:definitions> "));
         Assert.Fail();
     }
     catch (AtLeastOneEndEventRequiredException)
     {
     }
 }
示例#3
0
        public void BPMNProcessReplaceSafely_NoRisks()
        {
            var contract = new EditorContract()
            {
                Processes = new ContractProcesses()
                {
                }
            };

            contract.ReplaceSafely(BPMNProcessDiagram.Default());

            Assert.IsFalse(contract.AnalyzeIntegrityWhenReplacedWith(BPMNProcessDiagram.Default()).HasDeleteRisks());
        }
示例#4
0
        public void BPMNProcessReplaceSafely()
        {
            var contract = new EditorContract()
            {
                Processes = new ContractProcesses()
                {
                }
            };

            contract.ReplaceSafely(BPMNProcessDiagram.Default());

            Assert.AreEqual(0, contract.AnalyzeIntegrityWhenReplacedWith(BPMNProcessDiagram.FromXml(GetExampleBPMN())).DeleteRisks.Count());

            contract.ReplaceSafely(BPMNProcessDiagram.FromXml(GetExampleBPMN()));

            Assert.AreEqual(3, contract.AnalyzeIntegrityWhenReplacedWith(BPMNProcessDiagram.Default()).DeleteRisks.Count());
        }
        public async Task SaveAsync()
        {
            try
            {
                var xml = await Mediator.GetDiagramXML(Id);

                var newDiagram = BPMNProcessDiagram.FromXml(xml);
                diagramToSave = newDiagram;

                //Validate
                Contract.ValidatePotentialDiagram(newDiagram);
                saveIntegrityResult = Contract.AnalyzeIntegrityWhenReplacedWith(newDiagram);

                //Show dialog
                await saveDialogWindow.OpenAsync();
            }
            catch (Exception e)
            {
                alertController.AddAlert("Confirm unsuccessful: " + e.Message, AlertScheme.Danger);
            }
        }
        public static ContractProcess ValidatePotentialDiagram(this EditorContract contract, BPMNProcessDiagram newDiagram)
        {
            if (newDiagram == null)
            {
                throw new ArgumentNullException(nameof(newDiagram));
            }

            var processes = ProcessFactory.FromXML(newDiagram.DiagramXML);

            if (processes.Count() != 1)
            {
                throw new InvalidProcessCountException("The diagram must contain exactly one process");
            }

            var newMainProcess = processes.First();

            if (!newMainProcess.StartEvents.Any())
            {
                throw new AtLeastOneStartEventRequiredException("At least one start event is required");
            }

            if (!newMainProcess.EndEvents.Any())
            {
                throw new AtLeastOneEndEventRequiredException("At least one end event is required");
            }

            return(newMainProcess);
        }
        public static void ReplaceSafely(this EditorContract contract, BPMNProcessDiagram newDiagram)
        {
            if (contract == null)
            {
                throw new ArgumentNullException(nameof(contract));
            }

            if (newDiagram == null)
            {
                throw new ArgumentNullException(nameof(newDiagram));
            }

            if (BPMNProcessDiagram.IsNullOrEmpty(newDiagram))
            {
                contract.Processes.Diagram = BPMNProcessDiagram.Default();
                contract.Processes.Main    = ContractProcess.Empty();
                return;
            }

            var newMainProcess = contract.ValidatePotentialDiagram(newDiagram);

            if (contract.Processes.Main != null)
            {
                contract.AnalyzeIntegrityWhenReplacedWith(newDiagram).ResolveDeleteRisks();
            }

            var oldDiagram = contract.Processes.Diagram;

            contract.Processes.Diagram = newDiagram;

            var oldProcess = contract.Processes.Main;
            var newProcess = newMainProcess;

            contract.Processes.Main = newProcess;

            if (newProcess == null || oldProcess == null)
            {
                return;
            }

            //Update activities
            UpdateMainProcessActivities(oldProcess.ScriptActivities, newProcess.ScriptActivities);
            UpdateMainProcessActivities(oldProcess.BusinessActivities, newProcess.BusinessActivities);
            UpdateMainProcessActivities(oldProcess.UserActivities, newProcess.UserActivities);

            //Update start events
            UpdateMainProcessActivities(oldProcess.StartEvents, newProcess.StartEvents);


            //Add migration
            contract.GetMigrator().Notify(
                () => contract.Processes.Diagram,
                () =>
            {
                //Up
                contract.Processes.Diagram = newDiagram;
                contract.Processes.Main    = newProcess;
            },
                () =>
            {
                //Down
                contract.Processes.Diagram = oldDiagram;
                contract.Processes.Main    = oldProcess;
            }, MigratorMode.EveryChange);
        }
        public static ContractIntegrityAnalysisResult AnalyzeIntegrityWhenReplacedWith(this EditorContract contract, BPMNProcessDiagram newDiagram)
        {
            if (contract == null)
            {
                throw new ArgumentNullException(nameof(contract));
            }

            if (newDiagram == null)
            {
                throw new ArgumentNullException(nameof(newDiagram));
            }

            var deleteRisks      = new List <ContractIntegrityAnalysisDeleteCase>();
            var childrenAnalyses = new List <ContractIntegrityAnalysisResult>();

            //Figure out activities that will be deleted
            var oldActivities = new List <ContractActivity>()
                                .Concat(contract.Processes.Main.BusinessActivities)
                                .Concat(contract.Processes.Main.UserActivities)
                                .Concat(contract.Processes.Main.ScriptActivities)
                                .ToList();


            var newMainProcess = ProcessFactory.FromXML(newDiagram.DiagramXML).First();
            var newActivities  = new List <ContractActivity>()
                                 .Concat(newMainProcess.BusinessActivities)
                                 .Concat(newMainProcess.UserActivities)
                                 .Concat(newMainProcess.ScriptActivities)
                                 .ToList();

            var deletedActivities = new List <ContractActivity>();

            foreach (var oldActivity in oldActivities)
            {
                var linkedNewActivity = newActivities.Where(e => e.Id == oldActivity.Id).SingleOrDefault();
                if (linkedNewActivity == null)
                {
                    deletedActivities.Add(oldActivity);
                }
            }

            //Create delete risks
            foreach (var deletedActivity in deletedActivities)
            {
                deleteRisks.Add(new ContractIntegrityAnalysisDeleteCase($"Activity {deletedActivity.Name} will be deleted", () => { }));
            }

            //Add children risks
            foreach (var deletedActivity in deletedActivities)
            {
                childrenAnalyses.Add(contract.AnalyzeIntegrityOf(deletedActivity));
            }

            return(new ContractIntegrityAnalysisResult(deleteRisks, childrenAnalyses));
        }
示例#9
0
        public void SerializationWithDiagram()
        {
            var contract = new EditorContract()
            {
                Id        = "contract",
                Name      = "Contract",
                DataModel = GetExampleDataModel(),
                Processes = new ContractProcesses()
                {
                }
            };

            contract.ReplaceSafely(BPMNProcessDiagram.FromXml(GetExampleBPMN()));
            contract.Processes.Main.UserActivities.First().Form = new ContractForm()
            {
                Id = "XXX"
            };
            contract.Processes.Main.BusinessActivities.First().Diagram = DMNProcessDiagram.FromXml("YYY");
            contract.Processes.Main.ScriptActivities.First().Script    = "ZZZ";
            contract.Processes.Main.StartEvents.First().StartForm      = new ContractForm()
            {
                Id = "XXXX"
            };

            contract.Processes.Main.StartEvents.First().StartForm.Fields.Add(new ContractFormField()
            {
                PropertyBinding = new ContractPropertyBinding()
                {
                    Property = contract.DataModel.Entities[0].PrimitiveProperties[0]
                }
            });
            contract.Processes.Main.UserActivities.First().Form.Fields.Add(new ContractFormField()
            {
                PropertyBinding = new ContractPropertyBinding()
                {
                    Property = contract.DataModel.Entities[0].PrimitiveProperties[0]
                }
            });

            //Serialize
            var serializedContract = EditorContractXML.To(contract);

            //Deserialize
            var deserializedContract = EditorContractXML.From(serializedContract);

            //Check
            Assert.AreEqual("XXXX", contract.Processes.Main.StartEvents.First().StartForm.Id);
            Assert.AreEqual("XXX", contract.Processes.Main.UserActivities.First().Form.Id);
            Assert.AreEqual("YYY", contract.Processes.Main.BusinessActivities.First().Diagram.DiagramXML);
            Assert.AreEqual("ZZZ", contract.Processes.Main.ScriptActivities.First().Script);

            Assert.AreEqual(contract.DataModel.Entities[0].PrimitiveProperties[0],
                            contract.Processes.Main.StartEvents.First().StartForm.Fields[0].PropertyBinding.Property);
            Assert.AreEqual(contract.DataModel.Entities[0].PrimitiveProperties[0],
                            contract.Processes.Main.UserActivities.First().Form.Fields[0].PropertyBinding.Property);


            Assert.AreEqual("contract", deserializedContract.Id);
            Assert.AreEqual("Contract", deserializedContract.Name);
            AssertExampleDataModel(deserializedContract.DataModel);
            Assert.AreEqual(GetExampleBPMN(), deserializedContract.Processes.Diagram.DiagramXML);
            AssertExampleProcess(contract.Processes.Main);
        }
示例#10
0
 public void ValidatePotencialDiagram_OK()
 {
     contract.ValidatePotentialDiagram(BPMNProcessDiagram.Default());
     contract.ValidatePotentialDiagram(BPMNProcessDiagram.FromXml(GetExampleBPMN()));
 }