bool Start() { LingoGame lingoGame = new LingoGame(); lingoGame.Init(); Console.Clear(); PlayLingo(lingoGame); return(ProgramTools.LoopProgram()); }
bool Start() { Console.Write("Enter a sentence: "); string sentence = Console.ReadLine(); sentence = ShuffleWords(sentence); Console.WriteLine("The new sentence has become: " + sentence); return(ProgramTools.LoopProgram()); }
bool Start() { Position position = new Position(); ChessPiece[,] chessboard = new ChessPiece[8, 8]; InitChessboard(chessboard); DisplayChessboard(chessboard); PlayChess(chessboard); return(ProgramTools.LoopProgram()); }
bool Start() { ChessGame chessGame = new ChessGame(); Console.WriteLine("This chess game does not allow En Passant or Castling.\nThe game is won by capturing the king instead of getting checkmate.\nTherefore you can put your own king in check.\n"); chessGame.InitChessboard(); DisplayChessboard(chessGame); PlayChess(chessGame); return(ProgramTools.LoopGame()); }
bool Start() { string player1Name = ReadTools.ReadString("Player 1 (name): "); string player2Name = ReadTools.ReadString("Player 2 (name): "); Player player1 = new Player(player1Name); Player player2 = new Player(player2Name); WarCardGame war = new WarCardGame(player1, player2); PlayTheGame(war); return(ProgramTools.LoopGame()); }
bool Start() { RegularCandies[,] playingField; Position posRow = new Position(); Position posCol = new Position(); if (File.Exists("playingField.txt")) { playingField = ReadPlayingField("playingField.txt"); } else { playingField = new RegularCandies[10, 10]; InitCandies(playingField); WritePlayingField(playingField, "playingField.txt"); } DisplayCandies(playingField); Console.WriteLine(); if (ScoreRowPresent(playingField, out posRow)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Row score! "); Console.ResetColor(); Console.WriteLine($"First position: ({posRow.column}, {posRow.row})"); } else { Console.WriteLine("No row score."); } Console.WriteLine(); if (ScoreColumnPresent(playingField, out posCol)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Column score! "); Console.ResetColor(); Console.WriteLine($"First position: ({posCol.column}, {posCol.row})"); } else { Console.WriteLine("No column score."); } if (RemoveSaveFile()) { File.Delete("playingField.txt"); Console.WriteLine("Your safe file has been succesfully deleted."); } return(ProgramTools.LoopProgram()); }
bool Start() { DeckOfCards deck = new DeckOfCards(); Console.WriteLine("Ordered:"); deck.Print(); Console.WriteLine(); Console.WriteLine("Randomised:"); deck.Shuffle(); deck.Print(); return(ProgramTools.LoopProgram()); }
bool Start() { List <Premise> premises = ReadPremises("..\\..\\premises.txt"); List <Party> parties = ReadParties("..\\..\\parties.txt"); if (premises.Count < 1 || parties.Count < 1) { return(false); } string user = ProcessPremises(premises); CompareParties(user, parties); return(ProgramTools.LoopProgram()); }
bool Start() { Dictionary <string, string> words = new Dictionary <string, string>(); if (SetLanguage()) { words = ReadWords("..//..//dictionaryNL.csv", "nl"); } else { words = ReadWords("..//..//dictionaryENG.csv", "eng"); } TranslateWords(words); return(ProgramTools.LoopProgram()); }
static void Main(string[] args) { ProgramTools.SizeConsoleWindow(); new IsUnique().BuildAndRunTests(); new CheckPermutation().BuildAndRunTests(); new URLify().BuildAndRunTests(); new PalindromePermutation().BuildAndRunTests(); new OneAway().BuildAndRunTests(); new StringCompression().BuildAndRunTests(); new RotateMatrix().BuildAndRunTests(); new ZeroMatrix().BuildAndRunTests(); new StringRotation().BuildAndRunTests(); ProgramTools.PauseForAnyKey("Press any key to exit"); }
bool Start() { YahtzeeGame yahtzeeGame = new YahtzeeGame(); yahtzeeGame.Throw(); yahtzeeGame.DisplayValues(); yahtzeeGame.Throw(); yahtzeeGame.DisplayValues(); Console.WriteLine(); PlayYahtzee(yahtzeeGame); return(ProgramTools.LoopGame()); }
static void Main(string[] args) { ProgramTools.SizeConsoleWindow(); //new RemoveDupes ().BuildAndRunTests (); //new ReturnKthToLast ().BuildAndRunTests (); //new DeleteMiddleNode ().BuildAndRunTests (); //new Partition ().BuildAndRunTests (); //new SumListsReverse ().BuildAndRunTests (); //new SumLists ().BuildAndRunTests (); //new Palindrome ().BuildAndRunTests (); //new Intersection ().BuildAndRunTests (); new LoopDetection().BuildAndRunTests(); ProgramTools.PauseForAnyKey("Press any key to exit"); }
bool Start() { int value = ReadTools.ReadInt("Enter a value: "); Console.WriteLine("You entered {0}.", value); int age = ReadTools.ReadInt("How old are you? ", 0, 120); Console.WriteLine("You are {0} years old.", age); string name = ReadTools.ReadString("What is your name? "); Console.WriteLine("Nice meeting you {0}.", name); return(ProgramTools.LoopProgram()); }
bool Start() { Console.Write("Enter a word (to search): "); string searchTerm = Console.ReadLine(); while (searchTerm.Length < 1) { Console.Write("Enter a word (to search): "); searchTerm = Console.ReadLine(); } int numWord = SearchWordInFile("..//..//tweets-donaldtrump-2018.txt", searchTerm, out int numLines); Console.WriteLine("Word occurence: " + numWord); Console.WriteLine("Number of lines containing the word: " + numLines); return(ProgramTools.LoopProgram()); }
bool Start() { BookStore bookStore = new BookStore(); Book book1 = new Book("Dracula", "Bram Stoker", 15); Book book2 = new Book("Joe Speedboot", "Tommy Wieringa", 12.5); Book book3 = new Book("The Hobbit", "J.R.R. Tolkien", 12.5); Magazine magazine1 = new Magazine("Time", DayOfWeek.Friday, 3.9); Magazine magazine2 = new Magazine("Donald Duck", DayOfWeek.Thursday, 2.5); bookStore.Add(book1); bookStore.Add(book2); bookStore.Add(magazine1); bookStore.Add(magazine2); bookStore.Add(book3); bookStore.PrintCompleteStock(); return(ProgramTools.LoopProgram()); }
bool Start() { Programmer p1 = new Programmer("Hank", Specialty.PHP); Programmer p2 = new Programmer("Peter", Specialty.Java); Programmer p3 = new Programmer("Samantha", Specialty.HTML); Programmer p4 = new Programmer("Astrid"); p1.Print(); Team team = new Team(); team.AddProgrammer(p1); team.AddProgrammer(p2); team.AddProgrammer(p3); team.AddProgrammer(p4); team.PrintAllTeamMembers(); return(ProgramTools.LoopProgram()); }
static void Main(string[] args) { ProgramTools.Setup(); var config = new Config(); ExecutableTools.LogArgs(new StderrWriteLine(), args, (arg) => { ConfigTools.SetProperty(config, arg); }); if (!config.Daemon) { Logger.TRACE = new StderrWriteLine(); } Stdio.SetStatus("Ready"); var line = Stdio.ReadLine(); while (line != null) { Logger.Trace("> {0}", line); if (line == "ping") { Stdio.WriteLine("pong"); Logger.Trace("< pong"); } //throw Exception Message if (line.StartsWith("throw")) { throw new Exception(line.Substring(6)); } if (line == "exit!") { return; } line = Stdio.ReadLine(); } Logger.Trace("Stdin closed"); Environment.Exit(0); }
public static void Main() { Console.Title = "Semaphore Test"; STT = new SemaphoreTestAgent(); PT = new ProgramTools(); for (int i = 0; i < 10; i++) { Thread thread = new Thread(AcquireToken); thread.Name = String.Format("{0}", i + 1); thread.IsBackground = true; thread.Start(); STT.ThreadAcquisitionMap.Add(thread, new ThreadData()); } PT.Start(); STT.Start(ReleaseToken); }
bool Start() { HangmanGame hangman = new HangmanGame(); List <string> words = new List <string>(); words = ListOfWords(); string secretWord = SelectWord(words); hangman.Init(secretWord); if (PlayHangman(hangman)) { Console.WriteLine("You guessed the word!"); } else { Console.WriteLine("You didn't guess the word..."); Console.WriteLine($"The secret word was: {hangman.secretWord}"); } return(ProgramTools.LoopGame()); }
bool Start() { int[,] matrix = new int[5, 10]; matrix = FillMatrix(matrix); DisplayMatrix(matrix); Console.WriteLine(); int num = ReadTools.ReadInt("Enter a search number: "); while (!numberPresent(matrix, num)) { Console.WriteLine("That number is not present in the matrix, try another one."); num = ReadTools.ReadInt("Enter a search number: "); } matrix = shiftmatrix(matrix, num); Console.WriteLine(); Console.WriteLine("Shifting rows..."); Console.WriteLine(); DisplayMatrix(matrix); return(ProgramTools.LoopProgram()); }
bool Start() { Person person = new Person(); Console.Write("Enter your name: "); string name = Console.ReadLine(); if (File.Exists($"{name}.txt")) { Console.WriteLine($"Nice to see you again, {name}!"); Console.WriteLine($"We have the following information about you:"); person = ReadPerson($"{name}.txt"); DisplayPerson(person); } else { Console.WriteLine($"Welcome {name}!"); person = ReadPerson(); WritePerson(person, $"{person.name}.txt"); Console.WriteLine("Your data is written to file."); } return(ProgramTools.LoopProgram()); }
static void Main(string[] args) { ProgramTools.Setup(); var config = new Config(); //args will always log to stderr because trace flag not loaded yet ExecutableTools.LogArgs(new StderrWriteLine(), args, (arg) => { ConfigTools.SetProperty(config, arg); }); AssertTools.NotEmpty(config.EndPoint, "Missing EndPoint"); AssertTools.NotEmpty(config.Root, "Missing Root"); if (!config.Daemon) { Logger.TRACE = new StderrWriteLine(); } var uri = string.Format("http://{0}/", config.EndPoint); var http = new HttpListener(); http.Prefixes.Add(uri); http.Start(); var accepter = new Runner(new Runner.Args { ThreadName = "Accepter" }); var handler = new Runner(new Runner.Args { ThreadName = "Handler" }); accepter.Run(() => { while (http.IsListening) { var ctx = http.GetContext(); handler.Run(() => { var request = ctx.Request; var response = ctx.Response; var pass = true; var file = ctx.Request.RawUrl.Substring(1); //remove leading / if (!PathTools.IsChildPath(config.Root, file)) { pass = false; } var path = PathTools.Combine(config.Root, file); Logger.Trace("File {0} {1}", file, path); if (!File.Exists(path)) { pass = false; } if (ctx.Request.HttpMethod != "GET") { pass = false; } if (pass) { var fi = new FileInfo(path); var fs = new FileStream(path, FileMode.Open, FileAccess.Read); ctx.Response.StatusCode = (int)HttpStatusCode.OK; ctx.Response.ContentLength64 = fi.Length; ctx.Response.ContentType = "application/octet-stream"; var data = new byte[1024]; var count = fs.Read(data, 0, data.Length); while (count > 0) { ctx.Response.OutputStream.Write(data, 0, count); count = fs.Read(data, 0, data.Length); } } else { ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; ctx.Response.ContentLength64 = 0; } ctx.Response.Close(); }); } }); Stdio.SetStatus("Listeninig on {0}", uri); using (var disposer = new Disposer()) { disposer.Push(handler); disposer.Push(accepter); disposer.Push(http.Stop); var line = Stdio.ReadLine(); while (line != null) { line = Stdio.ReadLine(); } } Logger.Trace("Stdin closed"); Environment.Exit(0); }
bool Start() { Book book1 = new Book(1, "Dracula", "Bram Stoker"); Book book2 = new Book(2, "Joe Speedboot", "Tommy Wieringa"); Book book3 = new Book(3, "The Hobbit", "J.R.R. Tolkien"); Customer customer1 = new Customer(1, "Lionel", "Messi", "*****@*****.**"); Customer customer2 = new Customer(2, "Piet", "Paulusma", "*****@*****.**"); Reservation reservation1 = new Reservation(1, customer1, book1); Reservation reservation2 = new Reservation(1, customer1, book3); Reservation reservation3 = new Reservation(1, customer2, book2); Reservation reservation4 = new Reservation(1, customer2, book1); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Books"); Console.ResetColor(); Console.WriteLine(book1); Console.WriteLine(book2); Console.WriteLine(book3); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Customers"); Console.ResetColor(); Console.WriteLine(customer1); Console.WriteLine(customer2); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Reservations"); Console.ResetColor(); Console.WriteLine(reservation1); Console.WriteLine(reservation2); Console.WriteLine(reservation3); Console.WriteLine(reservation4); Console.WriteLine(); CustomerDAO customerDAO = new CustomerDAO(); foreach (Customer cust in customerDAO.GetAll()) { Console.WriteLine(cust); } Customer customer = customerDAO.GetById(2); Console.WriteLine(); Console.WriteLine("Searching for customer with id 2..."); if (customer != null) { Console.WriteLine(customer); } else { Console.WriteLine("Customer not found!"); } Console.WriteLine(); BookDAO bookDAO = new BookDAO(); foreach (Book b in bookDAO.GetAll()) { Console.WriteLine($"{b.Id}. {b}"); } Book book = bookDAO.GetById(2); Console.WriteLine(); Console.WriteLine("Searching for book with id 2..."); if (book != null) { Console.WriteLine(book); } else { Console.WriteLine("Book not found!"); } Console.WriteLine(); ReservationDAO reservationDAO = new ReservationDAO(); foreach (Reservation res in reservationDAO.GetAll()) { Console.WriteLine(res); } List <Book> books = reservationDAO.GetAllForCustomer(customerDAO.GetById(2)); Console.WriteLine(); Console.WriteLine("Searching for books reserved by customer with id 2..."); if (books.Count != 0) { foreach (Book b in books) { Console.WriteLine(b); } } else { Console.WriteLine("Books not found!"); } List <Customer> customers = reservationDAO.GetAllForBook(bookDAO.GetById(3)); Console.WriteLine(); Console.WriteLine("Searching for customers who reserved book with id 3..."); if (customers.Count != 0) { foreach (Customer cust in customers) { Console.WriteLine(cust); } } else { Console.WriteLine("Customers not found!"); } return(ProgramTools.LoopProgram()); }
static void Main(string[] args) { ProgramTools.Setup(); var config = new Config(); config.IP = "0.0.0.0"; config.Port = 22333; config.Delay = 5000; config.Timeout = 5000; config.Root = ExecutableTools.Relative("Root"); //args will always log to stderr because daemon flag not loaded yet ExecutableTools.LogArgs(new StderrWriteLine(), args, (arg) => { ConfigTools.SetProperty(config, arg); }); AssertTools.NotEmpty(config.Root, "Missing Root path"); AssertTools.NotEmpty(config.IP, "Missing IP"); AssertTools.Ip(config.IP, "Invalid IP"); var pid = Process.GetCurrentProcess().Id; var writers = new WriteLineCollection(); if (!config.Daemon) { writers.Add(new StderrWriteLine()); Logger.TRACE = new TimedWriter(writers); } Logger.Trace("Root {0}", config.Root); var dbpath = Path.Combine(config.Root, "SharpDaemon.LiteDb"); var logpath = Path.Combine(config.Root, "SharpDaemon.Log.txt"); var eppath = Path.Combine(config.Root, "SharpDaemon.Endpoint.txt"); var downloads = Path.Combine(config.Root, "Downloads"); Directory.CreateDirectory(downloads); //creates root as well //acts like mutex for the workspace var log = new StreamWriter(logpath, true); writers.Add(new TextWriterWriteLine(log)); ExecutableTools.LogArgs(new TextWriterWriteLine(log), args); var instance = new Instance(new Instance.Args { DbPath = dbpath, RestartDelay = config.Delay, Downloads = downloads, EndPoint = new IPEndPoint(IPAddress.Parse(config.IP), config.Port), }); Stdio.SetStatus("Listening on {0}", instance.EndPoint); using (var disposer = new Disposer()) { //wrap to add to disposable count disposer.Push(new Disposable.Wrapper(log)); disposer.Push(instance); disposer.Push(() => Disposing(config.Timeout)); if (config.Daemon) { Logger.Trace("Stdin loop..."); var line = Stdio.ReadLine(); while (line != null) { Logger.Trace("> {0}", line); if ("exit!" == line) { break; } line = Stdio.ReadLine(); } Logger.Trace("Stdin closed"); } else { Logger.Trace("Stdin loop..."); var shell = instance.CreateShell(); var stream = new ShellStream(new StdoutWriteLine(), new ConsoleReadLine()); //disposer.Push(stream); //stdin.readline wont return even after close/dispose call var line = stream.ReadLine(); while (line != null) { if ("exit!" == line) { break; } Shell.ParseAndExecute(shell, stream, line); line = stream.ReadLine(); } Logger.Trace("Stdin closed"); } } Environment.Exit(0); }
bool Start() { return(ProgramTools.LoopProgram()); }
bool Start() { Customer customer1 = new Customer("Lionel Messi", Convert.ToDateTime("1987/06/24")); Customer customer2 = new Customer("Piet Paulusma", Convert.ToDateTime("1956/02/15")); customer2.DateOfRegistration = Convert.ToDateTime("2017/02/20"); try { PrintCustomer(customer1); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); try { PrintCustomer(customer2); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine(); Ticket ticket1 = new Ticket("", 1, DateTime.ParseExact("25-02-20 18:30", "dd-MM-yy HH:mm", null), 10.5m, 0); Ticket ticket2 = new Ticket("Dracula", 7, DateTime.ParseExact("25-02-20 18:30", "dd-MM-yy HH:mm", null), 10.5m, 0); Ticket ticket3 = new Ticket("Star Wars", 1, DateTime.ParseExact("25-02-20 18:30", "dd-MM-yy HH:mm", null), 10.5m, 13); Ticket ticket4 = new Ticket("Dracula", 1, DateTime.ParseExact("25-02-20 18:15", "dd-MM-yy HH:mm", null), 10.5m, 0); Ticket ticket5 = new Ticket("Dracula", 2, DateTime.ParseExact("26-02-20 18:30", "dd-MM-yy HH:mm", null), 10.5m, 6); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Creating tickets"); Console.ResetColor(); try { PrintTicket(ticket1); } catch (Exception e) { Console.WriteLine(e.Message); } try { PrintTicket(ticket2); } catch (Exception e) { Console.WriteLine(e.Message); } try { PrintTicket(ticket3); } catch (Exception e) { Console.WriteLine(e.Message); } try { PrintTicket(ticket4); } catch (Exception e) { Console.WriteLine(e.Message); } try { PrintTicket(ticket5); } catch (Exception e) { Console.WriteLine(e.Message); } Ticket ticket6 = new Ticket("Green Book", 5, DateTime.ParseExact("24-02-20 19:00", "dd-MM-yy HH:mm", null), 10.5m, 12); Ticket ticket7 = new Ticket("The prodigy", 3, DateTime.ParseExact("23-02-20 17:30", "dd-MM-yy HH:mm", null), 10.5m, 16); Console.WriteLine(); Reservation reservation1 = new Reservation(customer1, ticket6); reservation1.Add(ticket7); reservation1.Add(ticket5); PrintReservation(reservation1); Console.WriteLine(); Reservation reservation2 = new Reservation(customer2, ticket5); reservation2.Add(ticket6); reservation2.Add(ticket7); PrintReservation(reservation2); return(ProgramTools.LoopProgram()); }
public EntryTypeVM(Type type) { Type = type; Name = ProgramTools.GetAttributeValue <DescriptionAttribute>(type, a => a.Description); }
static void Main(string[] args) { ProgramTools.Setup(); ServiceBase.Run(new Program()); }