/// <summary>Generates the Swagger definition for the given controller.</summary>
 /// <param name="controllerClassName">The full name of the controller class.</param>
 /// <returns>The Swagger definition.</returns>
 public SwaggerService GenerateForSingleController(string controllerClassName)
 {
     using (var isolated = new AppDomainIsolation<AssemblyLoader>(Path.GetDirectoryName(Settings.AssemblyPath)))
     {
         var service = isolated.Object.GenerateForSingleController(controllerClassName, JsonConvert.SerializeObject(Settings)); 
         return SwaggerService.FromJson(service);
     }
 }
 /// <summary>Gets the available controller classes from the given assembly.</summary>
 /// <returns>The controller classes.</returns>
 public string[] GetClasses()
 {
     if (File.Exists(Settings.AssemblyPath))
     {
         using (var isolated = new AppDomainIsolation<AssemblyLoader>(Path.GetDirectoryName(Settings.AssemblyPath)))
             return isolated.Object.GetClasses(Settings.AssemblyPath);
     }
     return new string[] { };
 }
 /// <summary>Gets the available controller classes from the given assembly.</summary>
 /// <returns>The controller classes.</returns>
 public string[] GetClasses()
 {
     if (File.Exists(_assemblyPath))
     {
         using (var isolated = new AppDomainIsolation<AssemblyLoader>())
             return isolated.Object.GetClasses(_assemblyPath);
     }
     return new string[] { };
 }
        /// <summary>Generates the Swagger definition for all controllers in the assembly.</summary>
        /// <param name="urlTemplate">The default Web API URL template.</param>
        /// <returns>The Swagger definition.</returns>
        public SwaggerService GenerateForAssemblyControllers(string urlTemplate)
        {
            using (var isolated = new AppDomainIsolation<AssemblyLoader>(Path.GetDirectoryName(_assemblyPath)))
            {
                var service = isolated.Object.GenerateForAssemblyControllers(
                    _assemblyPath, urlTemplate, JsonConvert.SerializeObject(JsonSchemaGeneratorSettings));

                return SwaggerService.FromJson(service);
            }
        }
        /// <summary>Generates the Swagger definition for all controllers in the assembly.</summary>
        /// <param name="urlTemplate">The default Web API URL template.</param>
        /// <returns>The Swagger definition.</returns>
        public SwaggerService GenerateForAssemblyControllers(string urlTemplate)
        {
            using (var isolated = new AppDomainIsolation <AssemblyLoader>(Path.GetDirectoryName(_assemblyPath)))
            {
                var service = isolated.Object.GenerateForAssemblyControllers(
                    _assemblyPath, urlTemplate, JsonConvert.SerializeObject(JsonSchemaGeneratorSettings));

                return(SwaggerService.FromJson(service));
            }
        }
        /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
        /// <param name="classNames">The class names.</param>
        /// <returns>The Swagger definition.</returns>
        public override SwaggerDocument Generate(string[] classNames)
        {
#if FullNet
            using (var isolated = new AppDomainIsolation<NetAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPath)), Settings.AssemblyConfig))
                return SwaggerDocument.FromJson(isolated.Object.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings)));
#else
            var loader = new NetAssemblyLoader();
            var data = loader.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings));
            return SwaggerDocument.FromJson(data);
#endif
        }
        /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
        /// <param name="classNames">The class names.</param>
        /// <returns>The Swagger definition.</returns>
        public override SwaggerDocument Generate(string[] classNames)
        {
#if FullNet
            using (var isolated = new AppDomainIsolation <NetAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPath)), Settings.AssemblyConfig))
                return(SwaggerDocument.FromJson(isolated.Object.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings))));
#else
            var loader = new NetAssemblyLoader();
            var data   = loader.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings));
            return(SwaggerDocument.FromJson(data));
#endif
        }
Esempio n. 8
0
        protected async Task <TResult> RunIsolatedAsync(string configurationFile)
        {
            var assemblyDirectory = AssemblyPaths.Any() ? Path.GetDirectoryName(Path.GetFullPath(PathUtilities.ExpandFileWildcards(AssemblyPaths).First())) : configurationFile;
            var bindingRedirects  = GetBindingRedirects();
            var assemblies        = GetAssemblies(assemblyDirectory);

            using (var isolated = new AppDomainIsolation <IsolatedCommandAssemblyLoader <TResult> >(assemblyDirectory, AssemblyConfig, bindingRedirects, assemblies))
            {
                return(await Task.Run(() => isolated.Object.Run(GetType().FullName, JsonConvert.SerializeObject(this), AssemblyPaths, ReferencePaths)).ConfigureAwait(false));
            }
        }
