protected override void ProcessRecord() { try { WriteVerbose(pass); WriteVerbose("Query: " + query); SplunkConnection con = new SplunkConnection(serverUrl); if (login.StartsWith("\\")) { login = login.Substring(1); } string sessionKey = con.Authenticate(login, pass); WriteVerbose("SessionKey: " + sessionKey); SearchManager searchManager = new SearchManager(con); // searchManager.ControlAllJobs(JobAction.CANCEL); SearchJob job = searchManager.SyncSearch(query, null); WriteVerbose("Job ID: " + job.Id); EventParameters ep = new EventParameters(); if (fields != null && fields.Length > 0) { ep.FieldList = fields; } DataTable dt = job.GetEventsTable(ep); WriteObject(dt); job.Cancel(); } catch (Exception e) { WriteObject(e.Message); } }
private void DoSearch() { if (radioButton_selected.Checked && SelectedItems == null) { return; } button_seach.Enabled = false; button_cancel.Enabled = true; button_showresult.Enabled = false; var typeAll = radioButton_typeAll.Checked; var typeFolder = radioButton_typeFolder.Checked; var typeFile = radioButton_typeFile.Checked; var selectall = radioButton_SearchAll.Checked; var selectitem = radioButton_selected.Checked; var selecttree = radioButton_SerachFolder.Checked; var treepath = textBox_SearchFolder.Text; var searchStr = comboBox_name.Text; var strstarts = radioButton_startswith.Checked; var strends = radioButton_endswith.Checked; var strcontain = radioButton_contain.Checked; var strregex = checkBox_regex.Checked; var strcase = checkBox_case.Checked; var SizeOver = checkBox_Over.Checked; var SizeUnder = checkBox_Under.Checked; var Over = numericUpDown_over.Value; var Under = numericUpDown_under.Value; var modifiedFromEnable = dateTimePicker_modifiedFrom.Checked; var modifiedToEnable = dateTimePicker_modifiedTo.Checked; var createdFromEnable = dateTimePicker_createdFrom.Checked; var createdToEnable = dateTimePicker_createdTo.Checked; var modifiedFrom = dateTimePicker_modifiedFrom.Value; var modifiedTo = dateTimePicker_modifiedTo.Value; var createdFrom = dateTimePicker_createdFrom.Value; var createdTo = dateTimePicker_createdTo.Value; progressBar1.Style = ProgressBarStyle.Marquee; label_result.Text = "wait for system..."; SearchJob?.Cancel(); SearchJob = JobControler.CreateNewJob(); SearchJob.DisplayName = "Search"; JobControler.Run(SearchJob, (j) => { j.ProgressStr = "Create index..."; j.Progress = -1; TSviewCloudConfig.Config.Log.LogOut("[Search] start"); var sw = new System.Diagnostics.Stopwatch(); try { List <IRemoteItem> initselection = new List <IRemoteItem>(); List <IRemoteItem> selection = new List <IRemoteItem>(); if (selectall) { initselection.AddRange(RemoteServerFactory.ServerList.Values.Select(x => x[""])); } if (selectitem) { initselection.AddRange(SelectedItems); } if (selecttree) { initselection.Add(RemoteServerFactory.PathToItem(treepath).Result); } synchronizationContext.Post((o) => { label_result.Text = o as string; }, "Prepare items..."); TSviewCloudConfig.Config.Log.LogOut("[Search] Create index"); sw.Start(); Parallel.ForEach( initselection, new ParallelOptions { MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling((Environment.ProcessorCount * 0.75) * 1.0)) }, () => new List <IRemoteItem>(), (x, state, local) => { if (x == null) { return(local); } var item = RemoteServerFactory.PathToItem(x.FullPath).Result; if (item == null) { return(local); } local.AddRange(GetItems(item)); return(local); }, (result) => { lock (selection) selection.AddRange(result); } ); synchronizationContext.Post((o) => { label_result.Text = o as string; }, "Prepare items done."); sw.Stop(); var itemsearch_time = sw.Elapsed; var search = selection.AsParallel(); if (typeFile) { search = search.Where(x => x.ItemType == RemoteItemType.File); } if (typeFolder) { search = search.Where(x => x.ItemType == RemoteItemType.Folder); } if (strregex) { if (!strcase) { search = search.Where(x => Regex.IsMatch(x.Name ?? "", searchStr)); } else { search = search.Where(x => Regex.IsMatch(x.Name ?? "", searchStr, RegexOptions.IgnoreCase)); } } else { if (!strcase) { if (strstarts) { search = search.Where(x => (x.Name?.StartsWith(searchStr) ?? searchStr == "")); } if (strends) { search = search.Where(x => (x.Name?.EndsWith(searchStr) ?? searchStr == "")); } if (strcontain) { search = search.Where(x => (x.Name?.IndexOf(searchStr) >= 0)); } } else { search = search.Where(x => ( System.Globalization.CultureInfo.CurrentCulture.CompareInfo.IndexOf( x.Name ?? "", searchStr, System.Globalization.CompareOptions.IgnoreCase | System.Globalization.CompareOptions.IgnoreKanaType | System.Globalization.CompareOptions.IgnoreWidth | System.Globalization.CompareOptions.IgnoreNonSpace | System.Globalization.CompareOptions.IgnoreSymbols ) >= 0)); } } if (SizeOver) { search = search.Where(x => (x.Size ?? 0) > Over); } if (SizeUnder) { search = search.Where(x => (x.Size ?? 0) < Under); } if (modifiedFromEnable) { search = search.Where(x => x.ModifiedDate > modifiedFrom); } if (modifiedToEnable) { search = search.Where(x => x.ModifiedDate < modifiedTo); } if (createdFromEnable) { search = search.Where(x => x.CreatedDate > createdFrom); } if (createdToEnable) { search = search.Where(x => x.CreatedDate < createdTo); } synchronizationContext.Post((o) => { label_result.Text = o as string; }, "Search..."); j.ProgressStr = "Search..."; TSviewCloudConfig.Config.Log.LogOut("[Search] Search"); sw.Restart(); SearchResult = search.ToArray(); sw.Stop(); var filteritem_time = sw.Elapsed; j.Progress = 1; j.ProgressStr = "Found : " + SearchResult.Count().ToString(); synchronizationContext.Post((o) => { label_result.Text = o as string; button_seach.Enabled = true; button_cancel.Enabled = false; button_showresult.Enabled = true; progressBar1.Style = ProgressBarStyle.Continuous; SearchJob = null; }, string.Format("Found : {0}, Index {1} search {2}", SearchResult.Count(), itemsearch_time, filteritem_time)); TSviewCloudConfig.Config.Log.LogOut("[Search] found " + SearchResult.Count().ToString()); } catch { TSviewCloudConfig.Config.Log.LogOut("[Search] Abort"); synchronizationContext.Post((o) => { label_result.Text = "abort"; button_seach.Enabled = true; button_cancel.Enabled = false; progressBar1.Style = ProgressBarStyle.Continuous; SearchJob = null; }, null); } }); }