static void Main(string[] args) { int result = 2; while (result == 2) { IGarageManager garageManager = new GarageManagerFactory().Create(); IConsoleInputOutput consoleInputOutput = new ConsoleInputOutput(); IVehicleManager vehicleManager = VehicleManagerFactory.Create(garageManager); IVehicleParser vehicleParser = new VehicleParser(); IGarageParser garageParser = new GarageParser(); IFileInputOutput file = new FileInputOutput(); ICsvImporter csvImporter = new CsvImporter(file, vehicleParser); ICommandExecuterFactory commandExecuterFactory = new CommandExecuterFactory(vehicleManager, consoleInputOutput, vehicleParser, garageManager, garageParser, csvImporter, file); var commandLineParser = new CommandLineParser(consoleInputOutput, CommandDictionaryFactory.Create(), vehicleManager, commandExecuterFactory); while ((result = commandLineParser.ReadCommand()) == 1) { ; } if (result == 2) { consoleInputOutput.WriteInfo("Daten werden wiederhergestellt."); } } }
/// <summary> /// Reads the string representation of a number from the standard input stream /// and converts it to for the specified type. /// </summary> /// <param name="reader">The string representation of a number from the standard input stream.</param> /// <returns> The the specified type of inValue string representation.</returns> public static T Read <T>(this ConsoleInputOutput reader) { string inValue = Console.ReadLine(); TypeConverter converter = TypeDescriptor.GetConverter(typeof(T)); return((T)converter.ConvertFromString(null, CultureInfo.InvariantCulture, inValue)); }
public void HumanWinsWithBlackJackEnum() { var dealerCards = new DeckMock(new[] { new Card(CardFace.Eight, Suit.Hearts), new Card(CardFace.Ten, Suit.Diamonds), }); var playerCards = new DeckMock(new[] { new Card(CardFace.Ace, Suit.Hearts), new Card(CardFace.Jack, Suit.Diamonds), }); var playerResponse = new TestResponder(new [] { StayResponse, }); var player = new Human(playerCards, playerResponse); var soft17Player = new Soft17Player(dealerCards); var console = new ConsoleInputOutput(); var blackjack = new BlackJack(new List <Player> { player }, console, soft17Player); blackjack.StartGame(); Assert.AreEqual(GameStatus.BlackJack, player.GameStatus); }
/// <summary> /// Retries the DoLogin method until success or fail conditions have been met. /// </summary> /// <param name="retryWait">The TimeSpan in which to wait between requests.</param> /// <param name="retryLimit">The max number of requests to perform before failing.</param> /// <param name="username">Username to use</param> /// <param name="password">Password to use</param> /// <param name="machineAuth">Steam machine auth string. /// You should save Web.SteamMachineAuth after the code has been entered and the request has /// been successful and pass it to DoLogin in future attempts to login. /// This field can be left blank, but if the account is SteamGuard protected /// it will ask you for a new code every time.</param> /// <returns></returns> public Account RetryDoLogin(TimeSpan retryWait, int retryLimit, string username, string password, string machineAuth = "", IUserInputOutputHandler userInputOutput = null) { if (userInputOutput == null) { userInputOutput = new ConsoleInputOutput(); } int retries = 0; Account account = null; do { try { account = DoLogin(username, password, machineAuth, userInputOutput); } catch (WebException) { retries++; if (retries == retryLimit) { throw; } Thread.Sleep(retryWait); } } while (account == null); return(account); }
/// <summary> /// Retries the DoLogin method until success or fail conditions have been met. /// </summary> /// <param name="retryWait">The TimeSpan in which to wait between requests.</param> /// <param name="retryLimit">The max number of requests to perform before failing.</param> /// <param name="username">Username to use</param> /// <param name="password">Password to use</param> /// <param name="machineAuth">Steam machine auth string. /// You should save Web.SteamMachineAuth after the code has been entered and the request has /// been successful and pass it to DoLogin in future attempts to login. /// This field can be left blank, but if the account is SteamGuard protected /// it will ask you for a new code every time.</param> /// <returns></returns> public Account RetryDoLogin(TimeSpan retryWait, int retryLimit, string username, string password, string machineAuth = "", IUserInputOutputHandler userInputOutput = null) { if (userInputOutput == null) { userInputOutput = new ConsoleInputOutput(); } int retries = 0; Account account = null; do { try { account = DoLogin(username, password, machineAuth, userInputOutput); } catch (WebException) { retries++; if (retries == retryLimit) { throw; } userInputOutput.OutputMessage("Connection failed... retrying in: " + retryWait.Milliseconds + "ms. Retries: " + retries); Thread.Sleep(retryWait); } } while (account == null); return(account); }
public ConsoleInputOutputTests() { this.originalOutputWriter = Console.Out; this.mockedOutputWriter = new StringWriter(); Console.SetOut(this.mockedOutputWriter); this.consoleInputOutput = new ConsoleInputOutput(); }
static void Main() { var console = new ConsoleInputOutput(); var ticTacToeRule = new TicTacToeRule(); var player1 = new Player(Piece.X, "Player 1"); var player2 = new Player(Piece.O, "Player 2"); var newGame = new Game(console, ticTacToeRule, player1, player2); newGame.Play(); }
public static void Main(string[] args) { ISettingsProvider settingsProvider = new SettingsProvider(); IPhraseProvider phraseProvider = new JsonPhraseProvider(settingsProvider); IInputOutput inputOutput = new ConsoleInputOutput(); IBoard board = new Board(inputOutput, settingsProvider); Game game = new Game(phraseProvider, inputOutput, settingsProvider, board); game.Run(); }
public void NumberOfTimesPlayTurnCalledForPlayer() { var deck = new Deck(); var player = new PlayerSpy(deck, OneHit); var dealer = new Soft17Player(deck); var console = new ConsoleInputOutput(); var blackjack = new BlackJack(new Player[] { player }, console, dealer); blackjack.StartGame(); Assert.AreEqual(1, player.NumberOfTimesTurnPlayed); }
/// <summary> /// This method is an entry point. /// </summary> private static void Main() { IInputOutput inputOutputComponent = new ConsoleInputOutput(); ISettingsProvider settingsProvider = new SettingsProvider(); IPhraseProvider phraseProvider = new PhraseProvider(); IBoard board = new Board(); IFigureProvider figureProvider = new FigureComponent(); Game game = new Game(settingsProvider, inputOutputComponent, phraseProvider, board, figureProvider); game.Run(); }
public void Start_Should_InitializeTwoCardsInHandForPlayerAndDealer() { Player newPlayer = new Player(); Dealer newDealer = new Dealer(); Deck newDeck = new Deck(); var console = new ConsoleInputOutput(); Game newGame = new Game(newPlayer, newDealer, newDeck, console); newGame.Start(); Assert.Equal(2, newDealer.CardsInHand.Count); Assert.Equal(2, newPlayer.CardsInHand.Count); Assert.Equal(48, newDeck.Cards.Count); }
public void CallingTheInputAction_ReadsTheParameterFromConsoleOut() { var stringReader = new StringReader("The input"); Console.SetIn(stringReader); var consoleInOut = new ConsoleInputOutput(); // Act var input = consoleInOut.ReadFromInput(); input.Should().Be("The input"); }
static void Main(string[] args) { var rand = new RandomGenerator(); var inout = new ConsoleInputOutput(); var game = new Mastermind(inout, rand); var password = args.Length > 0 ? args[0] : null; game.Play(password); inout.WriteLine("Press any key to quit."); inout.Read(); }
private static void Main(string[] args) { var inputOutput = new ConsoleInputOutput(); var parser = new Parser(); var programRepository = new FileProgramRepository(parser); using (var rte = new RunTimeEnvironment(inputOutput, programRepository)) { var readEvaluatePrintLoop = new ReadEvaluatePrintLoop(rte, parser); PrintSalute(inputOutput); Run(readEvaluatePrintLoop); } }
public void CallingTheOutputAction_WritesTheParameterToConsoleOut() { var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var consoleInOut = new ConsoleInputOutput(); // Act consoleInOut.WriteToOutput("The message"); var output = stringWriter.ToString(); output.Should().Be("The message\r\n"); }
static void Main(string[] args) { args = new[] { "compress", "source.txt", "target.zip" }; // dependencies IInputOutput io = new ConsoleInputOutput(); ILogger logger = new ConsoleLogger(); IStreamFactory streamFactory = new CompressorStreamFactory(); ICompressorSettings settings = new CompressorSettings(); var app = new CompressorApplication(io, logger, streamFactory, settings); app.Execute(args); Console.ReadLine(); Stack s = new Stack(); }
public void EachPlayerPlaysTheirTurn() { var deck = new Deck(); var player1 = new PlayerSpy(deck, NoHits); var player2 = new PlayerSpy(deck, OneHit); var dealer = new Soft17Player(deck); var console = new ConsoleInputOutput(); var blackjack = new BlackJack(new Player[] { player1, player2 }, console, dealer); blackjack.StartGame(); Assert.NotZero(player1.NumberOfTimesTurnPlayed); Assert.NotZero(player2.NumberOfTimesTurnPlayed); }
public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; IInputOutput consoleInputOutput = new ConsoleInputOutput(); IRecyclingStationRepository repository = new RecyclingStationRepository(); IStrategyHolder strategyHolder = new StrategyHolder(); IGarbageProcessor garbageProcessor = new GarbageProcessor(strategyHolder); IEngine engine = new Engine( repository, garbageProcessor, strategyHolder, consoleInputOutput); engine.Run(); }
public void DealerWins() { var player = PlayerSpy.CreateLosingPlayer(); var dealerDeck = new DeckMock(new[] { new Card(CardFace.Eight, Suit.Hearts), new Card(CardFace.Ten, Suit.Diamonds), new Card(CardFace.Ace, Suit.Hearts), }); var dealer = new Soft17Player(dealerDeck); var console = new ConsoleInputOutput(); var blackjack = new BlackJack(new List <Player> { player }, console, dealer); blackjack.StartGame(); Assert.AreEqual(GameStatus.Won, dealer.GameStatus); }
public void HumanHitsAndBusts() { var player = PlayerSpy.CreateBustedPlayer(); var dealerDeck = new DeckMock(new[] { new Card(CardFace.Jack, Suit.Hearts), new Card(CardFace.Eight, Suit.Spades), }); var dealer = new Soft17Player(dealerDeck); var console = new ConsoleInputOutput(); var blackjack = new BlackJack(new List <Player> { player }, console, dealer); blackjack.StartGame(); Assert.AreEqual(GameStatus.Busted, player.GameStatus); }
public void DealerBusts() { var player = PlayerSpy.CreatePlayerHandValue18(); var dealerDeck = new DeckMock(new[] { new Card(CardFace.Jack, Suit.Hearts), new Card(CardFace.Six, Suit.Spades), new Card(CardFace.Nine, Suit.Diamonds), }); var dealer = new Soft17Player(dealerDeck); var console = new ConsoleInputOutput(); var blackjack = new BlackJack(new List <Player> { player }, console, dealer); blackjack.StartGame(); Assert.AreEqual(GameStatus.Busted, dealer.GameStatus); }
private static string CheckForWinnerGetActualResult(Card newCard, Card newCard2, Card newCardForListTwo, Card newCardTwoForListTwo) { var listOfCardsForTest = new List <Card>() { newCard, newCard2 }; var listTwoOfCardsForTest = new List <Card>() { newCardForListTwo, newCardTwoForListTwo }; var newPlayer = new Player(listOfCardsForTest); var newDealer = new Dealer(listTwoOfCardsForTest); var console = new ConsoleInputOutput(); var newDeck = new Deck(); var newGame = new Game(newPlayer, newDealer, newDeck, console); var actualResult = newGame.CheckForWinner(); return(actualResult); }
public void DealerPlaysTurnAfterAllPlayersPlayTurn() { var deck = new Deck(); var deckStartCount = deck.CardsLeft(); var players = new List <Player>() { new Soft17Player(deck), new Soft17Player(deck), new Soft17Player(deck), }; var dealer = new DealerSpy(deck); var console = new ConsoleInputOutput(); var blackjack = new BlackJack(players, console, dealer); blackjack.StartGame(); var cardsLeftBeforeDealersTurn = dealer.CardsLeftInDeckBeforeTurn; var cardsIfNoPlayerPlayed = deckStartCount - players.Count * CardsDealtToPlayer - CardsDealtToDealer; Assert.AreNotEqual(cardsIfNoPlayerPlayed, cardsLeftBeforeDealersTurn); }
/// <summary> /// Retries the DoLogin method until success or fail conditions have been met. /// </summary> /// <param name="retryWait">The TimeSpan in which to wait between requests.</param> /// <param name="retryLimit">The max number of requests to perform before failing.</param> /// <param name="username">Username to use</param> /// <param name="password">Password to use</param> /// <param name="machineAuth">Steam machine auth string. /// You should save Web.SteamMachineAuth after the code has been entered and the request has /// been successful and pass it to DoLogin in future attempts to login. /// This field can be left blank, but if the account is SteamGuard protected /// it will ask you for a new code every time.</param> /// <returns></returns> public Account RetryDoLogin(TimeSpan retryWait, int retryLimit, string username, string password, string machineAuth = "", IUserInputOutputHandler userInputOutput = null) { if (userInputOutput == null) userInputOutput = new ConsoleInputOutput(); int retries = 0; Account account = null; do { try { account = DoLogin(username, password, machineAuth, userInputOutput); } catch (WebException) { retries++; if (retries == retryLimit) throw; userInputOutput.OutputMessage("Connection failed... retrying in: " + retryWait.Milliseconds + "ms. Retries: " + retries); Thread.Sleep(retryWait); } } while (account == null); return account; }
public ConsoleManager(string[] args) { IO = new ConsoleInputOutput(); ArgumentParser = new ArgumentParser(args); }
/// <summary> /// Retries the DoLogin method until success or fail conditions have been met. /// </summary> /// <param name="retryWait">The TimeSpan in which to wait between requests.</param> /// <param name="retryLimit">The max number of requests to perform before failing.</param> /// <param name="username">Username to use</param> /// <param name="password">Password to use</param> /// <param name="machineAuth">Steam machine auth string. /// You should save Web.SteamMachineAuth after the code has been entered and the request has /// been successful and pass it to DoLogin in future attempts to login. /// This field can be left blank, but if the account is SteamGuard protected /// it will ask you for a new code every time.</param> /// <returns></returns> public Account RetryDoLogin(TimeSpan retryWait, int retryLimit, string username, string password, string machineAuth = "", IUserInputOutputHandler userInputOutput = null) { if (userInputOutput == null) userInputOutput = new ConsoleInputOutput(); int retries = 0; Account account = null; do { try { account = DoLogin(username, password, machineAuth, userInputOutput); } catch (WebException) { retries++; if (retries == retryLimit) throw; Thread.Sleep(retryWait); } } while (account == null); return account; }
/// <summary> /// Executes the web login using the Steam website. /// </summary> /// <param name="username">Username to use</param> /// <param name="password">Password to use</param> /// <param name="machineAuth">Steam machine auth string. /// <param name="userInputOutput">The user I/O handler to use. If null, defaults to Console.Write/Read</param> /// You should save Account.SteamMachineAuth after the code has been entered and the request has /// been successful and pass it to DoLogin in future attempts to login. /// This field can be left blank, but if the account is SteamGuard protected /// it will ask you for a new code every time.</param> /// <returns>An Account object to that contains the SteamId and AuthContainer.</returns> public Account DoLogin(string username, string password, string machineAuth = "", IUserInputOutputHandler userInputOutput = null) { if (userInputOutput == null) { userInputOutput = new ConsoleInputOutput(); } Thread.Sleep(2000); var rsaHelper = new RsaHelper(password); var loginDetails = new Dictionary <string, string> { { "username", username } }; IResponse response = Fetch("https://steamcommunity.com/login/getrsakey", "POST", loginDetails); string encryptedBase64Password = rsaHelper.EncryptPassword(response); if (encryptedBase64Password == null) { return(null); } LoginResult loginJson = null; CookieCollection cookieCollection; string steamGuardText = string.Empty; string steamGuardId = string.Empty; string twoFactorText = string.Empty; do { bool captcha = loginJson != null && loginJson.CaptchaNeeded; bool steamGuard = loginJson != null && loginJson.EmailAuthNeeded; bool twoFactor = loginJson != null && loginJson.RequiresTwofactor; var time = Uri.EscapeDataString(rsaHelper.RsaJson.TimeStamp); string capGid = "-1"; if (loginJson != null && loginJson.CaptchaNeeded) { capGid = Uri.EscapeDataString(loginJson.CaptchaGid); } var data = new Dictionary <string, string> { { "password", encryptedBase64Password }, { "username", username }, { "loginfriendlyname", string.Empty }, { "remember_login", "false" } }; // Captcha string capText = string.Empty; if (captcha) { Process.Start("https://steamcommunity.com/public/captcha.php?gid=" + loginJson.CaptchaGid); capText = userInputOutput.GetInput( "Please note, if you enter in your captcha correctly and it still opens up new captchas, double check your username and password.\n Please enter the numbers/letters from the picture that opened up: ", "Captcha"); } data.Add("captchagid", capGid); data.Add("captcha_text", captcha ? capText : string.Empty); // Captcha end // SteamGuard if (steamGuard) { steamGuardText = userInputOutput.GetInput("SteamGuard code required: ", "SteamGuard"); steamGuardId = loginJson.EmailSteamId; } data.Add("emailauth", steamGuardText); data.Add("emailsteamid", steamGuardId); // SteamGuard end //TwoFactor if (twoFactor && !loginJson.Success) { twoFactorText = userInputOutput.GetInput("TwoFactor code required: ", "Two Factor Authentication"); } data.Add("twofactorcode", twoFactor ? twoFactorText : string.Empty); data.Add("rsatimestamp", time); CookieContainer cc = null; if (!string.IsNullOrEmpty(machineAuth)) { cc = new CookieContainer(); var split = machineAuth.Split('='); var machineCookie = new Cookie(split[0], split[1]); cc.Add(new Uri("https://steamcommunity.com/login/dologin/"), machineCookie); } using (IResponse webResponse = Fetch("https://steamcommunity.com/login/dologin/", "POST", data, cc)) { string json = webResponse.ReadStream(); loginJson = JsonConvert.DeserializeObject <LoginResult>(json); cookieCollection = webResponse.Cookies; } } while (loginJson.CaptchaNeeded || loginJson.EmailAuthNeeded || (loginJson.RequiresTwofactor && !loginJson.Success)); Account account; if (loginJson.EmailSteamId != null) { account = new Account(Convert.ToUInt64(loginJson.EmailSteamId)); } else if (loginJson.TransferParameters?.Steamid != null) { account = new Account(Convert.ToUInt64(loginJson.TransferParameters.Steamid)); } else { return(null); } if (loginJson.Success) { _cookies = new CookieContainer(); foreach (Cookie cookie in cookieCollection) { _cookies.Add(cookie); switch (cookie.Name) { case "steamLogin": account.AuthContainer.Add(cookie); break; case "steamLoginSecure": account.AuthContainer.Add(cookie); break; case "timezoneOffset": account.AuthContainer.Add(cookie); break; } if (cookie.Name.StartsWith("steamMachineAuth")) { account.SteamMachineAuth = cookie.Name + "=" + cookie.Value; } else if (!string.IsNullOrEmpty(machineAuth)) { account.SteamMachineAuth = machineAuth; } } SubmitCookies(_cookies); // ReSharper disable once AssignNullToNotNullAttribute account.AuthContainer.Add(_cookies.GetCookies(new Uri("https://steamcommunity.com"))["sessionid"]); return(account); } userInputOutput.OutputMessage("SteamWeb Error: " + loginJson.Message); return(null); }
/// <summary> /// Executes the web login using the Steam website. /// </summary> /// <param name="username">Username to use</param> /// <param name="password">Password to use</param> /// <param name="machineAuth">Steam machine auth string. /// <param name="userInputOutput">The user I/O handler to use. If null, defaults to Console.Write/Read</param> /// You should save Account.SteamMachineAuth after the code has been entered and the request has /// been successful and pass it to DoLogin in future attempts to login. /// This field can be left blank, but if the account is SteamGuard protected /// it will ask you for a new code every time.</param> /// <returns>An Account object to that contains the SteamId and AuthContainer.</returns> public Account DoLogin(string username, string password, string machineAuth = "", IUserInputOutputHandler userInputOutput = null) { if (userInputOutput == null) userInputOutput = new ConsoleInputOutput(); Thread.Sleep(2000); var rsaHelper = new RsaHelper(password); var loginDetails = new Dictionary<string, string> { { "username", username } }; IResponse response = Fetch("https://steamcommunity.com/login/getrsakey", "POST", loginDetails); string encryptedBase64Password = rsaHelper.EncryptPassword(response); if (encryptedBase64Password == null) return null; LoginResult loginJson = null; CookieCollection cookieCollection; string steamGuardText = string.Empty; string steamGuardId = string.Empty; string twoFactorText = string.Empty; do { bool captcha = loginJson != null && loginJson.CaptchaNeeded; bool steamGuard = loginJson != null && loginJson.EmailAuthNeeded; bool twoFactor = loginJson != null && loginJson.RequiresTwofactor; var time = Uri.EscapeDataString(rsaHelper.RsaJson.TimeStamp); string capGid = "-1"; if (loginJson != null && loginJson.CaptchaNeeded) capGid = Uri.EscapeDataString(loginJson.CaptchaGid); var data = new Dictionary<string, string> { {"password", encryptedBase64Password}, {"username", username}, {"loginfriendlyname", string.Empty}, {"remember_login", "false"} }; // Captcha string capText = string.Empty; if (captcha) { Process.Start("https://steamcommunity.com/public/captcha.php?gid=" + loginJson.CaptchaGid); capText = userInputOutput.GetInput( "Please note, if you enter in your captcha correctly and it still opens up new captchas, double check your username and password.\n Please enter the numbers/letters from the picture that opened up: ", "Captcha"); } data.Add("captchagid", capGid); data.Add("captcha_text", captcha ? capText : string.Empty); // Captcha end // SteamGuard if (steamGuard) { steamGuardText = userInputOutput.GetInput("SteamGuard code required: ", "SteamGuard"); steamGuardId = loginJson.EmailSteamId; } data.Add("emailauth", steamGuardText); data.Add("emailsteamid", steamGuardId); // SteamGuard end //TwoFactor if (twoFactor && !loginJson.Success) { twoFactorText = userInputOutput.GetInput("TwoFactor code required: ", "Two Factor Authentication"); } data.Add("twofactorcode", twoFactor ? twoFactorText : string.Empty); data.Add("rsatimestamp", time); CookieContainer cc = null; if (!string.IsNullOrEmpty(machineAuth)) { cc = new CookieContainer(); var split = machineAuth.Split('='); var machineCookie = new Cookie(split[0], split[1]); cc.Add(new Uri("https://steamcommunity.com/login/dologin/"), machineCookie); } using (IResponse webResponse = Fetch("https://steamcommunity.com/login/dologin/", "POST", data, cc)) { string json = webResponse.ReadStream(); loginJson = JsonConvert.DeserializeObject<LoginResult>(json); cookieCollection = webResponse.Cookies; } } while (loginJson.CaptchaNeeded || loginJson.EmailAuthNeeded || (loginJson.RequiresTwofactor && !loginJson.Success)); Account account; if (loginJson.EmailSteamId != null) account = new Account(Convert.ToUInt64(loginJson.EmailSteamId)); else if (loginJson.TransferParameters?.Steamid != null) account = new Account(Convert.ToUInt64(loginJson.TransferParameters.Steamid)); else return null; if (loginJson.Success) { _cookies = new CookieContainer(); foreach (Cookie cookie in cookieCollection) { _cookies.Add(cookie); switch (cookie.Name) { case "steamLogin": account.AuthContainer.Add(cookie); break; case "steamLoginSecure": account.AuthContainer.Add(cookie); break; case "timezoneOffset": account.AuthContainer.Add(cookie); break; } if (cookie.Name.StartsWith("steamMachineAuth")) { account.SteamMachineAuth = cookie.Name + "=" + cookie.Value; } else if (!string.IsNullOrEmpty(machineAuth)) { account.SteamMachineAuth = machineAuth; } } SubmitCookies(_cookies); // ReSharper disable once AssignNullToNotNullAttribute account.AuthContainer.Add(_cookies.GetCookies(new Uri("https://steamcommunity.com"))["sessionid"]); return account; } userInputOutput.OutputMessage("SteamWeb Error: " + loginJson.Message); return null; }