Skip to content

Commit

Permalink
fix infinite loading bug due to delayed change textbox.
Browse files Browse the repository at this point in the history
beautify the create table sql script a bit
fix broken User Guide link after migrating to .net 6
  • Loading branch information
mukunku committed Sep 27, 2022
1 parent 56c88fb commit 025f1b2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 50 deletions.
43 changes: 31 additions & 12 deletions src/ParquetFileViewer/Controls/DelayedOnChangedTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace ParquetFileViewer.Controls
{
public class DelayedOnChangedTextBox : TextBox
{
private Timer m_delayedTextChangedTimer;
private bool _skipNextTextChange = false;
private Timer _delayedTextChangedTimer;

public event EventHandler DelayedTextChanged;

Expand All @@ -23,11 +24,11 @@ public DelayedOnChangedTextBox(int secondsDelay)

protected override void Dispose(bool disposing)
{
if (m_delayedTextChangedTimer != null)
if (_delayedTextChangedTimer != null)
{
m_delayedTextChangedTimer.Stop();
_delayedTextChangedTimer.Stop();
if (disposing)
m_delayedTextChangedTimer.Dispose();
_delayedTextChangedTimer.Dispose();
}

base.Dispose(disposing);
Expand All @@ -42,23 +43,41 @@ protected virtual void OnDelayedTextChanged(EventArgs e)

protected override void OnTextChanged(EventArgs e)
{
this.InitializeDelayedTextChangedEvent();
if (this._skipNextTextChange)
{
_skipNextTextChange = false;
}
else
{
this.InitializeDelayedTextChangedEvent();
}

base.OnTextChanged(e);
}

/// <summary>
/// Sets the Text value of the textbox without triggering the text changed event
/// </summary>
/// <param name="text">New value to set as the textbox's text</param>
public void SetTextQuiet(string text)
{
this._skipNextTextChange = true;
this.Text = text;
}

private void InitializeDelayedTextChangedEvent()
{
if (m_delayedTextChangedTimer != null)
m_delayedTextChangedTimer.Stop();
if (_delayedTextChangedTimer != null)
_delayedTextChangedTimer.Stop();

if (m_delayedTextChangedTimer == null || m_delayedTextChangedTimer.Interval != this.DelayedTextChangedTimeout)
if (_delayedTextChangedTimer == null || _delayedTextChangedTimer.Interval != this.DelayedTextChangedTimeout)
{
m_delayedTextChangedTimer = new Timer();
m_delayedTextChangedTimer.Tick += new EventHandler(HandleDelayedTextChangedTimerTick);
m_delayedTextChangedTimer.Interval = this.DelayedTextChangedTimeout;
_delayedTextChangedTimer = new Timer();
_delayedTextChangedTimer.Tick += new EventHandler(HandleDelayedTextChangedTimerTick);
_delayedTextChangedTimer.Interval = this.DelayedTextChangedTimeout;
}

m_delayedTextChangedTimer.Start();
_delayedTextChangedTimer.Start();
}

private void HandleDelayedTextChangedTimerTick(object sender, EventArgs e)
Expand Down
44 changes: 23 additions & 21 deletions src/ParquetFileViewer/Helpers/CustomScriptBasedSchemaAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ public class CustomScriptBasedSchemaAdapter

static CustomScriptBasedSchemaAdapter()
{
Hashtable hashtable = new Hashtable();
hashtable.Add(typeof(ulong), "bigint {1}NULL");
hashtable.Add(typeof(long), "bigint {1}NULL");
hashtable.Add(typeof(bool), "bit {1}NULL");
hashtable.Add(typeof(char), "char {1}NULL");
hashtable.Add(typeof(DateTime), "datetime {1}NULL");
hashtable.Add(typeof(double), "float {1}NULL");
hashtable.Add(typeof(uint), "int {1}NULL");
hashtable.Add(typeof(int), "int {1}NULL");
hashtable.Add(typeof(Guid), "uniqueidentifier {1}NULL");
hashtable.Add(typeof(ushort), "smallint {1}NULL");
hashtable.Add(typeof(short), "smallint {1}NULL");
hashtable.Add(typeof(decimal), "real {1}NULL");
hashtable.Add(typeof(byte), "tinyint {1}NULL");
hashtable.Add(typeof(sbyte), "tinyint {1}NULL");
hashtable.Add(typeof(string), "nvarchar({0}) {1}NULL");
hashtable.Add(typeof(TimeSpan), "int {1}NULL");
hashtable.Add(typeof(byte[]), "varbinary {1}NULL");
Hashtable hashtable = new Hashtable
{
{ typeof(ulong), "BIGINT {1}NULL" },
{ typeof(long), "BIGINT {1}NULL" },
{ typeof(bool), "BIT {1}NULL" },
{ typeof(char), "CHAR {1}NULL" },
{ typeof(DateTime), "DATETIME {1}NULL" },
{ typeof(double), "FLOAT {1}NULL" },
{ typeof(uint), "INT {1}NULL" },
{ typeof(int), "INT {1}NULL" },
{ typeof(Guid), "UNIQUEIDENTIFIER {1}NULL" },
{ typeof(ushort), "SMALLINT {1}NULL" },
{ typeof(short), "SMALLINT {1}NULL" },
{ typeof(decimal), "REAL {1}NULL" },
{ typeof(byte), "TINYINT {1}NULL" },
{ typeof(sbyte), "TINYINT {1}NULL" },
{ typeof(string), "NVARCHAR({0}) {1}NULL" },
{ typeof(TimeSpan), "INT {1}NULL" },
{ typeof(byte[]), "VARBINARY {1}NULL" }
};
TypeMap = hashtable;
}

Expand Down Expand Up @@ -132,7 +134,7 @@ private string MakeList(DataColumnCollection columns)
{
if (!flag)
{
stringBuilder.Append(" , ");
stringBuilder.Append(", ");
}
string str = this.MakeSafe(column.ColumnName);
string typeFor = this.GetTypeFor(column);
Expand Down Expand Up @@ -163,7 +165,7 @@ private string MakeRelation(DataRelation relation)
protected string MakeSafe(string inputValue)
{
string str = inputValue.Trim();
string str1 = string.Format("[{0}]", str.Substring(0, Math.Min(128, str.Length)));
string str1 = string.Format("[{0}]", str[..Math.Min(128, str.Length)]);
return str1;
}

Expand All @@ -172,7 +174,7 @@ private string MakeTable(DataTable table, bool markTablesAsLocalTemp)
StringBuilder stringBuilder = new StringBuilder();
string str = this.MakeSafe(string.Concat(markTablesAsLocalTemp ? "#" : string.Empty, this.TablePrefix, table.TableName));
string str1 = this.MakeList(table.Columns);
stringBuilder.AppendFormat("CREATE TABLE {0} ({1});\n", str, str1);
stringBuilder.AppendFormat("CREATE TABLE {0} ({1}\n);", str, str1);
return stringBuilder.ToString();
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/ParquetFileViewer/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions src/ParquetFileViewer/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -144,8 +144,8 @@ public MainForm()
{
InitializeComponent();
this.DefaultFormTitle = this.Text;
this.offsetTextBox.Text = DefaultOffset.ToString();
this.recordCountTextBox.Text = DefaultRowCount.ToString();
this.offsetTextBox.SetTextQuiet(DefaultOffset.ToString());
this.recordCountTextBox.SetTextQuiet(DefaultRowCount.ToString());
this.MainDataSource = new DataTable();
this.OpenFilePath = null;

Expand Down Expand Up @@ -396,7 +396,7 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e)

private void userGuideToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(WikiURL);
Process.Start(new ProcessStartInfo(WikiURL) { UseShellExecute = true });
}

private void MainGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
Expand Down Expand Up @@ -668,8 +668,18 @@ private void mainGridView_DataBindingComplete(object sender, DataGridViewBinding
private void OpenNewFile(string filePath)
{
this.OpenFilePath = filePath;
this.offsetTextBox.Text = string.IsNullOrWhiteSpace(this.offsetTextBox.Text) ? DefaultOffset.ToString() : this.offsetTextBox.Text;
this.recordCountTextBox.Text = string.IsNullOrWhiteSpace(this.recordCountTextBox.Text) ? DefaultRowCount.ToString() : this.recordCountTextBox.Text;

if (!DefaultOffset.ToString().Equals(this.offsetTextBox.Text)) //Without this 'if' SetTextQuiet doesn't work correctly!
{
this.offsetTextBox.SetTextQuiet(DefaultOffset.ToString());
this.currentMaxRowCount = DefaultRowCount;
}

if (!DefaultRowCount.ToString().Equals(this.recordCountTextBox.Text)) //Without this 'if' SetTextQuiet doesn't work correctly!
{
this.recordCountTextBox.SetTextQuiet(DefaultRowCount.ToString());
this.currentOffset = DefaultOffset;
}

this.OpenFieldSelectionDialog(false);
}
Expand Down Expand Up @@ -852,15 +862,9 @@ public ParquetReadResult(DataTable result, long totalNumberOfRecordsInFile)

private void GetSQLCreateTableScriptToolStripMenuItem_Click(object sender, EventArgs e)
{
string tableName = DefaultTableName;
try
{
tableName = Path.GetFileNameWithoutExtension(this.OpenFilePath);
}
catch { /* just in case */ }

try
{
string tableName = Path.GetFileNameWithoutExtension(this.OpenFilePath) ?? DefaultTableName;
if (this.mainDataSource?.Columns.Count > 0)
{
var dataset = new DataSet();
Expand Down
2 changes: 1 addition & 1 deletion src/ParquetFileViewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.4.1.0")]
[assembly: AssemblyVersion("2.4.1.1")]

0 comments on commit 025f1b2

Please sign in to comment.