Example #1
0
        public virtual RegisteredSpawner CreateSpawner(IPeer peer, SpawnerOptions options)
        {
            var spawner = new RegisteredSpawner(GenerateSpawnerId(), peer, options);

            if (!(peer.GetProperty((int)PeerPropertyKeys.RegisteredSpawners) is Dictionary <int, RegisteredSpawner> peerSpawners))
            {
                // If this is the first time registering a spawners

                // Save the dictionary
                peerSpawners = new Dictionary <int, RegisteredSpawner>();
                peer.SetProperty((int)PeerPropertyKeys.RegisteredSpawners, peerSpawners);

                peer.Disconnected += OnRegisteredPeerDisconnect;
            }

            // Add a new spawner
            peerSpawners[spawner.SpawnerId] = spawner;

            // Add the spawner to a list of all spawners
            Spawners[spawner.SpawnerId] = spawner;

            // Invoke the event
            SpawnerRegistered?.Invoke(spawner);

            return(spawner);
        }
Example #2
0
        /// <summary>
        /// Requests a specific spawner to spawn a process
        /// </summary>
        /// <param name="properties"></param>
        /// <param name="customArgs"></param>
        /// <param name="spawner"></param>
        /// <returns></returns>
        public SpawnTask Spawn(RegisteredSpawner spawner, Dictionary <string, string> properties, string customArgs)
        {
            var task = new SpawnTask(GenerateSpawnTaskId(), spawner, properties, customArgs);

            _spawnTasks[task.SpawnId] = task;

            spawner.AddTaskToQueue(task);

            _logger.Debug("Spawner was found, and spawn task created: " + task);

            return(task);
        }
Example #3
0
        public SpawnTask(int spawnId, RegisteredSpawner spawner,
                         Dictionary <string, string> properties, string customArgs)
        {
            SpawnId = spawnId;

            Spawner    = spawner;
            Properties = properties;
            CustomArgs = customArgs;

            UniqueCode        = Util.CreateRandomString(6);
            WhenDoneCallbacks = new List <Action <SpawnTask> >();
        }
Example #4
0
        private void DestroySpawner(RegisteredSpawner spawner)
        {
            var peer = spawner.Peer;

            if (peer != null &&
                peer.GetProperty((int)PeerPropertyKeys.RegisteredSpawners) is Dictionary <int, RegisteredSpawner>
                peerRooms)
            {
                peerRooms.Remove(spawner.SpawnerId);
            }

            _spawners.Remove(spawner.SpawnerId);

            _logger.Info($"Spawner disconnected. ID: {spawner.SpawnerId}");
        }
Example #5
0
        public void DestroySpawner(RegisteredSpawner spawner)
        {
            var peer = spawner.Peer;

            if (peer != null && peer.GetProperty((int)PeerPropertyKeys.RegisteredSpawners) is Dictionary <int, RegisteredSpawner> peerRooms)
            {
                // Remove the spawner from peer
                peerRooms.Remove(spawner.SpawnerId);
            }

            // Remove the spawner from all spawners
            Spawners.Remove(spawner.SpawnerId);

            _logger.Info($"Spawner disconnected. ID: {spawner.SpawnerId}");
            // Invoke the event
            SpawnerDestroyed?.Invoke(spawner);
        }