Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 50 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@
# Dax Formatter [![NuGet](https://github.com/sql-bi/DaxFormatter/actions/workflows/dotnet.yml/badge.svg)](https://github.com/sql-bi/DaxFormatter/actions/workflows/dotnet.yml)

DAX Formatter is a service available at https://www.daxformatter.com
The service receives DAX expressions and format them according to rules for [DAX code formatting](https://www.sqlbi.com/articles/rules-for-dax-code-formatting/)
The service receives DAX expressions and format them according to rules for [DAX code formatting](https://www.sqlbi.com/articles/rules-for-dax-code-formatting/).
The NuGet package contains a client library to invoke the serivce from your .NET application.
All the requests are designed to be asynchronous.
You should minimize the requests made to the service: to format multiple expressions, use a single API call providing the DaxFormatterMultipleRequest structure.
You should minimize the requests made to the service: to format multiple expressions, use a single API call providing the `DaxFormatterMultipleRequest` structure.

# Quick guide
Create an instance of DaxFormatterClient.
Invoke the FormatAsync method for each request.
Possibly, use the DaxFormatterMultipleRequest structure to provide more statistical details about the database and the server (all the names are anonymized and used only to count the number of unique servers/databases serviced).

Create an instance of `DaxFormatterClient`.
Invoke the `FormatAsync` method for each request.
Possibly, use the `DaxFormatterMultipleRequest` structure to provide more statistical details about the database and the server (all the names are anonymized and used only to count the number of unique servers/databases serviced).

# DaxFormatterClient

The default constructor creates an instance of the client using the current assembly name and version to identify the client. You can specify an application name and version in the constructor arguments.
The client instance resolve the server endpoint just once and reuse it in following requests.
It is suggested to reuse the same instance in multiple requests to minimize the latency.
`var formatter = new DaxFormatterClient();
var response1 = await formatter.FormatAsync( "evaluate('Table') order by 'Table'[Column]" );`

```csharp
var formatter = new DaxFormatterClient();
var response1 = await formatter.FormatAsync( "evaluate('Table') order by 'Table'[Column]" );
```
# DaxFormatterMultipleRequest
Use the DaxFormatterMultipleRequest class to send multiple DAX expressions in a single API call.
```var formatter = new DaxFormatterClient();
Use the `DaxFormatterMultipleRequest` class to send multiple DAX expressions in a single API call.
```csharp
var formatter = new DaxFormatterClient();
var request = new DaxFormatterMultipleRequest
{
DatabaseName = "MyDatabaseName", // The name will be anonymized by the client library
ServerName = "MyServerName", // The name will be anonymized by the client library
// Format arguments (you can skip all of them to keep the default values)
ListSeparator = ',',
DecimalSeparator = '.',
MaxLineLenght = DaxFormatterLineStyle.LongLine,
SkipSpaceAfterFunctionName = DaxFormatterSpacingStyle.BestPractice,
// Identify the server type using the corresponding enum values
ServerMode = Dax.Formatter.AnalysisServices.ServerMode.Tabular,
ServerType = Dax.Formatter.AnalysisServices.ServerType.AnalysisServices,
ServerEdition = Dax.Formatter.AnalysisServices.ServerEdition.Enterprise,
ServerLocation = Dax.Formatter.AnalysisServices.ServerLocation.OnPremise,
};
{
DatabaseName = "MyDatabaseName", // The name will be anonymized by the client library
ServerName = "MyServerName", // The name will be anonymized by the client library

// Format arguments (you can skip all of them to keep the default values)
ListSeparator = ',',
DecimalSeparator = '.',
MaxLineLenght = DaxFormatterLineStyle.LongLine,
SkipSpaceAfterFunctionName = DaxFormatterSpacingStyle.BestPractice,

// Identify the server type using the corresponding enum values
ServerMode = Dax.Formatter.AnalysisServices.ServerMode.Tabular,
ServerType = Dax.Formatter.AnalysisServices.ServerType.AnalysisServices,
ServerEdition = Dax.Formatter.AnalysisServices.ServerEdition.Enterprise,
ServerLocation = Dax.Formatter.AnalysisServices.ServerLocation.OnPremise,
};

// Add the code to format
request.Dax.Add( "evaluate('Table') order by 'Table'[Column]" );
Expand All @@ -55,36 +56,33 @@ foreach (var response in responses)
Console.WriteLine(response.Formatted);
}
```


# DaxFormatterSingleRequest
Use the DaxFormatterSingleRequest class to send one DAX expressions in a single API call.
```var formatter = new DaxFormatterClient();
Use the `DaxFormatterSingleRequest` class to send one DAX expressions in a single API call.
```csharp
var formatter = new DaxFormatterClient();
var request = new DaxFormatterSingleRequest
{
Dax = "evaluate('Table') order by 'Table'[Column]",
DatabaseName = "MyDatabaseName", // The name will be anonymized by the client library
ServerName = "MyServerName", // The name will be anonymized by the client library
// Format arguments (you can skip all of them to keep the default values)
ListSeparator = ',',
DecimalSeparator = '.',
MaxLineLenght = DaxFormatterLineStyle.LongLine,
SkipSpaceAfterFunctionName = DaxFormatterSpacingStyle.BestPractice,
// Identify the server type using the corresponding enum values
ServerMode = Dax.Formatter.AnalysisServices.ServerMode.Tabular,
ServerType = Dax.Formatter.AnalysisServices.ServerType.AnalysisServices,
ServerEdition = Dax.Formatter.AnalysisServices.ServerEdition.Enterprise,
ServerLocation = Dax.Formatter.AnalysisServices.ServerLocation.OnPremise,
};

{
Dax = "evaluate('Table') order by 'Table'[Column]",

DatabaseName = "MyDatabaseName", // The name will be anonymized by the client library
ServerName = "MyServerName", // The name will be anonymized by the client library

// Format arguments (you can skip all of them to keep the default values)
ListSeparator = ',',
DecimalSeparator = '.',
MaxLineLenght = DaxFormatterLineStyle.LongLine,
SkipSpaceAfterFunctionName = DaxFormatterSpacingStyle.BestPractice,

// Identify the server type using the corresponding enum values
ServerMode = Dax.Formatter.AnalysisServices.ServerMode.Tabular,
ServerType = Dax.Formatter.AnalysisServices.ServerType.AnalysisServices,
ServerEdition = Dax.Formatter.AnalysisServices.ServerEdition.Enterprise,
ServerLocation = Dax.Formatter.AnalysisServices.ServerLocation.OnPremise,
};
// Send the request and wait the result
var response = await formatter.FormatAsync(request);

// Display the result
Console.WriteLine(response.Formatted);
```