public static void rodar(Life life) { System.Console.WriteLine("\nMeu nome é: " + life.Name); string opcao = ""; if (life.Name == null) life.Name = "SEM_NOME"; PeerNetwork com = new PeerNetwork(life); //cria Thread que fica verificando se os contatos estão online ou offline. com.VerifyContacts(); thrServidor = new Thread(new ThreadStart(com.MakeAvailable)); System.Console.WriteLine("Voce esta OnLine: " +life.Name); thrServidor.IsBackground = true; thrServidor.Start(); SovereChat chat = new SovereChat(life); Thread thrServidor2 = new Thread(new ThreadStart(chat.Listen)); thrServidor2.IsBackground = true; thrServidor2.Start(); Thread thrServidor4 = new Thread(new ThreadStart(com.ContactListener)); thrServidor4.IsBackground = true; thrServidor4.Start(); //return share files list. Thread thrServidor5 = new Thread(new ThreadStart(com.FilesNameListener)); thrServidor5.IsBackground = true; thrServidor5.Start(); //return file. Thread thrServidor6 = new Thread(new ThreadStart(com.FileListener)); thrServidor6.IsBackground = true; thrServidor6.Start(); while(opcao.ToUpper() != "S") { // My Funcitions System.Console.WriteLine("\n\n " + life.Name + " What do you do ?"); System.Console.WriteLine("N. Change Name"); System.Console.WriteLine("L. Nickname List"); System.Console.WriteLine("T. See Photo"); System.Console.WriteLine("F. Change Photo"); System.Console.WriteLine("B. Change Default Browser's Path"); System.Console.WriteLine("E. Sharing File List"); System.Console.WriteLine("C. Connect"); // On my contacts System.Console.WriteLine("A. Add contact/change nickname"); System.Console.WriteLine("R. Remove Nickname"); System.Console.WriteLine("D. Change trust degree"); System.Console.WriteLine("J. Get Picture"); System.Console.WriteLine("K. Get File"); System.Console.WriteLine("P. FindIpAddress Contact"); System.Console.WriteLine("Z . Navegation on Contacts"); // System.Console.WriteLine("M. Start Chat"); only for GUI System.Console.WriteLine("S. Sair"); opcao = System.Console.ReadLine(); switch (opcao.ToUpper()) { case "A": { System.Console.Write("Digite o Apelido do seu novo Contato: "); string nickname = System.Console.ReadLine(); System.Console.Write("Digite o IP de " + nickname + ": "); string ip = System.Console.ReadLine(); life.AddContact(nickname,ip); break; } case "D": { System.Console.Write("Type the NickName of your contact: "); string nick = System.Console.ReadLine(); Contact contact = life.SearchContact(nick); if(contact != null) { while(true) { try { System.Console.Write("\nType the new trust degree ( 0 to 100 ): "); int trust = int.Parse(System.Console.ReadLine()); if (trust >= 0 && trust <= 100) contact.Trust = trust; else throw(new System.Exception("")); break; } catch { System.Console.WriteLine("Invalid option, try again!"); } } } else { System.Console.WriteLine("Invalid NickName!"); } break; } case "F": { System.Console.WriteLine("Enter path of pícture: "); life.PathToPhoto = System.Console.ReadLine(); break; } case "T": { Photo.ShowPicture(life); break; } case "J": { System.Console.WriteLine("View Picture From: "); string nickname = System.Console.ReadLine(); com.PictureRequest(nickname, life); break; } case "C": { System.Console.WriteLine("Enter the nickname: "); string nick = System.Console.ReadLine(); Contact contact = life.SearchContact(nick); System.Console.WriteLine("Your buddy at [" + contact.IP + "] is " + PeerNetwork.RetrieveStatus(contact)); break; } case "N": { System.Console.WriteLine("Enter your real name: "); life.Name = System.Console.ReadLine(); System.Console.Write("Your name is now : : "); System.Console.WriteLine(life.Name); break; } case "L": { System.Console.WriteLine("Yuors Contacts so:"); IDictionaryEnumerator enumerator = life.Contacts.GetEnumerator(); while (enumerator.MoveNext()) { System.Console.Write(" Apelido: "); System.Console.Write(enumerator.Key); System.Console.Write(" IP: "); System.Console.Write(((Contact)enumerator.Value).IP); System.Console.Write(" Trust degree:"); System.Console.Write(((Contact)enumerator.Value).Trust.ToString() + "%"); System.Console.Write(" Status: "); System.Console.WriteLine(PeerNetwork.RetrieveStatus((Contact)enumerator.Value)); } System.Console.WriteLine("--- FIM DA LISTA ---\n\n"); break; } // This is only available on GUI case "M": { //ChatWindow.Factory(life); System.Console.WriteLine("Enter the Nickname of your contact:"); string nome = System.Console.ReadLine(); string ip = life.FindIpAddress(nome); if (ip == null ) { System.Console.WriteLine("Apelido não existe!!!"); } else { SovereChat message = new SovereChat(ip,life.Name); } break; } case "P": { System.Console.WriteLine("Digite o Apelido:"); string nome = System.Console.ReadLine(); string ip = life.FindIpAddress(nome); System.Console.WriteLine("-------->>Apelido : {0} IP: {1} ", nome,ip); break; } case "R": { System.Console.Write("Digite o Apelido que deseja remover: "); string nickname = System.Console.ReadLine(); life.RemoveContact(nickname); System.Console.Write(nickname + " foi removido da sua lista."); break; } case "B": { System.Console.Write("Enter the new default browser's path: "); string browserPath = System.Console.ReadLine(); life.BrowserPath = browserPath; System.Console.Write(browserPath + " is your new browser's path."); break; } case "Z": { // Passagem de 1 para o primeiro nível de trusting por ele ser vc mesmo o nível de confiança é total Navigator.ConsoleNavigator(">",life.Contacts,100); break; } case "E": { life.RetrieveFiles(); System.Console.WriteLine("Your sharing files are:"); IDictionaryEnumerator enumerator = life.Files.GetEnumerator(); while (enumerator.MoveNext()) { System.Console.Write(" Name: "); System.Console.WriteLine(enumerator.Key); } System.Console.WriteLine("--- END OF FILES LIST ---\n\n"); break; } case "K": { System.Console.WriteLine("Enter contact's nickname to get files:"); string nickname = System.Console.ReadLine(); Hashtable contactFiles = PeerNetwork.GetRemoteFilesNames(life.FindIpAddress(nickname)); System.Console.WriteLine("{0}'s sharing files are:",nickname); IDictionaryEnumerator enumerator = contactFiles.GetEnumerator(); while (enumerator.MoveNext()) System.Console.WriteLine(" Name: " + enumerator.Key); System.Console.WriteLine("--- END OF FILES LIST ---\n\n"); System.Console.WriteLine("Which file would you like to get? "); string fileName = System.Console.ReadLine(); System.Console.WriteLine("Which name would you like to save it?"); string nameToSave = System.Console.ReadLine(); PeerNetwork.GetRemoteFiles(life.FindIpAddress(nickname),fileName, nameToSave, life.FilesPath); System.Console.WriteLine("Sucessfull download of {0} executed!", fileName); break; } default: { if (thrServidor != null) { if (thrServidor.IsAlive) { //thrServidor.Interrupt(); thrServidor.Abort(); } } break; } } } }
public static void Run(Life life) { Hashtable chats = new Hashtable(); if (life.Name == null) life.Name = "SEM_NOME"; PeerNetwork com = new PeerNetwork(life); //cria Thread que fica verificando se os contatos estão online ou offline. com.VerifyContacts(); thrServidor = new Thread(new ThreadStart(com.MakeAvailable)); System.Console.WriteLine("You are now onLine: " +life.Name); thrServidor.IsBackground = true; thrServidor.Start(); LifeLets.GUI.SovereChat chat = new LifeLets.GUI.SovereChat(life, chats); Thread thrServidor2 = new Thread(new ThreadStart(chat.Listen)); thrServidor2.IsBackground = true; thrServidor2.Start(); Thread thrServidor4 = new Thread(new ThreadStart(com.ContactListener)); thrServidor4.IsBackground = true; thrServidor4.Start(); new LLMainWindow(life, chats); }