public void StartSend(FileInfo file, Action <int> readyCallback) { _fileInfo = file; this.Header = string.Format("[SEND] {0}", this.Target.Name); this.Title = string.Format("{0} - [DCC {1}] Sending file {2}", App.Product, this.Target.Name, _fileInfo.Name); this.Description = string.Format("Sending {0}...", file.Name); this.FileSize = file.Length; this.Status = FileStatus.Working; switch (this.DccMethod) { case DccMethod.Send: _dcc = new DccSendSender(_fileInfo); break; case DccMethod.Xmit: _dcc = new DccXmitSender(_fileInfo); break; } _dcc.Connected += dcc_Connected; _dcc.Disconnected += dcc_Disconnected; _dcc.Error += dcc_Error; try { _port = _dcc.Listen(App.Settings.Current.Dcc.LowPort, App.Settings.Current.Dcc.HighPort); } catch (InvalidOperationException) { this.Status = FileStatus.Cancelled; this.StatusText = "Error: No ports available"; _port = 0; } if (App.Settings.Current.Dcc.EnableUpnp && NatHelper.IsAvailable) { this.StatusText = "Forwarding port"; NatHelper.BeginAddForwardingRule(_port, System.Net.Sockets.ProtocolType.Tcp, "Floe DCC", (o) => { this.Dispatcher.BeginInvoke((Action)(() => { this.StatusText = "Listening for connection"; readyCallback(_port); })); }); _isPortForwarding = true; } else { this.StatusText = "Listening for connection"; readyCallback(_port); } }
public void StartListen(Action <int> readyCallback) { _dcc = new DccChat(); _dcc.Connected += dcc_Connected; _dcc.Disconnected += dcc_Disconnected; _dcc.Error += dcc_Error; _dcc.MessageReceived += dcc_MessageReceived; try { _port = _dcc.Listen(App.Settings.Current.Dcc.LowPort, App.Settings.Current.Dcc.HighPort); } catch (InvalidOperationException) { this.Write("Error", "No available ports."); _port = 0; } if (App.Settings.Current.Dcc.EnableUpnp && NatHelper.IsAvailable) { this.Write("Client", "Forwarding port..."); NatHelper.BeginAddForwardingRule(_port, System.Net.Sockets.ProtocolType.Tcp, "Floe DCC", (o) => { this.Dispatcher.BeginInvoke((Action)(() => { this.Write("Client", "Waiting for connection..."); readyCallback(_port); })); }); _isPortForwarding = true; } else { this.Write("Client", "Waiting for connection..."); readyCallback(_port); } }