private async void PutClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if (Convert.ToBoolean(eventArgs.Parameter) == false) { _cts.Cancel(); return; } var dialogModel = (eventArgs.Session.Content as UserControl)?.DataContext as TransferDialogViewModel; var dir = dialogModel?.LocalDirectory; var zkPath = dialogModel?.ZkPath; if (string.IsNullOrEmpty(dir) || string.IsNullOrEmpty(zkPath)) { //TODO: Throw the snackbar return; } _cts = new CancellationTokenSource(); //OK, lets cancel the close... eventArgs.Cancel(); //...now, lets update the "session" with some new content! eventArgs.Session.UpdateContent(new ProgressDialog()); //note, you can also grab the session when the dialog opens via the DialogOpenedEventHandler await Task.Run(async() => { using (var zkClient = new SolrZkClient($"{ZkHostConnected}:{ZkPortConnected}")) { try { await zkClient.uploadToZK(dir, zkPath, ZkConfigManager.UploadFilenameExcludeRegex, _cts.Token); } catch (Exception ex) { //TODO: Show error; } } }).ContinueWith((t, _) => { }, null, TaskScheduler.FromCurrentSynchronizationContext()); //TODO: Do if ex was not throwen if (!_cts.IsCancellationRequested) { eventArgs.Session.UpdateContent(new CheckDialog()); await Task.Delay(TimeSpan.FromMilliseconds(CheckDialogShowingTimeMillis)) .ContinueWith((t, _) => eventArgs.Session.Close(false), null, TaskScheduler.FromCurrentSynchronizationContext()); } UpdateZkTree(ZkHostConnected, ZkPortConnected); }
private async void DeletePathClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if (Convert.ToBoolean(eventArgs.Parameter) == false) { _cts.Cancel(); return; } var dialogModel = (eventArgs.Session.Content as UserControl)?.DataContext as CommonDialogViewModel; var zkPath = dialogModel?.Name; _cts = new CancellationTokenSource(); //OK, lets cancel the close... eventArgs.Cancel(); //...now, lets update the "session" with some new content! eventArgs.Session.UpdateContent(new ProgressDialog()); //note, you can also grab the session when the dialog opens via the DialogOpenedEventHandler await Task.Run(async() => { using (var zkClient = new SolrZkClient($"{ZkHostConnected}:{ZkPortConnected}")) { try { await zkClient.clean(zkPath, _cts.Token); } catch (Exception ex) { //TODO: Show error; } } }).ContinueWith((t, _) => { }, null, TaskScheduler.FromCurrentSynchronizationContext()); if (!_cts.IsCancellationRequested) { eventArgs.Session.UpdateContent(new CheckDialog()); await Task.Delay(TimeSpan.FromMilliseconds(CheckDialogShowingTimeMillis)) .ContinueWith((t, _) => eventArgs.Session.Close(false), null, TaskScheduler.FromCurrentSynchronizationContext()); } //TODO: Do if ex was not throwen UpdateZkTree(ZkHostConnected, ZkPortConnected); }
private void ShowData(object sender, EventArgs args) { var path = string.Empty; switch (sender) { case TreeViewDirectory dir: path = dir.Path; break; case TreeViewFile file: path = file.Path; break; } Task.Run(async() => { using (var zkClient = new SolrZkClient($"{ZkHostConnected}:{ZkPortConnected}")) { try { var data = await zkClient.getData(path, null, null, true); if (data == null) { _snackbarMessageQueue.Enqueue("There is no data to show!", "OK", () => Trace.WriteLine("Actioned")); } else { var relativePath = path.Replace("/", "\\"); var dirPath = MainWindow.TempDirectory + Path.GetDirectoryName(relativePath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var filePath = Path.Combine(dirPath, Path.GetFileName(path)); File.WriteAllBytes(filePath, data); Process.Start(filePath); } } catch (Exception ex) { //TODO: Show error; } } }); }
private async Task <TreeViewDirectory> GetZkTree(SolrZkClient zkCnxn, string zooPath = "/", int depth = 2) { var children = (await zkCnxn.getChildren(zooPath, null, false)); if (!children.Any()) { return(null); } var dir = zooPath.Split('/').Length <= depth ? new TreeViewDirectory(zooPath, zooPath) : new TreeViewDirectory(zooPath); dir.ShowDataEvent += ShowData; if (zooPath.Last() != '/') { zooPath += "/"; } var files = new List <TreeViewFile>(); var dirs = new List <TreeViewDirectory>(); foreach (var child in children) { if (await ZkMaintenanceUtils.isEphemeral(zkCnxn, zooPath + child)) { //TODO: Show or not to show (add the checkbox) continue; } var entry = await GetZkTree(zkCnxn, zooPath + child); if (entry == null) { var file = new TreeViewFile(zooPath + child, child); file.ShowDataEvent += ShowData; files.Add(file); } else { dirs.Add(entry); } } dir.Directories = dirs; dir.Files = files; return(dir); }
private async void LinkConfigClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if (Convert.ToBoolean(eventArgs.Parameter) == false) { return; } var dialogModel = (eventArgs.Session.Content as UserControl)?.DataContext as LinkConfigDialogViewModel; var configName = dialogModel?.ConfigName; var collectionName = dialogModel?.CollectionName; //OK, lets cancel the close... eventArgs.Cancel(); //...now, lets update the "session" with some new content! eventArgs.Session.UpdateContent(new ProgressDialog(false)); //note, you can also grab the session when the dialog opens via the DialogOpenedEventHandler await Task.Run(async() => { using (var zkClient = new SolrZkClient($"{ZkHostConnected}:{ZkPortConnected}")) { try { var manager = new ZkConfigManager(zkClient); await manager.linkConfSet(collectionName, configName); } catch (Exception ex) { //TODO: Show error; } } }).ContinueWith((t, _) => { }, null, TaskScheduler.FromCurrentSynchronizationContext()); //TODO: Do if ex was not throwen eventArgs.Session.UpdateContent(new CheckDialog()); await Task.Delay(TimeSpan.FromMilliseconds(CheckDialogShowingTimeMillis)) .ContinueWith((t, _) => eventArgs.Session.Close(false), null, TaskScheduler.FromCurrentSynchronizationContext()); UpdateZkTree(ZkHostConnected, ZkPortConnected); }
private TreeViewDirectory ConnectToZkTree(string zkHost, string zkPort) { using (var zkClient = new SolrZkClient($"{zkHost}:{zkPort}")) { try { var tree = GetZkTree(zkClient).Result; IsZkConnected = true; tree.IsExpanded = true; ZkHostConnected = ZkHost; ZkPortConnected = ZkPort; return(tree); } catch (Exception) { _snackbarMessageQueue.Enqueue("Could not connect to ZK host!", "OK", () => Trace.WriteLine("Actioned")); IsZkConnected = false; ZkHostConnected = null; ZkPortConnected = null; } } return(null); }