Ejemplo n.º 1
0
        public async Task <DaxFormatterResponse> FormatAsync(string expression, CancellationToken cancellationToken = default)
        {
            var request  = DaxFormatterSingleRequest.GetFrom(_application, _version, expression);
            var response = await _formatter.FormatAsync(request, cancellationToken).ConfigureAwait(false);

            return(response);
        }
Ejemplo n.º 2
0
        private static async Task FormatSingleRequest()
        {
            var formatter = new DaxFormatterClient();

            var request = new DaxFormatterSingleRequest
            {
                Dax = DaxSingleExpression,

                DatabaseName = "MyDatabaseName",
                ServerName   = "MyServerName",

                ListSeparator              = ',',
                DecimalSeparator           = '.',
                MaxLineLength              = DaxFormatterLineStyle.LongLine,
                SkipSpaceAfterFunctionName = DaxFormatterSpacingStyle.BestPractice,

                ServerMode     = Dax.Formatter.AnalysisServices.ServerMode.Tabular,
                ServerType     = Dax.Formatter.AnalysisServices.ServerType.AnalysisServices,
                ServerEdition  = Dax.Formatter.AnalysisServices.ServerEdition.Enterprise,
                ServerLocation = Dax.Formatter.AnalysisServices.ServerLocation.OnPremise,
            };

            var response = await formatter.FormatAsync(request);

            Console.WriteLine(response.Formatted);
        }
        private static JsonElement GetJsonProperty(DaxFormatterSingleRequest request, string propertyName)
        {
            var json     = JsonSerializer.Serialize(request);
            var document = JsonDocument.Parse(json);
            var property = document.RootElement.GetProperty(propertyName);

            return(property);
        }
Ejemplo n.º 4
0
        public async Task <DaxFormatterResponse> FormatAsync(DaxFormatterSingleRequest request, CancellationToken cancellationToken = default)
        {
            request.CallerApp     = _application;
            request.CallerVersion = _version;

            var response = await _formatter.FormatAsync(request, cancellationToken).ConfigureAwait(false);

            return(response);
        }
Ejemplo n.º 5
0
        public async Task DaxFormatterClient_FormatAsync_SingleRequestSucceded(string expression, string expectedExpression)
        {
            var request = new DaxFormatterSingleRequest();

            request.Dax = expression;

            var response = await _fixture.Client.FormatAsync(request);

            AssertSingleSucceded(response, expectedExpression);
        }
Ejemplo n.º 6
0
        public async Task DaxFormatterClient_FormatAsync_SingleRequestFails(string expression, int expectedErrorLine, int expectedErrorColumn)
        {
            var request = new DaxFormatterSingleRequest();

            request.Dax = expression;

            var response = await _fixture.Client.FormatAsync(request);

            AssertSingleFails(response, expectedErrorLine, expectedErrorColumn);
        }
        public void DaxFormatterSingleRequest_SensitiveDatabaseNameIsProtected()
        {
            var expected = "6341a49658aeebdfbcc648aea92b6005b393d3f89205cf56166c5626c80b9863";

            var request = new DaxFormatterSingleRequest()
            {
                DatabaseName = "MyDatabaseName1"
            };

            Assert.Equal(expected, request.DatabaseName);
        }
        public void DaxFormatterSingleRequest_SensitiveServerNameIsProtected()
        {
            var expected = "f4139cb312e198bedebf0d71198c27db761f5c4cab73da7dd2faea2672d082af";

            var request = new DaxFormatterSingleRequest()
            {
                ServerName = "MyServerName1"
            };

            Assert.Equal(expected, request.ServerName);
        }
Ejemplo n.º 9
0
        public async Task DaxFormatterClient_FormatAsync_ParallelSingleRequestSucceded(string expression, string expectedExpression, int repeat)
        {
            var request = new DaxFormatterSingleRequest();

            request.Dax = expression;

            var tasks     = Enumerable.Repeat(request, repeat).AsParallel().Select((r) => _fixture.Client.FormatAsync(r));
            var responses = await Task.WhenAll(tasks);

            AssertParallelSingleSucceded(responses, expectedExpression, repeat);
        }
        public void DaxFormatterSingleRequest_SkipSpaceAfterFunctionNameSerialization(DaxFormatterSpacingStyle spacingStyle, bool expectedSpacingStyle)
        {
            var request = new DaxFormatterSingleRequest
            {
                SkipSpaceAfterFunctionName = spacingStyle
            };

            var property            = GetJsonProperty(request, nameof(DaxFormatterSingleRequest.SkipSpaceAfterFunctionName));
            var currentSpacingStyle = property.GetBoolean();

            Assert.Equal(expectedSpacingStyle, currentSpacingStyle);
        }
        public void DaxFormatterSingleRequest_MaxLineLengthSerialization(DaxFormatterLineStyle lineStyle, int expectedLineStyle)
        {
            var request = new DaxFormatterSingleRequest
            {
                MaxLineLength = lineStyle
            };

            var property         = GetJsonProperty(request, nameof(DaxFormatterSingleRequest.MaxLineLength));
            var currentLineStyle = property.GetInt32();

            Assert.Equal(expectedLineStyle, currentLineStyle);
        }
        public void DaxFormatterSingleRequest_ServerTypeSerialization(ServerType serverType, string expectedServerType)
        {
            var request = new DaxFormatterSingleRequest
            {
                ServerType = serverType
            };

            var property          = GetJsonProperty(request, nameof(DaxFormatterSingleRequest.ServerType));
            var currentServerType = property.GetString();

            Assert.Equal(expectedServerType, currentServerType);
        }
Ejemplo n.º 13
0
        public async Task DaxFormatterClient_FormatAsync_LineStyleIsHonored(DaxFormatterLineStyle lineStyle, string expression, string expectedExpression)
        {
            var request = new DaxFormatterSingleRequest
            {
                Dax           = expression,
                MaxLineLength = lineStyle
            };

            var response = await _fixture.Client.FormatAsync(request);

            Assert.NotNull(response);

            var actualExpression = response.Formatted;

            Assert.Equal(expectedExpression, actualExpression);
        }
Ejemplo n.º 14
0
        public async Task DaxFormatterClient_FormatAsync_SpacingStyleIsHonored(DaxFormatterSpacingStyle spacingStyle, string expression, string expectedExpression)
        {
            var request = new DaxFormatterSingleRequest
            {
                Dax = expression,
                SkipSpaceAfterFunctionName = spacingStyle
            };

            var response = await _fixture.Client.FormatAsync(request);

            Assert.NotNull(response);

            var actualExpression = response.Formatted;

            Assert.Equal(expectedExpression, actualExpression);
        }
Ejemplo n.º 15
0
        public async Task <DaxFormatterResponse> FormatAsync(DaxFormatterSingleRequest request, CancellationToken cancellationToken)
        {
            await _formatSemaphore.WaitAsync();

            try
            {
                var message = await FormatAsyncInternal(request, cancellationToken);

                var result = JsonSerializer.Deserialize <DaxFormatterResponse>(message, _serializerOptions);

                return(result);
            }
            finally
            {
                _formatSemaphore.Release();
            }
        }