public void TestGenerateFickleFileAndParse() { var reflectedServiceModel = ReflectServiceModel(); using (var memoryStream = new MemoryStream()) { using (var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true)) { var writer = new FicklefileWriter(streamWriter); writer.Write(reflectedServiceModel); } memoryStream.Seek(0, SeekOrigin.Begin); using (var streamReader = new StreamReader(memoryStream)) { var fickleFile = streamReader.ReadToEnd(); Console.WriteLine(fickleFile); var parsedServiceModel = FicklefileParser.Parse(fickleFile); AssertModelsMatch(parsedServiceModel, reflectedServiceModel); } } }
internal static ServiceModel GetTestServiceModel2() { var assembly = Assembly.GetExecutingAssembly(); var resourceName = typeof(FicklefileParserTests).Namespace + ".TestFiles.Test2.fickle"; using (var stream = assembly.GetManifestResourceStream(resourceName)) { using (var reader = new StreamReader(stream)) { return(FicklefileParser.Parse(reader)); } } }
static int Main(string[] args) { ServiceModel serviceModel; var options = new CommandLineOptions(); if (!CommandLine.Parser.Default.ParseArguments(args, options)) { Console.Error.WriteLine("Unable to parse command line arguments"); return(1); } if (options.Input == null) { Console.Error.WriteLine("Must specify input file"); return(1); } TextReader textReader = null; foreach (var url in options.Input) { var currentUrl = url; if (currentUrl.IndexOf(":", StringComparison.Ordinal) <= 0) { currentUrl = "./" + url; } var reader = FileSystemManager.Default.ResolveFile(currentUrl).GetContent().GetReader(FileShare.Read); textReader = textReader == null ? reader : textReader.Concat(reader); } if (!string.IsNullOrEmpty(options.Output) && options.Output.IndexOf(":", StringComparison.Ordinal) <= 0) { options.Output = "./" + options.Output; } using (var reader = textReader) { serviceModel = FicklefileParser.Parse(reader); } object outputObject = Console.Out; if (!string.IsNullOrEmpty(options.Output)) { var dir = FileSystemManager.Default.ResolveDirectory(options.Output); dir.Create(true); outputObject = dir; } var codeGenerationOptions = new CodeGenerationOptions(); var defaultServiceModelInfo = codeGenerationOptions.ServiceModelInfo; var serviceModelInfo = new ServiceModelInfo(); serviceModelInfo.Import(defaultServiceModelInfo); serviceModelInfo.Import(serviceModel.ServiceModelInfo); if (options.Author != null) { serviceModelInfo.Author = options.Author; } if (options.Name != null) { serviceModelInfo.Name = options.Name; } if (options.Summary != null) { serviceModelInfo.Summary = options.Summary; } if (options.Version != null) { serviceModelInfo.Version = options.Version; } if (options.Homepage != null) { serviceModelInfo.Homepage = options.Homepage; } if (options.License != null) { serviceModelInfo.License = options.License; } if (options.PodspecSource != null) { serviceModelInfo.ExtendedValues["podspec.source"] = options.PodspecSource; } if (options.PodspecSourceFiles != null) { serviceModelInfo.ExtendedValues["podspec.source_files"] = options.PodspecSourceFiles; } codeGenerationOptions.GeneratePod = options.Pod; codeGenerationOptions.ImportDependenciesAsFramework = options.ImportDependenciesAsFramework; codeGenerationOptions.ServiceModelInfo = serviceModelInfo; using (var codeGenerator = ServiceModelCodeGenerator.GetCodeGenerator(options.Language, outputObject, codeGenerationOptions)) { codeGenerator.Generate(serviceModel); } return(0); }