825 lines
29 KiB
C#
825 lines
29 KiB
C#
using bts;
|
|
using bts.utils;
|
|
|
|
using mbts.config;
|
|
using mbts.spark;
|
|
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using System.Text.RegularExpressions;
|
|
using System.IO;
|
|
using System.Diagnostics;
|
|
|
|
using BCG.Utilities;
|
|
// using BCG.Utilities.BlueConfiguration;
|
|
using BCG.Utilities.General;
|
|
using Spark.DataStream;
|
|
using Bts.DataStreamExpressions;
|
|
// using BCG.Evaluator.DataStreamExpression;
|
|
// using BCG.Utilities.Win32;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace BCG
|
|
{
|
|
public partial class MainForm : System.Windows.Forms.Form
|
|
{
|
|
// static async Task _run() {
|
|
// var login = "bts";
|
|
// var passwd = String.Empty;
|
|
// Console.WriteLine("Starting DSQA... ");
|
|
// // Log.notnull(login);
|
|
// // Log.notnull(passwd);
|
|
// var service_ctx = bts.api.core.ServiceContext.create();
|
|
// await service_ctx.login(login, passwd);
|
|
// }
|
|
private bool myChangeStyle = false;
|
|
private PersistWindowState myWindowState;
|
|
private string? myLastFileName;
|
|
private ViewStream? myCurrentStream;
|
|
private List<ToolStripMenuItem> mySiteItems = new List<ToolStripMenuItem>();
|
|
// private string mySite = SitesCore.getMySiteName ();
|
|
private string mySite = "TODO";
|
|
private string myLastClassName = "MyView";
|
|
private ViewStream? myAllTagsStream;
|
|
private string myKQ;
|
|
private TextWriter? myConsoleOutput;
|
|
|
|
public MainForm()
|
|
{
|
|
//Task.Run(async () => await _run());
|
|
InitializeComponent();
|
|
// myKQ = ConfigurationRequester.getApplicationQualifier();
|
|
myKQ = "TODO";
|
|
mySetText();
|
|
|
|
myWindowState = new PersistWindowState();
|
|
myWindowState.parent = this;
|
|
myWindowState.saveState = false;
|
|
|
|
this.Load += new EventHandler(myLoad);
|
|
this.Closing += new CancelEventHandler(myClosing);
|
|
myQueryTextBox.TextChanged += (o, e) =>
|
|
{
|
|
myQueryTextBox.ForeColor = Color.White;
|
|
};
|
|
}
|
|
|
|
public string query_text
|
|
{
|
|
get { return myQueryTextBox.Text; }
|
|
set { myQueryTextBox.Text = value; }
|
|
}
|
|
private ViewStream myGetAllTagsStream()
|
|
{
|
|
// TODO: Port PublishedTagsStream from edge (then we can uncomment impl below)
|
|
//ViewStream vs = new PubSubServerStateStream();
|
|
ViewStream vs = new PubSubServerStateStream();
|
|
return new FilterStream(vs, "tag~='DS_'");
|
|
//return new LiteralStream("tag/String", "DS_table1;DS_table2");
|
|
}
|
|
|
|
private void mySetText()
|
|
{
|
|
ViewStream routes = new PubsubRoutesStream();
|
|
routes.onChange += (o) => { };
|
|
var rows = routes.rows;
|
|
string route_txt = String.Empty;
|
|
foreach (IBlueRow r in rows)
|
|
{
|
|
var tag_regexp = r.get<string>("tag_regexp");
|
|
var server_url = r.get<string>("server_url");
|
|
route_txt += $"{tag_regexp} : {server_url},";
|
|
}
|
|
|
|
this.Text = $"Data Stream Query Analyzer | routes: {route_txt}";
|
|
myToolStripStatusLabelTime.Text = "Ready";
|
|
myToolStripStatusLabelRows.Text = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the data in the form of a multilevel IDictionary
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private IDictionary myGetLibraryData()
|
|
{
|
|
SortedList retVal = new SortedList();
|
|
string[] primitiveNames = PrimitiveManager.instance.getPrimitiveNames();
|
|
foreach (string pName in primitiveNames)
|
|
{
|
|
string aName = PrimitiveManager.instance.getAssemblyName(pName);
|
|
ICollection cNames = PrimitiveManager.instance.getConstructorSigns(pName);
|
|
if (!retVal.Contains(aName))
|
|
retVal.Add(aName, new SortedList());
|
|
(retVal[aName] as IDictionary)[pName] = new ArrayList(cNames);
|
|
|
|
}
|
|
foreach (DictionaryEntry outerDe in retVal)
|
|
foreach (DictionaryEntry innerDe in (outerDe.Value as IDictionary))
|
|
(innerDe.Value as ArrayList).Sort();
|
|
return retVal;
|
|
}
|
|
|
|
|
|
private void myLoadAssemblies()
|
|
{
|
|
myTreeView.Nodes.Clear();
|
|
IDictionary libraryData = myGetLibraryData();
|
|
foreach (DictionaryEntry de in libraryData)
|
|
{
|
|
TreeNode assemblyNode = new TreeNode(de.Key as String);
|
|
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);
|
|
assemblyNode.Nodes.Add(primitiveNode);
|
|
}
|
|
myTreeView.Nodes.Add(assemblyNode);
|
|
}
|
|
/*
|
|
myPrimitivesTextBox.Clear ();
|
|
ArrayList al = new ArrayList(PrimitiveManager.instance.getPrimitiveNames());
|
|
al.Sort();
|
|
foreach (string s in al)
|
|
{
|
|
myPrimitivesTextBox.Text += "\n" + s + " (from " + PrimitiveManager.instance.getAssemblyName(s) + ")\n";
|
|
foreach (string desc in PrimitiveManager.instance.getConstructorSigns(s))
|
|
myPrimitivesTextBox.Text += "\t" + desc + "\n";
|
|
}*/
|
|
}
|
|
|
|
private void myHandleTableListChange(object o)
|
|
{
|
|
IBlueRowCollection rows = (o as DataPacket).newRows;
|
|
myUpdateTableList();
|
|
}
|
|
|
|
|
|
#region Persistence Keys
|
|
public int textBoxHeight
|
|
{
|
|
get { return myQueryTextBox.Height; }
|
|
set { myQueryTextBox.Height = value; }
|
|
}
|
|
#endregion
|
|
|
|
private void myTryExpression(string expStr)
|
|
{
|
|
myFreezeView(false); // force unfreeze the view
|
|
DataStreamExpression oldExp = myExp;
|
|
try
|
|
{
|
|
var exp = DataStreamExpressionsInterpreter.Evaluate(expStr);
|
|
|
|
if (exp == null)
|
|
throw new Exception("Syntax error. I am afraid I have no further details. Let Pedro know if you are really bothered about it.");
|
|
|
|
myDataGrid.DataSource = null;
|
|
myTabControl.SelectedIndex = 0;
|
|
myErrorTextBox.Text = "";
|
|
// myDataGrid.CaptionText = "";
|
|
|
|
if (myCurrentStream != null)
|
|
myCurrentStream.onChange -= new BCG.DataStream.ChangeDelegate(myCallback);
|
|
myCurrentStream = null;
|
|
|
|
myExp = exp;
|
|
myCrono.Restart();
|
|
|
|
(myCurrentStream = myExp.getView(new Dictionary<string, StatementExpression>(0))).onChange += new DataStream.ChangeDelegate(myCallback);
|
|
myChangeStyle = true;
|
|
//new SimpleBindableStream(myExp.getView(new Hashtable())).onChange += new DataStream.ChangeDelegate(myCallback);
|
|
/*
|
|
if (oldExp != null)
|
|
oldExp.getView(new Hashtable()).onChange -= new DataStream.ChangeDelegate(myCallback);
|
|
*/
|
|
//myQueryTextBox.Text = expStr;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Ui.warn(exc.ToString());
|
|
|
|
myDataGrid.DataSource = null;
|
|
myTabControl.SelectedIndex = 2;
|
|
myExp = oldExp;
|
|
myErrorTextBox.Text = exc.Message + "\n";
|
|
if (exc.InnerException != null)
|
|
myErrorTextBox.Text += "Inner Exception: " + exc.InnerException.Message + "\n";
|
|
myErrorTextBox.Text += "\n" + exc.StackTrace;
|
|
myCSharpText.Text = "";
|
|
}
|
|
}
|
|
|
|
private string myExtractFromClass(TextReader r)
|
|
{
|
|
string line = r.ReadLine();
|
|
while (line != null && line.IndexOf("*Expression*") == -1)
|
|
line = r.ReadLine();
|
|
|
|
if (line == null)
|
|
throw new Exception("Unexpected EOF");
|
|
|
|
r.ReadLine();
|
|
|
|
string result = "";
|
|
line = r.ReadLine();
|
|
|
|
while (line != null && line.IndexOf("----------------------------------------------------------------------") == -1)
|
|
{
|
|
if (line != "")
|
|
result += line.Substring(" ".Length) + "\n";
|
|
line = r.ReadLine();
|
|
}
|
|
if (line == null)
|
|
throw new Exception("Unexpected EOF");
|
|
|
|
return result;
|
|
}
|
|
|
|
public void loadFile(string fileName)
|
|
{
|
|
try
|
|
{
|
|
TextReader r = new StreamReader(fileName);
|
|
try
|
|
{
|
|
myQueryTextBox.Text = myExtractFromClass(r);
|
|
}
|
|
finally
|
|
{
|
|
r.Close();
|
|
}
|
|
myLastFileName = fileName;
|
|
this.Text = fileName;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Ui.warn(exc.ToString());
|
|
|
|
myDataGrid.DataSource = null;
|
|
myTabControl.SelectedIndex = 1;
|
|
myErrorTextBox.Text = exc.Message;
|
|
myErrorTextBox.Text += "\n" + exc.StackTrace;
|
|
}
|
|
|
|
}
|
|
|
|
private void myPrintCode(IBlueTableSchema schema, ICollection vars, string code)
|
|
{
|
|
|
|
myCSharpText.Text = "using System;\n\nnamespace BCG\n{";
|
|
|
|
myCSharpText.Text += "\n/*";
|
|
myCSharpText.Text += "\n ----------------------------------------------------------------------";
|
|
myCSharpText.Text += "\n *Expression*";
|
|
myCSharpText.Text += "\n ----------------------------------------------------------------------";
|
|
foreach (string line in myQueryTextBox.Text.Split('\n'))
|
|
myCSharpText.Text += "\n " + line;
|
|
myCSharpText.Text += "\n\n ----------------------------------------------------------------------";
|
|
myCSharpText.Text += "\n *Schema*";
|
|
myCSharpText.Text += "\n ----------------------------------------------------------------------";
|
|
foreach (ColumnInfo ci in schema.columnInfo)
|
|
myCSharpText.Text += "\n " + ci.colName + new string(' ', Math.Max(32 - ci.colName.Length, 1)) + ci.colType.ToString();
|
|
myCSharpText.Text += "\n*/\n";
|
|
|
|
|
|
string lastVar = null;
|
|
string variableDeclarations = "";
|
|
foreach (string var in vars)
|
|
{
|
|
variableDeclarations += " ViewStream " + var + ";\n";
|
|
lastVar = var;
|
|
}
|
|
|
|
|
|
|
|
myLastClassName = null;
|
|
if (lastVar != null)
|
|
myLastClassName = lastVar[0].ToString().ToUpper() + lastVar.Substring(1);
|
|
else
|
|
myLastClassName = "MyView";
|
|
|
|
myCSharpText.Text += "\n\n public class " + myLastClassName + " : ViewStream \n {\n";
|
|
|
|
myCSharpText.Text += " public " + myLastClassName + "() : this(null) {}\n";
|
|
myCSharpText.Text += " public " + myLastClassName + "(ViewStreamDatabase db)\n {\n";
|
|
|
|
myCSharpText.Text += variableDeclarations;
|
|
|
|
if (lastVar != null)
|
|
myCSharpText.Text += "\n";
|
|
myCSharpText.Text += code + "\n";
|
|
if (lastVar != null)
|
|
myCSharpText.Text += " mySetRealSource(" + lastVar + ");\n";
|
|
myCSharpText.Text += " }\n";
|
|
myCSharpText.Text += " }\n";
|
|
myCSharpText.Text += "}";
|
|
}
|
|
|
|
static DataGridViewColumn _column_factory(ColumnInfo ci)
|
|
{
|
|
return new DataGridViewTextBoxColumn
|
|
{
|
|
HeaderText = ci.colName,
|
|
Width = get_col_width(ci)
|
|
};
|
|
|
|
static int get_col_width(ColumnInfo ci)
|
|
{
|
|
const int CHAR_WIDTH = 10;
|
|
const int MIN_WIDTH = 50;
|
|
const int MIN_DATE_WIDTH = 200;
|
|
var header_width = ci.colName.Length * CHAR_WIDTH;
|
|
var min_width = ci.colType == typeof(DateTime) ? MIN_DATE_WIDTH : MIN_WIDTH;
|
|
return Math.Max(header_width, min_width);
|
|
}
|
|
}
|
|
|
|
// this is the stream callback
|
|
private void myCallback(object o)
|
|
{
|
|
var timer = Stopwatch.StartNew();
|
|
DataPacket dp = o as DataPacket;
|
|
myCrono.Stop();
|
|
Log.Ui.diag($"Received callback for {dp.schema.tableName}");
|
|
if (o == null)
|
|
{
|
|
System.Windows.Forms.MessageBox.Show(this, "Received a Null Data packet",
|
|
"Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
Log.Ui.diag(dp.toIncrementalIDString());
|
|
myToolStripStatusLabelTime.BackColor = Color.Black;
|
|
myToolStripStatusLabelRows.BackColor = Color.Black;
|
|
myToolStripStatusLabelTime.ForeColor = Color.White;
|
|
myToolStripStatusLabelRows.ForeColor = Color.White;
|
|
myToolStripStatusLabelTime.Text = "Last update: " + DateTime.Now.ToString("hh:mm:ss:fff tt");
|
|
myToolStripStatusLabelRows.Text = "New = " + dp.newRows.Count + " Added = " + dp.addedRows.Count + " Deleted = " + dp.deletedRows.Count;
|
|
Log.Ui.diag(Text);
|
|
int hscrollval = myChangeStyle ? 0 : myDataGrid.HorizScrollBarValue;
|
|
|
|
myDataGrid.DataSource = new SimpleBindableCollection(dp.newRows.schema, dp.newRows);
|
|
var force = false;
|
|
if (myChangeStyle && force)
|
|
{
|
|
myChangeStyle = false;
|
|
myDataGrid.Columns.Clear();
|
|
myDataGrid.Columns.AddRange(Array.ConvertAll(dp.schema.columnInfo, _column_factory));
|
|
}
|
|
myCrono.Restart();
|
|
// myDataGrid.CaptionText = myCrono.time.TotalMilliseconds + " ms ";
|
|
// myDataGrid.CaptionText += dp.newRows.Count.ToString () + " records";
|
|
|
|
|
|
myDataGrid.HorizScrollBarValue = hscrollval;
|
|
|
|
var varNames = new List<string>(0);
|
|
var code = myExp?.print(9, varNames);
|
|
myPrintCode(dp.schema, varNames, code);
|
|
myConsoleRichTextBox.Clear();
|
|
// this was was very very slow
|
|
//myConsoleRichTextBox.Text = BlueDataUtility.get_printed_rows(dp.newRows, (col) => 30);
|
|
timer.Stop();
|
|
Log.Gen.info(
|
|
$"DSQA MainForm.myCallback table: {dp.schema.tableName} rows: {dp.newRows.Count} time: {timer.Elapsed.TotalMilliseconds:0.00}ms");
|
|
}
|
|
|
|
private Stopwatch myCrono = new();
|
|
|
|
private DataStreamExpression? myExp;
|
|
|
|
private void myTimer_Tick(object sender, System.EventArgs e)
|
|
{
|
|
// try
|
|
// {
|
|
ViewStreamDatabase.instance.doWork();
|
|
MasterWorker.getInstance(false).doWork();
|
|
//}
|
|
// catch (Exception exc) {
|
|
// Log.Ui.warn(exc.ToString());
|
|
|
|
// myDataGrid.DataSource = null;
|
|
// //myTabControl.SelectedIndex = 1;
|
|
// myTabControl.SelectedTab = myErrorTabPage;
|
|
// myErrorTextBox.Text = exc.Message;
|
|
// myErrorTextBox.Text += "\n" + exc.StackTrace;
|
|
// }
|
|
}
|
|
|
|
class StringWrapper
|
|
{
|
|
public StringWrapper(string s)
|
|
{
|
|
myTableName = s;
|
|
}
|
|
public string tableName
|
|
{
|
|
get { return myTableName; }
|
|
}
|
|
private string myTableName;
|
|
}
|
|
|
|
private void MainForm_Closed(object sender, System.EventArgs e)
|
|
{
|
|
if (myExp != null)
|
|
myExp.getView(new Dictionary<string, StatementExpression>(0)).onChange -= new DataStream.ChangeDelegate(myCallback);
|
|
}
|
|
|
|
private void myMenuItemExecuteQueryClick(object sender, System.EventArgs e)
|
|
{
|
|
myQueryTextBox.SelectionStart = myQueryTextBox.Text.Length;
|
|
myQueryTextBox.SelectionLength = myQueryTextBox.Text.Length;
|
|
myQueryTextBox.SelectionColor = Color.White;
|
|
myQueryTextBox.SelectionLength = 0;
|
|
myTryExpression(myQueryTextBox.Text);
|
|
}
|
|
|
|
private void myToolStripMenuItemExecSel_Click(object sender, EventArgs e)
|
|
{
|
|
// int selstart = myQueryTextBox.SelectionStart;
|
|
// int sellength = myQueryTextBox.SelectionLength;
|
|
// myQueryTextBox.SelectionStart = 0;
|
|
// myQueryTextBox.SelectionLength = myQueryTextBox.Text.Length;
|
|
// myQueryTextBox.SelectionColor = Color.White;
|
|
// myQueryTextBox.SelectionStart = selstart;
|
|
// myQueryTextBox.SelectionLength = sellength;
|
|
// myQueryTextBox.SelectionColor = Color.Crimson;
|
|
// myTryExpression(myQueryTextBox.SelectedText);
|
|
// myQueryTextBox.SelectionStart = myQueryTextBox.Text.Length;
|
|
// myQueryTextBox.SelectionLength = 0;
|
|
// myQueryTextBox.SelectionColor = Color.White;
|
|
}
|
|
|
|
private void myMenuItemOpenClick(object sender, System.EventArgs e)
|
|
{
|
|
OpenFileDialog od = new OpenFileDialog();
|
|
od.Filter = "C# class (*.cs)|*.cs";
|
|
|
|
if (od.ShowDialog() == DialogResult.OK)
|
|
loadFile(od.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)
|
|
{
|
|
if (myLastFileName == null)
|
|
myMenuItemSaveAsClick(sender, e);
|
|
else
|
|
mySave(myLastFileName);
|
|
}
|
|
|
|
private void myMenuItemSaveAsClick(object sender, System.EventArgs e)
|
|
{
|
|
SaveFileDialog sd = new SaveFileDialog();
|
|
if (myLastFileName != null)
|
|
sd.FileName = myLastFileName;
|
|
else
|
|
sd.FileName = myLastClassName + ".cs";
|
|
|
|
if (sd.ShowDialog() == DialogResult.OK)
|
|
mySave(sd.FileName);
|
|
}
|
|
|
|
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)
|
|
{
|
|
//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)
|
|
{
|
|
//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)
|
|
{
|
|
//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)
|
|
{
|
|
//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)
|
|
{
|
|
//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)
|
|
{
|
|
//myTableListBox.BackColor = Color.White;
|
|
myTableListBox.Font = new Font(myTableListBox.Font.Name, myTableListBox.Font.Size, FontStyle.Regular);
|
|
}
|
|
|
|
private void myLoad(object sender, EventArgs e)
|
|
{
|
|
myFreezeView(false);
|
|
|
|
myToolStripMenuItemSite.DropDownItems.Clear();
|
|
// foreach (var name in SitesCfg.instance.siteNames)
|
|
// {
|
|
// ToolStripMenuItem mi = new ToolStripMenuItem (name);
|
|
// mi.Click += new EventHandler (myMenuItemSiteClick);
|
|
// mySiteItems.Add (mi);
|
|
// mi.Enabled = true;
|
|
// myToolStripMenuItemSite.DropDownItems.Add (mi);
|
|
|
|
// if (name == mySite)
|
|
// mi.Checked = true;
|
|
// }
|
|
|
|
myConsoleRichTextBox.ReadOnly = true;
|
|
myConsoleOutput = new RichTextBoxStreamWriter(myConsoleRichTextBox);
|
|
Console.SetOut(myConsoleOutput);
|
|
Console.SetError(myConsoleOutput);
|
|
if (BCG.Utilities.Win32.WindowsAPI.SetStdHandle(-11, myConsoleRichTextBox.Handle) == 0) // set stdout
|
|
{
|
|
var ex = new Win32Exception(); // same as new Win32Exception(Marshal.GetLastWin32Error())
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Set stdout worked.");
|
|
}
|
|
|
|
if (BCG.Utilities.Win32.WindowsAPI.SetStdHandle(-12, myConsoleRichTextBox.Handle) == 0) // set stderr
|
|
{
|
|
var ex = new Win32Exception(); // same as new Win32Exception(Marshal.GetLastWin32Error())
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Set stderr worked.");
|
|
}
|
|
Console.WriteLine("Redirecting console ouput to this window...");
|
|
|
|
myLoadAssemblies();
|
|
|
|
ViewStreamDatabase.instance = new ViewStreamDatabase();
|
|
myAllTagsStream = myGetAllTagsStream();
|
|
myAllTagsStream.onChange += new BCG.DataStream.ChangeDelegate(myHandleTableListChange);
|
|
myTabControl.SelectedIndex = 3;
|
|
myTreeView.AfterSelect += new TreeViewEventHandler(myHandleTreeNodeSelect);
|
|
//do this lazily so we don't have to have bps, etc up to run dsqa
|
|
//_library = new LibraryForm(this);
|
|
}
|
|
|
|
private void myMenuItemSiteClick(object sender, System.EventArgs e)
|
|
{
|
|
ToolStripMenuItem mi = (ToolStripMenuItem)sender;
|
|
|
|
if (mi.Text != mySite)
|
|
{
|
|
mySite = mi.Text;
|
|
foreach (var m in mySiteItems)
|
|
m.Checked = false;
|
|
mi.Checked = true;
|
|
|
|
myAllTagsStream.onChange -= new BCG.DataStream.ChangeDelegate(myHandleTableListChange);
|
|
myTableListBox.Items.Clear();
|
|
|
|
// SitesCore.setMySiteName (mySite);
|
|
|
|
ViewStreamDatabase.instance = new ViewStreamDatabase();
|
|
myAllTagsStream = myGetAllTagsStream();
|
|
myAllTagsStream.onChange += new BCG.DataStream.ChangeDelegate(myHandleTableListChange);
|
|
|
|
myDataGrid.DataSource = null;
|
|
myTabControl.SelectedIndex = 3;
|
|
mySetText();
|
|
}
|
|
}
|
|
|
|
private void myClosing(object sender, CancelEventArgs e)
|
|
{
|
|
}
|
|
|
|
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)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void myToolStripMenuItemFreeze_Click(object sender, EventArgs e)
|
|
{
|
|
myFreezeView(myTimer.Enabled);
|
|
}
|
|
|
|
private void myFreezeView(bool freeze)
|
|
{
|
|
myTimer.Enabled = !freeze;
|
|
myToolStripMenuItemFreeze.Checked = freeze;
|
|
myToolStripMenuItemStep.Enabled = freeze;
|
|
}
|
|
|
|
private void myToolStripMenuItemStep_Click(object sender, EventArgs e)
|
|
{
|
|
ViewStreamDatabase.instance.doWork();
|
|
}
|
|
|
|
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)
|
|
{
|
|
PrimitiveManager.instance.loadAssembly(ofd.FileName);
|
|
myLoadAssemblies();
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
myConsoleRichTextBox.Clear();
|
|
Console.WriteLine("Redirecting console ouput to this window...");
|
|
}
|
|
|
|
private void myTableFilterBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
myUpdateTableList();
|
|
}
|
|
|
|
private void myUpdateTableList()
|
|
{
|
|
IBlueRowCollection rows = myAllTagsStream.rows;
|
|
if (rows == null)
|
|
return;
|
|
|
|
|
|
ICollection oldItems = myTableListBox.Items;
|
|
|
|
myTableListBox.BeginUpdate();
|
|
int topindex = myTableListBox.TopIndex;
|
|
string topitem = (myTableListBox.Items.Count > 0) ? myTableListBox.Items[topindex].ToString() : string.Empty;
|
|
|
|
myTableListBox.Items.Clear();
|
|
SortedList<string, bool> sl = new SortedList<string, bool>();
|
|
if (string.IsNullOrEmpty(myTableFilterBox.Text))
|
|
foreach (IBlueRow r in rows)
|
|
{
|
|
sl[r["tag"].ToString().Substring(DSTagManager.get_stream_tag("").Length)] = true;
|
|
}
|
|
else
|
|
{
|
|
Regex tableRegex = new Regex(myTableFilterBox.Text);
|
|
foreach (IBlueRow r in rows)
|
|
{
|
|
string thisTable = r["tag"].ToString().Substring(DSTagManager.get_stream_tag("").Length);
|
|
if (tableRegex.IsMatch(thisTable))
|
|
sl[thisTable] = true;
|
|
}
|
|
}
|
|
string[] list = new string[sl.Keys.Count];
|
|
sl.Keys.CopyTo(list, 0);
|
|
myTableListBox.Items.AddRange(list);
|
|
|
|
int top = sl.IndexOfKey(topitem);
|
|
if (top >= 0)
|
|
myTableListBox.TopIndex = top;
|
|
else
|
|
myTableListBox.TopIndex = Math.Min(sl.Count - 1, topindex);
|
|
myTableListBox.EndUpdate();
|
|
}
|
|
|
|
private void testGridToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var timer = new Stopwatch();
|
|
//while (true)
|
|
//{
|
|
// Random rnd = new Random(DateTime.Now.Millisecond);
|
|
// List<double> rand_nos = new List<double>();
|
|
// for (int i = 0; i < 10000; i++)
|
|
// rand_nos.Add(rnd.NextDouble());
|
|
// timer.start();
|
|
// rand_nos.Sort();
|
|
// timer.stop();
|
|
// BCG.Utilities.BlueEventLog.logEvent(String.Format("nrows = {0} sorting time = {1}", rand_nos.Count, timer.lastIntervalTime), BCG.Utilities.BlueEventLevel.Performance);
|
|
// System.Threading.Thread.Sleep(10);
|
|
//}
|
|
|
|
ViewStream s = new LoaderStream(@"P:\Dropbox\Data\spread_md_esoa_cme");
|
|
s = new MutableAppendStream(s, s);
|
|
//s = new MutableAppendStream(s, s);
|
|
List<IBlueRow> rows = new List<IBlueRow>();
|
|
foreach (IBlueRow r in s.rows)
|
|
rows.Add(r);
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
timer.Restart();
|
|
rows.Sort(delegate (IBlueRow r1, IBlueRow r2)
|
|
{
|
|
return _sort_dicts_index(r1, r2, 5, true);
|
|
});
|
|
timer.Stop();
|
|
Log.Ui.diag($"nrows = {rows.Count} sorting time = {timer.Elapsed.TotalMilliseconds:0.00}ms");
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
//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)
|
|
{
|
|
if (myIsDontCare(o1))
|
|
return myIsDontCare(o2) ? 0 : 1;
|
|
else
|
|
return myIsDontCare(o2) ? -1 : (low_to_high ? ((IComparable)o1).CompareTo(o2)
|
|
: ((IComparable)o2).CompareTo(o1));
|
|
}
|
|
|
|
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)
|
|
{
|
|
//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),
|
|
// "Diagnosis");
|
|
//ViewStream s = args as ViewStream;
|
|
//BTSTabularGridTestForm f = new BTSTabularGridTestForm(s);
|
|
//Application.Run(f);
|
|
}
|
|
|
|
private void libraryToolStripMenuItem_Click(object sender, EventArgs e) { }
|
|
|
|
private void myTableFilterLabel_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|