Пример #1
0
        private void SwitchAgentType(AgentModel oldModel)
        {
            AgentModel newModel;

            switch (latestData.Item1.AgentType)
            {
            case AgentType.Agent:
                newModel = new AgentModel(oldModel.Name, oldModel.Namespace, oldModel.ConsumingMessages,
                                          oldModel.ProducedMessages, oldModel.IncomingEvents,
                                          oldModel.ProducedEvents,
                                          oldModel.Id);
                break;

            case AgentType.Interceptor:
                newModel = new InterceptorAgentModel(oldModel.Name, oldModel.Namespace, oldModel.ConsumingMessages,
                                                     oldModel.ProducedMessages, oldModel.IncomingEvents,
                                                     oldModel.ProducedEvents,
                                                     oldModel.Id);
                break;

            default:
                throw new InvalidOperationException($"Agent type {latestData.Item1.AgentType} is not known.");
            }

            OnMessage(new ModificationRequest(latestData.Item2, new Modification(ModificationType.Change, oldModel, newModel,
                                                                                 oldModel.ContainingPackage, new PackageAgentsProperty())));
        }
Пример #2
0
        public void ThenTheGraphContainsTheInterceptorAgent(string name)
        {
            scenarioContext.WaitForSilentPulse();

            GraphViewModel        viewModel = scenarioContext.Get <GraphViewModel>(StringConstants.GraphViewModelCreated);
            InterceptorAgentModel model     = viewModel.Graph.Nodes.Select(n => n.UserData)
                                              .OfType <InterceptorAgentModel>()
                                              .FirstOrDefault(i => i.Name == name);

            model.Should()
            .NotBeNull(
                $"the interceptor {name} was expected to exist in the graph. Available nodes are:{Environment.NewLine}{string.Join(Environment.NewLine, viewModel.Graph.Nodes.Select(n => n.UserData))}");
        }
Пример #3
0
        protected override void ExecuteCore(Message messageData)
        {
            ModifyModel    modifyModel = messageData.Get <ModifyModel>();
            CommunityModel model       = modifyModel.CurrentVersion;

            if (modifyModel.Modification.Target is not AgentModel agentModel)
            {
                return;
            }

            AgentModel updatedModel;

            switch (modifyModel.Modification.Property)
            {
            case AgentNameProperty _:
                updatedModel = agentModel.Clone(name: modifyModel.Modification.NewValue.AssertTypeOf <string>());
                break;

            case AgentNamespaceProperty _:
                updatedModel = agentModel.Clone(@namespace: modifyModel.Modification.NewValue.AssertTypeOf <string>());
                break;

            case AgentConsumingMessagesProperty _:
                updatedModel = agentModel.Clone(consumingMessages: ModifyMessages(modifyModel, agentModel.ConsumingMessages));
                break;

            case AgentProducedMessagesProperty _:
                updatedModel = agentModel.Clone(producedMessages: ModifyMessages(modifyModel, agentModel.ProducedMessages));
                break;

            case InterceptorAgentInterceptingMessagesProperty _:
                InterceptorAgentModel interceptorAgentModel = (InterceptorAgentModel)agentModel;
                updatedModel = interceptorAgentModel.Clone(ModifyMessages(modifyModel, interceptorAgentModel.InterceptingMessages));
                break;

            case AgentIncomingEventsProperty _:
                updatedModel = agentModel.Clone(incomingEvents: ModifyEvents(modifyModel, agentModel.IncomingEvents));
                break;

            case AgentProducedEventsProperty _:
                updatedModel = agentModel.Clone(producedEvents: ModifyEvents(modifyModel, agentModel.ProducedEvents));
                break;

            default:
                throw new InvalidOperationException($"Property {modifyModel.Modification.Property} unknown for agent model.");
            }

            CommunityModel updatedCommunity = new(model.GeneratorSettings,
                                                  ReplaceAgent(),
                                                  model.Messages);

            OnMessage(new ModificationResult(updatedCommunity, messageData));

            AgentModel[] ReplaceAgent()
            {
                AgentModel[] agents = new AgentModel[model.Agents.Length];
                Array.Copy(model.Agents, agents, agents.Length);
                int agentIndex = agents.TakeWhile(a => a.Id != agentModel.Id).Count();

                if (agentIndex == agents.Length)
                {
                    throw new InvalidOperationException("Could not find agent model in community.");
                }

                agents[agentIndex] = updatedModel;
                return(agents);
            }
        }