static void Dain() { Thread sendThread = new Thread(new ThreadStart(ConnectionV2.SendBroadcastOfferToConnect)); //созадем новый поток отдельно для получения sendThread.IsBackground = true; //sendThread.Start(); // запускаем процесс отправки сообщений Thread DoRequestsRecieveingThread = new Thread(new ThreadStart(RequestInteractivity.DoRequestsRecieveing)); //созадем новый поток отдельно для получения DoRequestsRecieveingThread.IsBackground = true; DoRequestsRecieveingThread.Start();// Запускаем процесс получния запросов AvailableConection available = new AvailableConection(); Thread receiveThread = new Thread(new ParameterizedThreadStart(ConnectionV2.ReciveBroadcastOffer)); receiveThread.IsBackground = true; receiveThread.Start(available); Console.ReadLine(); //var availbCon = AvailableConection.ReturnGroupList(); //for (int i = 0; i < availbCon.Count; i++) //{ // Console.WriteLine($"{i} - {availbCon[i].Item2}"); //} //Console.WriteLine("enter the host number to interact"); //var p = int.Parse(Console.ReadLine()); //var reciverIP = availbCon[p].Item2; var reciverIP = "127.0.0.1"; string pass = "******"; while (true) { var ans = RequestInteractivity.SendRequst(reciverIP, RequestTipe.GetDirectoryFiles, pass); ans = ans.Remove(0, 7); var files = ans.Split('\n'); foreach (var file in files) { Console.WriteLine(file); } string add = ""; add = Console.ReadLine(); if (pass[pass.Length - 1] == '.') { pass = add; } else { if (pass[pass.Length - 1] != '\\') { pass += '\\'; } pass += add; } } }
static void Main(string[] args) { //Thread getConnectThread = new Thread(new ThreadStart(ConnectionV2.GetConnect)); //getConnectThread.Start(); //ConnectionV2.GetConnect(); Thread getConnectThread = new Thread(new ThreadStart(RequestInteractivity.DoRequestsRecieveing)); getConnectThread.Start(); RequestInteractivity.SendRequst("127.0.0.1"); }
/// <summary> /// Загружает файлы в форму по заданному пути /// </summary> /// <param name="sender">Указываем форму, в которой будем отрисовывать</param> /// <param name="ip">Указываем Ip адрес пк, у которого запрашивает директории по указанному пути</param> /// <param name="path">Указываем сам путь</param> /// <param name="control">Рисуем в первом контроле или во втором(по умолчанию - 0, (0/1))</param> public async void loadFiles(object sender, string ip, string path, int control = 0) { var myIp = ip;//ip текущего пк linkedList0.Add(path); var ans = ""; if (myIp != "127.0.0.1") { ans = RequestInteractivity.SendRequst(myIp, RequestTipe.GetDirectoryFiles, path); ans = ans.Remove(0, 7); } else { ans = GetDirectory(path); } var files = ans.Split('\n'); files[files.Length - 1] = null; MainWindow mainWindow = (MainWindow)sender; if (control == 0) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( () => { // Очищаем list //******************* ***** listUsers0.Items.Clear(); })); } else if (control == 1) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( () => { // Очищаем list //************************ listUsers1.Items.Clear(); })); } foreach (var file in files) { if (file != null) { List <(string, string, string)> ps = mainWindow.CuttingMessages(file); if (control == 0) { await Task.Run(() => mainWindow.loadInfromationAboutFiles0(ps[0].Item1, ps[0].Item2, ps[0].Item3)); } else if (control == 1) { await Task.Run(() => mainWindow.loadInfromationAboutFiles1(ps[0].Item1, ps[0].Item2, ps[0].Item3)); } } else { // . . . } //linkedList0.Remove(path); } if (control == 0) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( () => { pathbox0.IsEnabled = true; })); } else if (control == 1) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( () => { pathbox1.IsEnabled = true; })); } }
private MenuItem CreateDirectoryNodeForRemote(object direct) { ClassAboutFilesAdding directoryInfo = (ClassAboutFilesAdding)direct; string ip_sender = ""; if (directoryInfo.Sender == "Этот компьютер") { ip_sender = "127.0.0.1"; } else { ip_sender = directoryInfo.Sender; } var ans = RequestInteractivity.SendRequst(ip_sender, RequestTipe.GetDirectoryFiles, directoryInfo.RootLocationFilesOrDirectory + directoryInfo.nameFile); //Получить папки от удаленного пк (здесь от отправителя) if (ans[0].ToString() == "A") { ans = ans.Remove(0, 7); var files = ans.Split('\n'); files[files.Length - 1] = null; object papka_ = null; System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( () => { WpfControlLibrary3.UserControl1 papka = new WpfControlLibrary3.UserControl1(); papka.Ip_From = directoryInfo.Sender; papka.Ip_To = directoryInfo.Receiver; papka.Path_From = directoryInfo.RootLocationFilesOrDirectory + directoryInfo.nameFile; papka.Path_To = directoryInfo.RemoteLocationFilesOrDirectory + directoryInfo.nameFile; papka.IsHeightValue = files.Length - 1; if (sbros != null) { WpfControlLibrary3.UserControl1 tyc = (WpfControlLibrary3.UserControl1)sbros; papka.OnCompleteTransmit += tyc.ChangedvalueForProgressBar; } papka_ = papka; })); var directoryNode = new MenuItem() { Title = directoryInfo.nameFile, flk = papka_ }; //создаем фалй или папку, пока что мы не знаем foreach (var file in files) { if (file != null) { string name = ""; List <(string, string, string)> ps = CuttingMessages(file); if (ps[0].Item3 == "-1") { name = ps[0].Item1 + "\\"; } else { name = ps[0].Item1; } ClassAboutFilesAdding files1 = new ClassAboutFilesAdding() // создаём экземпляр класса { nameFile = ps[0].Item1, // указываем имя файла time = ps[0].Item2, // указываем время создания sizeFile = ps[0].Item3, // указываем размер LocalParentPath = directoryInfo.RootLocationFilesOrDirectory, LocalParentName = directoryInfo.nameFile, RootLocationFilesOrDirectory = directoryInfo.RootLocationFilesOrDirectory + directoryInfo.nameFile + "\\", Receiver = directoryInfo.Receiver, Sender = directoryInfo.Sender, RemoteLocationFilesOrDirectory = directoryInfo.RemoteLocationFilesOrDirectory + directoryInfo.nameFile + "\\", RemoteParentName = directoryInfo.nameFile, RemoteParentPath = directoryInfo.RemoteLocationFilesOrDirectory }; if (ps[0].Item3 == "" || ps[0].Item3 == "-1") { sbros = directoryNode.flk; directoryNode.Items.Add(CreateDirectoryNodeForRemote(files1)); } else { System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( () => { UserControl1 flk = new UserControl1(); flk.Ip_From = files1.Sender; flk.Ip_To = files1.Receiver; flk.Path_From = files1.RootLocationFilesOrDirectory; flk.Path_To = files1.RemoteLocationFilesOrDirectory; flk.NameFile = files1.nameFile; WpfControlLibrary3.UserControl1 _papka = (WpfControlLibrary3.UserControl1)directoryNode.flk; flk.OnCompleteTransmit += _papka.ChangedvalueForProgressBar; if (files1.Sender != "Этот компьютер") { var client = new TcpFileClient(files1.Sender); //Подписываемся на события client.SendingEvent += flk.ChangedvalueForProgressBar; client.FailEvent += flk.SendingFailMessage; client.ReadyEvent += flk.SendingSuccessfullyMessage; ////var ans = RequestInteractivity.SendRequst(ip_to, RequestTipe.GetFileFromMe, flk.Path_To + "|" + flk.Path_From); string path = flk.Path_To + files1.nameFile + "|" + flk.Path_From + files1.nameFile; client.SendFileRequest(path); //Запускаем процесс получения файла } else { var client = new TcpFileClient(files1.Receiver); //Подписываемся на события client.SendingEvent += flk.ChangedvalueForProgressBar; client.FailEvent += flk.SendingFailMessage; client.ReadyEvent += flk.SendingSuccessfullyMessage; ////var ans = RequestInteractivity.SendRequst(ip_to, RequestTipe.GetFileFromMe, flk.Path_To + "|" + flk.Path_From); string path = flk.Path_To + files1.nameFile + "|" + flk.Path_From + files1.nameFile; client.SendFileRequest(path); //Запускаем процесс получения файла } directoryNode.Items.Add(new MenuItem() { Title = ps[0].Item1, flk = flk }); })); } } } return(directoryNode); } else { return(null); } }