コード例 #1
0
        public void ExecuteCommand(Guid guid, byte[] parameter, IFeedbackFactory feedbackFactory)
        {
            StaticCommand staticCommand;

            if (StaticCommands.TryGetValue(guid, out staticCommand))
            {
                staticCommand.Execute(new CommandParameter(parameter), feedbackFactory, _clientInfo);
            }
        }
コード例 #2
0
        private void ExecutePotentialCommand(PotentialCommand potentialCommand)
        {
            StaticCommand staticCommand;

            if (StaticCommands.TryGetValue(potentialCommand.CommandId, out staticCommand))
            {
                var activeStaticCommand = staticCommand as ActiveStaticCommand;
                if (activeStaticCommand != null)
                {
                    //create a new instance because the commands are session based
                    activeStaticCommand = (ActiveStaticCommand)Activator.CreateInstance(activeStaticCommand.GetType());
                    activeStaticCommand.ExecutionStopped += ActiveStaticCommandOnExecutionStopped;

                    //the command is automatically removed
                    if (!_activeCommandStopScheduler.ExecuteActiveCommand(potentialCommand, activeStaticCommand))
                    {
                        return;
                    }

                    lock (_activeCommandsLock)
                        ActiveCommands.Add(potentialCommand, activeStaticCommand);

                    var serverConnection = (ServerConnection)_clientInfo.ServerConnection;
                    lock (serverConnection.SendLock)
                    {
                        DynamicCommandFeedbackFactory.PushEvent(serverConnection.BinaryWriter,
                                                                potentialCommand.CallbackId, ActivityType.Active, null);
                    }

                    new Thread(() =>
                    {
                        try
                        {
                            activeStaticCommand.Execute(new CommandParameter(potentialCommand.Parameter), null,
                                                        _clientInfo);
                        }
                        catch (Exception)
                        {
                            ActiveStaticCommandOnExecutionStopped(activeStaticCommand, EventArgs.Empty);
                        }
                    })
                    {
                        IsBackground = true
                    }.Start();
                }
                else
                {
                    var feedbackFactory =
                        new DynamicCommandFeedbackFactory((ServerConnection)_clientInfo.ServerConnection,
                                                          potentialCommand.CallbackId);

                    new Thread(() =>
                    {
                        try
                        {
                            staticCommand.Execute(new CommandParameter(potentialCommand.Parameter), feedbackFactory,
                                                  _clientInfo);
                        }
                        catch (Exception ex)
                        {
                            feedbackFactory.Failed("Critical error: " + ex.Message);
                        }

                        //that will execute anyways only if it wasn't pushed yet
                        feedbackFactory.Succeeded();
                    })
                    {
                        IsBackground = true
                    }.Start();
                }
            }
        }