private async void HyperlinkButtonOpenClose_Click(object sender, RoutedEventArgs e) { HyperlinkButton btn = sender as HyperlinkButton; if (btn.Content.ToString() == "open") { bool result = await EsService.OpenIndex(esdata.EsConnInfo, btn.CommandParameter.ToString()); if (result == false) { (new MessageDialog("open fail")).ShowAsync(); } else { ToggleSwitch_Toggled(sender, e); //重新加载索引列表 } } if (btn.Content.ToString() == "close") { bool result = await EsService.CloseIndex(esdata.EsConnInfo, btn.CommandParameter.ToString()); if (result == false) { (new MessageDialog("close fail")).ShowAsync(); } else { ToggleSwitch_Toggled(sender, e); //重新加载索引列表 } } }
private async void Menu_Delete_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { var dialog = new MessageDialog("Are you sure to delete this connection?"); dialog.Commands.Add(new UICommand("ok", cmd => { }, commandId: 0)); dialog.Commands.Add(new UICommand("cancel", cmd => { }, commandId: 1)); //设置默认按钮,不设置的话默认的确认按钮是第一个按钮 dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 1; //获取返回值 IUICommand result = await dialog.ShowAsync(); if (result.Label == "ok") { if (lastTreeNode != null && lastTreeNode.Data != null) { EsSystemData esSD = (EsSystemData)lastTreeNode.Data; Menu_Close_Click(sender, e); //先关闭,再删除 EsService.DelEsFile(esSD.EsConnInfo); lastTreeNode.ParentNode.Remove(lastTreeNode); } } }
private async void btnSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(IndexName.Text.Trim())) { (new MessageDialog("please input the index name.")).ShowAsync(); //args.Cancel = true; return; } if (string.IsNullOrEmpty(TypeName.Text.Trim())) { (new MessageDialog("please input the type name.")).ShowAsync(); //args.Cancel = true; return; } string json = ""; if (checkAllField(ref json) == false) { //args.Cancel = true; return; } await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { result = await EsService.CreateIndex(esdata.EsConnInfo, IndexName.Text.Trim(), json); if (result.Success == false) { //args.Cancel = true; (new MessageDialog(result.Message)).ShowAsync(); return; } this.Hide(); }); }
private async void HyperlinkButtonDelete_Click(object sender, RoutedEventArgs e) { var dialog = new MessageDialog("are you sure to delete this index?"); dialog.Commands.Add(new UICommand("ok", cmd => { }, commandId: 0)); dialog.Commands.Add(new UICommand("cancel", cmd => { }, commandId: 1)); //设置默认按钮,不设置的话默认的确认按钮是第一个按钮 dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 1; //获取返回值 var result = await dialog.ShowAsync(); if (result.Label == "ok") { HyperlinkButton btn = sender as HyperlinkButton; bool resultBool = await EsService.DeleteIndex(esdata.EsConnInfo, btn.CommandParameter.ToString()); if (resultBool == false) { (new MessageDialog("delete fail")).ShowAsync(); } else { ToggleSwitch_Toggled(sender, e); //重新加载索引列表 } } }
private async void comboxIndex_SelectionChanged(object sender, SelectionChangedEventArgs e) { EsIndex esIndex = comboxIndex.SelectedItem as EsIndex; if (esIndex != null) { List <string> list = await EsService.GetFieldsByJson(esdata.EsConnInfo, esIndex.Name); //comboxField.SelectionChanged -= comboxField_SelectionChanged; comboxField.Items.Clear(); comboxField.Items.Add(new ComboBoxItem() { Content = "match_all", IsSelected = true }); comboxField.Items.Add(new ComboBoxItem() { Content = "_all" }); foreach (string str in list) { comboxField.Items.Add(new ComboBoxItem() { Content = str }); } //comboxField.SelectionChanged += comboxField_SelectionChanged; spContent.Children.Clear(); } }
private async void HyperlinkButtonDelete_Click(object sender, RoutedEventArgs e) { var dialog = new MessageDialog("are you sure to delete this template?"); dialog.Commands.Add(new UICommand("ok", cmd => { }, commandId: 0)); dialog.Commands.Add(new UICommand("cancel", cmd => { }, commandId: 1)); //设置默认按钮,不设置的话默认的确认按钮是第一个按钮 dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 1; //获取返回值 var result = await dialog.ShowAsync(); if (result.Label == "ok") { HyperlinkButton btn = sender as HyperlinkButton; string tempName = btn.CommandParameter.ToString(); FuncResult funcResult = await EsService.DeleteTemplate(esdata.EsConnInfo, tempName); if (funcResult.Success == false) { PageUtil.ShowMsg(funcResult.Message); return; } else { InitData(); } } }
private async void Menu_DeleteIndex_Click(object sender, RoutedEventArgs e) { var dialog = new MessageDialog("are you sure to delete the \"" + CommandParameter + "\" ?"); dialog.Commands.Add(new UICommand("ok", cmd => { }, commandId: 0)); dialog.Commands.Add(new UICommand("cancel", cmd => { }, commandId: 1)); //设置默认按钮,不设置的话默认的确认按钮是第一个按钮 dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 1; //获取返回值 var result = await dialog.ShowAsync(); if (result.Label == "ok") { bool resultBool = await EsService.DeleteIndex(esdata.EsConnInfo, CommandParameter); if (resultBool == false) { PageUtil.ShowMsg("delete fail"); //(new MessageDialog("delete fail")).ShowAsync(); } else { ToggleSwitch_Toggled(sender, e); //重新加载索引列表 } } }
private async void Menu_IndexMapping_Click(object sender, RoutedEventArgs e) { JObject jObject = await EsService.GetIndexMapping(esdata.EsConnInfo, CommandParameter); ContentDialog_Mapping mappingDig = new ContentDialog_Mapping(jObject.ToString()); mappingDig.ShowAsync(); }
private async Task InitData(bool isShowSysIndex) { listview1.ItemsSource = null; List <EsIndex> listIndex = await EsService.GetIndexList(esdata.EsConnInfo, isShowSysIndex); listview1.ItemsSource = listIndex; MainPage.mainPage.listIndex = listIndex; }
private async void HyperlinkButtonMapping_Click(object sender, RoutedEventArgs e) { HyperlinkButton btn = sender as HyperlinkButton; JObject jObject = await EsService.GetIndexMapping(esdata.EsConnInfo, btn.CommandParameter.ToString()); ContentDialog_Mapping mappingDig = new ContentDialog_Mapping(jObject.ToString()); mappingDig.ShowAsync(); }
private void Menu_Refresh_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { sampleTreeView.RootNode.Clear(); listConnectionInfo = EsService.GetEsFiles(); foreach (EsConnectionInfo connInfo in listConnectionInfo) { AddNode(connInfo); } }
private async void Menu_CreateMapping_Click(object sender, RoutedEventArgs e) { JObject jObject = await EsService.GetIndexMapping(esdata.EsConnInfo, CommandParameter); var tokens = jObject.SelectTokens(CommandParameter + ".mappings"); string mappings = (tokens.First <JToken>() as JObject).ToString(); mappings = "put " + CommandParameter + "{ \"mappings\":" + mappings + "}"; esdata.Tag = mappings; MainPage.mainPage.AddPivotItem(typeof(Page_Query), esdata, "Query@" + esdata.Name); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter == null) { return; } EsSystemData esSystemData = e.Parameter as EsSystemData; txtBlock1.Text = await EsService.GetPlugin(esSystemData.EsConnInfo); }
private async void Menu_CloseIndex_Click(object sender, RoutedEventArgs e) { bool result = await EsService.CloseIndex(esdata.EsConnInfo, CommandParameter); if (result == false) { PageUtil.ShowMsg("close fail"); //(new MessageDialog("close fail")).ShowAsync(); } else { ToggleSwitch_Toggled(sender, e); //重新加载索引列表 } }
private void Menu_Open_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { PageUtil.SetLoadingCursor(); try { if (lastTreeNode != null && lastTreeNode.Data != null) { if (lastTreeNode.HasItems) { PageUtil.SetDefaultCursor(); return; //lastTreeNode.Clear(); } EsSystemData esSD = (EsSystemData)lastTreeNode.Data; if (esSD.EsConnInfo.isUseSSH) { if (esSD.SSHClient == null || esSD.SSHClient.IsConnected == false) { esSD.SSHClient = EsService.GetSshClient(esSD.EsConnInfo); } } if (EsService.ConnectionTest(esSD.EsConnInfo) == false) //最终检查是否能获取到Es 版本信息 为判断依据 { PageUtil.ShowMsg("connect fail!"); //(new MessageDialog("连接失败!")).ShowAsync(); return; } (lastTreeNode.Data as EsSystemData).IsConnect = true; lastTreeNode.Data = esSD; if (lastTreeNode.IsExpanded == false) { lastTreeNode.IsExpanded = true; } AddTreeNodeChild(lastTreeNode); } PageUtil.SetDefaultCursor(); } catch { PageUtil.ShowMsg("connect error!"); //(new MessageDialog("连接异常!")).ShowAsync(); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter == null) { return; } esdata = e.Parameter as EsSystemData; if (MainPage.mainPage.listIndex.Count == 0) { MainPage.mainPage.listIndex = await EsService.GetIndexList(esdata.EsConnInfo); } comboxIndex.ItemsSource = MainPage.mainPage.listIndex; comboxIndex.SelectedIndex = 0; }
private async Task GetBrowsePageData(string indexName, int pIndex) { PerPageData perPageData = await EsService.GetIndexData(esdata.EsConnInfo, indexName, pIndex); pageIndex = perPageData.pageIndex; totalPageCount = perPageData.totalPageCount; textBlockPageIndex.Text = (perPageData.pageIndex + 1).ToString(); textBlockTotalPageCount.Text = perPageData.totalPageCount.ToString(); //pivot1.SelectedIndex = 1; int rowIndex = 0; gridData.ColumnSpacing = 2; gridData.RowSpacing = 5; gridData.Children.Clear(); gridData.RowDefinitions.Clear(); gridData.ColumnDefinitions.Clear(); if (perPageData != null) { JObject jObject = perPageData.pageData as JObject; JArray arrData = jObject.Root["hits"]["hits"] as JArray; if (arrData.Count > 0) { gridData.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(40) }); //添加一行, 存放标题栏 foreach (JObject jObj in arrData) //行 { gridData.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); //添加一行 GetAllProperty(jObj, 0, rowIndex, gridData); rowIndex++; } gridData.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); //添加一行 } } }
private async void AppBarButtonRun_Click(object sender, RoutedEventArgs e) { PageUtil.SetLoadingCursor(); try { string commandTxt = string.IsNullOrEmpty(txtBoxCommand.SelectedText) ? txtBoxCommand.Text.Trim() : txtBoxCommand.SelectedText; if (string.IsNullOrEmpty(commandTxt) == false) { string[] arrCommandTxt = commandTxt.Split(new char[] { '{' }, 2, StringSplitOptions.RemoveEmptyEntries); if (arrCommandTxt.Length == 1) { string[] arr1 = arrCommandTxt[0].ToString().Split(' '); if (arr1.Length == 2) { string method = arr1[0].Trim(); string command = arr1[1].Trim(); ShowResult(await EsService.RunJson(esdata.EsConnInfo, method, command)); } } else if (arrCommandTxt.Length == 2) //带{}的命令 { string[] arr1 = arrCommandTxt[0].ToString().Split(' '); if (arr1.Length == 2) { string method = arr1[0].Trim(); string command = arr1[1].Trim().Trim('/'); string json = "{" + arrCommandTxt[1].Trim(); string result = await EsService.RunJson(esdata.EsConnInfo, method, command, json); ShowResult(result); } } } } catch { } PageUtil.SetDefaultCursor(); }
private async void ButtonSearch_Click(object sender, RoutedEventArgs e) { mustJson = new List <string>(); mustnotJson = new List <string>(); shouldJson = new List <string>(); GetSearchLineCondition(comboxMust.Parent as StackPanel); foreach (StackPanel sp in spContent.Children) { GetSearchLineCondition(sp); } string indexName = (comboxIndex.SelectedItem as EsIndex).Name; string mustStr = "", mustnotStr = "", shouldStr = ""; foreach (string str in mustJson) { mustStr += str; } mustStr = "\"must\":[" + mustStr.Trim(',') + "]"; foreach (string str in mustnotJson) { mustnotStr += str; } mustnotStr = "\"must_not\":[" + mustnotStr.Trim(',') + "]"; foreach (string str in shouldJson) { shouldStr += str; } shouldStr = "\"should\":[" + shouldStr.Trim(',') + "]"; string json = "\"bool\":{" + mustStr + "," + mustnotStr + "," + shouldStr + "}"; PerPageData perPageData = await EsService.GetIndexData(esdata.EsConnInfo, indexName, pageIndex : pageIndex, strJson : json); int rowIndex = 0; gridData.ColumnSpacing = 2; gridData.RowSpacing = 5; gridData.Children.Clear(); gridData.RowDefinitions.Clear(); gridData.ColumnDefinitions.Clear(); if (perPageData != null) { txtJson.Text = perPageData.json; pageIndex = perPageData.pageIndex; totalPageCount = perPageData.totalPageCount; JObject jObject = perPageData.pageData as JObject; JArray arrData = jObject.Root["hits"]["hits"] as JArray; if (arrData.Count > 0) { gridData.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) }); //添加一行, 存放标题栏 foreach (JObject jObj in arrData) //行 { gridData.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); //添加一行 Page_BrowData.GetAllProperty(jObj, 0, rowIndex, gridData); rowIndex++; } gridData.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); //添加一行 } } }
private async System.Threading.Tasks.Task InitData() { listview1.ItemsSource = await EsService.GetTemplate(esdata.EsConnInfo); }
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { PageUtil.SetLoadingCursor(); connInfo = new EsConnectionInfo(); connInfo.connectionName = connetionName.Text.Trim() == "" ? esIp.Text.Trim() + "_" + esPort.Text.Trim() : connetionName.Text.Trim(); if (EsService.checkFileName(connInfo.connectionName) == false) { PageUtil.ShowMsg("Connection name invalid"); //(new MessageDialog("连接名称无效!")).ShowAsync(); args.Cancel = true; return; } if (EsService.checkFileExists(connInfo.connectionName)) { PageUtil.ShowMsg("Connection name already exists"); //(new MessageDialog("连接名称重复!")).ShowAsync(); args.Cancel = true; return; } connInfo.esIp = esIp.Text.Trim(); int intLanPort = 0; if (int.TryParse(esPort.Text.Trim(), out intLanPort) == false) { PageUtil.ShowMsg("Lan Port is not correct"); //(new MessageDialog("内网端口输入不正确!")).ShowAsync(); args.Cancel = true; return; } connInfo.esPort = intLanPort; connInfo.esUsername = esUserName.Text.Trim(); connInfo.esPassword = esPassword.Text.Trim(); connInfo.localPort = connInfo.esPort + 1; //把本地端口设置为es端口加1 connInfo.isUseSSH = isUseSSH.IsOn; if (isUseSSH.IsOn) { if (string.IsNullOrEmpty(sshIp.Text.Trim()) || string.IsNullOrEmpty(sshPort.Text.Trim()) || string.IsNullOrEmpty(userName.Text.Trim())) { PageUtil.ShowMsg("Lan Port is not correct"); //(new MessageDialog("必须输入SSH主机名、端口和用户名!")).ShowAsync(); args.Cancel = true; return; } connInfo.sshIp = sshIp.Text.Trim(); int intSshPort = 0; if (int.TryParse(sshPort.Text.Trim(), out intSshPort) == false) { PageUtil.ShowMsg("Port is not correct"); //(new MessageDialog("端口输入不正确!")).ShowAsync(); args.Cancel = true; return; } connInfo.sshPort = intSshPort; connInfo.username = userName.Text.Trim(); connInfo.password = password.Text.Trim(); } try { SshClient sshClient = null; if (connInfo.isUseSSH) { sshClient = EsService.GetSshClient(connInfo); //连接测试 } isSuccess = EsService.ConnectionTest(connInfo); if (isSuccess == false) //最终检查是否能获取到Es 版本信息 为判断依据 { PageUtil.ShowMsg("Connect fail"); //(new MessageDialog("连接失败!")).ShowAsync(); args.Cancel = true; return; } if (connInfo.isUseSSH && sshClient.IsConnected) { sshClient.Disconnect(); sshClient.Dispose(); } EsService.SaveEsFile(connInfo); PageUtil.SetDefaultCursor(); } catch (Exception ex) { PageUtil.ShowMsg("Connect error"); //(new MessageDialog("连接异常!")).ShowAsync(); args.Cancel = true; } }