/// <summary> /// Opens a dialog /// </summary> /// <param name="dialogType">The type of dialog to open</param> public static async void Show(Structures.DialogTypes dialogType) { Wind.SettingsDialog.Visibility = System.Windows.Visibility.Collapsed; Wind.MessageDialog.Visibility = System.Windows.Visibility.Collapsed; Wind.YesNoDialog.Visibility = System.Windows.Visibility.Collapsed; switch (dialogType) { case Structures.DialogTypes.SettingsDialog: SettingsDialog.InitDialog(); Wind.SettingsDialog.Visibility = System.Windows.Visibility.Visible; break; case Structures.DialogTypes.MessageDialog: Wind.MessageDialog.Visibility = System.Windows.Visibility.Visible; break; case Structures.DialogTypes.YesNoDialog: Wind.YesNoDialog.Visibility = System.Windows.Visibility.Visible; break; } try { var result = await Wind.dialogHost.ShowDialog( Wind.DialogContent, delegate(object send, DialogOpenedEventArgs args) { DialogManager.OpenDialogSession = args.Session; }); } catch (InvalidOperationException) { } }
public FoldersViewModel(DialogSession sessionMainDialogHost, string identifierDialogHost, ContentDB db, double widthColumnName, DataGridSelectionMode selectionMode) : base(sessionMainDialogHost, identifierDialogHost, db, widthColumnName, selectionMode) { MultimediaСontent = new Content() { DataContext = new ContentViewModel(ContentWorkMode.Folders) }; _contentControlViewModel = MultimediaСontent?.DataContext as ContentViewModel; HeaderViewModel.ContentControlHeader = ContentControlViewModel?.HeaderControl as ContentHeader; }
public void ShowLoading(string rootDialogName = "RootDialog") { _progress = default(ProgressState); var view = new ProgressIndicator() { DataContext = this }; _dialogTask = DialogHost.Show(view, rootDialogName, (sender, args) => _session = args.Session, null); }
public void CanOpenAndCloseDialogWithIsOpen() { _dialogHost.IsOpen = true; DialogSession session = _dialogHost.CurrentSession; Assert.False(session.IsEnded); _dialogHost.IsOpen = false; Assert.False(_dialogHost.IsOpen); Assert.Null(_dialogHost.CurrentSession); Assert.True(session.IsEnded); }
public async Task <object> ShowDialog(string id, object view) { void Openedhandler(object sender, DialogOpenedEventArgs eventArgs) { DialogSession = eventArgs.Session; } void Closinghandler(object sender, DialogClosingEventArgs e) { DialogSession = null; } return(await DialogHost.Show(view, id, Openedhandler, Closinghandler)); }
public async Task CanCloseDialogWithRoutedEvent() { Guid closeParameter = Guid.NewGuid(); Task <object> showTask = _dialogHost.ShowDialog("Content"); DialogSession session = _dialogHost.CurrentSession; Assert.False(session.IsEnded); DialogHost.CloseDialogCommand.Execute(closeParameter, _dialogHost); Assert.False(_dialogHost.IsOpen); Assert.Null(_dialogHost.CurrentSession); Assert.True(session.IsEnded); Assert.Equal(closeParameter, await showTask); }
private async Task StartTimer(DialogSession sessionArg = null) { int timer = 10; //Trace.WriteLine($"=======IDLE COUNTDOWN STARTS==========timer={timer}"); while (timer >= 0 && !sessionArg.IsEnded) { textBlock1.Text = $"Вам еще нужно время? ({timer})"; //Trace.WriteLine($"=======IDLE WHILE==timer={timer}"); await Task.Delay(1000); timer--; } //Trace.WriteLine("=======IDLE COUNTDOWN close dialog timeout=========="); DialogHost.CloseDialogCommand.Execute(false, this); }
public async Task <OsmoMessageBoxResult> ShowDialog(MaterialMessageBox msgBox) { while (IsOpen) { await Task.Delay(100); } IsOpen = true; await DialogHost.Show(msgBox, delegate(object sender, DialogOpenedEventArgs args) { session = args.Session; }); IsOpen = false; session = null; return(msgBox.Result); }
public DirectoriesViewModel(DialogSession sessionMainDialogHost, string identifierDialogHost, ContentDB db, double widthColumnName, DataGridSelectionMode selectionMode) { _identifierDialogHost = identifierDialogHost; _sessionMainDialogHost = sessionMainDialogHost; //SessionMainDialogHost?.UpdateContent(new SampleProgressDialog() { DataContext = new SampleProgressDialogViewModel(Settings.Same().LocalisationHelper["DMLRes.ConnectingDatabaseCaption"]) }); HeaderControlHorizontalAlignment = HorizontalAlignment.Left; HeaderControlInit(); SelectionChangedCommand = new DelegateCommand(SelectionChanged); MainWindowViewModel.LocalizationChangedEvent += new Action(SetColumNameCaption); // Init data _db = db; DataGridViewDepProp.Instance.WidthColumnName = widthColumnName; _tableName = typeof(T).Name + "s"; _columnNameLocalizationIndex = GetColumnNameLocalizationIndex(); SetColumNameCaption(); Load(); SelectionMode = selectionMode; SessionMainDialogHost?.Close(false); }
private static void DeleteFiles(IEnumerable <Redistributables> redistributables, ProgressBar progressBar, DialogSession dialogSession) { Task.Factory.StartNew(() => { var failures = new List <string>(); foreach (var item in redistributables.Select((red, idx) => new { red, idx })) { progressBar.Dispatcher.BeginInvoke(new Action(() => progressBar.Value = item.idx)); try { if (File.Exists(item.red.Path)) { File.Delete(item.red.Path); } } catch { failures.Add(item.red.Path); } } if (failures.Count > 0) { progressBar.Dispatcher.BeginInvoke(new Action(() => { var failuresDialog = new FailuresDialog { FailuresListBox = { ItemsSource = failures } }; dialogSession.UpdateContent(failuresDialog); })); } else { progressBar.Dispatcher.BeginInvoke(new Action(dialogSession.Close)); } }); }
public CatalogViewModel(DialogSession sessionMainDialogHost, ContentDB db) { _sessionMainDialogHost = sessionMainDialogHost; HeaderControl = new CatalogHeader() { DataContext = new CatalogHeaderViewModel(o => UpdCommandValidate(), o => DelCommandValidate()) }; HeaderControlHorizontalAlignment = HorizontalAlignment.Left; _headerViewModel = HeaderControl.DataContext as CatalogHeaderViewModel; // Subscriptions on events _headerViewModel.AddRootCommandEvent += () => AddRoot(); _headerViewModel.AddCommandEvent += () => Add(); _headerViewModel.UpdCommandEvent += () => Upd(); _headerViewModel.DelCommandEvent += () => Del(); _headerViewModel.ReplaceCommandEvent += () => Replace(); _headerViewModel.ConditionsEvent += (o) => ImplementConditions(o); CatalogSelectedItemChangedCommand = new DelegateCommand(CatalogSelectedItemChanged); // Init data _db = db; SelectedIndex = -1; Load(); }
private async void StartCleaning(ProgressBar progressBar, DialogSession session) { var callback = new Progress <int>( i => { progressBar.Dispatcher.BeginInvoke(new Action(() => { progressBar.Value = i; })); }); var result = await cleanerService.CleanAsync(currentResult, callback); if (result.Failures.Count > 0) { await progressBar.Dispatcher.BeginInvoke(new Action(() => { var failuresDialog = new FailuresDialog { FailuresListBox = { ItemsSource = result.Failures } }; session.UpdateContent(failuresDialog); })); } else { await progressBar.Dispatcher.BeginInvoke(new Action(session.Close)); } CanRefresh = true; await RunRefresh(); }
private void CloseDialog(DialogSession ds) { ds.Close(); }
public void ExtendedOpenedEventHandler(object sender, DialogOpenedEventArgs eventargs) { _session = eventargs.Session; }
public void OnDialogOpened(object sender, DialogOpenedEventArgs e) { Session = e.Session; }
public void DialogHost_DialogOpened(object sender, DialogOpenedEventArgs eventArgs) { dialogSession = eventArgs.Session; }
public void NotifyDialogClosed() { session = null; dialogSender = null; IsOpen = false; }
private void CloseDialog(DialogSession dc) { dc.Close(); }
protected virtual void OnDialogOpened(object sender, DialogOpenedEventArgs e) { Session = e.Session; }
public void updateShow(Exception ex, DialogSession session) { InitalMessage(ex); view = new ErrorDialog(); session.UpdateContent(view); }
private void ExtendedOpenedEventHandler(object sender, DialogOpenedEventArgs eventArgs) { // 关闭对话框传值 dialogSession = eventArgs.Session; }
public KaleidoscopeImagesViewModel(DialogSession sessionMainDialogHost) : this() { _sessionMainDialogHost = sessionMainDialogHost; }
public MDSession(DialogSession session) { Session = session; }
public void SetSession(DialogSession s) { Session = s; }
public CreateAPISecretView(DialogSession session) { this.session = session; }
private void OpenedEventHandler(object sender, DialogOpenedEventArgs eventargs) { _dialogSession = eventargs.Session; }
public void NotifyDialogOpened(DialogSession session) { this.session = session; IsOpen = true; }
async Task DialogSessionMainProcAsync(DialogSession session, CancellationToken cancel) { session.Debug("Start"); ThinClientConnectOptions connectOptions = (ThinClientConnectOptions)session.Param !; await using WideTunnel wt = new WideTunnel(this.Options.WideTunnelOptions); ThinClientAuthResponse authResponseCache = null !; session.Debug($"Begin DcConnectEx. connectOptions: {connectOptions._GetObjectDump()}"); await using ThinClientConnection firstConnection = await DcConnectEx(wt, connectOptions, cancel, true, true, async (req, c) => { // 認証コールバック var response = (ThinClientAuthResponse)(await session.RequestAndWaitResponseAsync(req, Consts.ThinClient.RequestHardTimeoutMsecs, Consts.ThinClient.RequestSoftTimeoutMsecs, cancel)); authResponseCache = response; return(response); }, async (req, c) => { // OTP コールバック var response = (ThinClientOtpResponse)(await session.RequestAndWaitResponseAsync(req, Consts.ThinClient.RequestHardTimeoutMsecs, Consts.ThinClient.RequestSoftTimeoutMsecs, cancel)); return(response); }, async (req, c) => { // 検疫・MAC アドレスコールバック var response = (ThinClientInspectResponse)(await session.RequestAndWaitResponseAsync(req, Consts.ThinClient.RequestHardTimeoutMsecs, Consts.ThinClient.RequestSoftTimeoutMsecs, cancel)); return(response); }); //if (connectOptions.DebugGuacMode == false) //{ // session.Debug("Switching to WebSocket mode..."); // string webSocketUrl = await firstConnection.Socket.RequestSwitchToWebSocketAsync(cancel, Consts.ThinClient.RequestSwitchToWebSocketTimeoutMsecs); // session.Debug($"Switching to WebSocket mode OK. webSocketUrl = {webSocketUrl}"); //} session.Debug("First WideTunnel Connected."); if (connectOptions.DebugGuacMode == false) { // ThinGate ネイティブ WebSocket モード (ThinGate が WebSocket を直接話す) if (firstConnection.Caps.Bit(ThinServerCaps.GuacdSupported) == false) { // 古いバージョンであり、サポートされていない throw new VpnException(VpnError.ERR_DESK_GUACD_NOT_SUPPORTED_VER); } // 'A' を送信 // この段階でサーバー機の Guacd にソケットが接続された状態となる byte[] a = new byte[] { (byte)'A' }; await firstConnection.Stream.SendAsync(a, cancel); // 最初に少し Guacamole Protocol で ThinWebClient と guacd との間で対話を行なう。 // これを行なうことにより、guacd が、local PC の RDP/VNC に接続し通信を初期化する。 // その後、WebSocket への切替えを行ない、それ以降は guacd とクライアント Web ブラウザが直接対話する。 await using var guaClient = new GuaClient( new GuaClientSettings( "", 0, firstConnection.SvcType == ThinSvcType.Rdp ? GuaProtocol.Rdp : GuaProtocol.Vnc, "127.0.0.1", firstConnection.SvcPort, connectOptions.GuaPreference !, connectOptions.IsWebpSupported, firstConnection.Caps.Bit(ThinServerCaps.AudioInSupported)), firstConnection.Stream); string webSocketUrl = ""; // この非同期 StartAsync は、Guacd Protocol で "select, rdp" のような最初の hello に相当するプロトコルを送付し、 // その後、最初の応答を受信してから、いくつかの追加パラメータを送付し、最後に、Connect パケットを送付する直前に呼び出される。 // Connect パケットの本体は文字列にして HTML5 クライアントに渡される。 // その後、HTML5 クライアントが WebSocket を ThinGate との間で確立した後に、 // HTML5 クライアントから最初のパケットとして Connect パケットの本体が渡されることになるのである。 string connectPacketData = await guaClient.StartAsync(cancel); webSocketUrl = await firstConnection.Socket.RequestSwitchToWebSocketAsync(cancel, Consts.ThinClient.RequestSwitchToWebSocketTimeoutMsecs); $"webSocketUrl = {webSocketUrl}"._Debug(); webSocketUrl._NotEmptyCheck(nameof(webSocketUrl)); // フル WebSocket URL を生成する var gateEndPoint = firstConnection.Socket.GatePhysicalEndPoint; // WebSocket URL を HTML クライアントに通知する var ready = new ThinClientAcceptReadyNotification { WebSocketFullUrl = "wss://" + IPUtil.GenerateWildCardDnsFqdn(gateEndPoint.Address, firstConnection.Socket.Options.ConnectParam.WebSocketWildCardDomainName, "ws-", "") + (gateEndPoint.Port == 443 ? "" : ":" + gateEndPoint.Port.ToString()) + webSocketUrl, SvcType = firstConnection.SvcType, ConnectPacketData = connectPacketData, WatermarkStr1 = firstConnection.WatermarkStr1, WatermarkStr2 = firstConnection.WatermarkStr2, Misc = firstConnection.Misc, Caps = firstConnection.Caps, IsStandaloneMode = firstConnection.Socket.Options.ConnectParam.IsStandaloneMode, }; if (firstConnection.Socket.Options.ConnectParam.WebSocketWildCardDomainName._IsSamei("<<!!samehost!!>>")) { ready.WebSocketFullUrl = webSocketUrl; } Dbg.Where(); await session.RequestAndWaitResponseAsync(ready, Consts.ThinClient.RequestHardTimeoutMsecs, Consts.ThinClient.RequestSoftTimeoutMsecs, isFinalAnswer : true); // 確立済みの firstConnection は何か 1 バイトでもデータを受信するか切断されるまで待機する // (このコネクションは ThinGate からみると用済みのため、新たなデータが届くことはないはずである) Dbg.Where("Waiting for unnecessary connection (already switched to WebSocket) disconnects."); // タイムアウトは 30 秒であります。 try { var data2 = await firstConnection.Stream._ReadAsyncWithTimeout(maxSize : 1024, timeout : 30 * 1000, cancel : cancel); } catch (Exception ex) { ex._Debug(); } Dbg.Where("Unnecessary connection (already switched to WebSocket) is disconnected."); } else { // Guacd Proxy Mode (デバッグ・開発用) await using var abort = new CancelWatcher(cancel); AsyncAutoResetEvent connectionAddedEvent = new AsyncAutoResetEvent(); AsyncAutoResetEvent connectedEvent = new AsyncAutoResetEvent(); Task? connectionKeepTask = null; NetTcpListener?listener = null; // このコネクションをキューに追加する ConcurrentQueue <ThinClientConnection> connectionQueue = new ConcurrentQueue <ThinClientConnection>(); try { connectionQueue.Enqueue(firstConnection); // コネクションのキューの長さが ConnectionQueueLength 未満になると自動的にコネクションを張る非同期タスクを開始する connectionKeepTask = TaskUtil.StartAsyncTaskAsync(async() => { int numRetry = 0; while (abort.IsCancellationRequested == false) { // キューの長さが少なくなれば追加コネクションを接続する while (abort.IsCancellationRequested == false) { if (connectionQueue.Count < Consts.ThinClient.ConnectionQueueLength) { session.Debug($"connectionQueue.Count ({connectionQueue.Count}) < Consts.ThinClient.ConnectionQueueLength ({Consts.ThinClient.ConnectionQueueLength})"); try { // 追加接続 ThinClientConnection additionalConnection = await DcConnectEx(wt, connectOptions, abort, false, false, async(req, c) => { // 認証コールバック await Task.CompletedTask; // キャッシュされた認証情報をそのまま応答 return(authResponseCache); }, async(req, c) => { // OTP コールバック await Task.CompletedTask; // OTP チケットを応答 return(new ThinClientOtpResponse { Otp = firstConnection.OtpTicket }); }, async(req, c) => { // 検疫・MAC コールバック await Task.CompletedTask; // チケットを応答 return(new ThinClientInspectResponse { Ticket = firstConnection.InspectTicket }); }); // 接続に成功したのでキューに追加 connectionQueue.Enqueue(additionalConnection); session.Debug($"Additional WideTunnel Connected. connectionQueue.Count = ({connectionQueue.Count})"); connectionAddedEvent.Set(true); numRetry = 0; } catch (Exception ex) { // 接続に失敗したので一定時間待ってリトライする ex._Debug(); session.Error(ex._GetObjectDump()); numRetry++; int waitTime = Util.GenRandIntervalWithRetry(Consts.ThinClient.ReconnectRetrySpanMsecs, numRetry, Consts.ThinClient.ReconnectRetrySpanMaxMsecs); if (waitTime == 0) { waitTime = 1; } session.Debug($"Additional tunnel establish failed. numRetry = {numRetry}. Wait for {waitTime} msecs..."); await connectedEvent.WaitOneAsync(waitTime, abort); } } else { break; } } if (abort.IsCancellationRequested) { break; } await connectedEvent.WaitOneAsync(1000, abort); } }); // Listen ソケットの開始 listener = LocalNet.CreateTcpListener(new TcpListenParam(isRandomPortMode: EnsureSpecial.Yes, async(listen, sock) => { session.Debug($"Listener ({sock.EndPointInfo._GetObjectDump()}) Accepted."); ThinClientConnection?connection = null; long giveupTick = TickNow + Consts.ThinClient.ConnectionQueueWaitTimeout; // キューにコネクションが貯まるまで待機する while (connectionQueue.TryDequeue(out connection) == false) { if (TickNow >= giveupTick) { session.Debug($"Listener ({sock.EndPointInfo._GetObjectDump()}): TickNow ({TickNow}) >= giveupTick ({giveupTick})"); return; } abort.ThrowIfCancellationRequested(); await connectionAddedEvent.WaitOneAsync(100, abort.CancelToken); } await using ThinClientConnection connection2 = connection; session.Debug($"Listener ({sock.EndPointInfo._GetObjectDump()}) Starting Relay Operation."); // 'A' を送信 byte[] a = new byte[] { (byte)'A' }; await connection.Stream.SendAsync(a, abort); var sockStream = sock.GetStream(true); RefLong totalBytes = new RefLong(); try { await Util.RelayDuplexStreamAsync(sockStream, connection.Stream, abort, totalBytes: totalBytes); } catch (Exception ex) { session.Debug($"Listener ({sock.EndPointInfo._GetObjectDump()}) RelayDuplexStreamAsync Exception = {ex._GetObjectDump()}"); } session.Debug($"Listener ({sock.EndPointInfo._GetObjectDump()}) Finished Relay Operation. Total Bytes = {totalBytes.Value}"); // RDP の場合はダミーデータを最後に流す if (connection.SvcType == ThinSvcType.Rdp) { byte[] dummySize = new byte[4096]; await sockStream.SendAsync(dummySize, abort); await Task.Delay(50, abort); } }, family: Options.ListenAddressFamily, address: Options.ListenAddress)); session.Debug($"Create Listener. Assigned Random Port = {listener.AssignedRandomPort}"); // 接続が完了いたしました var ready = new ThinClientAcceptReadyNotification { ListenEndPoint = new IPEndPoint(listener.AssignedRandomPort !.IPAddress, listener.AssignedRandomPort.Port), FirstConnection = firstConnection, Caps = firstConnection.Caps, }; Dbg.Where(); await session.RequestAndWaitResponseAsync(ready, Consts.ThinClient.RequestHardTimeoutMsecs, Consts.ThinClient.RequestSoftTimeoutMsecs, abort, isFinalAnswer : true); // コネクション数が 0 の状態が 30 秒以上継続した場合は終了します long connectionZeroStartTick = 0; while (true) { abort.ThrowIfCancellationRequested(); long now = TickNow; //$"listener.CurrentConnections = {listener.CurrentConnections}"._Debug(); if (listener.CurrentConnections == 0) { if (connectionZeroStartTick == 0) { connectionZeroStartTick = now; } } else { connectionZeroStartTick = 0; } if (connectionZeroStartTick != 0 && now >= (connectionZeroStartTick + Consts.ThinClient.ConnectionZeroTimeout)) { session.Debug($"All client connections disconnected. No more connection exists. connectionZeroStartTick = {connectionZeroStartTick}, now = {now}"); throw new CoresException("All client connections disconnected. No more connection exists."); } await abort.CancelToken._WaitUntilCanceledAsync(1000); } } catch (Exception ex) { session.Error(ex); throw; } finally { abort.Cancel(); await connectionKeepTask._TryAwait(noDebugMessage : true); await listener._DisposeSafeAsync(); foreach (var connection in connectionQueue) { await connection._DisposeSafeAsync(); } Dbg.Where(); } } }
private void DialogOpenHandler(object sender, DialogOpenedEventArgs eventargs) { _currentDialogSession = eventargs.Session; }
private void SaveHandler(ConnectionEditorViewModel connectionEditorViewModel, DialogSession dialogSession) { var connection = new ExplicitConnection(connectionEditorViewModel.Id.GetValueOrDefault(Guid.NewGuid()), connectionEditorViewModel.Label, connectionEditorViewModel.Host, connectionEditorViewModel.AuthorisationKey, connectionEditorViewModel.DatabaseId, connectionEditorViewModel.CollectionId); _explicitConnectionCache.AddOrUpdate(connection); dialogSession.Close(connection); }