Skip to content

Commit

Permalink
convert LF to CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsilva committed Mar 13, 2017
1 parent 3289c15 commit a1926aa
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 243 deletions.
342 changes: 171 additions & 171 deletions src/SwaggerWcf/Support/ServiceBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,172 +1,172 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using SwaggerWcf.Attributes;
using SwaggerWcf.Configuration;
using SwaggerWcf.Models;
using SettingElement = SwaggerWcf.Configuration.SettingElement;

namespace SwaggerWcf.Support
{
internal class ServiceBuilder
{
public static Service Build()
{
Service service = BuildService();

return service;
}

public static Service Build<TBusiness>()
{
Service service = BuildService<TBusiness>();

return service;
}

private static Service BuildService()
{
const string sectionName = "swaggerwcf";
SwaggerWcfSection config =
(SwaggerWcfSection)(ConfigurationManager.GetSection(sectionName) ?? new SwaggerWcfSection());

List<Type> definitionsTypesList = new List<Type>();
Service service = new Service();
List<string> hiddenTags = GetHiddenTags(config);
List<string> visibleTags = GetVisibleTags(config);
IReadOnlyDictionary<string, string> settings = GetSettings(config);

ProcessSettings(service, settings);

BuildPaths(service, hiddenTags, visibleTags, definitionsTypesList);

service.Definitions = DefinitionsBuilder.Process(hiddenTags, visibleTags, definitionsTypesList);

return service;
}

private static Service BuildService<TBusiness>()
{
const string sectionName = "swaggerwcf";
SwaggerWcfSection config =
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using SwaggerWcf.Attributes;
using SwaggerWcf.Configuration;
using SwaggerWcf.Models;
using SettingElement = SwaggerWcf.Configuration.SettingElement;

namespace SwaggerWcf.Support
{
internal class ServiceBuilder
{
public static Service Build()
{
Service service = BuildService();

return service;
}

public static Service Build<TBusiness>()
{
Service service = BuildService<TBusiness>();

return service;
}

private static Service BuildService()
{
const string sectionName = "swaggerwcf";
SwaggerWcfSection config =
(SwaggerWcfSection)(ConfigurationManager.GetSection(sectionName) ?? new SwaggerWcfSection());

List<Type> definitionsTypesList = new List<Type>();
Service service = new Service();
List<string> hiddenTags = GetHiddenTags(config);
List<string> visibleTags = GetVisibleTags(config);
IReadOnlyDictionary<string, string> settings = GetSettings(config);

ProcessSettings(service, settings);

BuildPaths(service, hiddenTags, visibleTags, definitionsTypesList);

service.Definitions = DefinitionsBuilder.Process(hiddenTags, visibleTags, definitionsTypesList);

return service;
}

private static Service BuildService<TBusiness>()
{
const string sectionName = "swaggerwcf";
SwaggerWcfSection config =
(SwaggerWcfSection)(ConfigurationManager.GetSection(sectionName) ?? new SwaggerWcfSection());

List<Type> definitionsTypesList = new List<Type>();
Service service = new Service();
List<string> hiddenTags = GetHiddenTags(config);
List<string> visibleTags = GetVisibleTags(config);
IReadOnlyDictionary<string, string> settings = GetSettings(config);

ProcessSettings(service, settings);

BuildPaths<TBusiness>(service, hiddenTags, visibleTags, definitionsTypesList);

service.Definitions = DefinitionsBuilder.Process(hiddenTags, visibleTags, definitionsTypesList);

return service;
}


private static List<string> GetHiddenTags(SwaggerWcfSection config)
{
return config.Tags == null
? new List<string>()
: config.Tags.OfType<TagElement>()
.Where(t => t.Visibile.Equals(false))
.Select(t => t.Name)
.ToList();
}

private static List<string> GetVisibleTags(SwaggerWcfSection config)
{
return config.Tags == null
? new List<string>()
: config.Tags.OfType<TagElement>()
.Where(t => t.Visibile.Equals(true))
.Select(t => t.Name)
.ToList();
}

private static IReadOnlyDictionary<string, string> GetSettings(SwaggerWcfSection config)
{
return config.Settings == null
? new Dictionary<string, string>()
: config.Settings.OfType<SettingElement>().ToDictionary(se => se.Name, se => se.Value);
}

private static void ProcessSettings(Service service, IReadOnlyDictionary<string, string> settings)
{
if (settings.ContainsKey("BasePath"))
service.BasePath = settings["BasePath"];
if (settings.ContainsKey("Host"))
service.Host = settings["Host"];

if (settings.Keys.Any(k => k.StartsWith("Info")))
service.Info = new Info();
if (settings.ContainsKey("InfoDescription"))
service.Info.Description = settings["InfoDescription"];
if (settings.ContainsKey("InfoVersion"))
service.Info.Version = settings["InfoVersion"];
if (settings.ContainsKey("InfoTermsOfService"))
service.Info.TermsOfService = settings["InfoTermsOfService"];
if (settings.ContainsKey("InfoTitle"))
service.Info.Title = settings["InfoTitle"];

if (settings.Keys.Any(k => k.StartsWith("InfoContact")))
service.Info.Contact = new InfoContact();
if (settings.ContainsKey("InfoContactName"))
service.Info.Contact.Name = settings["InfoContactName"];
if (settings.ContainsKey("InfoContactUrl"))
service.Info.Contact.Url = settings["InfoContactUrl"];
if (settings.ContainsKey("InfoContactEmail"))
service.Info.Contact.Email = settings["InfoContactEmail"];

if (settings.Keys.Any(k => k.StartsWith("InfoLicense")))
service.Info.License = new InfoLicense();
if (settings.ContainsKey("InfoLicenseUrl"))
service.Info.License.Url = settings["InfoLicenseUrl"];
if (settings.ContainsKey("InfoLicenseName"))
service.Info.License.Name = settings["InfoLicenseName"];
}

private static void BuildPaths(Service service, IList<string> hiddenTags, List<string> visibleTags, IList<Type> definitionsTypesList)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
service.Paths = new List<Path>();

foreach (Assembly assembly in assemblies)
{
IEnumerable<TypeInfo> types;
try
{
types = assembly.DefinedTypes;
}
catch (Exception)
{
// ignore assembly and continue
continue;
}

foreach (TypeInfo ti in types)
{
SwaggerWcfAttribute da = ti.GetCustomAttribute<SwaggerWcfAttribute>();
if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
continue;

Mapper mapper = new Mapper(hiddenTags, visibleTags);

IEnumerable<Path> paths = mapper.FindMethods(da.ServicePath, ti.AsType(), definitionsTypesList);
service.Paths.AddRange(paths);
}
}
}

List<Type> definitionsTypesList = new List<Type>();
Service service = new Service();
List<string> hiddenTags = GetHiddenTags(config);
List<string> visibleTags = GetVisibleTags(config);
IReadOnlyDictionary<string, string> settings = GetSettings(config);

ProcessSettings(service, settings);

BuildPaths<TBusiness>(service, hiddenTags, visibleTags, definitionsTypesList);

service.Definitions = DefinitionsBuilder.Process(hiddenTags, visibleTags, definitionsTypesList);

return service;
}


private static List<string> GetHiddenTags(SwaggerWcfSection config)
{
return config.Tags == null
? new List<string>()
: config.Tags.OfType<TagElement>()
.Where(t => t.Visibile.Equals(false))
.Select(t => t.Name)
.ToList();
}

private static List<string> GetVisibleTags(SwaggerWcfSection config)
{
return config.Tags == null
? new List<string>()
: config.Tags.OfType<TagElement>()
.Where(t => t.Visibile.Equals(true))
.Select(t => t.Name)
.ToList();
}

private static IReadOnlyDictionary<string, string> GetSettings(SwaggerWcfSection config)
{
return config.Settings == null
? new Dictionary<string, string>()
: config.Settings.OfType<SettingElement>().ToDictionary(se => se.Name, se => se.Value);
}

private static void ProcessSettings(Service service, IReadOnlyDictionary<string, string> settings)
{
if (settings.ContainsKey("BasePath"))
service.BasePath = settings["BasePath"];
if (settings.ContainsKey("Host"))
service.Host = settings["Host"];

if (settings.Keys.Any(k => k.StartsWith("Info")))
service.Info = new Info();
if (settings.ContainsKey("InfoDescription"))
service.Info.Description = settings["InfoDescription"];
if (settings.ContainsKey("InfoVersion"))
service.Info.Version = settings["InfoVersion"];
if (settings.ContainsKey("InfoTermsOfService"))
service.Info.TermsOfService = settings["InfoTermsOfService"];
if (settings.ContainsKey("InfoTitle"))
service.Info.Title = settings["InfoTitle"];

if (settings.Keys.Any(k => k.StartsWith("InfoContact")))
service.Info.Contact = new InfoContact();
if (settings.ContainsKey("InfoContactName"))
service.Info.Contact.Name = settings["InfoContactName"];
if (settings.ContainsKey("InfoContactUrl"))
service.Info.Contact.Url = settings["InfoContactUrl"];
if (settings.ContainsKey("InfoContactEmail"))
service.Info.Contact.Email = settings["InfoContactEmail"];

if (settings.Keys.Any(k => k.StartsWith("InfoLicense")))
service.Info.License = new InfoLicense();
if (settings.ContainsKey("InfoLicenseUrl"))
service.Info.License.Url = settings["InfoLicenseUrl"];
if (settings.ContainsKey("InfoLicenseName"))
service.Info.License.Name = settings["InfoLicenseName"];
}

private static void BuildPaths(Service service, IList<string> hiddenTags, List<string> visibleTags, IList<Type> definitionsTypesList)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
service.Paths = new List<Path>();

foreach (Assembly assembly in assemblies)
{
IEnumerable<TypeInfo> types;
try
{
types = assembly.DefinedTypes;
}
catch (Exception)
{
// ignore assembly and continue
continue;
}

foreach (TypeInfo ti in types)
{
SwaggerWcfAttribute da = ti.GetCustomAttribute<SwaggerWcfAttribute>();
if (da == null || hiddenTags.Any(ht => ht == ti.AsType().Name))
continue;

Mapper mapper = new Mapper(hiddenTags, visibleTags);

IEnumerable<Path> paths = mapper.FindMethods(da.ServicePath, ti.AsType(), definitionsTypesList);
service.Paths.AddRange(paths);
}
}
}

private static void BuildPaths<TBusiness>(Service service, IList<string> hiddenTags, List<string> visibleTags, IList<Type> definitionsTypesList)
{
Type type = typeof(TBusiness);
private static void BuildPaths<TBusiness>(Service service, IList<string> hiddenTags, List<string> visibleTags, IList<Type> definitionsTypesList)
{
Type type = typeof(TBusiness);
service.Paths = new List<Path>();

SwaggerWcfAttribute da = type.GetCustomAttribute<SwaggerWcfAttribute>();
Expand All @@ -176,7 +176,7 @@ private static void BuildPaths<TBusiness>(Service service, IList<string> hiddenT
Mapper mapper = new Mapper(hiddenTags, visibleTags);

IEnumerable<Path> paths = mapper.FindMethods(da.ServicePath, type, definitionsTypesList);
service.Paths.AddRange(paths);
}
}
}
service.Paths.AddRange(paths);
}
}
}
12 changes: 6 additions & 6 deletions src/SwaggerWcf/SwaggerWcf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@
<None Include="SwaggerWcf.nuspec" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit a1926aa

Please sign in to comment.