Skip to content

Commit 91a23f8

Browse files
committed
Version 1.1
1 parent d932761 commit 91a23f8

29 files changed

+1355
-157
lines changed

Client/Client.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
<Reference Include="System.Core" />
4747
<Reference Include="System.Runtime.Serialization" />
4848
<Reference Include="System.ServiceModel" />
49+
<Reference Include="System.Web" />
50+
<Reference Include="System.Web.Extensions" />
4951
<Reference Include="System.Xml.Linq" />
5052
<Reference Include="System.Data.DataSetExtensions" />
5153
<Reference Include="Microsoft.CSharp" />
@@ -55,6 +57,7 @@
5557
</ItemGroup>
5658
<ItemGroup>
5759
<Compile Include="Credential.cs" />
60+
<Compile Include="CredentialFolder.cs" />
5861
<Compile Include="CredentialSQL.cs" />
5962
<Compile Include="CredentialWeb.cs" />
6063
<Compile Include="CredentialFile.cs" />
@@ -68,6 +71,7 @@
6871
<Compile Include="ObjectExtension.cs" />
6972
<Compile Include="PowerQueryCommand.cs" />
7073
<Compile Include="Properties\AssemblyInfo.cs" />
74+
<Compile Include="SqlTableAction.cs" />
7175
</ItemGroup>
7276
<ItemGroup>
7377
<None Include="PowerQueryNet.Client.snk" />

Client/Credential.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace PowerQueryNet.Client
1313
/// </summary>
1414
[XmlInclude(typeof(CredentialFile))]
1515
[KnownType(typeof(CredentialFile))]
16+
[XmlInclude(typeof(CredentialFolder))]
17+
[KnownType(typeof(CredentialFolder))]
1618
[XmlInclude(typeof(CredentialWeb))]
1719
[KnownType(typeof(CredentialWeb))]
1820
[XmlInclude(typeof(CredentialSQL))]

Client/CredentialFolder.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace PowerQueryNet.Client
8+
{
9+
/// <summary>
10+
/// Credential to access a folder from the Power Query (M) formulas.
11+
/// </summary>
12+
public class CredentialFolder : Credential
13+
{
14+
/// <summary>
15+
/// Full path of the folder
16+
/// </summary>
17+
public string Path { get; set; }
18+
}
19+
}

Client/CredentialSQL.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ namespace PowerQueryNet.Client
1212
public class CredentialSQL : Credential
1313
{
1414
/// <summary>
15-
/// Full path of the file
15+
/// SQL Server Name and database name. Format: serverName;databaseName
1616
/// </summary>
1717
public string SQL { get; set; }
18+
19+
/// <summary>
20+
/// Username value
21+
/// </summary>
22+
public string Username { get; set; }
23+
24+
/// <summary>
25+
/// Password value
26+
/// </summary>
27+
public string Password { get; set; }
1828
}
1929
}

Client/ExecuteOutputFlags.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,35 @@ namespace PowerQueryNet.Client
1212
[Flags]
1313
public enum ExecuteOutputFlags
1414
{
15+
16+
/// <summary>
17+
/// Outputs result to comma-separated values (CSV)
18+
/// </summary>
19+
Csv = 1,
20+
1521
/// <summary>
1622
/// Outputs result to DataTable
1723
/// </summary>
18-
DataTable = 1,
24+
DataTable = 2,
1925

2026
/// <summary>
21-
/// Outputs result to Xml
27+
/// Outputs result to HTML
2228
/// </summary>
23-
Xml = 2,
29+
Html = 4,
2430

2531
/// <summary>
26-
/// Outputs result to comma-separated values (CSV)
32+
/// Outputs result to JSON
2733
/// </summary>
28-
Csv = 4,
34+
Json = 8,
2935

3036
/// <summary>
3137
/// Outputs result to a SQL Server Table
3238
/// </summary>
33-
Sql = 8
39+
Sql = 16,
40+
41+
/// <summary>
42+
/// Outputs result to Xml
43+
/// </summary>
44+
Xml = 32
3445
}
3546
}

