/// <summary> /// If query uses the current list be sure the server has the proper current list /// </summary> /// <param name="query"></param> static void WriteCurrentListToServerIfNeeded( Query q) { if (Lex.Contains(q.KeyCriteria, UserObject.TempFolderName + ".Current")) { CidListCommand.WriteCurrentList(); } }
/// <summary> /// Show the form /// </summary> public static new void Show() { if (Instance == null) { Instance = new ListLogic(); } Instance.Setup(); CidListCommand.WriteCurrentList(); // be sure current is on the server DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm); return; }
/// <summary> /// Open the specified query or copy the list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GridView_RowCellClick(object sender, RowCellClickEventArgs e) { StreamReader sr; int r = e.RowHandle; int c = e.Column.AbsoluteIndex; HistoryItem hi = SS.I.History[r]; // get item allowing for header row if (c == 0) // open query { sr = new StreamReader(hi.QueryFileName); string queryText = sr.ReadToEnd(); Query q = Query.Deserialize(queryText); q.UserObject.Name = // append time to name q.UserObject.Name + " - " + hi.DateTime.ToLongTimeString(); q.Mode = QueryMode.Build; // want to be in build mode q.UserObject.Content = q.Serialize(); // set content so not prompted for save when closed QbUtil.AddQueryAndRender(q, false); } // Copy list to current list sr = new StreamReader(hi.ListFileName); string listText = sr.ReadToEnd(); CidList cidList = new CidList(listText); CidListCommand.WriteCurrentList(cidList); SessionManager.CurrentResultKeys = cidList.ToStringList(); SessionManager.DisplayCurrentCount(); if (c == 1) // return message if just copying list to current { string msg = "The list has been copied to the current list (" + SessionManager.CurrentResultKeysCount + ")"; MessageBoxMx.Show(msg); } HistoryList_Deactivate(null, null); return; }
/// <summary> /// Execute search & get hit list /// </summary> /// <param name="saveHitlist"></param> /// <returns></returns> public bool ExecuteSearch(bool saveHitlist) { int voi, ti, fi; ResultsTable rt; ResultsField rfld; MetaTable mt; MetaColumn mc, mc2; if (saveHitlist) // clear current list { SessionManager.CurrentResultKeys = new List <string>(); if (QueryManager.StatusBarManager != null) { QueryManager.StatusBarManager.DisplayCurrentCount(); } } // Start thread running the query QueryResultsAvailable = false; QueryEngineException = null; ThreadStart ts = new ThreadStart(ExecuteQueryThreadMethod); Thread executeQueryThread = new Thread(ts); executeQueryThread.Name = "ExecuteSearch"; executeQueryThread.IsBackground = true; executeQueryThread.SetApartmentState(ApartmentState.STA); executeQueryThread.Start(); // Put up message for user if (((Query.ResultKeys != null && Query.UseResultKeys) || // already have list ResultsFormat.SessionOutputFormContext) && !QueryEngineStatsForm.ShowStats) { Progress.Show("Retrieving data...", UmlautMobius.String, true, "Cancelling retrieval..."); } else // normal type search { Progress.Show("Searching database - 0:00", UmlautMobius.String, true, "Cancelling search..."); if (QueryEngineStatsForm.ShowStats) { QueryEngineStatsForm.StartNewQueryExecution(Query); QueryEngineStatsForm.StartingSearch(); } } // Wait until results available or the query is cancelled by the user while (true) { Thread.Sleep(100); Application.DoEvents(); if (QueryResultsAvailable) // completed normally { ResultsKeys = QueryEngine.GetKeys(); if (saveHitlist) // store for session manager also (may differ but probably shouldn't) { SessionManager.CurrentResultKeys = ResultsKeys; } //Progress.Hide(); break; } else if (QueryEngineException != null) { Progress.Hide(); if (QueryEngineException is QueryException || QueryEngineException is UserQueryException) { throw QueryEngineException; } else { throw new Exception(QueryEngineException.Message, QueryEngineException); } } else if (Progress.CancelRequested) { if (QueryEngine != null) { QueryEngine.Cancel(false); // start the cancel } Thread.Sleep(250); Application.DoEvents(); if (executeQueryThread != null) { executeQueryThread.Abort(); // kill the local thread executing the query } Progress.Hide(); return(false); } } // If the query contains tables marked for remapping then build new expanded query & use going forward // modifiedQuery = QueryEngine.DoPresearchChecksAndTransforms(Query); // do any presearch transforms OriginalQuery = Query; if (TransformedQuery != null) { //ResultsPages qrp = query.ResultsPages; //ResultsPages mqrp = modifiedQuery.ResultsPages; // use same set of results pages so view changes propagate back to original query Query.PresearchDerivedQuery = TransformedQuery; // link original query to the transformed query Query = TransformedQuery; // replace original query with this query } else { Query.PresearchDerivedQuery = null; } InitializeQueryManager(QueryManager, Query, QueryManager.ResultsFormat, QueryEngine, ResultsKeys); // Save the hit list as needed if (saveHitlist) { CidList currentList = new CidList(ResultsKeys); CidListCommand.WriteCurrentList(currentList); SessionManager.DisplayCurrentCount(); } return(true); }
/// <summary> /// Run the query /// </summary> /// <param name="browseExistingResults">If true browse existing results</param> /// <returns></returns> public string RunQuery3( ResultsFormat rf, bool saveHitlist, bool browseExistingResults) { Query modifiedQuery; QueryTable qt; QueryColumn qc; ResultsTable rt; ResultsField rfld; MetaTable mt; MetaColumn mc; string txt, msg; DialogResult dr; bool success; CellGraphic cg; Lex lex = new Lex(); string tempfile, tok, command, unrecognizedCommand, response; int ti, gi, rc, i1, i2; // Begin execution if (rf == null) { throw new Exception("QueryExec.Run - Null ResultsFormat"); } if (ResultsFormatter == null) { throw new Exception("QueryExec.Run - Null ResultsFormatter"); } if (rf.Segments == null) { throw new Exception("QueryExec.Run - Null ResultsFormat.Segments"); } if (Query == null) { throw new Exception("QueryExec.Run - Null Rf.Query"); } if (Query.Tables == null || Query.Tables.Count <= 0) { throw new QueryException("QueryExec.Run - No Query Tables"); } QueryManager qm = QueryManager; ReturnMsg = ""; //bool useExistingQueryEngine = Rf.ParentQe != null; //bool useExistingDataTable = Query.BrowseExistingResultsWhenOpened && Query.SerializeResults && // qm.DataTable != null && qm.DataTable.Rows.Count > 0; try { //if (Math.Sqrt(4) == 2) throw new Exception("test"); // debug if (!browseExistingResults) // normal open of search { Progress.Show("Analyzing query..."); // put up a status message to the user as soon as possible to let them know something is happening... dr = ValidateQuery(Query); if (dr == DialogResult.Cancel) { return(""); } WriteCurrentListToServerIfNeeded(Query); if (rf.OutputDestination == OutputDest.WinForms) // update access stats if grid { UpdateTableUsageStatistics(Query); } Query.ResultsDataTable = null; // be sure to get new results qm = BuildQueryManager(Query, rf); Query.ResetViewStates(); // reset state of views for proper operation if (Rf.ParentQe == null) // open search unless using existing query engine { if (!ExecuteSearch(saveHitlist)) // returns false if cancelled by user { Progress.Hide(); return(""); } } if ((ResultsKeys == null || ResultsKeys.Count == 0) && // nothing for search !Query.Preview && !MqlUtil.SingleStepExecution(Query) && qm.DataTable.Rows.Count == 0 && Query.RetrievesDataFromQueryEngine) { // if (!Rf.PopupDisplay) Progress.Hide(); if (qm.StatusBarManager != null) { qm.StatusBarManager.DisplayStatusMessage(""); } // if (QueryEngine.Cancelled) return ""; // cancelled by user msg = "No data have been found that matches your query."; if (ResultsFormat.PopupOutputFormContext && !ResultsFormat.SuppressNoDataMessage) { MessageBoxMx.Show(msg, "Search Result", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return("Command EditQuery"); // return to edit query menu } else { return(msg); } } //if (ResultsFormat.PopupDisplay) // SessionManager.DisplayStatusMessage("Retrieving data..."); //else Progress.Show("Retrieving data...", UmlautMobius.Value, true, "Cancelling Retrieval..."); //Progress.Show("Retrieving data...", UmlautMobius.String, true, "Cancelling Retrieval..."); Progress.Hide(); // hide progress - "Retrieving data..." message now appears as bottom line of grid if (ResultsFormat.Grid) { if (ResultsFormat.SessionOutputFormContext) // if normal main session form grid display, set browse mode & view state { Query.ResetViewStates(); // reset view state for all views QbUtil.SetMode(QueryMode.Browse, Query); if (ResultsFormat.Query.LogicType == QueryLogicType.And) // log grid query by logic type { UsageDao.LogEvent("QueryGridAnd", ""); } else if (ResultsFormat.Query.LogicType == QueryLogicType.Or) { UsageDao.LogEvent("QueryGridOr", ""); } else if (ResultsFormat.Query.LogicType == QueryLogicType.Complex) { UsageDao.LogEvent("QueryGridComplex", ""); } } else if (ResultsFormat.PopupOutputFormContext) // create popup window & configure { PopupResults.Show(qm); //MoleculeGridPanel.ConfigureAndShow(qm, null); } else if (ResultsFormat.ToolOutputFormContext) { ContainerControl cc; QueryResultsControl qrc = ResultsFormat.OutputContainerControl as QueryResultsControl; AssertMx.IsTrue(qrc != null, "ResultsFormat.OutputContainerControl must be a QueryResultsControl"); if (!WindowsHelper.FindContainerControl(qrc, typeof(ToolResultsContainer), out cc)) { throw new Exception("ToolResultsContainer not found"); } ToolResultsContainer trc = cc as ToolResultsContainer; trc.SetupQueryResultsControlForResultsDisplay(qm); } else { throw new Exception("Invalid OutputformContext: " + ResultsFormat.OutputFormContext); } } } else // reentering display switch to browse tab { QbUtil.SetMode(QueryMode.Browse, Query); } response = ResultsFormatter.BeginFormatting(browseExistingResults); // format the data if (ResultsFormat.SessionOutputFormContext) // normal display { if (MqlUtil.SingleStepExecution(Query)) { // be sure hit count display is up to date if (ResultsKeys != null) { if (qm.StatusBarManager != null) { qm.StatusBarManager.DisplayCurrentCount(); } } } if (saveHitlist) { CidList hitList = new CidList(ResultsKeys); rc = CidListCommand.WriteCurrentList(hitList); SessionManager.DisplayCurrentCount(); } } return(response); } // end of surrounding try catch (Exception ex) { Progress.Hide(); if (ex is UserQueryException) // exception that can occur from user error { throw new UserQueryException(ex.Message, ex); } else { msg = DebugLog.FormatExceptionMessage(ex); if (!Lex.Contains(msg, "QueryLogged:")) // exception & query { QueryEngine.LogExceptionAndSerializedQuery(msg, Query); } else { ServicesLog.Message(msg); // just log exception } throw new Exception(ex.Message, ex); // pass it up } } }