Ejemplo n.º 1
0
        public void ClientDisconnected(Client client)
        {
            lock (_activeCommandsLock)
                for (int i = ActiveCommands.Count - 1; i >= 0; i--)
                {
                    var activeCommand = ActiveCommands[i];

                    lock (activeCommand.ClientsLock)
                        if (activeCommand.Clients.Contains(client))
                        {
                            activeCommand.Clients.Remove(client);
                            ActiveCommandEventManager.RemoveClient(activeCommand, client);
                        }

                    if (activeCommand.Clients.Count == 0)
                    {
                        ActiveCommands.Remove(activeCommand);
                        if (activeCommand.DynamicCommand.Status == DynamicCommandStatus.Active)
                        {
                            //don't change the status when stopped
                            activeCommand.DynamicCommand.Status = DynamicCommandStatus.Done;
                        }
                        ActiveCommandEventManager.RemoveActiveCommand(activeCommand);
                    }
                }
        }
Ejemplo n.º 2
0
        public void ReceivedResult(DynamicCommandEvent dynamicCommandEvent, Client client)
        {
            _cacheManager.AddCommandEvent(dynamicCommandEvent);

            if (dynamicCommandEvent.Status == ActivityType.Active || dynamicCommandEvent.Status == ActivityType.Stopped)
            {
                lock (_activeCommandsLock)
                {
                    var activeCommand =
                        ActiveCommands.FirstOrDefault(x => x.DynamicCommand.Id == dynamicCommandEvent.DynamicCommand);
                    if (activeCommand == null)
                    {
                        var dynamicCommand =
                            _databaseManager.GetDynamicCommandById(dynamicCommandEvent.DynamicCommand);
                        if (dynamicCommand == null)
                        {
                            //when there is no command on this server with the id, we stop it because it may be removed by an administrator
                            client.StopActiveCommand(dynamicCommandEvent.DynamicCommand);
                            return;
                        }

                        ActiveCommands.Add(activeCommand = new ActiveCommandInfo(dynamicCommand));
                    }

                    switch (dynamicCommandEvent.Status)
                    {
                    case ActivityType.Active:
                        lock (activeCommand.ClientsLock)
                            activeCommand.Clients.Add(client);
                        ActiveCommandEventManager.AddClient(activeCommand, client);
                        CheckClientExecuteActiveCommand(activeCommand, client);
                        break;

                    case ActivityType.Stopped:
                        lock (activeCommand.ClientsLock)
                            activeCommand.Clients.Remove(client);
                        ActiveCommandEventManager.RemoveClient(activeCommand, client);

                        if (activeCommand.Clients.Count == 0)
                        {
                            ActiveCommands.Remove(activeCommand);
                            if (activeCommand.DynamicCommand.Status == DynamicCommandStatus.Active)
                            {
                                //don't change the status when stopped
                                activeCommand.DynamicCommand.Status = DynamicCommandStatus.Done;
                            }
                            ActiveCommandEventManager.RemoveActiveCommand(activeCommand);
                        }
                        break;
                    }
                }
            }
        }