/// <summary>
        /// Handles config update request
        /// </summary>
        /// <param name="parameters">Request parameters</param>
        /// <param name="requestContext">Request Context</param>
        /// <returns></returns>
        public async Task HandleServerConfigUpdateRequest(ServerConfigUpdateRequestParams parameters, RequestContext <ServerConfigUpdateResponseParams> requestContext)
        {
            Logger.Write(TraceEventType.Verbose, "HandleServerConfigUpdateRequest");
            try
            {
                ConnectionInfo connInfo;
                ConnectionServiceInstance.TryFindConnection(
                    parameters.OwnerUri,
                    out connInfo);
                ServerConfigUpdateResponseParams response = new ServerConfigUpdateResponseParams
                {
                };

                if (connInfo == null)
                {
                    await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
                }
                else
                {
                    var serverConnection = ConnectionService.OpenServerConnection(connInfo);
                    UpdateConfig(serverConnection, parameters.ConfigNumber, parameters.ConfigValue);
                    response.ConfigProperty = GetConfig(serverConnection, parameters.ConfigNumber);
                    await requestContext.SendResult(response);
                }
            }
            catch (Exception e)
            {
                // Exception related to run task will be captured here
                await requestContext.SendError(e);
            }
        }
Esempio n. 2
0
        public async void VerifyUpdatingConfigs()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                List <ServerConfigProperty> configs = await GetAllConfigs();

                Assert.NotNull(configs);
                Assert.True(configs.Count > 0);
                ServerConfigProperty sampleConfig = configs[0];

                ServerConfigViewResponseParams   result       = null;
                ServerConfigUpdateResponseParams updateResult = null;
                int newValue = sampleConfig.ConfigValue == sampleConfig.Minimum ? sampleConfig.Maximum : sampleConfig.Minimum;

                var requestContext       = RequestContextMocks.Create <ServerConfigViewResponseParams>(r => result = r).AddErrorHandling(null);
                var updateRequestContext = RequestContextMocks.Create <ServerConfigUpdateResponseParams>(r => updateResult = r).AddErrorHandling(null);

                ServerConfigViewRequestParams requestParams = new ServerConfigViewRequestParams
                {
                    OwnerUri     = connectionResult.ConnectionInfo.OwnerUri,
                    ConfigNumber = sampleConfig.Number
                };
                ServerConfigUpdateRequestParams updateRequestParams = new ServerConfigUpdateRequestParams
                {
                    OwnerUri     = connectionResult.ConnectionInfo.OwnerUri,
                    ConfigNumber = sampleConfig.Number,
                    ConfigValue  = newValue
                };

                await ServerConfigService.Instance.HandleServerConfigViewRequest(requestParams, requestContext.Object);

                Assert.NotNull(result);
                Assert.Equal(result.ConfigProperty.ConfigValue, sampleConfig.ConfigValue);
                await ServerConfigService.Instance.HandleServerConfigUpdateRequest(updateRequestParams, updateRequestContext.Object);

                Assert.NotNull(updateResult);
                Assert.Equal(updateResult.ConfigProperty.ConfigValue, newValue);
                updateRequestParams.ConfigValue = sampleConfig.ConfigValue;
                await ServerConfigService.Instance.HandleServerConfigUpdateRequest(updateRequestParams, updateRequestContext.Object);

                Assert.NotNull(updateResult);
                Assert.Equal(updateResult.ConfigProperty.ConfigValue, sampleConfig.ConfigValue);
                ServerConfigService.Instance.ConnectionServiceInstance.Disconnect(new DisconnectParams
                {
                    OwnerUri = queryTempFile.FilePath,
                    Type     = ServiceLayer.Connection.ConnectionType.Default
                });
            }
        }
Esempio n. 3
0
        public async void VerifyConfigUpdateRequestSendErrorGivenInvalidConnection()
        {
            ServerConfigUpdateResponseParams result = null;
            var requestContext = RequestContextMocks.Create <ServerConfigUpdateResponseParams>(r => result = r).AddErrorHandling(null);

            requestContext.Setup(x => x.SendError(It.IsAny <Exception>())).Returns(System.Threading.Tasks.Task.FromResult(true));

            ServerConfigUpdateRequestParams requestParams = new ServerConfigUpdateRequestParams
            {
                OwnerUri    = "invalid uri",
                ConfigValue = 1
            };

            await ServerConfigService.Instance.HandleServerConfigUpdateRequest(requestParams, requestContext.Object);

            requestContext.Verify(x => x.SendError(It.IsAny <Exception>()));
        }