Esempio n. 9
0
        /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
        /// <param name="classNames">The class names.</param>
        /// <returns>The Swagger definition.</returns>
        public async Task <SwaggerDocument> GenerateAsync(string[] classNames)
        {
            var assemblyPath      = Settings.AssemblySettings.AssemblyPaths.First();
            var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(assemblyPath));

            using (var isolated = new AppDomainIsolation <NetAssemblyLoader>(
                       assemblyDirectory, Settings.AssemblySettings.AssemblyConfig, AssemblyLoaderUtilities.GetBindingRedirects(), AssemblyLoaderUtilities.GetAssemblies(assemblyDirectory)))
            {
                var json = await Task.Run(() => isolated.Object.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings))).ConfigureAwait(false);

                return(await SwaggerDocument.FromJsonAsync(json).ConfigureAwait(false));
            }
        }
        /// <summary>Generates the Swagger definition for all controllers in the assembly.</summary>
        /// <param name="controllerClassNames">The controller class names.</param>
        /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
        /// <returns>The Swagger definition.</returns>
        public override SwaggerDocument GenerateForControllers(IEnumerable<string> controllerClassNames)
        {
#if FullNet
            using (var isolated = new AppDomainIsolation<WebApiAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPaths.First())), Settings.AssemblyConfig))
            {
                var document = isolated.Object.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings));
                return SwaggerDocument.FromJson(document);
            }
#else
            var loader = new WebApiAssemblyLoader();
            var data = loader.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings));
            return SwaggerDocument.FromJson(data);
#endif
        }
Esempio n. 11
0
        /// <summary>Generates the Swagger definition for all controllers in the assembly.</summary>
        /// <param name="controllerClassNames">The controller class names.</param>
        /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
        /// <returns>The Swagger definition.</returns>
        public override SwaggerDocument GenerateForControllers(IEnumerable <string> controllerClassNames)
        {
#if FullNet
            using (var isolated = new AppDomainIsolation <WebApiAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPaths.First())), Settings.AssemblyConfig))
            {
                var document = isolated.Object.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings));
                return(SwaggerDocument.FromJson(document));
            }
#else
            var loader = new WebApiAssemblyLoader();
            var data   = loader.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings));
            return(SwaggerDocument.FromJson(data));
#endif
        }
        /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
        /// <param name="classNames">The class names.</param>
        /// <returns>The Swagger definition.</returns>
        public override async Task <SwaggerDocument> GenerateAsync(string[] classNames)
        {
#if FullNet
            using (var isolated = new AppDomainIsolation <NetAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPath)), Settings.AssemblyConfig))
            {
                var json = await Task.Run(() => isolated.Object.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings))).ConfigureAwait(false);

                return(await SwaggerDocument.FromJsonAsync(json).ConfigureAwait(false));
            }
#else
            var loader = new NetAssemblyLoader();
            var data   = loader.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings));
            return(await SwaggerDocument.FromJsonAsync(data).ConfigureAwait(false));
#endif
        }
Esempio n. 13
0
        /// <summary>Generates the Swagger definition for all controllers in the assembly.</summary>
        /// <param name="controllerClassNames">The controller class names.</param>
        /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
        /// <returns>The Swagger definition.</returns>
        public override async Task <SwaggerDocument> GenerateForControllersAsync(IEnumerable <string> controllerClassNames)
        {
#if FullNet
            using (var isolated = new AppDomainIsolation <WebApiAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPaths.First())), Settings.AssemblyConfig))
            {
                var document = await Task.Run(() => isolated.Object.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings))).ConfigureAwait(false);

                return(await SwaggerDocument.FromJsonAsync(document).ConfigureAwait(false));
            }
#else
            var loader = new WebApiAssemblyLoader();
            var data   = loader.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings));
            return(await SwaggerDocument.FromJsonAsync(data).ConfigureAwait(false));
#endif
        }
        /// <summary>Gets the available controller classes from the given assembly.</summary>
        /// <returns>The controller classes.</returns>
        /// <exception cref="FileNotFoundException">The assembly could not be found.</exception>
        /// <exception cref="FileNotFoundException">The assembly config file could not be found..</exception>
        public string[] GetControllerClasses()
        {
            if (!File.Exists(Settings.AssemblyPath))
            {
                throw new FileNotFoundException("The assembly could not be found.", Settings.AssemblyPath);
            }

            if (!string.IsNullOrEmpty(Settings.AssemblyConfig) && !File.Exists(Settings.AssemblyConfig))
            {
                throw new FileNotFoundException("The assembly config file could not be found.", Settings.AssemblyConfig);
            }

            using (var isolated = new AppDomainIsolation <WebApiAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPath)), Settings.AssemblyConfig))
                return(isolated.Object.GetControllerClasses(Settings.AssemblyPath, Settings.ReferencePaths));
        }
        /// <summary>Gets the available controller classes from the given assembly.</summary>
        /// <returns>The controller classes.</returns>
        public override string[] GetClasses()
        {
            if (File.Exists(Settings.AssemblyPath))
            {
#if FullNet
                using (var isolated = new AppDomainIsolation<NetAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPath)), Settings.AssemblyConfig))
                    return isolated.Object.GetClasses(Settings.AssemblyPath, GetAllReferencePaths(Settings));