Client/ExecuteRequest.cs

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,66 @@ namespace PowerQueryNet.Client
1111
/// </summary>
1212
public class ExecuteRequest
1313
{
14+
private string mashup = null;
15+
private Queries queries = null;
16+
17+
/// <summary>
18+
/// Initializes a new instance of the ExecuteRequest class.
19+
/// </summary>
20+
public ExecuteRequest()
21+
{
22+
Credentials = new Credentials();
23+
//Parameters = new Parameters();
24+
Queries = new Queries();
25+
SqlDecimalPrecision = 18;
26+
SqlDecimalScale = 6;
27+
}
28+
1429
/// <summary>
15-
/// Credentials to access one or many ressources when executing the query.
30+
/// Collection of instances of Credential to access one or many ressources from the Power Query (M) formulas.
1631
/// </summary>
1732
public Credentials Credentials { get; set; }
1833

1934
/// <summary>
20-
/// Queries that will compose the mashup from which the query will be executed.
35+
/// Collection of instances of Parameter in the Power Query (M) formulas.
2136
/// </summary>
22-
public Queries Queries { get; set; }
37+
//public Parameters Parameters { get; set; }
38+
39+
/// <summary>
40+
/// Collection of instances of Query to execute Power Query (M) formulas.
41+
/// </summary>
42+
public Queries Queries
43+
{
44+
get
45+
{
46+
return queries;
47+
}
48+
set
49+
{
50+
if (value != null && value.Count > 0 && mashup != null)
51+
throw new InvalidOperationException("Queries cannot be assigned when Mashup is defined.");
52+
53+
queries = value;
54+
}
55+
}
56+
57+
/// <summary>
58+
/// Mashup (queries) from which the query will be executed.
59+
/// </summary>
60+
public string Mashup
61+
{
62+
get
63+
{
64+
return mashup;
65+
}
66+
set
67+
{
68+
if (value != null && Queries != null && Queries.Count > 0)
69+
throw new InvalidOperationException("Mashup cannot be assigned when Queries are defined.");
70+
71+
mashup = value;
72+
}
73+
}
2374

2475
/// <summary>
2576
/// Name of the query to execute.
@@ -36,6 +87,16 @@ public class ExecuteRequest
3687
/// </summary>
3788
public string CsvFileName { get; set; }
3889

90+
/// <summary>
91+
/// Full path of the HTML file that will be generated after the execution of the query.
92+
/// </summary>
93+
public string HtmlFileName { get; set; }
94+
95+
/// <summary>
96+
/// Full path of the JSON file that will be generated after the execution of the query.
97+
/// </summary>
98+
public string JsonFileName { get; set; }
99+
39100
/// <summary>
40101
/// Full path of the XML file that will be generated after the execution of the query.
41102
/// </summary>
@@ -46,10 +107,29 @@ public class ExecuteRequest
46107
/// </summary>
47108
public string SqlConnectionString { get; set; }
48109

110+
/// <summary>
111+
/// For SQL decimal data type, the maximum total number of decimal digits to be stored.
112+
/// </summary>
113+
public int SqlDecimalPrecision { get; set; }
114+
115+
/// <summary>
116+
/// For SQL decimal data type, the number of decimal digits that are stored to the right of the decimal point.
117+
/// </summary>
118+
public int SqlDecimalScale{ get; set; }
119+
49120
/// <summary>
50121
/// When SqlConnectionString is not null, name of the SQL Table that will be generated after the execution of the query. If this property is null, the default name will correspond to the QueryName.
51122
/// </summary>
52123
public string SqlTableName { get; set; }
53124

125+
/// <summary>
126+
/// Action taken when SqlConnectionString and SqlTableName are not null
127+
/// </summary>
128+
public SqlTableAction SqlTableAction { get; set; }
129+
130+
/// <summary>
131+
/// Path of the folder to create temporary files.
132+
/// </summary>
133+
public string TempPath { get; set; }
54134
}
55135
}

Client/ExecuteResponse.cs

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,74 @@ namespace PowerQueryNet.Client
1313
/// </summary>
1414
public class ExecuteResponse
1515
{
16+
1617
/// <summary>
1718
/// Result returned as a System.Data.DataTable serialized in XML.
1819
/// </summary>
19-
public string DataTableXML { get; set; }
20+
private string DataTableXML { get; set; } = null;
2021

2122
/// <summary>
22-
/// Result returned as a readable XML.
23+
/// Result returned as a comma-separated values (CSV)
2324
/// </summary>
24-
public string Xml { get; set; }
25+
public string Csv { get; set; }
26+
27+
/// <summary>
28+
/// Result returned as a System.Data.DataTable.
29+
/// </summary>
30+
public DataTable DataTable { get; set; } = null;
31+
32+
/// <summary>
33+
/// Path of the temporary file created from DataTableXML.
34+
/// </summary>
35+
public string DataTableFile { get; set; }
2536

2637
/// <summary>
2738
/// Exception message when an error occured.
2839
/// </summary>
2940
public string ExceptionMessage { get; set; }
3041

3142
/// <summary>
32-
/// Result returned as a System.Data.DataTable.
43+
/// Result returned as HTML
44+
/// </summary>
45+
public string Html { get; set; }
46+
47+
/// <summary>
48+
/// Result returned as JSON
3349
/// </summary>
34-
public DataTable DataTable
50+
public string Json { get; set; }
51+
52+
/// <summary>
53+
/// Result returned as a readable XML.
54+
/// </summary>
55+
public string Xml { get; set; } = null;
56+
57+
internal void LoadReturnValues(ExecuteOutputFlags executeOutputFlags)
3558
{
36-
get
59+
if (DataTableFile != null)
3760
{
38-
if (DataTableXML != null)
39-
{
40-
var dt = new DataTable();
41-
StringReader sr = new StringReader(DataTableXML);
42-
dt.ReadXml(sr);
43-
return dt;
44-
}
45-
else
46-
return null;
47-
}
61+
DataTableXML = File.ReadAllText(DataTableFile);
62+
File.Delete(DataTableFile);
63+
DataTableFile = null;
4864

49-
}
65+
var dataTable = new DataTable();
66+
StringReader sr = new StringReader(DataTableXML);
67+
dataTable.ReadXml(sr);
5068

69+
if (executeOutputFlags == ExecuteOutputFlags.DataTable)
70+
DataTable = dataTable;
71+
72+
if (executeOutputFlags == ExecuteOutputFlags.Csv)
73+
Csv = dataTable.ToDelimitedFile(',', true);
74+
75+
if (executeOutputFlags == ExecuteOutputFlags.Html)
76+
Html = dataTable.ToHTML();
77+
78+
if (executeOutputFlags == ExecuteOutputFlags.Json)
79+
Json = dataTable.ToContentJSON();
80+
81+
if (executeOutputFlags == ExecuteOutputFlags.Xml)
82+
Xml = dataTable.ToContentXML();
83+
}
84+
}
5185
}
5286
}

Client/IPowerQueryService.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public interface IPowerQueryService
2323
//ExecuteResponse Execute(string queryName, Queries queries, Credentials credentials);
2424
ExecuteResponse Execute(ExecuteRequest executeRequest);
2525

26-
//[OperationContract]
27-
//string ExecuteToSQL(string connectionString, string queryName, Queries queries, Credentials credentials);
28-
2926
/// <summary>
3027
/// Get the mashup (queries) from an Excel or Power BI file.
3128
/// </summary>

0 commit comments

Comments
 (0)