Beispiel #1
0
        private UndoCommand SpreadSheetUndo()
        {
            ICommandInterface command    = this.undoStack.Pop();
            UndoCommand       newCommand = command as UndoCommand;

            while (newCommand.Content == null)
            {
                command    = this.undoStack.Pop();
                newCommand = command as UndoCommand;
            }

            if (newCommand.CommandType == CommandType.Text)
            {
                ICommandInterface newRedoCommand = new RedoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Text);
                this.redoStack.Push(newRedoCommand);
            }
            else if (newCommand.CommandType == CommandType.Color)
            {
                ICommandInterface newRedoCommand = new RedoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Color.ToString());
                this.redoStack.Push(newRedoCommand);
            }

            command.Action();
            return(newCommand);
        }
Beispiel #2
0
 public Laboratory(ICommandInterface cli)
 {
     _cli      = cli;
     _animals  = new List <Animal>();
     _barker   = new Barker(_cli);
     _purrer   = new Purrer(_cli);
     _squeaker = new Squeaker(_cli);
 }
Beispiel #3
0
        /// <summary>
        /// The constructor for setting expected command ID and command interface.
        /// Sets self as listener for command in command interface.
        ///
        /// <param name="commandId">the command ID</param>
        /// <param name="commandInterface">the command interface</param>
        /// </summary>
        public BlockingCommandReceiver(ZToolCMD commandId, ICommandInterface commandInterface)
        {
            _getCommandLockObject = new object();

            _commandId        = commandId;
            _commandInterface = commandInterface;
            Log.Verbose("Waiting for asynchronous response message {}.", commandId);
            _commandInterface.AddAsynchronousCommandListener(this);
        }
        public StrategyMaker(ICommandInterface cli)
        {
            var barkStrategy = new BarkStrategy(cli);

            _typeToStrategy = new Dictionary <Type, ISoundStrategy>()
            {
                { typeof(IBarkable), barkStrategy }
            };
        }
Beispiel #5
0
        /// <summary>
        /// Service is being started
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            MasterServer.ParseCommandLineVars(String.Format("xmpms {0}", String.Join(" ", args)));

            ICommandInterface commandInterface = ModuleManager.GetModule <ICommandInterface>(typeof(TelnetCommandLine));

            if (!MasterServer.Start(null, commandInterface))
            {
                throw new InvalidOperationException("Error initialising service");
            }
        }
Beispiel #6
0
        /// <summary>
        /// Master server constructor. Initialises child objects, helpers and listeners
        /// </summary>
        /// <param name="statusDisplay"></param>
        /// <param name="commandInterface"></param>
        private MasterServer(IStatusDisplay statusDisplay, ICommandInterface commandInterface, ICDKeyValidator cdKeyValidator, IGameStatsLog gameStats, ILogWriter logWriter)
        {
            if (MasterServer.instance != null)
            {
                throw new InvalidOperationException("Attempted to create a Master Server instance whilst another instance was still active");
            }

            // Assign static references
            MasterServer.instance  = this;
            MasterServer.logWriter = logWriter;

            // Assign instance references
            this.statusDisplay    = statusDisplay;
            this.commandInterface = commandInterface;
            this.cdKeyValidator   = cdKeyValidator;
            this.gameStats        = gameStats;

            // Initialise the command interface if we have one
            if (commandInterface != null)
            {
                commandInterface.OnChange += new EventHandler(DisplayCommandInterface);
            }

            // GeoIP resolver is used to resolve IP addresses to locations
            geoIP = new GeoIP();

            // MD5 database is used to download new MD5 package data to connecting servers
            md5Manager = new MD5Manager();

            // IP ban manager used to ban clients from accessing the server
            banManager = new IPBanManager();

            // Create the Server List object
            serverList = new ServerList(this);

            // Create the web server
            webServer = new WebServer(banManager);

            // Initialise the status display module if we have one
            if (statusDisplay != null)
            {
                logBufferSize = statusDisplay.LogBufferSize;
                logBufferWrap = statusDisplay.LogBufferWrap;

                displayTimer = new Timer(new TimerCallback(this.Display));
                Display(null);
            }

            // Load the GeoIP database, MD5 database and ban list from the files (this happens last because they may take a while)
            geoIP.Load(MasterServer.Settings.GeoIPDataFile);
            md5Manager.Load(MasterServer.Settings.MD5DataFile);
            banManager.Load(MasterServer.Settings.BanListFile);
        }
Beispiel #7
0
        public NetworkManager(ICommandInterface commandInterface, NetworkMode mode, long timeout)
        {
            _announceListenerFilter.OnStateChanged += (object sender, DriverStatus status) => SetState(status);
            _afMessageListenerFilter = new AFMessageListenerFilter(_messageListeners);

            _mode             = mode;
            _commandInterface = commandInterface;

            Timeout             = DEFAULT_TIMEOUT;
            ResetTimeout        = RESET_TIMEOUT_DEFAULT;
            StartupTimeout      = STARTUP_TIMEOUT_DEFAULT;
            ResendOnlyException = RESEND_ONLY_EXCEPTION_DEFAULT;

            _state = DriverStatus.CLOSED;
        }
