// 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); } }
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(); } }
public async Task UpdateFiles() { var files = Directory.GetFiles(Path, Filter, SearchOption.AllDirectories); try { var f = files.Select(async i => (i, System.IO.Path.GetRelativePath(Path, i), await i.ReadFile())) .Select(async i => (new RazorParser().ParseAllAll((await i).Item3), (await i).Item2)) .Select(async i => await i); var a = await Task.WhenAll(f); //a.Map(); var TsProject = new DataAtr.Models.Typescript.TypeDeffinition(a.Map()).TypescriptPoject(); await File.WriteAllTextAsync(OutFile, TsProject); } catch (Exception ex) { throw; } foreach (var file in files) { var relativePath = System.IO.Path.GetRelativePath(Path, file); var fileModel = FileModels.FirstOrDefault(i => i.FilePath == relativePath); if (fileModel == null) { fileModel = new FileModel(relativePath); FileModels.Add(fileModel); } logger.Info($"Starting {file}"); var text = await file.ReadFile(); try { var temp = new RazorParser().ParseAllAll(text); } catch (Exception ex) { } //var atrs = AllDataAtrs(text); //if (atrs != null) // fileModel.DataAtrs.AddRange(atrs); //else //{ // Console.WriteLine($"ERROR: {file} is null"); //} } }