// POST: api/Convert
        public HttpResponseMessage Post(FileModels file)
        {
            var response = new HttpResponseMessage();

            try
            {
                if (file != null && file.Exists)
                {
                    var conversion = new ConversionModels();

                    //Do the conversion
                    conversion.Convert(file as IFileModels);

                    //Prepare the response
                    response.Content    = new StringContent(conversion.Result);
                    response.StatusCode = conversion.Status;

                    return(response);
                }
                else
                {
                    response.Content    = new StringContent("Error: file does not exist");
                    response.StatusCode = HttpStatusCode.ExpectationFailed;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.Content    = new StringContent(ex.Message);
                response.StatusCode = HttpStatusCode.InternalServerError;
                return(response);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            string result = "Error Occured";

            try
            {
                string filePath = PromptUserForFilepath();
                var    file     = new FileModels(filePath);

                if (filePath != null && filePath != "" && file.Exists)
                {
                    var conversion = new ConversionModels();

                    //Do the Conversion
                    conversion.Convert(file as IFileModels);

                    //Prepare the results
                    result = conversion.Result;
                }
                else
                {
                    result = "Error: file does not exist";
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            finally
            {
                Console.WriteLine(result);
                Console.Read();
            }
        }