private void DeletePortForwarding() { if (_isPortForwarding) { NatHelper.BeginDeleteForwardingRule(_port, System.Net.Sockets.ProtocolType.Tcp, (ar) => NatHelper.EndDeleteForwardingRule(ar)); _isPortForwarding = false; } }
public App() { AppDomain.CurrentDomain.UnhandledException += (sender, e) => { LogUnhandledException(e.ExceptionObject); }; NatHelper.BeginDiscover((ar) => NatHelper.EndDiscover(ar)); }
public App() { this.Startup += new StartupEventHandler(App_Startup); this.Exit += new ExitEventHandler(App_Exit); AppDomain.CurrentDomain.UnhandledException += (sender, e) => { LogUnhandledException(e.ExceptionObject); }; NatHelper.BeginDiscover((ar) => NatHelper.EndDiscover(ar)); }
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); } }
protected override async void OnStartup(object sender, StartupEventArgs e) { var startupTasks = GetAllInstances(typeof(StartupTask)) .Cast <ExportedDelegate>() .Select(exportedDelegate => (StartupTask)exportedDelegate.CreateDelegate(typeof(StartupTask))); startupTasks.Apply(s => s()); base.OnStartup(sender, e); await NatHelper.DiscoverAsync(); ThemeManager.AddAppTheme("CobaltLight", new Uri("pack://application:,,,/Themes/CobaltLight.xaml")); ThemeManager.AddAppTheme("CobaltDark", new Uri("pack://application:,,,/Themes/CobaltDark.xaml")); ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.Accents.First(a => a.Name == "Blue"), ThemeManager.GetAppTheme("CobaltLight")); }
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); } }