private void tranlistening_Accepted(object sender, Listen e) { try { // return; //Create our new transfer client. //And attempt to connect transferClient = new Tranferclint(e.Accepted); //transferClient.Connect(Sk); transferClient.OutputFolder = outputFolder; // Run the client transferClient.Queued += TransferClient_Queued; transferClient.ProgressChanged += TransferClient_ProgressChanged; // Enabled = false; transferClient.Stopped += TransferClient_Stopped; transferClient.Complete += TransferClient_Complete; transferClient.Disconnected += TransferClient_Disconnected;; ClintConnction = true; chekconnction = true; transferClient.Run(); } catch { } }
public static queue CreateUploadQueue(Tranferclint client, string fileName) { try { //We will create a new upload queue var queue = new queue(); //Set our filename queue.Filename = Path.GetFileName(fileName); queue.Typefile = Path.GetFileName(fileName).ToLower().Contains("jpg") || Path.GetFileName(fileName).ToLower().Contains("png") ? "Image":"Video"; // queue._Type = "image"; //Set our client queue.Client = client; //Set our queue type to upload. queue.Type = QueueType.Upload; //Create our file stream for reading. queue.FS = new FileStream(fileName, FileMode.Open); //Create our transfer thread queue.Thread = new Thread(new ParameterizedThreadStart(transferProc)); // queue.Thread.IsBackground = true; //Generate our ID queue.ID = Program.Rand.Next(); //Set our length to the size of the file. queue.Length = queue.FS.Length; return(queue); } catch { //If something goes wrong, return null return(null); } }
public static queue CreateDownloadQueue(Tranferclint client, int id, string trpe, string SName, string saveName, long length) { try { //Same as above with some changes. var queue = new queue(); queue.Filename = Path.GetFileName(saveName); queue.Shortename = SName; queue.Client = client; queue.Type = QueueType.Download; //Create our file stream for writing. queue.FS = new FileStream(saveName, FileMode.Create); //Fill the stream will 0 bytes based on the real size. So we can index write. queue.Length = length; queue.FS.SetLength(length); // queue.Length = length; //Instead of generating an ID, we will set the ID that has been sent. queue.ID = id; return(queue); } catch { return(null); } }
public void Close() { try { //Remove the current queue from the client transfer list. Client.Transfers.Remove(ID); } catch { } Running = false; //Close the stream FS.Close(); //Dispose the ResetEvent. pauseEvent.Dispose(); Client = null; }
private void TransferClient_Disconnected(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(TransferClient_Disconnected), sender, e); return; } // throw new NotImplementedException(); foreach (queue q in queueList) { q.Close(); } transferClient.Close(); transferClient = null; deregisterEvents(); clear_Listview(); //ClintConnction = false; }