#else
                var loader = new NetAssemblyLoader();
                return loader.GetClasses(Settings.AssemblyPath, GetAllReferencePaths(Settings));
#endif
            }
            else
                return new string[] { };
        }
Esempio n. 16
0
        protected Task <TResult> RunIsolatedAsync(string configurationFile)
        {
            var assemblyDirectory = AssemblyPaths.Any() ? Path.GetDirectoryName(Path.GetFullPath(PathUtilities.ExpandFileWildcards(AssemblyPaths).First())) : configurationFile;
            var bindingRedirects  = GetBindingRedirects();
            var assemblies        = GetAssemblies(assemblyDirectory);

            if (UseNuGetCache)
            {
                var defaultNugetPackages = LoadDefaultNugetCache();
                ReferencePaths = ReferencePaths.Concat(defaultNugetPackages).ToArray();
            }

            using (var isolated = new AppDomainIsolation <IsolatedCommandAssemblyLoader>(assemblyDirectory, AssemblyConfig, bindingRedirects, assemblies))
            {
                return(Task.FromResult(isolated.Object.Run(GetType().FullName, JsonConvert.SerializeObject(this), AssemblyPaths, ReferencePaths)));
            }
        }
        /// <summary>Gets the available controller classes from the given assembly.</summary>
        /// <returns>The controller classes.</returns>
        public override string[] GetClasses()
        {
            if (File.Exists(Settings.AssemblyPath))
            {
#if FullNet
                using (var isolated = new AppDomainIsolation <NetAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPath)), Settings.AssemblyConfig))
                    return(isolated.Object.GetClasses(Settings.AssemblyPath, GetAllReferencePaths(Settings)));
#else
                var loader = new NetAssemblyLoader();
                return(loader.GetClasses(Settings.AssemblyPath, GetAllReferencePaths(Settings)));
#endif
            }
            else
            {
                return new string[] { }
            };
        }
        /// <summary>Gets the available controller classes from the given assembly.</summary>
        /// <returns>The controller classes.</returns>
        /// <exception cref="FileNotFoundException">The assembly could not be found.</exception>
        /// <exception cref="FileNotFoundException">The assembly config file could not be found..</exception>
        /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
        public override string[] GetControllerClasses()
        {
            if (Settings.AssemblyPaths == null || Settings.AssemblyPaths.Length == 0)
                throw new InvalidOperationException("No assembly paths have been provided.");

            if (!File.Exists(Settings.AssemblyPaths.First()))
                throw new FileNotFoundException("The assembly could not be found.", Settings.AssemblyPaths.First());

            if (!string.IsNullOrEmpty(Settings.AssemblyConfig) && !File.Exists(Settings.AssemblyConfig))
                throw new FileNotFoundException("The assembly config file could not be found.", Settings.AssemblyConfig);

#if FullNet
            using (var isolated = new AppDomainIsolation<WebApiAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPaths.First())), Settings.AssemblyConfig))
                return isolated.Object.GetControllerClasses(Settings.AssemblyPaths, GetAllReferencePaths(Settings));
#else
            var loader = new WebApiAssemblyLoader();
            return loader.GetControllerClasses(Settings.AssemblyPaths, GetAllReferencePaths(Settings));
#endif
        }
        /// <summary>Gets the available controller classes from the given assembly.</summary>
        /// <returns>The controller classes.</returns>
        /// <exception cref="FileNotFoundException">The assembly could not be found.</exception>
        /// <exception cref="FileNotFoundException">The assembly config file could not be found..</exception>
        /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
        public string[] GetControllerClasses()
        {
            if (Settings.AssemblyPaths == null || Settings.AssemblyPaths.Length == 0)
            {
                throw new InvalidOperationException("No assembly paths have been provided.");
            }

            if (!File.Exists(Settings.AssemblyPaths.First()))
            {
                throw new FileNotFoundException("The assembly could not be found.", Settings.AssemblyPaths.First());
            }

            if (!string.IsNullOrEmpty(Settings.AssemblyConfig) && !File.Exists(Settings.AssemblyConfig))
            {
                throw new FileNotFoundException("The assembly config file could not be found.", Settings.AssemblyConfig);
            }

            using (var isolated = new AppDomainIsolation <WebApiAssemblyLoader>(Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblyPaths.First())), Settings.AssemblyConfig))
                return(isolated.Object.GetControllerClasses(Settings.AssemblyPaths, Settings.ReferencePaths));
        }
