public static void Generate(string proxyOutputFile, SwaggerApiProxySettingsEndPoint[] endpoints, string baseUrl) { // init _swaggerDocDictionaryList = new ConcurrentDictionary<SwaggerApiProxySettingsEndPoint, string>(); FileText = new StringBuilder(); Console.WriteLine(); Console.WriteLine("Requesting Swagger documents.."); List<Task> taskList = new List<Task>(); foreach (var endPoint in endpoints) { var requestUri = endPoint.Url.StartsWith(baseUrl) ? endPoint.Url : string.Format("{0}{1}", baseUrl, endPoint.Url); Console.WriteLine("Requested: {0}", requestUri); taskList.Add(GetEndpointSwaggerDoc(requestUri, endPoint)); } Console.WriteLine(); Console.WriteLine("Waiting for Swagger documents to complete downloading..."); Task.WaitAll(taskList.ToArray()); ProcessSwaggerDocuments(proxyOutputFile); }
public static void Generate(string proxyOutputFile, SwaggerApiProxySettingsEndPoint[] endpoints, TestServer testServer) { // init _swaggerDocDictionaryList = new ConcurrentDictionary<SwaggerApiProxySettingsEndPoint, string>(); FileText = new StringBuilder(); Console.WriteLine(); Console.WriteLine("Requesting Swagger documents.."); List<Task> taskList = new List<Task>(); foreach (var endPoint in endpoints) { Console.WriteLine("Requested: {0}", endPoint.Url); taskList.Add(GetEndpointSwaggerDoc(testServer, endPoint)); } Console.WriteLine(); Console.WriteLine("Waiting for Swagger documents to complete downloading..."); Task.WaitAll(taskList.ToArray()); ProcessSwaggerDocuments(proxyOutputFile); }
private static int ProcessInMemory(string assemblyFile, string appConfigFile, string proxyOutputFile, SwaggerApiProxySettingsEndPoint[] endpoints) { string exeBinDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) .Replace(@"file:\", string.Empty) + @"\bin"; Console.WriteLine("Copying assembly xml comments to executable bin directory... \n{0}", exeBinDirectory); Console.WriteLine(); try { var sourcePath = assemblyFile.Replace(".dll", ".xml"); var destFileName = Path.Combine(exeBinDirectory, Path.GetFileName(sourcePath)); if (!Directory.Exists(exeBinDirectory)) { Directory.CreateDirectory(exeBinDirectory); } File.Copy(sourcePath, destFileName, true); } catch (Exception ex) { Console.WriteLine("Could not copy assembly xml file. Exception: {0}", ex.Message); Console.WriteLine(); } Console.WriteLine("Loading app.config... \n{0}", appConfigFile); Console.WriteLine(); AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", appConfigFile); ResetConfigMechanism(); Console.WriteLine("Loading Owin Web API Assembly... \n{0}", assemblyFile); Console.WriteLine(); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler((source, e) => CustomResolver(source, e, assemblyFile)); var assembly = Assembly.LoadFrom(assemblyFile); Type owinStartupClassType = null; var startupAttribute = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(OwinStartupAttribute)); Console.WriteLine("Locating Startup Class... \n{0}", startupAttribute.ConstructorArguments.First().Value.ToString()); Console.WriteLine(); if (startupAttribute == null) { Console.WriteLine("Could not located OwinStartupAttribute."); return 1; } Console.WriteLine("Starting in memory server..."); Console.WriteLine(); owinStartupClassType = (Type)startupAttribute.ConstructorArguments.First().Value; dynamic owinStartupClass = Activator.CreateInstance(owinStartupClassType); TestServer testServer = TestServer.Create(builder => { owinStartupClass.Configuration(builder); }); Console.WriteLine("Generating Proxy..."); Generator.ProxyGenerator.Generate(proxyOutputFile, endpoints, testServer); return 0; }
private static async Task GetEndpointSwaggerDoc(string requestUri, SwaggerApiProxySettingsEndPoint endPoint) { using (var httpClient = new HttpClient()) { var swaggerString = await httpClient.GetStringAsync(requestUri); if (swaggerString == null) { throw new Exception(string.Format("Error downloading from: (TestServer){0}", endPoint.Url)); } Console.WriteLine("Downloaded: {0}", requestUri); _swaggerDocDictionaryList.GetOrAdd(endPoint, swaggerString); } }