Exemplo n.º 1
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="workspaceId">The workspace unique identifier.</param>
        /// <returns></returns>
        public async Task <T> ExecuteCommandAsync <T>(IEnvironmentConnection connection, Guid workspaceId)
        {
            // build the service request payload ;)
            var serializer = new Dev2JsonSerializer();

            if (connection == null || !connection.IsConnected)
            {
                if (connection != null)
                {
                    var popupController = CustomContainer.Get <IPopupController>();
                    if (popupController != null && connection.HubConnection.State == ConnectionStateWrapped.Disconnected)
                    {
                        popupController.Show(string.Format("Server: {0} has disconnected.", connection.DisplayName) + Environment.NewLine +
                                             "Please reconnect before performing any actions", "Disconnected Server", MessageBoxButton.OK, MessageBoxImage.Information, "");
                    }
                }
            }
            else
            {
                // now bundle it up into a nice string builder ;)
                if (ServicePayload == null)
                {
                    ServicePayload = new EsbExecuteRequest();
                }

                ServicePayload.ServiceName = ServiceName;
                StringBuilder toSend  = serializer.SerializeToBuilder(ServicePayload);
                var           payload = await connection.ExecuteCommandAsync(toSend, workspaceId);

                return(serializer.Deserialize <T>(payload));
            }
            return(default(T));
        }
Exemplo n.º 2
0
        public async Task <T> ExecuteCompressedCommandAsync <T>(IEnvironmentConnection connection, Guid workspaceId) where T : class
        {
            // build the service request payload ;)
            var serializer = new Dev2JsonSerializer();

            if (connection == null || !connection.IsConnected)
            {
                if (connection != null)
                {
                    if (!connection.IsConnecting)
                    {
                        var popupController = CustomContainer.Get <IPopupController>();
                        popupController?.Show(string.Format(ErrorResource.ServerDisconnected, connection.DisplayName) + Environment.NewLine +
                                              ErrorResource.ServerReconnectForActions, ErrorResource.ServerDisconnectedHeader, MessageBoxButton.OK,
                                              MessageBoxImage.Information, "", false, false, true, false, false, false);
                    }
                }
            }
            else
            {
                // now bundle it up into a nice string builder ;)
                if (ServicePayload == null)
                {
                    ServicePayload = new EsbExecuteRequest();
                }

                ServicePayload.ServiceName = ServiceName;
                StringBuilder toSend  = serializer.SerializeToBuilder(ServicePayload);
                var           payload = await connection.ExecuteCommandAsync(toSend, workspaceId);

                try
                {
                    var message = serializer.Deserialize <CompressedExecuteMessage>(payload).GetDecompressedMessage();
                    return(serializer.Deserialize <T>(message));
                }
                catch (NullReferenceException e)
                {
                    Dev2Logger.Debug("fallback to non compressed", e);
                    return(serializer.Deserialize <T>(payload));
                }
            }
            return(default(T));
        }
Exemplo n.º 3
0
 public async Task <StringBuilder> ExecuteCommandAsync(StringBuilder xmlRequest, Guid workspaceId) => await _wrappedConnection.ExecuteCommandAsync(xmlRequest, workspaceId).ConfigureAwait(true);
Exemplo n.º 4
0
        public async Task <T> ExecuteCommandAsync <T>(IEnvironmentConnection connection, Guid workspaceId) where T : class
        {
            // build the service request payload ;)
            var serializer = new Dev2JsonSerializer();

            if (connection == null || !connection.IsConnected)
            {
                if (connection != null && !connection.IsConnecting)
                {
                    var popupController = CustomContainer.Get <IPopupController>();
                    popupController?.Show(string.Format(ErrorResource.ServerDisconnected, connection.DisplayName) + Environment.NewLine +
                                          ErrorResource.ServerReconnectForActions, ErrorResource.ServerDisconnectedHeader, MessageBoxButton.OK,
                                          MessageBoxImage.Information, "", false, false, true, false, false, false);
                }
                return(default(T));
            }
            try
            {
                if (ServicePayload == null)
                {
                    ServicePayload = new EsbExecuteRequest();
                }

                ServicePayload.ServiceName = ServiceName;
                var toSend  = serializer.SerializeToBuilder(ServicePayload);
                var payload = await connection.ExecuteCommandAsync(toSend, workspaceId).ConfigureAwait(true);

                var executeCommand = serializer.Deserialize <T>(payload);
                if (executeCommand == null)
                {
                    var execMessage = serializer.Deserialize <ExecuteMessage>(payload);
                    if (execMessage != null)
                    {
                        return(CheckAuthorization <T>(execMessage));
                    }
                }
                else
                {
                    if (typeof(T) == typeof(ExecuteMessage))
                    {
                        return(CheckAuthorization <T>(executeCommand as ExecuteMessage));
                    }
                    return(executeCommand);
                }
            }
            catch (ServiceNotAuthorizedException ex)
            {
                ShowAuthorizationErrorPopup(ex.Message);
                return(default(T));
            }
            catch (AggregateException ex)
            {
                var aggregateException   = ex.Flatten();
                var baseException        = aggregateException.GetBaseException();
                var isAuthorizationError = baseException is ServiceNotAuthorizedException;
                if (isAuthorizationError)
                {
                    ShowAuthorizationErrorPopup(ex.Message);
                    return(default(T));
                }
            }
            return(default(T));
        }
Exemplo n.º 5
0
 public async Task <StringBuilder> ExecuteCommandAsync(StringBuilder xmlRequest, Guid workspaceId)
 {
     return(await _wrappedConnection.ExecuteCommandAsync(xmlRequest, workspaceId));
 }