public static async Task JoinInvitation([NotNull] string ip, int port, [CanBeNull] string password) { OnlineManager.EnsureInitialized(); var list = OnlineManager.Instance.List; var source = new FakeSource(ip, port); var wrapper = new OnlineSourceWrapper(list, source); ServerEntry server; using (var waiting = new WaitingDialog()) { waiting.Report(ControlsStrings.Common_Loading); await wrapper.EnsureLoadedAsync(); server = list.GetByIdOrDefault(source.Id); if (server == null) { throw new Exception(@"Unexpected"); } } if (password != null) { server.Password = password; } var content = new OnlineServer(server) { Margin = new Thickness(0, 0, 0, -38), ToolBar = { FitWidth = true }, // Values taken from ModernDialog.xaml // TODO: Extract them to some style? Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) } }; content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal); var dlg = new ModernDialog { ShowTitle = false, Content = content, MinHeight = 400, MinWidth = 450, MaxHeight = 99999, MaxWidth = 700, Padding = new Thickness(0), ButtonsMargin = new Thickness(8), SizeToContent = SizeToContent.Manual, ResizeMode = ResizeMode.CanResizeWithGrip, LocationAndSizeKey = @".OnlineServerDialog" }; dlg.SetBinding(Window.TitleProperty, new Binding { Path = new PropertyPath(nameof(server.DisplayName)), Source = server }); dlg.ShowDialog(); await wrapper.ReloadAsync(true); }
public async Task <ArgumentHandleResult> ProgressRaceOnlineJoin(NameValueCollection p) { /* required arguments */ var ip = p.Get(@"ip"); var httpPort = FlexibleParser.TryParseInt(p.Get(@"httpPort")); var password = p.Get(@"plainPassword"); var encryptedPassword = p.Get(@"password"); if (string.IsNullOrWhiteSpace(ip)) { throw new InformativeException("IP is missing"); } if (!httpPort.HasValue) { throw new InformativeException("HTTP port is missing or is in invalid format"); } OnlineManager.EnsureInitialized(); if (string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(encryptedPassword)) { password = OnlineServer.DecryptSharedPassword(ip, httpPort.Value, encryptedPassword); } var list = OnlineManager.Instance.List; var source = new FakeSource(ip, httpPort.Value); var wrapper = new OnlineSourceWrapper(list, source); ServerEntry server; using (var waiting = new WaitingDialog()) { waiting.Report(ControlsStrings.Common_Loading); await wrapper.EnsureLoadedAsync(); server = list.GetByIdOrDefault(source.Id); if (server == null) { throw new Exception(@"Unexpected"); } } if (password != null) { server.Password = password; } var content = new OnlineServer(server) { Margin = new Thickness(0, 0, 0, -43), ToolBar = { FitWidth = true }, // Values taken from ModernDialog.xaml // TODO: Extract them to some style? Title = { FontSize = 24, FontWeight = FontWeights.Light, Margin = new Thickness(6, 0, 0, 8) } }; content.Title.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal); var dlg = new ModernDialog { ShowTitle = false, Content = content, MinHeight = 400, MinWidth = 450, MaxHeight = 99999, MaxWidth = 700, Padding = new Thickness(0), ButtonsMargin = new Thickness(8), SizeToContent = SizeToContent.Manual, ResizeMode = ResizeMode.CanResizeWithGrip, LocationAndSizeKey = @".OnlineServerDialog" }; dlg.SetBinding(Window.TitleProperty, new Binding { Path = new PropertyPath(nameof(server.DisplayName)), Source = server }); dlg.ShowDialog(); await wrapper.ReloadAsync(true); return(ArgumentHandleResult.Successful); }