Skip to content

Commit

Permalink
refactored to class
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatandrei committed May 9, 2020
1 parent 0dcbdc5 commit 718105d
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 134 deletions.
68 changes: 3 additions & 65 deletions src/NetCore2Blockly/NetCore2Blockly/ActionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,9 @@ namespace NetCore2Blockly
/// generator
/// </summary>

class ActionInfo : IActionInfo
class ActionInfoFromNetAPI : ActionInfo
{

/// <summary>
/// Gets or sets the name of the controller.
/// </summary>
/// <value>
/// The name of the controller.
/// </value>
public string ControllerName { get; set; }

/// <summary>
/// Gets or sets the type of the return.
/// </summary>
/// <value>
/// The type of the return.
/// </value>
public Type ReturnType { get; set; }

/// <summary>
/// Gets or sets the name of the action.
/// </summary>
/// <value>
/// The name of the action.
/// </value>
public string ActionName { get; set; }

/// <summary>
/// Gets or sets the host.
/// </summary>
/// <value>
/// The host.
/// </value>
public string Host { get; set; }

/// <summary>
/// Gets or sets the relative request URL.
/// </summary>
/// <value>
/// The relative request URL.
/// </value>
public string RelativeRequestUrl { get; set; }
/// <summary>
/// Gets or sets the verb.
/// </summary>
/// <value>
/// The verb.
/// </value>
public string Verb { get; set; }

/// <summary>
///
/// </summary>
/// <returns></returns>
public int CustomGetHashCode()
{
int hash = 13;
hash = (hash * 7) + Host?.GetHashCode() ?? 0;
hash = (hash * 7) + ControllerName.GetHashCode();

return hash;
}

public Dictionary<string, (Type type, BindingSourceDefinition bs)> Params { get; set; }
internal bool HasParams => (Params?.Count ?? 0) > 0;
private BindingSourceDefinition ConvertFromBindingSource(BindingSource bs)
{
return bs switch
Expand Down Expand Up @@ -138,10 +76,10 @@ private BindingSourceDefinition ConvertFromBindingSource(BindingSource bs)
}

/// <summary>
/// Initializes a new instance of the <see cref="ActionInfo"/> class.
/// Initializes a new instance of the <see cref="ActionInfoFromNetAPI"/> class.
/// </summary>
/// <param name="apiDescription">The API description.</param>
public ActionInfo(ApiDescription apiDescription)
public ActionInfoFromNetAPI(ApiDescription apiDescription)
{

ActionName = apiDescription.RelativePath;
Expand Down
37 changes: 35 additions & 2 deletions src/NetCore2Blockly/NetCore2Blockly/BindingSourceDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
namespace NetCore2Blockly
{
/// <summary>
/// defintion of binding
/// definition of binding
/// See BindingSource
/// </summary>
public enum BindingSourceDefinition
{
{
/// <summary>
/// See BindingSource
/// </summary>
None = 0,
/// <summary>
/// See BindingSource
/// </summary>
Body,
/// <summary>
/// See BindingSource
/// </summary>
Custom,
/// <summary>
/// See BindingSource
/// </summary>
Form,
/// <summary>
/// See BindingSource
/// </summary>
Header,
/// <summary>
/// See BindingSource
/// </summary>
ModelBinding,
/// <summary>
/// See BindingSource
/// </summary>
Path,
/// <summary>
/// See BindingSource
/// </summary>
Query,
/// <summary>
/// See BindingSource
/// </summary>
Services,
/// <summary>
/// See BindingSource
/// </summary>
Special,
/// <summary>
/// See BindingSource
/// </summary>
FormFile,
}
}
4 changes: 2 additions & 2 deletions src/NetCore2Blockly/NetCore2Blockly/BlocklyFileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace NetCore2Blockly
public class BlocklyFileGenerator
{
JavascriptGenerator _jsGenerator;
List<IActionInfo> _actionList;
List<ActionInfo> _actionList;


/// <summary>
/// Initializes a new instance of the <see cref="BlocklyFileGenerator"/> class.
/// </summary>
/// <param name="actionList">The action list.</param>
public BlocklyFileGenerator(List<IActionInfo> actionList)
public BlocklyFileGenerator(List<ActionInfo> actionList)
{
_jsGenerator = new JavascriptGenerator();
_actionList = actionList;
Expand Down
6 changes: 3 additions & 3 deletions src/NetCore2Blockly/NetCore2Blockly/EnumerateWebAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public EnumerateWebAPI(IApiDescriptionGroupCollectionProvider api)
/// Creates the action list to generate blocks
/// </summary>
/// <returns></returns>
public List<IActionInfo> CreateActionList()
public List<ActionInfo> CreateActionList()
{
var allActions = new List<IActionInfo>();
var allActions = new List<ActionInfo>();
var groups = api.ApiDescriptionGroups;

foreach (var g in groups.Items)
{

foreach (var api in g.Items)
{
var controllerInformation = new ActionInfo(api);
var controllerInformation = new ActionInfoFromNetAPI(api);

allActions.Add(controllerInformation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class ActionInfoExtensions
/// </summary>
/// <param name="actionInfo">The action information.</param>
/// <returns></returns>
public static string GenerateCommandName(this IActionInfo actionInfo)
public static string GenerateCommandName(this ActionInfo actionInfo)
{
var nameCommand = actionInfo.ActionName.Replace("/", "_");
nameCommand = nameCommand.Replace("{", "_").Replace("}", "_");
Expand All @@ -27,7 +27,7 @@ public static string GenerateCommandName(this IActionInfo actionInfo)
/// </summary>
/// <param name="actionInfo">The action information.</param>
/// <returns></returns>
public static string CommandDisplayName(this IActionInfo actionInfo)
public static string CommandDisplayName(this ActionInfo actionInfo)
{

return actionInfo.Verb + " " + actionInfo.ActionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class ActionListExtensions
/// </summary>
/// <param name="list">The list.</param>
/// <returns></returns>
public static Type[] GetAllTypesWithNullBlocklyType(this List<IActionInfo> list)
public static Type[] GetAllTypesWithNullBlocklyType(this List<ActionInfo> list)
{
return list

Expand Down
90 changes: 80 additions & 10 deletions src/NetCore2Blockly/NetCore2Blockly/IActionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,88 @@

namespace NetCore2Blockly
{
public interface IActionInfo
/// <summary>
/// generic action info
/// </summary>
public abstract class ActionInfo
{
string ActionName { get; set; }
string ControllerName { get; set; }
string Host { get; set; }
string RelativeRequestUrl { get; set; }
Type ReturnType { get; set; }
string Verb { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ActionInfo"/> class.
/// </summary>
public ActionInfo()
{
Params = new Dictionary<string, (Type type, BindingSourceDefinition bs)>();
}
/// <summary>
/// Gets or sets the name of the action.
/// </summary>
/// <value>
/// The name of the action.
/// </value>
public string ActionName { get; set; }
/// <summary>
/// Gets or sets the name of the controller.
/// </summary>
/// <value>
/// The name of the controller.
/// </value>
public string ControllerName { get; set; }
/// <summary>
/// Gets or sets the host.
/// </summary>
/// <value>
/// The host.
/// </value>
public string Host { get; set; }
/// <summary>
/// Gets or sets the relative request URL.
/// </summary>
/// <value>
/// The relative request URL.
/// </value>
public string RelativeRequestUrl { get; set; }
/// <summary>
/// Gets or sets the type of the return.
/// </summary>
/// <value>
/// The type of the return.
/// </value>
public Type ReturnType { get; set; }
/// <summary>
/// Gets or sets the verb.
/// </summary>
/// <value>
/// The verb.
/// </value>
public string Verb { get; set; }

int CustomGetHashCode();
Dictionary<string, (Type type, BindingSourceDefinition bs)> Params { get; set; }
/// <summary>
/// hash code do display.
/// </summary>
/// <returns></returns>
public int CustomGetHashCode()
{
int hash = 13;
hash = (hash * 7) + Host?.GetHashCode() ?? 0;
hash = (hash * 7) + ControllerName.GetHashCode();

bool HasParams => (Params?.Count > 0);
return hash;

}
/// <summary>
/// Gets or sets the parameters.
/// </summary>
/// <value>
/// The parameters.
/// </value>
public Dictionary<string, (Type type, BindingSourceDefinition bs)> Params { get; set; }

/// <summary>
/// Gets a value indicating whether this instance has parameters.
/// </summary>
/// <value>
/// <c>true</c> if this instance has parameters; otherwise, <c>false</c>.
/// </value>
public bool HasParams => (Params?.Count > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BlocklyFunctionDefinitionGenerator
/// </summary>
/// <param name="actionInfo">The action information.</param>
/// <returns></returns>
public string GeneratePropertyDefinitions(IActionInfo actionInfo)
public string GeneratePropertyDefinitions(ActionInfo actionInfo)
{
string tooltip = $"{actionInfo.GenerateCommandName()} :";
var strPropsDefinition = "";
Expand Down Expand Up @@ -46,7 +46,7 @@ public string GeneratePropertyDefinitions(IActionInfo actionInfo)
/// </summary>
/// <param name="actionInfo">The action information.</param>
/// <returns></returns>
public string GenerateFunctionDefinition(IActionInfo actionInfo)
public string GenerateFunctionDefinition(ActionInfo actionInfo)
{
var strPropsDefinition = GeneratePropertyDefinitions(actionInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BlocklyFunctionJSGenerator
/// </summary>
/// <param name="actionInfo">The action information.</param>
/// <returns></returns>
public string GenerateFunctionJS(IActionInfo actionInfo)
public string GenerateFunctionJS(ActionInfo actionInfo)
{
var paramsStr = "";
var paramsBodyStr = "";
Expand Down Expand Up @@ -69,7 +69,7 @@ public string GenerateFunctionJS(IActionInfo actionInfo)
";
}

internal string GenerateGet(IActionInfo actionInfo)
internal string GenerateGet(ActionInfo actionInfo)
{
var paramsXHR = "strUrl";
bool existBody = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BlocklyToolBoxFunctionDefinitionsGenerator
/// </summary>
/// <param name="actionList">The action list.</param>
/// <returns></returns>
public string GenerateBlocklyToolBoxFunctionDefinitions(List<IActionInfo> actionList)
public string GenerateBlocklyToolBoxFunctionDefinitions(List<ActionInfo> actionList)
{
string blockText = "var blockTextLocalSiteFunctions='';";
foreach (var actionsGroupedByController in actionList.GroupBy(it => it.ControllerName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public string GenerateBlocklyToolBoxValue(Type[] types)
/// </summary>
/// <param name="actionList">The action list.</param>
/// <returns></returns>
public string GenerateBlocklyToolBoxFunctionDefinitions(List<IActionInfo> actionList)
public string GenerateBlocklyToolBoxFunctionDefinitions(List<ActionInfo> actionList)
{
return _toolBoxFunctionDefinitionGenerator.GenerateBlocklyToolBoxFunctionDefinitions(actionList);
}
Expand All @@ -61,7 +61,7 @@ public string GenerateBlocklyToolBoxFunctionDefinitions(List<IActionInfo> action
/// </summary>
/// <param name="action">The action.</param>
/// <returns></returns>
public string GenerateFunctionJS(IActionInfo action)
public string GenerateFunctionJS(ActionInfo action)
{
return _functionJSGenerator.GenerateFunctionJS(action);
}
Expand All @@ -71,7 +71,7 @@ public string GenerateFunctionJS(IActionInfo action)
/// </summary>
/// <param name="action">The action.</param>
/// <returns></returns>
public string GenerateFunctionDefinition(IActionInfo action)
public string GenerateFunctionDefinition(ActionInfo action)
{
return _functionDefinitionGenerator.GenerateFunctionDefinition(action);
}
Expand Down
4 changes: 2 additions & 2 deletions src/NetCore2Blockly/NetCore2Blockly/NetCore2Blockly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageTags>WebAPI;ASP.NET Core;.NET Core;Blockly</PackageTags>
<Description>
This program will generate ASP.NET Core WebAPI blockly blocks.
This program will generate ASP.NET Core WebAPI blockly blocks. And from other swagger files.
Can be usefull for just making a demo, interacting or others.
Please see https://github.com/ignatandrei/NETCoreBlockly for details
</Description>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile></DocumentationFile>
<DocumentationFile>NetCore2Blockly.xml</DocumentationFile>
<WarningsAsErrors></WarningsAsErrors>
</PropertyGroup>

Expand Down
Loading

0 comments on commit 718105d

Please sign in to comment.