コード例 #1
0
        private static IEnumerable <CompositeRootCommandResponse> GetCommandResponses(WebRequest request, IEnumerable <CompositeRootCommandRequest> commands)
        {
            using (var requestContentStream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(commands))))
            {
                var returnedBytes = CompositeRootHttpServerTesterConnection.SendRequest(request, "application/json", requestContentStream, out string responseContentType, out string responseContentEncoding);

                try
                {
                    return(JsonConvert.DeserializeObject <CompositeRootCommandResponse[]>(Encoding.UTF8.GetString(returnedBytes)) as IEnumerable <CompositeRootCommandResponse>);
                }
                catch
                {
                    return(new CompositeRootCommandResponse[]
                    {
                        new CompositeRootCommandResponse
                        {
                            Success = true,
                            ReturnValue = returnedBytes,
                            ReturnValueContentType = responseContentType,
                            ReturnValueContentEncoding = responseContentEncoding
                        }
                    });
                }
            }
        }
コード例 #2
0
        public static IEnumerable <CompositeRootCommandResponse> SendRequest(CompositeRootConfiguration configuration, string command, IEnumerable <FileInfo> files, string sessionToken)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var commandPath = new Uri("file:///" + command);
            var formFields  = GetFormFields(commandPath);

            var returnedBytes = CompositeRootHttpServerTesterConnection.SendMultipartFormDataRequest(
                configuration.Endpoint + sessionToken + commandPath.AbsolutePath,
                files.Select(f => f.FullName).ToArray(),
                formFields, out string responseContentType, out string responseContentEncoding);

            try
            {
                return(JsonConvert.DeserializeObject <CompositeRootCommandResponse[]>(Encoding.UTF8.GetString(returnedBytes)) as IEnumerable <CompositeRootCommandResponse>);
            }
            catch
            {
                return(new CompositeRootCommandResponse[]
                {
                    new CompositeRootCommandResponse
                    {
                        Success = true,
                        ReturnValue = returnedBytes,
                        ReturnValueContentType = responseContentType,
                        ReturnValueContentEncoding = responseContentEncoding
                    }
                });
            }
        }
コード例 #3
0
        public static IEnumerable <CompositeRootCommandResponse> SendRequest(WebRequest request, IEnumerable <FileInfo> files)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var formFields = GetFormFields(request.RequestUri);

            var returnedBytes = CompositeRootHttpServerTesterConnection.SendMultipartFormDataRequest(
                request,
                files.Select(f => f.FullName).ToArray(),
                formFields, out string responseContentType, out string responseContentEncoding);

            try
            {
                return(JsonConvert.DeserializeObject <CompositeRootCommandResponse[]>(Encoding.UTF8.GetString(returnedBytes)) as IEnumerable <CompositeRootCommandResponse>);
            }
            catch
            {
                return(new CompositeRootCommandResponse[]
                {
                    new CompositeRootCommandResponse
                    {
                        Success = true,
                        ReturnValue = returnedBytes,
                        ReturnValueContentType = responseContentType,
                        ReturnValueContentEncoding = responseContentEncoding
                    }
                });
            }
        }
コード例 #4
0
        private CompositeRootHttpServerTesterConnection CreateCompositeRootHttpServerTesterConnection(CompositeRootConfiguration configuration, WebRequest request)
        {
            var response = JsonConvert.DeserializeObject <CompositeRootAuthenticatorResponse>(Encoding.UTF8.GetString(CompositeRootHttpServerTesterConnection.SendRequest(request, out _, out _)));

            var sessionToken = response.SessionToken;
            CompositeRootHttpServerTesterConnection compositeRootHttpServerTesterConnection = null;

            try
            {
                compositeRootHttpServerTesterConnection = new CompositeRootHttpServerTesterConnection(configuration.Endpoint, sessionToken);
                if (!_connections.TryAdd(sessionToken, compositeRootHttpServerTesterConnection))
                {
                    return(null);
                }
            }
            catch
            {
                compositeRootHttpServerTesterConnection?.Dispose();
                throw;
            }

            return(compositeRootHttpServerTesterConnection);
        }