Merge lp:~mandel/wadlsharp/fix_names into lp:~manishsinha/wadlsharp/trunk

Proposed by Manuel de la Peña
Status: Rejected
Rejected by: Manish Sinha (मनीष सिन्हा)
Proposed branch: lp:~mandel/wadlsharp/fix_names
Merge into: lp:~manishsinha/wadlsharp/trunk
Prerequisite: lp:~mandel/wadlsharp/add_command_line
Diff against target: 636 lines (+289/-47)
10 files modified
LpNet.WadlSharp.Common/Generator/LpClass.cs (+45/-12)
LpNet.WadlSharp.Common/Generator/LpMethod.cs (+47/-13)
LpNet.WadlSharp.Common/Generator/LpNamespace.cs (+32/-2)
LpNet.WadlSharp.Common/Generator/LpProperty.cs (+28/-2)
LpNet.WadlSharp.Common/Generator/LpReturn.cs (+33/-6)
LpNet.WadlSharp.Common/Utils.cs (+42/-4)
LpNet.WadlSharp.Common/WadlConverter.cs (+32/-1)
WadlConsole/Program.cs (+16/-5)
WadlConsole/Resources.Designer.cs (+10/-1)
WadlConsole/Resources.resx (+4/-1)
To merge this branch: bzr merge lp:~mandel/wadlsharp/fix_names
Reviewer Review Type Date Requested Status
Manish Sinha (मनीष सिन्हा) Disapprove
Review via email: mp+35843@code.launchpad.net

Description of the change

Allows users to provide a command line parameter that will allow to fix the casing of the code by using PAscalCase notation. Other notations can be added to the code.

To post a comment you must log in.
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Since this is implemented after implementing WadlConsole and WadlConsole itself is broken, so merging this will make introduce one feature and one defect.

The Fixing of names is really great except that WadlConsole project needs to be fixed first.

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Manual, can you try to merge this branch with trunk which is at r30 ATM. If it works, then please merge it yourself. Reviewing this merge request will take just too much of my time.

Revision history for this message
Manuel de la Peña (mandel) wrote :

Ok, no worries, I'll take care of it.

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Wait. This branch has been asked to merge in the wrong branch. It should be requested to merge in lp:wadlsharp and not lp:~manishsinha/wadlsharp/trunk

The correct merge request is at
https://code.launchpad.net/~mandel/wadlsharp/fix_names/+merge/36070

Manual, please try to merge it in lp:wadlsharp yourself because of the reason I told in the above comment. I am Disapproving this merge request as it asked to merge in the wrong branch.

review: Disapprove
Revision history for this message
Manuel de la Peña (mandel) wrote :

Cool, agree! it should not be merged to your personal branch but the teams one. I'll make sure everything is done in the correct branch.

Unmerged revisions

30. By Manuel de la Peña

Fixed issue with not using the identify generator for the results.

29. By Manuel de la Peña

Modified the code to allow the users to fix the casing of the generated code to follow naming conventions.

28. By Manuel de la Peña

Added implementation of console application that will allow user to automate the code generation.

27. By Manuel de la Peña

Ignore resharper user config.

26. By Manuel de la Peña

