public static void ForAll(Assembly assembly, string servicePrefix)
        {
            var generator = new AssemblyTypeToSwaggerGenerator(assembly.CodeBase);
            var allClassNames = generator.GetAbpServiceBaseClasses();
            foreach (var item in allClassNames)
            {
                var service = generator.FromAbpApplicationMoudleAssembly(item, UrlTemplate.Replace("{servicePrefix}", servicePrefix));
                if (service == null)
                    continue;

                var converter = new SwaggerOperationsExtendedConverter(typeof(SwaggerOperationsExtended));

                var jsontext = service.ToJson(converter);

                //gen json file 
                if (HttpContext.Current != null)
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/apidoc/"));
                    var file = HttpContext.Current.Server.MapPath("~/apidoc/") + "/" + item + ".js";
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }

                    var writer = File.CreateText(file);
                    writer.Write(jsontext);
                    writer.Close();
                }
            }
        }
Esempio n. 2
0
        public static void ForAll(Assembly assembly, string servicePrefix)
        {
            var generator     = new AssemblyTypeToSwaggerGenerator(assembly.CodeBase);
            var allClassNames = generator.GetAbpServiceBaseClasses();

            foreach (var item in allClassNames)
            {
                var service = generator.FromAbpApplicationMoudleAssembly(item, UrlTemplate.Replace("{servicePrefix}", servicePrefix));
                if (service == null)
                {
                    continue;
                }

                var converter = new SwaggerOperationsExtendedConverter(typeof(SwaggerOperationsExtended));

                var jsontext = service.ToJson(converter);

                //gen json file
                if (HttpContext.Current != null)
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/apidoc/"));
                    var file = HttpContext.Current.Server.MapPath("~/apidoc/") + "/" + item + ".js";
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }

                    var writer = File.CreateText(file);
                    writer.Write(jsontext);
                    writer.Close();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 针对程序集获取Swagger信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="assembly"></param>
        /// <param name="servicePrefix"></param>
        public static void ForAll <T>(Assembly assembly, string servicePrefix)
        {
            var swagpath = HttpContext.Current != null?HttpContext.Current.Server.MapPath("~/Swag/") + servicePrefix + "/" : "";

            Task.Factory.StartNew(() =>
            {
                var generator     = new AssemblyTypeToSwaggerGenerator(assembly.CodeBase);
                var allClassNames = generator.GetAbpServiceBaseClasses();

                Parallel.ForEach <string>(allClassNames, item => GenJsonForOneClass(item, UrlTemplate.Replace("{servicePrefix}", servicePrefix), swagpath, generator));
            });
        }