Esempio n. 1
0
        /// <summary>
        /// Adds a core to the simulation
        /// </summary>
        /// <param name="core">CoflnetCore to add </param>
        public SimulationInstance AddCore(CoflnetCore core)
        {
            var newInstance = new SimulationInstance()
            {
                core = core
            };

            this.simulationInstances.Add(core.Id, newInstance);
            return(newInstance);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new Client to the simulation
        /// </summary>
        /// <param name="id">Id of the client</param>
        /// <param name="createDevice">If an instance of <see cref="CoflnetUser"/> should be created on  the server as well</param>
        public SimulationInstance AddClientCore(EntityId id, bool createDevice = false)
        {
            var newClientCore = new ClientCoreProxy(new CommandController(CoreCommands), ClientSocket.Instance, new ClientReferenceManager($"res{simulationInstances.Count}"))
            {
                Id = id
            };

            SetCoreForService(newClientCore);
            // for Services using the default Instance
            ClientCore.Instance = newClientCore;

            var addedInstance = AddCore(newClientCore);

            if (createDevice)
            {
                // create and add the user server and client side
                var device = new Device()
                {
                    Id = id
                };
                SimulationInstance server;
                if (simulationInstances.TryGetValue(id.FullServerId, out server))
                {
                    server.core.EntityManager.AddReference(device);
                }
                if (!newClientCore.EntityManager.AddReference(device))
                {
                    throw new Exception($"failed to add device {device.Id}");
                }
            }

            // activate commands
            newClientCore.SetCommandsLive();
            lastAddedClient = addedInstance;

            return(addedInstance);
        }