Skip to content

Commit c1a7374

Browse files
authored
Merge pull request #21 from mukunku/v2.2
V2.2
2 parents c877716 + 2fe3c1e commit c1a7374

11 files changed

+566
-153
lines changed

src/ParquetFileViewer/AboutBox.cs

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Drawing;
5-
using System.Linq;
62
using System.Reflection;
7-
using System.Threading.Tasks;
83
using System.Windows.Forms;
94

105
namespace ParquetFileViewer

src/ParquetFileViewer/App.config

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
1010
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
1111
</dependentAssembly>
12+
<dependentAssembly>
13+
<assemblyIdentity name="IronSnappy" publicKeyToken="b1d4b1dc83bdcf31" culture="neutral" />
14+
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
15+
</dependentAssembly>
16+
<dependentAssembly>
17+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
18+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
19+
</dependentAssembly>
1220
</assemblyBinding>
1321
</runtime>
1422
</configuration>

src/ParquetFileViewer/AppSettings.cs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using Microsoft.Win32;
2+
3+
namespace ParquetFileViewer
4+
{
5+
public static class AppSettings
6+
{
7+
private const string UseISODateFormatKey = "UseISODateFormat";
8+
private const string AlwaysSelectAllFieldsKey = "AlwaysSelectAllFields";
9+
public static bool UseISODateFormat
10+
{
11+
get
12+
{
13+
using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("ParquetViewer"))
14+
{
15+
bool value = false;
16+
bool.TryParse(registryKey.GetValue(UseISODateFormatKey)?.ToString(), out value);
17+
return value;
18+
}
19+
}
20+
set
21+
{
22+
using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("ParquetViewer"))
23+
{
24+
registryKey.SetValue(UseISODateFormatKey, value.ToString());
25+
}
26+
}
27+
}
28+
29+
public static bool AlwaysSelectAllFields
30+
{
31+
get
32+
{
33+
try
34+
{
35+
using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("ParquetViewer"))
36+
{
37+
bool value = false;
38+
bool.TryParse(registryKey.GetValue(AlwaysSelectAllFieldsKey)?.ToString(), out value);
39+
return value;
40+
}
41+
}
42+
catch
43+
{
44+
return false;
45+
}
46+
}
47+
set
48+
{
49+
using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("ParquetViewer"))
50+
{
51+
registryKey.SetValue(AlwaysSelectAllFieldsKey, value.ToString());
52+
}
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ParquetFileViewer
10+
{
11+
public class CustomScriptBasedSchemaAdapter
12+
{
13+
internal readonly static Hashtable TypeMap;
14+
15+
public string TablePrefix { get; set; }
16+
public bool CascadeDeletes { get; set; }
17+
18+
static CustomScriptBasedSchemaAdapter()
19+
{
20+
Hashtable hashtable = new Hashtable();
21+
hashtable.Add(typeof(ulong), "bigint {1}NULL");
22+
hashtable.Add(typeof(long), "bigint {1}NULL");
23+
hashtable.Add(typeof(bool), "bit {1}NULL");
24+
hashtable.Add(typeof(char), "char {1}NULL");
25+
hashtable.Add(typeof(DateTime), "datetime {1}NULL");
26+
hashtable.Add(typeof(double), "float {1}NULL");
27+
hashtable.Add(typeof(uint), "int {1}NULL");
28+
hashtable.Add(typeof(int), "int {1}NULL");
29+
hashtable.Add(typeof(Guid), "uniqueidentifier {1}NULL");
30+
hashtable.Add(typeof(ushort), "smallint {1}NULL");
31+
hashtable.Add(typeof(short), "smallint {1}NULL");
32+
hashtable.Add(typeof(decimal), "real {1}NULL");
33+
hashtable.Add(typeof(byte), "tinyint {1}NULL");
34+
hashtable.Add(typeof(sbyte), "tinyint {1}NULL");
35+
hashtable.Add(typeof(string), "nvarchar({0}) {1}NULL");
36+
hashtable.Add(typeof(TimeSpan), "int {1}NULL");
37+
hashtable.Add(typeof(byte[]), "varbinary {1}NULL");
38+
TypeMap = hashtable;
39+
}
40+
41+
public string GetCreateScript(string databaseName)
42+
{
43+
if (databaseName == null || databaseName.Trim().Length == 0)
44+
{
45+
throw new ArgumentException(string.Format("The database name passed is {0}", (databaseName == null ? "null" : "empty")), "databaseName");
46+
}
47+
48+
return string.Format("IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'{0}') BEGIN CREATE DATABASE {1};\n END\n", databaseName, this.MakeSafe(databaseName));
49+
}
50+
51+
public string GetSchemaScript(DataSet dataSet, bool markTablesAsLocalTemp)
52+
{
53+
if (dataSet == null)
54+
{
55+
throw new ArgumentException("null is not a valid parameter value", "dataSet");
56+
}
57+
StringBuilder stringBuilder = new StringBuilder();
58+
foreach (DataTable table in dataSet.Tables)
59+
{
60+
try
61+
{
62+
stringBuilder.Append(this.MakeTable(table, markTablesAsLocalTemp));
63+
}
64+
catch (ArgumentException argumentException)
65+
{
66+
throw new ArgumentException("Table does not contain any columns", table.TableName, argumentException);
67+
}
68+
}
69+
foreach (DataTable dataTable in dataSet.Tables)
70+
{
71+
if ((int)dataTable.PrimaryKey.Length <= 0)
72+
{
73+
continue;
74+
}
75+
string str = this.MakeSafe(string.Concat(this.TablePrefix, dataTable.TableName));
76+
string str1 = this.MakeSafe(string.Concat("PK_", this.TablePrefix, dataTable.TableName));
77+
string str2 = this.MakeList(dataTable.PrimaryKey);
78+
stringBuilder.AppendFormat("IF OBJECT_ID('{1}', 'PK') IS NULL BEGIN ALTER TABLE {0} WITH NOCHECK ADD CONSTRAINT {1} PRIMARY KEY CLUSTERED ({2}); END\n", str, str1, str2);
79+
}
80+
foreach (DataRelation relation in dataSet.Relations)
81+
{
82+
try
83+
{
84+
stringBuilder.Append(this.MakeRelation(relation));
85+
}
86+
catch (ArgumentException argumentException1)
87+
{
88+
throw new ArgumentException("Relationship has an empty column list", relation.RelationName, argumentException1);
89+
}
90+
}
91+
return stringBuilder.ToString();
92+
}
93+
94+
protected string GetTypeFor(DataColumn column)
95+
{
96+
string item = (string)TypeMap[column.DataType];
97+
if (item == null)
98+
{
99+
throw new NotSupportedException(string.Format("No type mapping is provided for {0}", column.DataType.Name));
100+
}
101+
return string.Format(item, column.DataType == typeof(string) ? "MAX" : column.MaxLength.ToString(), (column.AllowDBNull ? string.Empty : "NOT "));
102+
}
103+
104+
private string MakeList(DataColumn[] columns)
105+
{
106+
if (columns == null || (int)columns.Length < 1)
107+
{
108+
throw new ArgumentException("Invalid column list!", "columns");
109+
}
110+
StringBuilder stringBuilder = new StringBuilder();
111+
bool flag = true;
112+
DataColumn[] dataColumnArray = columns;
113+
for (int i = 0; i < (int)dataColumnArray.Length; i++)
114+
{
115+
DataColumn dataColumn = dataColumnArray[i];
116+
if (!flag)
117+
{
118+
stringBuilder.Append(", ");
119+
}
120+
stringBuilder.Append(this.MakeSafe(dataColumn.ColumnName));
121+
flag = false;
122+
}
123+
return stringBuilder.ToString();
124+
}
125+
126+
private string MakeList(DataColumnCollection columns)
127+
{
128+
if (columns == null || columns.Count < 1)
129+
{
130+
throw new ArgumentException("Invalid column list!", "columns");
131+
}
132+
StringBuilder stringBuilder = new StringBuilder();
133+
bool flag = true;
134+
foreach (DataColumn column in columns)
135+
{
136+
if (!flag)
137+
{
138+
stringBuilder.Append(", ");
139+
}
140+
string str = this.MakeSafe(column.ColumnName);
141+
string typeFor = this.GetTypeFor(column);
142+
stringBuilder.AppendFormat("{0} {1}", str, typeFor);
143+
flag = false;
144+
}
145+
return stringBuilder.ToString();
146+
}
147+
148+
private string MakeRelation(DataRelation relation)
149+
{
150+
if (relation == null)
151+
{
152+
throw new ArgumentException("Invalid argument value (null)", "relation");
153+
}
154+
155+
string childTable = this.MakeSafe(string.Concat(this.TablePrefix, relation.ChildTable.TableName));
156+
string parentTable = this.MakeSafe(string.Concat(this.TablePrefix, relation.ParentTable.TableName));
157+
string fkRelationName = this.MakeSafe(string.Concat(this.TablePrefix, relation.RelationName)); //Add prefix so same tables can be created using different prefixes. Otherwise collisions occur
158+
string childTableFKColumns = this.MakeList(relation.ChildColumns);
159+
string parentTableFKColumns = this.MakeList(relation.ParentColumns);
160+
161+
return $"IF OBJECT_ID('{fkRelationName}', 'F') IS NULL BEGIN ALTER TABLE {childTable} " +
162+
$"ADD CONSTRAINT {fkRelationName} FOREIGN KEY ({childTableFKColumns}) REFERENCES {parentTable} ({parentTableFKColumns})" +
163+
$"{(this.CascadeDeletes ? " ON DELETE CASCADE" : string.Empty)}; END\n";
164+
}
165+
166+
protected string MakeSafe(string inputValue)
167+
{
168+
string str = inputValue.Trim();
169+
string str1 = string.Format("[{0}]", str.Substring(0, Math.Min(128, str.Length)));
170+
return str1;
171+
}
172+
173+
private string MakeTable(DataTable table, bool markTablesAsLocalTemp)
174+
{
175+
StringBuilder stringBuilder = new StringBuilder();
176+
string str = this.MakeSafe(string.Concat(markTablesAsLocalTemp ? "#" : string.Empty, this.TablePrefix, table.TableName));
177+
string str1 = this.MakeList(table.Columns);
178+
stringBuilder.AppendFormat("CREATE TABLE {0} ({1});\n", str, str1);
179+
return stringBuilder.ToString();
180+
}
181+
}
182+
}

src/ParquetFileViewer/FieldSelectionDialog.Designer.cs

+25-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)