Beispiel #8
0
        public BaseCommand ExecuteCommand(ICommandInterface cmdInterface, ArgList argList)
        {
            var cmd = GetCommand(argList[0]);

            if (cmd == null)
            {
                return(null);
            }
            var cmdArgs = new CommandArguments {
                Interface = cmdInterface, Command = cmd, ArgumentList = argList
            };

            cmdInterface.OnCommandExecute(cmdArgs);
            cmd?.ExecuteCommand(cmdArgs);
            return(cmd);
        }
Beispiel #9
0
        /// <summary>
        /// Start the server instance
        /// </summary>
        /// <param name="statusDisplay">Status display object to use (can be null)</param>
        /// <param name="commandInterface">Command interface to use (can be null)</param>
        /// <param name="cdKeyValidator">CD key validator to use</param>
        /// <param name="connectionLogWriter">LogWriter writer to use</param>
        public static bool Start(IStatusDisplay statusDisplay, ICommandInterface commandInterface)
        {
            if (instance == null)
            {
                IGameStatsLog   gameStats;
                ICDKeyValidator cdKeyValidator;

                if (LoadConfiguredModules(out gameStats, out cdKeyValidator))
                {
                    log.Clear();
                    instance = new MasterServer(statusDisplay, commandInterface, cdKeyValidator, gameStats, logWriter);
                    instance.BeginListening();
                    return(true);
                }
            }

            return(false);
        }
Beispiel #10
0
        /// <summary>
        /// Spreadsheet undo execute.
        /// </summary>
        public void SpreadSheetUndo()
        {
            ICommandInterface command    = this.undoStack.Pop();
            UndoCommand       newCommand = command as UndoCommand;

            if (newCommand.CommandType == CommandType.Text)
            {
                ICommandInterface newRedoCommand = new RedoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Text);
                this.redoStack.Push(newRedoCommand);
            }
            else if (newCommand.CommandType == CommandType.Color)
            {
                ICommandInterface newRedoCommand = new RedoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Color.ToString());
                this.redoStack.Push(newRedoCommand);
            }

            command.Action();
        }
Beispiel #11
0
        /// <summary>
        /// Console Main function
        /// </summary>
        public static void ConsoleMain(string[] args)
        {
            IStatusDisplay    statusDisplay    = ModuleManager.GetModule <IStatusDisplay>(typeof(ConsoleStatusDisplay));
            ICommandInterface commandInterface = ModuleManager.GetModule <ICommandInterface>(typeof(ConsoleCommandLine));

            // Process the command-line options (allows settings overrides to be specified on the command line)
            ParseCommandLineVars(Environment.CommandLine);

            if (!Start(statusDisplay, commandInterface))
            {
                // Start was unsuccessful, release interface modules
                ModuleManager.ReleaseModule <IStatusDisplay>();
                ModuleManager.ReleaseModule <ICommandInterface>();
            }
            else
            {
                (commandInterface as ConsoleCommandLine).Run();
            }
        }
Beispiel #12
0
        private RedoCommand SpreadSheetRedo()
        {
            ICommandInterface command    = this.redoStack.Pop();
            RedoCommand       newCommand = command as RedoCommand;

            if (newCommand.CommandType == CommandType.Text)
            {
                ICommandInterface newUndoCommand = new UndoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Text);
                this.UndoStack.Push(newUndoCommand);
            }
            else if (newCommand.CommandType == CommandType.Color)
            {
                ICommandInterface newUndoCommand = new UndoCommand(newCommand.CommandType, newCommand.Cell, newCommand.Cell.Color.ToString());
                this.undoStack.Push(newUndoCommand);
            }

            command.Action();
            return(newCommand);
        }
Beispiel #13
0
        public void Simulator_ReturnPlaceRobotCommandObject()
        {
            //arrange
            TableTop     tt        = new TableTop(5, 5);
            ToyRobot     tr        = new ToyRobot();
            Simulator    simulator = new Simulator(tr, tt);
            CommandModel cm        = new CommandModel()
            {
                Command    = Command.PLACE,
                Coordinate = new Coordinate(3, 4),
                Facing     = Facing.NORTH
            };

            //act
            ICommandInterface placeRobotObject = simulator.Action(cm);

            //assert
            Assert.AreEqual(typeof(PlaceRobotCommand), placeRobotObject.GetType());
        }
Beispiel #14
0
        public void Simulator_ReturnMoveRobotCommandObject()
        {
            //arrange
            TableTop tt = new TableTop(5, 5);
            ToyRobot tr = new ToyRobot()
            {
                isRobotPlaced = true
            };
            Simulator    simulator = new Simulator(tr, tt);
            CommandModel cm        = new CommandModel()
            {
                Command = Command.MOVE
            };

            //act
            ICommandInterface MoveForwardCommandObject = simulator.Action(cm);

            //assert
            Assert.AreEqual(typeof(MoveForwardCommand), MoveForwardCommandObject.GetType());
        }