Esempio n. 20
0
        /// <summary>Generates the Swagger definition for all controllers in the assembly.</summary>
        /// <param name="controllerClassNames">The controller class names.</param>
        /// <exception cref="InvalidOperationException">No assembly paths have been provided.</exception>
        /// <returns>The Swagger definition.</returns>
        public async Task <SwaggerDocument> GenerateForControllersAsync(IEnumerable <string> controllerClassNames)
        {
            if (!(Settings.SchemaNameGenerator is DefaultSchemaNameGenerator))
            {
                throw new InvalidOperationException("The SchemaNameGenerator cannot be customized when loading types from external assemblies.");
            }

            if (!(Settings.TypeNameGenerator is DefaultTypeNameGenerator))
            {
                throw new InvalidOperationException("The TypeNameGenerator cannot be customized when loading types from external assemblies.");
            }

            var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(Settings.AssemblySettings.AssemblyPaths.First()));

            using (var isolated = new AppDomainIsolation <WebApiAssemblyLoader>(assemblyDirectory, Settings.AssemblySettings.AssemblyConfig, AssemblyLoaderUtilities.GetBindingRedirects(), AssemblyLoaderUtilities.GetAssemblies(assemblyDirectory)))
            {
                var document = await Task.Run(() => isolated.Object.GenerateForControllers(controllerClassNames, JsonConvert.SerializeObject(Settings))).ConfigureAwait(false);

                return(await SwaggerDocument.FromJsonAsync(document).ConfigureAwait(false));
            }
        }
 /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
 /// <param name="className">The class name.</param>
 /// <returns>The Swagger definition.</returns>
 public SwaggerService Generate(string className)
 {
     using (var isolated = new AppDomainIsolation<AssemblyLoader>())
         return SwaggerService.FromJson(isolated.Object.FromAssemblyType(_assemblyPath, className));
 }
 /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
 /// <param name="classNames">The class names.</param>
 /// <returns>The Swagger definition.</returns>
 public SwaggerService Generate(string[] classNames)
 {
     using (var isolated = new AppDomainIsolation<AssemblyLoader>(Path.GetDirectoryName(Settings.AssemblyPath)))
         return SwaggerService.FromJson(isolated.Object.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings)));
 }
Esempio n. 23
0
 /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
 /// <param name="className">The class name.</param>
 /// <returns>The Swagger definition.</returns>
 public SwaggerService Generate(string className)
 {
     using (var isolated = new AppDomainIsolation <AssemblyLoader>(Path.GetDirectoryName(_assemblyPath)))
         return(SwaggerService.FromJson(isolated.Object.FromAssemblyType(_assemblyPath, className, JsonConvert.SerializeObject(JsonSchemaGeneratorSettings))));
 }
 /// <summary>Generates the Swagger definition for the given controller.</summary>
 /// <param name="controllerClassName">The full name of the controller class.</param>
 /// <param name="urlTemplate">The default Web API URL template.</param>
 /// <returns>The Swagger definition.</returns>
 public SwaggerService Generate(string controllerClassName, string urlTemplate)
 {
     using (var isolated = new AppDomainIsolation<AssemblyLoader>())
         return SwaggerService.FromJson(isolated.Object.FromWebApiAssembly(_assemblyPath, controllerClassName, urlTemplate));
 }
Esempio n. 25
0
 /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
 /// <param name="classNames">The class names.</param>
 /// <returns>The Swagger definition.</returns>
 public SwaggerService Generate(string[] classNames)
 {
     using (var isolated = new AppDomainIsolation <NetAssemblyLoader>(Path.GetDirectoryName(Settings.AssemblyPath)))
         return(SwaggerService.FromJson(isolated.Object.FromAssemblyType(classNames, JsonConvert.SerializeObject(Settings))));
 }
Esempio n. 26
0
 /// <summary>Generates the Swagger definition for the given classes without operations (used for class generation).</summary>
 /// <param name="className">The class name.</param>
 /// <returns>The Swagger definition.</returns>
 public SwaggerService FromAssemblyType(string className)
 {
     using (var isolated = new AppDomainIsolation <NSwagServiceLoader>())
         return(SwaggerService.FromJson(isolated.Object.FromAssemblyType(_assemblyPath, className)));
 }