private void LoadSimulationCommandExecute(object obj) { var dialog = new OpenFileDialog() { DefaultExt = ".xml", Filter = "XML Files (.xml)|*.xml" }; if (dialog.ShowDialog() != true) { return; } ChunkControls.Clear(); xmlPath = dialog.FileName; var xml = File.ReadAllText(xmlPath); ParserResult = simulationCaseParser.Parse(xml); SimulationName = ParserResult.Name; foreach (var chunk in ParserResult.Chunks) { var chunkVm = new ChunkControlViewModel(this); foreach (var tEvent in chunk.GetEvents()) { // var actor = ParserResult.Actors.Find(x => x.Id == tEvent.RaisedByActorId); // var role = GetActorRole(actor.ActorKindId); // var actorVm = new ActorViewModel(actor.Id,actor.FullName,role.Name, role.Id); var tInstance = ParserResult.ProcessInstance.GetTransactionById(tEvent.TransactionInstanceId); // var tKind = ProcessKind.GetTransactionById(tInstance.TransactionKindId); var eventVm = new EventControlViewModel(chunkVm) { CreationTime = tEvent.Created.ToString(XmlParsersConfig.DateTimeFormat), SelectedCompletion = tEvent.Completion }; // eventVm.SelectedTransactionInstance = new TransactionViewModel(tInstance, tKind.Name); eventVm.SetSelectedTransactionInstance(tInstance.Id); eventVm.SetSelectedActor(tEvent.RaisedByActorId); chunkVm.Events.Add(new EventControl(eventVm)); } ChunkControls.Add(new ChunkControl(chunkVm)); } }
public async Task Parse_Cases_ShouldReturnWithoutException(string caseName) { var assembly = typeof(SimulationCases).GetTypeInfo().Assembly; Stream stream = assembly.GetManifestResourceStream(caseName); string xml = ""; using (var reader = new StreamReader(stream)) xml = await reader.ReadToEndAsync(); var parser = new SimulationCaseParser(); Action parse = () => parser.Parse(xml); parse.Should().NotThrow <Exception>(); }
public override void Prepare() { var parser = new SimulationCaseParser(); var result = parser.Parse(xml); ProcessInstance = result.ProcessInstance; Name = result.Name; foreach (var actor in result.Actors) { Actors.Add(actor); } foreach (var chunk in result.Chunks) { AddChunk(chunk); } }
public void Parse_SmallCase_ShouldReturnCorrectData() { var expectedFirst = new TransactionEvent(1, 1, 1, new DateTime(2018, 2, 1, 9, 0, 0), TransactionCompletion.Requested); var path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Business/XmlTestFiles/ChunksExample.xml"); var xml = File.ReadAllText(path); var parser = new SimulationCaseParser(); var result = parser.Parse(xml); result.ProcessInstance.Should().NotBeNull(); var transactions = result.ProcessInstance.GetTransactions(); var chunks = result.Chunks; transactions.Should().NotBeEmpty(); chunks.Should().NotBeEmpty().And.HaveCount(2); var firstChunk = chunks[0]; var secondChunk = chunks[1]; var firstEvents = firstChunk.GetEvents(); var secondEvents = secondChunk.GetEvents(); firstEvents.Should().NotBeEmpty().And.HaveCount(1); secondEvents.Should().NotBeEmpty().And.HaveCount(1); var firstEvent = firstEvents.FirstOrDefault(); firstEvent.Should().NotBeNull().And.BeEquivalentTo( new TransactionEvent(1, 1, 1, new DateTime(2018, 2, 1, 9, 0, 0), TransactionCompletion.Requested) , options => options.Excluding(p => p.Id)); // firstEvent.Completion.Should().HaveFlag(TransactionCompletion.Requested); var secondEvent = secondEvents.FirstOrDefault(); secondEvent.Should().NotBeNull().And.BeEquivalentTo( new TransactionEvent(2, 2, 4, new DateTime(2018, 2, 1, 9, 1, 0), TransactionCompletion.Stated), options => options.Excluding(p => p.Id)); }