Added lib dependencies so that the contributors have no ref errors.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'LpNet.WadlSharp.Common/Generator/LpClass.cs'
--- LpNet.WadlSharp.Common/Generator/LpClass.cs 2010-05-02 07:16:04 +0000
+++ LpNet.WadlSharp.Common/Generator/LpClass.cs 2010-09-17 16:11:21 +0000
@@ -26,6 +26,8 @@
26 ********************************************************************/26 ********************************************************************/
2727
2828
29using System;
30
29namespace LpNet.WadlSharp.Common.Generator31namespace LpNet.WadlSharp.Common.Generator
30{32{
31 using System.CodeDom;33 using System.CodeDom;
@@ -36,6 +38,36 @@
3638
37 public class LpClass : IClass39 public class LpClass : IClass
38 {40 {
41 #region Variables
42
43 private readonly Func<string, string> _createIdentifier;
44
45 #endregion
46
47 #region Constructors
48
49 /// <summary>
50 /// Creates a new instance of the class that will be use the
51 /// basic identifier generator.
52 /// </summary>
53 public LpClass()
54 : this(WadlSharpUtils.CreateIdentifier)
55 {
56
57 }
58
59 /// <summary>
60 /// Creates a new instance of the class with the given identifier generator.
61 /// </summary>
62 /// <param name="createIdentifier">The generator that will create
63 /// the identifiers used in the generated class.</param>
64 public LpClass(Func<string, string> createIdentifier)
65 {
66 _createIdentifier = createIdentifier;
67 }
68
69 #endregion
70
39 #region IClass Members71 #region IClass Members
4072
41 /// <summary>73 /// <summary>
@@ -47,12 +79,13 @@
47 /// <returns>Instance of CodeTypeDeclaration</returns>79 /// <returns>Instance of CodeTypeDeclaration</returns>
48 public CodeTypeDeclaration Create(representation_type repType, HashSet<string> nameSpaces, CodeNamespace ns)80 public CodeTypeDeclaration Create(representation_type repType, HashSet<string> nameSpaces, CodeNamespace ns)
49 {81 {
50 CodeTypeDeclaration cdDec= new CodeTypeDeclaration();82 CodeTypeDeclaration cdDec= new CodeTypeDeclaration
5183 {
52 cdDec.Name = WadlSharpUtils.CreateIdentifier(repType.id);84 Name = _createIdentifier(repType.id),
53 cdDec.IsClass = true;85 IsClass = true,
54 cdDec.Attributes = MemberAttributes.Public | MemberAttributes.Static;86 Attributes = MemberAttributes.Public | MemberAttributes.Static,
55 cdDec.IsPartial = true;87 IsPartial = true
88 };
5689
57 #region Namespaces Import90 #region Namespaces Import
5891
@@ -85,12 +118,12 @@
85 if (param.option != null)118 if (param.option != null)
86 {119 {
87 paramName = string.Format("{0}_{1}", cdDec.Name,120 paramName = string.Format("{0}_{1}", cdDec.Name,
88 WadlSharpUtils.CreateIdentifier(param.name));121 _createIdentifier(param.name));
89122
90 CodeTypeMember existingEnum = LpMethod.CheckEnumExists(ns, param, paramName);123 CodeTypeMember existingEnum = LpMethod.CheckEnumExists(ns, param, paramName);
91 if (existingEnum == null)124 if (existingEnum == null)
92 {125 {
93 string enumName = WadlSharpUtils.CreateIdentifier(param.name);126 string enumName = _createIdentifier(param.name);
94127
95 IEnum paramEnum = new LpEnum();128 IEnum paramEnum = new LpEnum();
96 CodeTypeDeclaration memberEnum = paramEnum.Create(paramName, param.option, nameSpaces);129 CodeTypeDeclaration memberEnum = paramEnum.Create(paramName, param.option, nameSpaces);
@@ -104,7 +137,7 @@
104137
105 CodeMemberField field;138 CodeMemberField field;
106139
107 IProperty property = new LpProperty();140 IProperty property = new LpProperty(_createIdentifier);
108 CodeMemberProperty prop = property.Create(param, out field, nameSpaces, ns, paramName);141 CodeMemberProperty prop = property.Create(param, out field, nameSpaces, ns, paramName);
109142
110 propertiesList.Add(prop);143 propertiesList.Add(prop);
@@ -139,7 +172,7 @@
139172
140 #region The Class Definition and Properties173 #region The Class Definition and Properties
141174
142 typeDeclaration.Name = WadlSharpUtils.CreateIdentifier(resourceType.id);175 typeDeclaration.Name = _createIdentifier(resourceType.id);
143 typeDeclaration.IsClass = true;176 typeDeclaration.IsClass = true;
144 typeDeclaration.Attributes = MemberAttributes.Public | MemberAttributes.Static;177 typeDeclaration.Attributes = MemberAttributes.Public | MemberAttributes.Static;
145 typeDeclaration.IsPartial = true;178 typeDeclaration.IsPartial = true;
@@ -177,7 +210,7 @@
177210
178 foreach (method method in resourceType.method)211 foreach (method method in resourceType.method)
179 {212 {
180 IMethod lpmethod = new LpMethod();213 IMethod lpmethod = new LpMethod(_createIdentifier);
181 CodeMemberMethod memberMethod;214 CodeMemberMethod memberMethod;
182215
183 if (method.request != null && method.request.representation != null)216 if (method.request != null && method.request.representation != null)
@@ -206,7 +239,7 @@
206 {239 {
207 foreach (param param in resourceType.param)240 foreach (param param in resourceType.param)
208 {241 {
209 IProperty paramInst = new LpProperty();242 IProperty paramInst = new LpProperty(_createIdentifier);
210 CodeMemberField field;243 CodeMemberField field;
211244
212 CodeMemberProperty prop = paramInst.Create(param, out field, nameSpaces, ns, string.Empty);245 CodeMemberProperty prop = paramInst.Create(param, out field, nameSpaces, ns, string.Empty);
213246
=== modified file 'LpNet.WadlSharp.Common/Generator/LpMethod.cs'
--- LpNet.WadlSharp.Common/Generator/LpMethod.cs 2010-05-02 07:16:04 +0000
+++ LpNet.WadlSharp.Common/Generator/LpMethod.cs 2010-09-17 16:11:21 +0000
@@ -24,26 +24,58 @@
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.25 * OTHER DEALINGS IN THE SOFTWARE.
26 ********************************************************************/26 ********************************************************************/
2727using System;
28using System.CodeDom;
29using System.Collections.Generic;
30using LpNet.WadlSharp.Common.Enum;
31using LpNet.WadlSharp.Common.Interface.Generator;
32using LpNet.WadlSharp.Common.Resources;
2833
29namespace LpNet.WadlSharp.Common.Generator34namespace LpNet.WadlSharp.Common.Generator
30{35{
31 using System.CodeDom;36
32 using System.Collections.Generic;
33 using Interface.Generator;
34 using Resources;
35 using Enum;
3637
37 public class LpMethod : IMethod38 public class LpMethod : IMethod
38 {39 {
40 #region Vars
41
42 private readonly Func<string, string> _createIdentifier;
43
44 #endregion
45
46 #region Constructors
47
48 /// <summary>
49 /// Creates a new instance of the class with the basic identifier generator.
50 /// </summary>
51 public LpMethod()
52 : this(WadlSharpUtils.CreateIdentifier)
53 {
54
55 }
56
57 /// <summary>
58 /// Creates a new instance of the class that will use the passed
59 /// identifier generator.
60 /// </summary>
61 /// <param name="createIdentifier">The identifier generator used to create the names of the methods.</param>
62 public LpMethod(Func<string, string> createIdentifier)
63 {
64 _createIdentifier = createIdentifier;
65 }
66
67 #endregion
68
39 #region Public Methods Exposed by Interface69 #region Public Methods Exposed by Interface
4070
41 public CodeMemberMethod Create(method methodInstance, HashSet<string> nameSpaces, CodeNamespace ns, CodeTypeDeclaration typeDeclaration)71 public CodeMemberMethod Create(method methodInstance, HashSet<string> nameSpaces, CodeNamespace ns, CodeTypeDeclaration typeDeclaration)
42 {72 {
43 // Create am instance of CodeMemberMethod and set it's name73 // Create am instance of CodeMemberMethod and set it's name
44 CodeMemberMethod memberMethod = new CodeMemberMethod();74 CodeMemberMethod memberMethod = new CodeMemberMethod
45 memberMethod.Name = WadlSharpUtils.CreateIdentifier(methodInstance.id);75 {
46 memberMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final;76 Name = _createIdentifier(methodInstance.id),
77 Attributes = MemberAttributes.Public | MemberAttributes.Final
78 };
4779
48 typeDeclarationField = typeDeclaration;80 typeDeclarationField = typeDeclaration;
4981
@@ -110,9 +142,11 @@
110 if (paramSet != null)142 if (paramSet != null)
111 {143 {
112 // Create am instance of CodeMemberMethod and set it's name144 // Create am instance of CodeMemberMethod and set it's name
113 CodeMemberMethod memberMethod = new CodeMemberMethod();145 CodeMemberMethod memberMethod = new CodeMemberMethod
114 memberMethod.Name = WadlSharpUtils.CreateIdentifier(methodInstance.id);146 {
115 memberMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final;147 Name = _createIdentifier(methodInstance.id),
148 Attributes = MemberAttributes.Public | MemberAttributes.Final
149 };
116150
117 typeDeclarationField = typeDeclaration;151 typeDeclarationField = typeDeclaration;
118152
@@ -384,7 +418,7 @@
384418
385 if (s.href != null)419 if (s.href != null)
386 {420 {
387 IReturn ret = new LpReturn();421 IReturn ret = new LpReturn(_createIdentifier);
388422
389 memberMethod.ReturnType.BaseType = ret.Create(s, nameSpaces, ns);423 memberMethod.ReturnType.BaseType = ret.Create(s, nameSpaces, ns);
390 }424 }
391425
=== modified file 'LpNet.WadlSharp.Common/Generator/LpNamespace.cs'
--- LpNet.WadlSharp.Common/Generator/LpNamespace.cs 2010-05-02 07:16:04 +0000
+++ LpNet.WadlSharp.Common/Generator/LpNamespace.cs 2010-09-17 16:11:21 +0000
@@ -25,6 +25,7 @@
25 * OTHER DEALINGS IN THE SOFTWARE.25 * OTHER DEALINGS IN THE SOFTWARE.
26 ********************************************************************/26 ********************************************************************/
2727
28using System;
28using LpNet.WadlSharp.Common.Custom;29using LpNet.WadlSharp.Common.Custom;
2930
30namespace LpNet.WadlSharp.Common.Generator31namespace LpNet.WadlSharp.Common.Generator
@@ -36,6 +37,35 @@
3637
37 public class LpNamespace : INamespace38 public class LpNamespace : INamespace
38 {39 {
40 #region Vars
41
42 private readonly Func<string, string> _createIdentifier;
43
44 #endregion
45
46 #region Constructors
47
48 /// <summary>
49 /// Creates a new instance of the class with the basic identifier generator.
50 /// </summary>
51 public LpNamespace()
52 : this(WadlSharpUtils.CreateIdentifier)
53 {
54
55 }
56
57 /// <summary>
58 /// Creates a new instance of the class that will use the passed
59 /// identifier generator.
60 /// </summary>
61 /// <param name="createIdentifier">The identifier generator used to create the names of the methods.</param>
62 public LpNamespace(Func<string, string> createIdentifier)
63 {
64 _createIdentifier = createIdentifier;
65 }
66
67 #endregion
68
39 #region INamespace Members69 #region INamespace Members
4070
41 public CodeNamespace Create(application app, string namespaceName)71 public CodeNamespace Create(application app, string namespaceName)
@@ -52,7 +82,7 @@
52 {82 {
53 representation_type repType = item as representation_type;83 representation_type repType = item as representation_type;
5484
55 IClass customType = new LpClass();85 IClass customType = new LpClass(_createIdentifier);
56 CodeTypeDeclaration typeDec = customType.Create(repType, namespaces, ns);86 CodeTypeDeclaration typeDec = customType.Create(repType, namespaces, ns);
5787
58 ns.Types.Add(typeDec);88 ns.Types.Add(typeDec);
@@ -61,7 +91,7 @@
61 {91 {
62 resource_type resType = item as resource_type;92 resource_type resType = item as resource_type;
6393
64 IClass customType = new LpClass();94 IClass customType = new LpClass(_createIdentifier);
65 CodeTypeDeclaration typeDec = customType.Create(resType, namespaces, ns);95 CodeTypeDeclaration typeDec = customType.Create(resType, namespaces, ns);
66 96
67 ns.Types.Add(typeDec);97 ns.Types.Add(typeDec);
6898
=== modified file 'LpNet.WadlSharp.Common/Generator/LpProperty.cs'
--- LpNet.WadlSharp.Common/Generator/LpProperty.cs 2010-05-01 21:19:11 +0000
+++ LpNet.WadlSharp.Common/Generator/LpProperty.cs 2010-09-17 16:11:21 +0000
@@ -38,6 +38,31 @@
3838
39 public class LpProperty : IProperty39 public class LpProperty : IProperty
40 {40 {
41 #region Vars
42
43 private readonly Func<string, string> _createIdentifier;
44
45 #endregion
46
47 /// <summary>
48 /// Creates a new instance of the class with the basic identifier generator.
49 /// </summary>
50 public LpProperty()
51 : this(WadlSharpUtils.CreateIdentifier)
52 {
53
54 }
55
56 /// <summary>
57 /// Creates a new instance of the class that will use the passed
58 /// identifier generator.
59 /// </summary>
60 /// <param name="createIdentifier">The identifier generator used to create the names of the methods.</param>
61 public LpProperty(Func<string, string> createIdentifier)
62 {
63 _createIdentifier = createIdentifier;
64 }
65
41 #region IProperty Method66 #region IProperty Method
4267
43 public CodeMemberProperty Create(param propertyInstance, out CodeMemberField memberField, HashSet<string> nameSpaces, CodeNamespace ns, string propertyType)68 public CodeMemberProperty Create(param propertyInstance, out CodeMemberField memberField, HashSet<string> nameSpaces, CodeNamespace ns, string propertyType)
@@ -67,7 +92,7 @@
6792
68 #endregion93 #endregion
6994
70 property.Name = WadlSharpUtils.CreateIdentifier(propertyInstance.name);95 property.Name = _createIdentifier(propertyInstance.name);
71 property.Attributes = MemberAttributes.Public | MemberAttributes.Final;96 property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
72 property.Type = new CodeTypeReference(dataType);97 property.Type = new CodeTypeReference(dataType);
7398
@@ -80,7 +105,8 @@
80 propertyInstance.link.resource_type)))));105 propertyInstance.link.resource_type)))));
81 }106 }
82107
83 string fieldName = string.Format("_{0}", property.Name);108 // always use camelcase for porperties
109 string fieldName = string.Format("_{0}", WadlSharpUtils.CreateCamelCaseIdentifier(propertyInstance.name));
84 property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName)));110 property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName)));
85 property.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName), new CodePropertySetValueReferenceExpression()));111 property.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName), new CodePropertySetValueReferenceExpression()));
86112
87113
=== modified file 'LpNet.WadlSharp.Common/Generator/LpReturn.cs'
--- LpNet.WadlSharp.Common/Generator/LpReturn.cs 2010-04-23 13:16:28 +0000
+++ LpNet.WadlSharp.Common/Generator/LpReturn.cs 2010-09-17 16:11:21 +0000
@@ -26,16 +26,43 @@
26 ********************************************************************/26 ********************************************************************/
2727
2828
29using System;
30using System.Collections.Generic;
31using System.Data;
32using LpNet.WadlSharp.Common.Interface.Generator;
33using LpNet.WadlSharp.Common.Resources;
34using System.CodeDom;
35
29namespace LpNet.WadlSharp.Common.Generator36namespace LpNet.WadlSharp.Common.Generator
30{37{
31 using System.Collections.Generic;38
32 using System.Data;
33 using Interface.Generator;
34 using Resources;
35 using System.CodeDom;
3639
37 public class LpReturn : IReturn40 public class LpReturn : IReturn
38 {41 {
42 #region Vars
43
44 private readonly Func<string, string> _createIdentifier;
45
46 #endregion
47
48 /// <summary>
49 /// Creates a new instance of the class with the basic identifier generator.
50 /// </summary>
51 public LpReturn()
52 : this(WadlSharpUtils.CreateIdentifier)
53 {
54
55 }
56
57 /// <summary>
58 /// Creates a new instance of the class that will use the passed
59 /// identifier generator.
60 /// </summary>
61 /// <param name="createIdentifier">The identifier generator used to create the names of the methods.</param>
62 public LpReturn(Func<string, string> createIdentifier)
63 {
64 _createIdentifier = createIdentifier;
65 }
39 #region IReturn Members66 #region IReturn Members
4067
41 /// <summary>68 /// <summary>
@@ -50,7 +77,7 @@
50 if (hashPos != -1)77 if (hashPos != -1)
51 {78 {
52 string href = repType.href.Substring(hashPos + 1);79 string href = repType.href.Substring(hashPos + 1);
53 href = WadlSharpUtils.CreateIdentifier(href);80 href = _createIdentifier(href);
5481
55 return href;82 return href;
56 }83 }
5784
=== modified file 'LpNet.WadlSharp.Common/Utils.cs'
--- LpNet.WadlSharp.Common/Utils.cs 2010-05-02 07:16:04 +0000
+++ LpNet.WadlSharp.Common/Utils.cs 2010-09-17 16:11:21 +0000
@@ -26,12 +26,12 @@
26 ********************************************************************/26 ********************************************************************/
2727
2828
2929using System.Text;
30using System.Text.RegularExpressions;
31using LpNet.WadlSharp.Common.Enum;
3032
31namespace LpNet.WadlSharp.Common33namespace LpNet.WadlSharp.Common
32{34{
33 using System.Text.RegularExpressions;
34 using Enum;
3535
36 public class WadlSharpUtils36 public class WadlSharpUtils
37 {37 {
@@ -49,6 +49,44 @@
49 return filteredString;49 return filteredString;
50 }50 }
5151
52 public static string CreateCamelCaseIdentifier(string methodCandidate)
53 {
54 var splittedPhrase = methodCandidate.Split(' ', '-', '.', '_');
55 var sb = new StringBuilder();
56
57 sb.Append(splittedPhrase[0].ToLower());
58
59 for (var index = 1; index < splittedPhrase.Length; index++)
60 {
61 var s = splittedPhrase[index];
62 var splittedPhraseChars = s.ToCharArray();
63 if (splittedPhraseChars.Length > 0)
64 {
65 splittedPhraseChars[0] = ((new string(splittedPhraseChars[0], 1)).ToUpper().ToCharArray())[0];
66 }
67 sb.Append(new string(splittedPhraseChars));
68 }
69
70 return sb.ToString();
71 }
72
73 public static string CreatePascalCaseIdentifier(string methodCandidate)
74 {
75 var splittedCancidate = methodCandidate.Split(' ', '-', '.', '_');
76 var sb = new StringBuilder();
77 foreach (var currentNamePart in splittedCancidate)
78 {
79 var splittedPhraseChars = currentNamePart.ToCharArray();
80 if (splittedPhraseChars.Length > 0)
81 {
82 splittedPhraseChars[0] = ((new string(splittedPhraseChars[0], 1)).ToUpper().ToCharArray())[0];
83 }
84 sb.Append(new string(splittedPhraseChars));
85 }
86
87 return sb.ToString();
88 }
89
52 public static string FilterComments(string commentString)90 public static string FilterComments(string commentString)
53 {91 {
54 string filteredText = commentString.Replace("\n", "");92 string filteredText = commentString.Replace("\n", "");
@@ -83,7 +121,7 @@
83121
84 public static HttpMethodType ParseHttpMethod(string methodName)122 public static HttpMethodType ParseHttpMethod(string methodName)
85 {123 {
86 HttpMethodType method = (HttpMethodType)System.Enum.Parse(typeof (HttpMethodType), methodName);124 HttpMethodType method = (HttpMethodType)System.Enum.Parse(typeof(HttpMethodType), methodName);
87125
88 return method;126 return method;
89 }127 }
90128
=== modified file 'LpNet.WadlSharp.Common/WadlConverter.cs'
--- LpNet.WadlSharp.Common/WadlConverter.cs 2010-09-17 11:19:00 +0000
+++ LpNet.WadlSharp.Common/WadlConverter.cs 2010-09-17 16:11:21 +0000
@@ -26,6 +26,8 @@
26 ********************************************************************/26 ********************************************************************/
2727
2828
29using System;
30
29namespace LpNet.WadlSharp.Common31namespace LpNet.WadlSharp.Common
30{32{
31 using Interface;33 using Interface;
@@ -40,6 +42,35 @@
4042
41 public class WadlConverter :IConverter43 public class WadlConverter :IConverter
42 {44 {
45 #region Vars
46
47 private readonly Func<string, string> _createIdentifier;
48
49 #endregion
50
51 #region Constructors
52
53 /// <summary>
54 /// Creates a new instance of the class with the basic identifier generator.
55 /// </summary>
56 public WadlConverter()
57 : this(WadlSharpUtils.CreateIdentifier)
58 {
59
60 }
61
62 /// <summary>
63 /// Creates a new instance of the class that will use the passed
64 /// identifier generator.
65 /// </summary>
66 /// <param name="createIdentifier">The identifier generator used to create the names of the methods.</param>
67 public WadlConverter(Func<string, string> createIdentifier)
68 {
69 _createIdentifier = createIdentifier;
70 }
71
72 #endregion
73
43 #region IConverter Members74 #region IConverter Members
4475
45 public void Convert(string inputFileName, string outputFileName, string rootNamespace)76 public void Convert(string inputFileName, string outputFileName, string rootNamespace)
@@ -60,7 +91,7 @@
6091
61 #region Create the Code File's DOM92 #region Create the Code File's DOM
6293
63 INamespace nsp = new LpNamespace();94 INamespace nsp = new LpNamespace(_createIdentifier);
64 CodeNamespace nameSpace = nsp.Create(app, rootNamespace);95 CodeNamespace nameSpace = nsp.Create(app, rootNamespace);
6596
66 #endregion97 #endregion
6798
=== modified file 'WadlConsole/Program.cs'
--- WadlConsole/Program.cs 2010-09-17 16:11:21 +0000
+++ WadlConsole/Program.cs 2010-09-17 16:11:21 +0000
@@ -77,9 +77,18 @@
77 /// <param name="outputFileName">The filename of the .cs file. If the file does not exist, 77 /// <param name="outputFileName">The filename of the .cs file. If the file does not exist,
78 /// it would be created. If it does exist, it would be truncated and then overwritten.</param>78 /// it would be created. If it does exist, it would be truncated and then overwritten.</param>
79 /// <param name="rootNamespace">The name of the namespace which you would like the generated code to have.</param>79 /// <param name="rootNamespace">The name of the namespace which you would like the generated code to have.</param>
80 private static void GenerateCode(string inputFileName, string outputFileName, string rootNamespace)80 /// <param name="fixCase">A flag that states if the case of the generated code should be fixed.</param>
81 private static void GenerateCode(string inputFileName, string outputFileName, string rootNamespace, bool fixCase)
81 {82 {
82 var converter = new WadlConverter();83 WadlConverter converter;
84 if(fixCase)
85 {
86 converter = new WadlConverter(WadlSharpUtils.CreatePascalCaseIdentifier);
87 }
88 else
89 {
90 converter = new WadlConverter();
91 }
83 converter.Convert(inputFileName, outputFileName, rootNamespace);92 converter.Convert(inputFileName, outputFileName, rootNamespace);
84 }93 }
8594
@@ -91,14 +100,16 @@
91 var outputFile = "";100 var outputFile = "";
92 var rootNamespace = "";101 var rootNamespace = "";
93 var input = "";102 var input = "";
94 var help = false;103 var help = false;
104 var fixCase = false;
95105
96 // create the option set that will provide the diff options106 // create the option set that will provide the diff options
97 // of the command line107 // of the command line
98 var options = new OptionSet108 var options = new OptionSet
99 {109 {
100 { "i|input=", Resources.InputDescription, v => input = v },110 { "i|input=", Resources.InputDescription, v => input = v },
101 { "u|url", Resources.UrlDescription, v=> isFile = false },111 { "u|url", Resources.UrlDescription, v => isFile = false },
112 { "c|fixCase", Resources.FixCaseDescription, v => fixCase = v != null },
102 { "o|output=", Resources.OutputDescription, v=> outputFile = v },113 { "o|output=", Resources.OutputDescription, v=> outputFile = v },
103 { "n|namespace=", Resources.NamespaceDescription, v=> rootNamespace = v },114 { "n|namespace=", Resources.NamespaceDescription, v=> rootNamespace = v },
104 { "h|?|help", Resources.HelpDescription, v => help = v != null },115 { "h|?|help", Resources.HelpDescription, v => help = v != null },
@@ -143,7 +154,7 @@
143 }154 }
144155
145 // eveyhthin is ok, therefore we generate the code156 // eveyhthin is ok, therefore we generate the code
146 GenerateCode(input, outputFile, rootNamespace);157 GenerateCode(input, outputFile, rootNamespace, fixCase);
147 Console.WriteLine(Resources.Completed);158 Console.WriteLine(Resources.Completed);
148 }159 }
149 }160 }
150161
=== modified file 'WadlConsole/Resources.Designer.cs'
--- WadlConsole/Resources.Designer.cs 2010-09-17 16:11:21 +0000
+++ WadlConsole/Resources.Designer.cs 2010-09-17 16:11:21 +0000
@@ -70,6 +70,15 @@
70 }70 }
71 71
72 /// <summary>72 /// <summary>
73 /// Looks up a localized string similar to A boolean flag stating if the case of the generated code should be fixed..
74 /// </summary>
75 internal static string FixCaseDescription {
76 get {
77 return ResourceManager.GetString("FixCaseDescription", resourceCulture);
78 }
79 }
80
81 /// <summary>
73 /// Looks up a localized string similar to Usage: wadl-sharp [OPTIONS]82 /// Looks up a localized string similar to Usage: wadl-sharp [OPTIONS]
74 ///83 ///
75 ///Generates the C# code required to communicate with a wadl service.84 ///Generates the C# code required to communicate with a wadl service.
@@ -109,7 +118,7 @@
109 }118 }
110 119
111 /// <summary>120 /// <summary>
112 /// Looks up a localized string similar to The fiilename of the .cs file to be generated. If the file does not exist, it would be created. If it does exist, it would be truncated and then overwritten..121 /// Looks up a localized string similar to The filename of the .cs file to be generated. If the file does not exist, it would be created. If it does exist, it would be truncated and then overwritten..
113 /// </summary>122 /// </summary>
114 internal static string OutputDescription {123 internal static string OutputDescription {
115 get {124 get {
116125
=== modified file 'WadlConsole/Resources.resx'
--- WadlConsole/Resources.resx 2010-09-17 16:11:21 +0000
+++ WadlConsole/Resources.resx 2010-09-17 16:11:21 +0000
@@ -120,6 +120,9 @@
120 <data name="Completed" xml:space="preserve">120 <data name="Completed" xml:space="preserve">
121 <value>Generation completed.</value>121 <value>Generation completed.</value>
122 </data>122 </data>
123 <data name="FixCaseDescription" xml:space="preserve">
124 <value>A boolean flag stating if the case of the generated code should be fixed.</value>
125 </data>
123 <data name="Help" xml:space="preserve">126 <data name="Help" xml:space="preserve">
124 <value>Usage: wadl-sharp [OPTIONS]127 <value>Usage: wadl-sharp [OPTIONS]
125128
@@ -136,7 +139,7 @@
136 <value>The name of the namespace which you would like the generated code to have.</value>139 <value>The name of the namespace which you would like the generated code to have.</value>
137 </data>140 </data>
138 <data name="OutputDescription" xml:space="preserve">141 <data name="OutputDescription" xml:space="preserve">
139 <value>The fiilename of the .cs file to be generated. If the file does not exist, it would be created. If it does exist, it would be truncated and then overwritten.</value>142 <value>The filename of the .cs file to be generated. If the file does not exist, it would be created. If it does exist, it would be truncated and then overwritten.</value>
140 </data>143 </data>
141 <data name="TryHelp" xml:space="preserve">144 <data name="TryHelp" xml:space="preserve">
142 <value>Try `wadl-sharp --help' for more information.</value>145 <value>Try `wadl-sharp --help' for more information.</value>

Subscribers

People subscribed via source and target branches