Ejemplo n.º 1
0
        public async Task Handle(Parameters parameters)
        {
            ApiSession apiSession = null;

            var cmd = CommandsFactory.Construct(parameters.Command, _output, _input, _apiClient);

            try
            {
                // if none space name was set - force to use 'default' space
                if (string.IsNullOrWhiteSpace(parameters.SpaceName))
                {
                    parameters.SpaceName = "default";
                }

#if DEBUG
                await Task.Factory.StartNew(async() => {
                    try {
                        await cmd.Execute(parameters);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });

                Console.ReadLine();
                cmd.CancellationTokenSource.Cancel();
                Console.ReadLine();
#else
                await cmd.Execute(parameters);
#endif
            }

            catch (WrongCommandFormatException)
            {
                _output.WriteError("Wrong command format");

                RunUsageSamples.WriteCommadUsage(parameters.Command, _output);

                throw;
            }
            finally
            {
                apiSession?.Dispose();
            }
        }