예제 #1
0
        public async Task <ActionResult <Stream> > ParseCsvAsync([FromQuery] string csvUri, [FromQuery] string outPutFormat)
        {
            if (string.IsNullOrEmpty(csvUri))
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(outPutFormat) ||
                !Enum.IsDefined(typeof(OutputFormats), outPutFormat.ToLower()) ||
                outPutFormat == "console")
            {
                outPutFormat = "json";
            }

            Stream outputStream = await CsvParserlogic.ParseCsvAsync(csvUri, (OutputFormats)Enum.Parse(typeof(OutputFormats), outPutFormat.ToLower()));

            if (outputStream != null)
            {
                FileStreamResult outputFileStreamResult = new FileStreamResult(outputStream, MimeProvider.GetMime(outPutFormat));

                return(outputFileStreamResult);
            }

            return(BadRequest());
        }
예제 #2
0
        public async Task Run(string ouputFormat)
        {
            Console.WriteLine("Enter The Uri for the Csv File");
            string csvUri = Console.ReadLine();

            Console.WriteLine();

            if (string.IsNullOrEmpty(csvUri))
            {
                Console.WriteLine("No Uri was provided for the Csv file");

                return;
            }

            OutputFormats outputformat = OutputFormats.console;

            if (!string.IsNullOrEmpty(ouputFormat) &&
                Enum.IsDefined(typeof(OutputFormats), ouputFormat.ToLower()))
            {
                outputformat = (OutputFormats)Enum.Parse(typeof(OutputFormats), ouputFormat.ToLower());
            }

            using (Stream stream = await CsvParserLogic.ParseCsvAsync(csvUri, outputformat))
            {
                if (stream != null)
                {
                    StreamReader reader = new StreamReader(stream);

                    Console.BufferHeight = short.MaxValue - 1;

                    Console.WriteLine(await reader.ReadToEndAsync());
                }
                else
                {
                    Console.WriteLine("The Output stream is empty");
                }
            }
        }