From 81ea106ce3873665b9a81e80be99e07ea6557ecc Mon Sep 17 00:00:00 2001 From: Taha Date: Mon, 23 Oct 2023 15:18:44 -0400 Subject: [PATCH] Fixing the DSQA query box font color --- .../DataStreamQueryAnalyzer/MainForm.cs | 264 ++++++------------ 1 file changed, 88 insertions(+), 176 deletions(-) diff --git a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs index 2fc290560..4335054a0 100644 --- a/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs +++ b/src/DataStreamSuite/DataStreamQueryAnalyzer/MainForm.cs @@ -25,10 +25,8 @@ using System.Threading.Tasks; -namespace BCG -{ - public partial class MainForm : System.Windows.Forms.Form - { +namespace BCG { + public partial class MainForm : System.Windows.Forms.Form { // static async Task _run() { // var login = "bts"; // var passwd = String.Empty; @@ -52,8 +50,7 @@ namespace BCG private string myKQ; private TextWriter myConsoleOutput; - public MainForm() - { + public MainForm() { //Task.Run(async () => await _run()); InitializeComponent(); // myKQ = ConfigurationRequester.getApplicationQualifier(); @@ -66,22 +63,22 @@ namespace BCG this.Load += new EventHandler(myLoad); this.Closing += new CancelEventHandler(myClosing); + myQueryTextBox.TextChanged += (o, e) => { + myQueryTextBox.ForeColor = Color.White; + }; } - public string query_text - { + public string query_text { get { return myQueryTextBox.Text; } set { myQueryTextBox.Text = value; } } - private ViewStream myGetAllTagsStream() - { + private ViewStream myGetAllTagsStream() { // TODO: Port PublishedTagsStream from edge (then we can uncomment impl below) return new FilterStream(new PubSubServerStateStream(), "tag~='DS_'"); //return new LiteralStream("tag/String", "DS_Comedians;DS_Baldies"); } - private void mySetText() - { + private void mySetText() { this.Text = "Data Stream Query Analyzer | Site: " + mySite + (string.IsNullOrEmpty(myKQ) ? string.Empty : " | Key Qualifier: " + myKQ); myToolStripStatusLabelTime.Text = "Ready"; myToolStripStatusLabelRows.Text = string.Empty; @@ -91,12 +88,10 @@ namespace BCG /// Gets the data in the form of a multilevel IDictionary /// /// - private IDictionary myGetLibraryData() - { + private IDictionary myGetLibraryData() { SortedList retVal = new SortedList(); string[] primitiveNames = PrimitiveManager.instance.getPrimitiveNames(); - foreach (string pName in primitiveNames) - { + foreach (string pName in primitiveNames) { string aName = PrimitiveManager.instance.getAssemblyName(pName); ICollection cNames = PrimitiveManager.instance.getConstructorSigns(pName); if (!retVal.Contains(aName)) @@ -111,15 +106,12 @@ namespace BCG } - private void myLoadAssemblies() - { + private void myLoadAssemblies() { myTreeView.Nodes.Clear(); IDictionary libraryData = myGetLibraryData(); - foreach (DictionaryEntry de in libraryData) - { + foreach (DictionaryEntry de in libraryData) { TreeNode assemblyNode = new TreeNode(de.Key as String); - foreach (DictionaryEntry innerDe in (de.Value as IDictionary)) - { + foreach (DictionaryEntry innerDe in (de.Value as IDictionary)) { TreeNode primitiveNode = new TreeNode(innerDe.Key as string); foreach (string con in (innerDe.Value as ICollection)) primitiveNode.Nodes.Add(con); @@ -139,27 +131,23 @@ namespace BCG }*/ } - private void myHandleTableListChange(object o) - { + private void myHandleTableListChange(object o) { IBlueRowCollection rows = (o as DataPacket).newRows; myUpdateTableList(); } #region Persistence Keys - public int textBoxHeight - { + public int textBoxHeight { get { return myQueryTextBox.Height; } set { myQueryTextBox.Height = value; } } #endregion - private void myTryExpression(string expStr) - { + private void myTryExpression(string expStr) { myFreezeView(false); // force unfreeze the view DataStreamExpression oldExp = myExp; - try - { + try { var exp = DataStreamExpressionsInterpreter.Evaluate(expStr); if (exp == null) @@ -186,9 +174,7 @@ namespace BCG oldExp.getView(new Hashtable()).onChange -= new DataStream.ChangeDelegate(myCallback); */ //myQueryTextBox.Text = expStr; - } - catch (Exception exc) - { + } catch (Exception exc) { Log.Ui.warn(exc.ToString()); myDataGrid.DataSource = null; @@ -202,8 +188,7 @@ namespace BCG } } - private string myExtractFromClass(TextReader r) - { + private string myExtractFromClass(TextReader r) { string line = r.ReadLine(); while (line != null && line.IndexOf("*Expression*") == -1) line = r.ReadLine(); @@ -216,8 +201,7 @@ namespace BCG string result = ""; line = r.ReadLine(); - while (line != null && line.IndexOf("----------------------------------------------------------------------") == -1) - { + while (line != null && line.IndexOf("----------------------------------------------------------------------") == -1) { if (line != "") result += line.Substring(" ".Length) + "\n"; line = r.ReadLine(); @@ -228,24 +212,17 @@ namespace BCG return result; } - public void loadFile(string fileName) - { - try - { + public void loadFile(string fileName) { + try { TextReader r = new StreamReader(fileName); - try - { + try { myQueryTextBox.Text = myExtractFromClass(r); - } - finally - { + } finally { r.Close(); } myLastFileName = fileName; this.Text = fileName; - } - catch (Exception exc) - { + } catch (Exception exc) { Log.Ui.warn(exc.ToString()); myDataGrid.DataSource = null; @@ -256,8 +233,7 @@ namespace BCG } - private void myPrintCode(IBlueTableSchema schema, ICollection vars, string code) - { + private void myPrintCode(IBlueTableSchema schema, ICollection vars, string code) { myCSharpText.Text = "using System;\n\nnamespace BCG\n{"; @@ -277,8 +253,7 @@ namespace BCG string lastVar = null; string variableDeclarations = ""; - foreach (string var in vars) - { + foreach (string var in vars) { variableDeclarations += " ViewStream " + var + ";\n"; lastVar = var; } @@ -308,16 +283,13 @@ namespace BCG myCSharpText.Text += "}"; } - static DataGridViewColumn _column_factory(ColumnInfo ci) - { - return new DataGridViewTextBoxColumn - { + static DataGridViewColumn _column_factory(ColumnInfo ci) { + return new DataGridViewTextBoxColumn { HeaderText = ci.colName, Width = get_col_width(ci) }; - static int get_col_width(ColumnInfo ci) - { + static int get_col_width(ColumnInfo ci) { const int CHAR_WIDTH = 10; const int MIN_WIDTH = 50; const int MIN_DATE_WIDTH = 200; @@ -328,14 +300,12 @@ namespace BCG } private HighPerformanceTimer _timer = new HighPerformanceTimer(); // this is the stream callback - private void myCallback(object o) - { + private void myCallback(object o) { _timer.start(); DataPacket dp = o as DataPacket; myCrono.stop(); Log.Ui.diag($"Received callback for {dp.schema.tableName}"); - if (o == null) - { + if (o == null) { System.Windows.Forms.MessageBox.Show(this, "Received a Null Data packet", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -352,8 +322,7 @@ namespace BCG myDataGrid.DataSource = new SimpleBindableCollection(dp.newRows.schema, dp.newRows); var force = false; - if (myChangeStyle && force) - { + if (myChangeStyle && force) { myChangeStyle = false; myDataGrid.Columns.Clear(); myDataGrid.Columns.AddRange(Array.ConvertAll(dp.schema.columnInfo, _column_factory)); @@ -380,15 +349,11 @@ namespace BCG private DataStreamExpression myExp; - private void myTimer_Tick(object sender, System.EventArgs e) - { - try - { + private void myTimer_Tick(object sender, System.EventArgs e) { + try { ViewStreamDatabase.instance.doWork(); MasterWorker.getInstance(false).doWork(); - } - catch (Exception exc) - { + } catch (Exception exc) { Log.Ui.warn(exc.ToString()); myDataGrid.DataSource = null; @@ -399,27 +364,22 @@ namespace BCG } } - class StringWrapper - { - public StringWrapper(string s) - { + class StringWrapper { + public StringWrapper(string s) { myTableName = s; } - public string tableName - { + public string tableName { get { return myTableName; } } private string myTableName; } - private void MainForm_Closed(object sender, System.EventArgs e) - { + private void MainForm_Closed(object sender, System.EventArgs e) { if (myExp != null) myExp.getView(new Dictionary(0)).onChange -= new DataStream.ChangeDelegate(myCallback); } - private void myMenuItemExecuteQueryClick(object sender, System.EventArgs e) - { + private void myMenuItemExecuteQueryClick(object sender, System.EventArgs e) { myQueryTextBox.SelectionStart = myQueryTextBox.Text.Length; myQueryTextBox.SelectionLength = myQueryTextBox.Text.Length; myQueryTextBox.SelectionColor = Color.Black; @@ -427,8 +387,7 @@ namespace BCG myTryExpression(myQueryTextBox.Text); } - private void myToolStripMenuItemExecSel_Click(object sender, EventArgs e) - { + private void myToolStripMenuItemExecSel_Click(object sender, EventArgs e) { // int selstart = myQueryTextBox.SelectionStart; // int sellength = myQueryTextBox.SelectionLength; // myQueryTextBox.SelectionStart = 0; @@ -443,8 +402,7 @@ namespace BCG // myQueryTextBox.SelectionColor = Color.White; } - private void myMenuItemOpenClick(object sender, System.EventArgs e) - { + private void myMenuItemOpenClick(object sender, System.EventArgs e) { OpenFileDialog od = new OpenFileDialog(); od.Filter = "C# class (*.cs)|*.cs"; @@ -452,24 +410,21 @@ namespace BCG loadFile(od.FileName); } - private void mySave(string fileName) - { + private void mySave(string fileName) { using (TextWriter w = new StreamWriter(fileName)) w.Write(myCSharpText.Text); myLastFileName = fileName; this.Text = fileName; } - private void myMenuItemSaveClick(object sender, System.EventArgs e) - { + private void myMenuItemSaveClick(object sender, System.EventArgs e) { if (myLastFileName == null) myMenuItemSaveAsClick(sender, e); else mySave(myLastFileName); } - private void myMenuItemSaveAsClick(object sender, System.EventArgs e) - { + private void myMenuItemSaveAsClick(object sender, System.EventArgs e) { SaveFileDialog sd = new SaveFileDialog(); if (myLastFileName != null) sd.FileName = myLastFileName; @@ -480,56 +435,47 @@ namespace BCG mySave(sd.FileName); } - private void myTableListBox_DoubleClick(object sender, System.EventArgs e) - { - if (myTableListBox.SelectedItem != null) - { + private void myTableListBox_DoubleClick(object sender, System.EventArgs e) { + if (myTableListBox.SelectedItem != null) { string tableName = myTableListBox.SelectedItem.ToString(); myQueryTextBox.Text = myQueryTextBox.Text == "" ? tableName : myQueryTextBox.Text + "\n" + tableName; myTryExpression(myQueryTextBox.Text); } } - private void myDataGrid_MouseEnter(object sender, System.EventArgs e) - { + private void myDataGrid_MouseEnter(object sender, System.EventArgs e) { //myDataGrid.TableStyles[0].GridLineColor = Color.LightSteelBlue; // if (myDataGrid.TableStyles.Count > 0) // myDataGrid.TableStyles[0].HeaderBackColor = Color.LightSteelBlue; } - private void myDataGrid_MouseLeave(object sender, System.EventArgs e) - { + private void myDataGrid_MouseLeave(object sender, System.EventArgs e) { //myDataGrid.TableStyles[0].GridLineColor = Color.Gainsboro; // if (myDataGrid.TableStyles.Count > 0) // myDataGrid.TableStyles[0].HeaderBackColor = Color.Gainsboro; } - private void myCSharpText_MouseEnter(object sender, System.EventArgs e) - { + private void myCSharpText_MouseEnter(object sender, System.EventArgs e) { //myCSharpText.BackColor = Color.Gainsboro; myCSharpText.Font = new Font(myCSharpText.Font.Name, myCSharpText.Font.Size, FontStyle.Bold); } - private void myCSharpText_MouseLeave(object sender, System.EventArgs e) - { + private void myCSharpText_MouseLeave(object sender, System.EventArgs e) { //myCSharpText.BackColor = Color.White; myCSharpText.Font = new Font(myCSharpText.Font.Name, myCSharpText.Font.Size, FontStyle.Regular); } - private void myTableListBox_MouseEnter(object sender, System.EventArgs e) - { + private void myTableListBox_MouseEnter(object sender, System.EventArgs e) { //myTableListBox.BackColor = Color.Gainsboro; myTableListBox.Font = new Font(myTableListBox.Font.Name, myTableListBox.Font.Size, FontStyle.Bold); } - private void myTableListBox_MouseLeave(object sender, System.EventArgs e) - { + private void myTableListBox_MouseLeave(object sender, System.EventArgs e) { //myTableListBox.BackColor = Color.White; myTableListBox.Font = new Font(myTableListBox.Font.Name, myTableListBox.Font.Size, FontStyle.Regular); } - private void myLoad(object sender, EventArgs e) - { + private void myLoad(object sender, EventArgs e) { myFreezeView(false); myToolStripMenuItemSite.DropDownItems.Clear(); @@ -553,9 +499,7 @@ namespace BCG { var ex = new Win32Exception(); // same as new Win32Exception(Marshal.GetLastWin32Error()) Console.WriteLine(ex.Message); - } - else - { + } else { Console.WriteLine("Set stdout worked."); } @@ -563,9 +507,7 @@ namespace BCG { var ex = new Win32Exception(); // same as new Win32Exception(Marshal.GetLastWin32Error()) Console.WriteLine(ex.Message); - } - else - { + } else { Console.WriteLine("Set stderr worked."); } Console.WriteLine("Redirecting console ouput to this window..."); @@ -581,12 +523,10 @@ namespace BCG //_library = new LibraryForm(this); } - private void myMenuItemSiteClick(object sender, System.EventArgs e) - { + private void myMenuItemSiteClick(object sender, System.EventArgs e) { ToolStripMenuItem mi = (ToolStripMenuItem)sender; - if (mi.Text != mySite) - { + if (mi.Text != mySite) { mySite = mi.Text; foreach (var m in mySiteItems) m.Checked = false; @@ -607,78 +547,63 @@ namespace BCG } } - private void myClosing(object sender, CancelEventArgs e) - { + private void myClosing(object sender, CancelEventArgs e) { } - private void myHandleTreeNodeSelect(object sender, TreeViewEventArgs e) - { - if (myTreeView.SelectedNode != null) - { - if (myTreeView.SelectedNode.LastNode == null) - { + private void myHandleTreeNodeSelect(object sender, TreeViewEventArgs e) { + if (myTreeView.SelectedNode != null) { + if (myTreeView.SelectedNode.LastNode == null) { string sn = myTreeView.SelectedNode.Parent.Text + "()"; myQueryTextBox.Text = myQueryTextBox.Text == "" ? sn : myQueryTextBox.Text + "\n" + sn; } } } - private void myToolStripMenuItemExit_Click(object sender, EventArgs e) - { + private void myToolStripMenuItemExit_Click(object sender, EventArgs e) { Close(); } - private void myToolStripMenuItemFreeze_Click(object sender, EventArgs e) - { + private void myToolStripMenuItemFreeze_Click(object sender, EventArgs e) { myFreezeView(myTimer.Enabled); } - private void myFreezeView(bool freeze) - { + private void myFreezeView(bool freeze) { myTimer.Enabled = !freeze; myToolStripMenuItemFreeze.Checked = freeze; myToolStripMenuItemStep.Enabled = freeze; } - private void myToolStripMenuItemStep_Click(object sender, EventArgs e) - { + private void myToolStripMenuItemStep_Click(object sender, EventArgs e) { ViewStreamDatabase.instance.doWork(); } - private void myToolStripMenuItemLoadAss_Click(object sender, EventArgs e) - { + private void myToolStripMenuItemLoadAss_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.ShowReadOnly = true; DialogResult dr = ofd.ShowDialog(this); - if (ofd.CheckFileExists && ofd.CheckPathExists && dr == DialogResult.OK) - { + if (ofd.CheckFileExists && ofd.CheckPathExists && dr == DialogResult.OK) { PrimitiveManager.instance.loadAssembly(ofd.FileName); myLoadAssemblies(); } } - private void myToolStripMenuItemTest_Click(object sender, EventArgs e) - { - if (myCurrentStream != null) - { + private void myToolStripMenuItemTest_Click(object sender, EventArgs e) { + if (myCurrentStream != null) { myCurrentStream.onChange -= new DataStream.ChangeDelegate(myCallback); myCurrentStream.onChange += new DataStream.ChangeDelegate(myCallback); } } - private void myToolStripMenuItemClearConsole_Click(object sender, EventArgs e) - { + private void myToolStripMenuItemClearConsole_Click(object sender, EventArgs e) { myConsoleRichTextBox.Clear(); Console.WriteLine("Redirecting console ouput to this window..."); } - private void myTableFilterBox_TextChanged(object sender, EventArgs e) - { + private void myTableFilterBox_TextChanged(object sender, EventArgs e) { myUpdateTableList(); } - private void myUpdateTableList() - { + private void myUpdateTableList() { IBlueRowCollection rows = myAllTagsStream.rows; if (rows == null) return; @@ -693,15 +618,12 @@ namespace BCG myTableListBox.Items.Clear(); SortedList sl = new SortedList(); if (string.IsNullOrEmpty(myTableFilterBox.Text)) - foreach (IBlueRow r in rows) - { + foreach (IBlueRow r in rows) { sl[r["tag"].ToString().Substring(PubStreamPrefixer.prefix("").Length)] = true; } - else - { + else { Regex tableRegex = new Regex(myTableFilterBox.Text); - foreach (IBlueRow r in rows) - { + foreach (IBlueRow r in rows) { string thisTable = r["tag"].ToString().Substring(PubStreamPrefixer.prefix("").Length); if (tableRegex.IsMatch(thisTable)) sl[thisTable] = true; @@ -719,8 +641,7 @@ namespace BCG myTableListBox.EndUpdate(); } - private void testGridToolStripMenuItem_Click(object sender, EventArgs e) - { + private void testGridToolStripMenuItem_Click(object sender, EventArgs e) { HighPerformanceTimer timer = new HighPerformanceTimer(); //while (true) //{ @@ -742,11 +663,9 @@ namespace BCG foreach (IBlueRow r in s.rows) rows.Add(r); - for (int i = 0; i < 100; i++) - { + for (int i = 0; i < 100; i++) { timer.start(); - rows.Sort(delegate (IBlueRow r1, IBlueRow r2) - { + rows.Sort(delegate (IBlueRow r1, IBlueRow r2) { return _sort_dicts_index(r1, r2, 5, true); }); timer.stop(); @@ -754,22 +673,19 @@ namespace BCG } } - private static int mySortDictionaries(IBlueRow r1, IBlueRow r2, string column, bool low_to_high) - { + private static int mySortDictionaries(IBlueRow r1, IBlueRow r2, string column, bool low_to_high) { if (r1.Contains(column) && r2.Contains(column)) return compare_send_dontcare_to_last(r1[column], r2[column], low_to_high); else return 0; } - private static int _sort_dicts_index(IBlueRow r1, IBlueRow r2, int col_no, bool low_to_high) - { + private static int _sort_dicts_index(IBlueRow r1, IBlueRow r2, int col_no, bool low_to_high) { //return compare_send_dontcare_to_last(r1[col_no], r2[col_no], low_to_high); return ((IComparable)r1[col_no]).CompareTo(r2[col_no]); } - internal static int compare_send_dontcare_to_last(object o1, object o2, bool low_to_high) - { + internal static int compare_send_dontcare_to_last(object o1, object o2, bool low_to_high) { if (myIsDontCare(o1)) return myIsDontCare(o2) ? 0 : 1; else @@ -777,16 +693,14 @@ namespace BCG : ((IComparable)o2).CompareTo(o1)); } - private static bool myIsDontCare(object o) - { + private static bool myIsDontCare(object o) { return o == null || o == DBNull.Value || o is string && String.IsNullOrEmpty((string)o) || o is double && (Double.IsInfinity((double)o) || Double.IsNaN((double)o)) || o is float && (Single.IsInfinity((float)o) || Single.IsNaN((float)o)); } - private void _new_grid_form(object args) - { + private void _new_grid_form(object args) { //System.Timers.Timer t = new System.Timers.Timer(); ////t.SynchronizingObject //BCG.Utilities.BlueEventLog.logEvent(String.Format("New BTSTabularGridTestForm created on thread {0}", System.Threading.Thread.CurrentThread.ManagedThreadId), @@ -798,13 +712,11 @@ namespace BCG private void libraryToolStripMenuItem_Click(object sender, EventArgs e) { } - private void myTableFilterLabel_Click(object sender, EventArgs e) - { + private void myTableFilterLabel_Click(object sender, EventArgs e) { } - private void MainForm_Load(object sender, EventArgs e) - { + private void MainForm_Load(object sender, EventArgs e) { } }