Beispiel #15
0
        /// <summary>
        /// Restart the master server instance
        /// </summary>
        public static void Restart()
        {
            if (instance != null)
            {
                if (service != null)
                {
                    MasterServer.LogMessage("Master server cannot be restarted in service mode, restart the service instead");
                }
                else if (instance.statusDisplay is ConsoleStatusDisplay && instance.commandInterface is ConsoleCommandLine)
                {
                    // Stop the server
                    instance.Shutdown();
                    instance = null;

                    // Release log writer, game stats, and validation modules
                    ReleaseModules();

                    // Clean up garbage
                    Console.WriteLine("Purging garbage...");
                    GC.Collect();

                    // Wait a couple of seconds to let any processes which haven't terminated yet finish closing
                    Console.WriteLine("Restarting master server...");
                    Thread.Sleep(2000);
                    Console.Clear();

                    // Get new status display and input modules
                    IStatusDisplay    statusDisplay    = ModuleManager.GetModule <IStatusDisplay>(typeof(ConsoleStatusDisplay));
                    ICommandInterface commandInterface = ModuleManager.GetModule <ICommandInterface>(typeof(ConsoleCommandLine));

                    // Start a new master server
                    Start(statusDisplay, commandInterface);
                }
            }

            if (shutdownThread != null)
            {
                shutdownThread = null;
            }
        }
Beispiel #16
0
        public CommandManager(ICommandInterface cmdDomain)
        {
            Owner = cmdDomain;
            foreach (var t in typeof(BaseCommand).Assembly.GetExportedTypes())
            {
                if (!t.IsSubclassOf(typeof(BaseCommand)) || t.HasAttribute <ManualCommandAttribute>())
                {
                    continue;
                }
                var ctors = t.GetConstructors();
                if (ctors.Length != 1)
                {
                    continue;
                }

                var parameters = ctors[0].GetParameters();
                if (parameters.Length != 1 || parameters[0].ParameterType != typeof(ICommandManager))
                {
                    continue;
                }

                RegisterCommand((BaseCommand)Activator.CreateInstance(t, this));
            }
        }
Beispiel #17
0
        protected override void Execute(ICommandInterface console, ArgList arguments)
        {
            var coreInterface = NodeRegistry.Get <Control>(nameof(GameFrontend));

            coreInterface.Visible = !coreInterface.Visible;
        }
Beispiel #18
0
        /// <summary>
        /// Shut down the master server instance
        /// </summary>
        private void Shutdown()
        {
            // End listen thread and close the listen sockets
            EndListening();

            // Web server
            if (webServer != null)
            {
                webServer.Dispose();
                webServer = null;
            }

            // Shut down the server list
            if (serverList != null)
            {
                serverList.Shutdown();
                serverList = null;
            }

            // Ban manager
            if (banManager != null)
            {
                banManager.Dispose();
                banManager = null;
            }

            // MD5 database
            if (md5Manager != null)
            {
                md5Manager.Dispose();
                md5Manager = null;
            }

            // GeoIP resolver
            if (geoIP != null)
            {
                geoIP.Dispose();
                geoIP = null;
            }

            // Display update timer
            if (displayTimer != null)
            {
                displayTimer.Change(Timeout.Infinite, Timeout.Infinite);
                displayTimer.Dispose();
                displayTimer = null;
            }

            // Shut down the status display if we have one
            if (statusDisplay != null)
            {
                statusDisplay.Notify("EXIT");
                ModuleManager.ReleaseModule <IStatusDisplay>();
                statusDisplay = null;
            }

            // Shut down the command interface if we have one
            if (commandInterface != null)
            {
                commandInterface.OnChange -= new EventHandler(DisplayCommandInterface);
                ModuleManager.ReleaseModule <ICommandInterface>();
                commandInterface = null;
            }
        }
Beispiel #19
0
 public Barker(ICommandInterface cli)
 {
     _cli = cli;
 }
Beispiel #20
0
 public void Bark(ICommandInterface cli)
 {
     cli.DisplayBark(Name);
 }
Beispiel #21
0
 void custCompletion_OnSelectItem(ICommandInterface cmd)
 {
     cmd.Execute();
 }
 public Purrer(ICommandInterface cli)
 {
     _cli = cli;
 }
Beispiel #23
0
 protected CompilerFixture(ICommandInterface commandInterface)
 {
     _commandInterfaceImplementation = commandInterface;
 }
 public BarkStrategy(ICommandInterface cli)
 {
     _cli = cli;
 }
 public Squeaker(ICommandInterface cli)
 {
     _cli = cli;
 }
Beispiel #26
0
 public void Squeak(ICommandInterface cli)
 {
     cli.DisplaySqueak(Name);
 }
Beispiel #27
0
 public void Purr(ICommandInterface cli)
 {
     cli.DisplayPurr(Name);
 }
 public BigMachine(ICommandInterface cli)
 {
     _cli           = cli;
     _strategyMaker = new StrategyMaker(_cli);
 }