Esempio n. 1
0
        private void ClientOnReceivedStaticCommandResult(object sender, DynamicCommandEvent dynamicCommandEvent)
        {
            var client = (Client)sender;

            DynamicCommandManager.ReceivedResult(dynamicCommandEvent, client);
            Logger.Debug("Received dynamic command result ({0}) from client CI-{1}", dynamicCommandEvent.Status, client.Id);
        }
Esempio 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;
                    }
                }
            }
        }
Esempio n. 3
0
        public void AddCommandEvent(DynamicCommandEvent commandEvent)
        {
            lock (_listLock)
            {
                _cacheItems.Add(commandEvent);

                if (_isRunning)
                {
                    return;
                }
            }

            new Thread(Run)
            {
                IsBackground = true
            }.Start();
        }