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 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)); }
ContractProcess GetExampleProcess() { return(ProcessFactory.FromXML(GetExampleBPMN()).First()); }