Skip to content

Commit 0912c25

Browse files
fixes for 1.2.2 release
- Visual Studio-friendly warning and error messages - Extracting types information from .exe assemblies - Initialization expression for fields AST - Assembly signing
1 parent 883e2a9 commit 0912c25

35 files changed

+614
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,4 @@ FakesAssemblies/
203203
*.opt
204204
Playground/
205205
/Reinforced.Typings.Private.sln
206+
/Reinforced.Typings/Reinforced.Typings.pfx

Reinforced.Typings.Cli/Bootstrapper.cs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Reflection;
7+
using Reinforced.Typings.Exceptions;
78
using Reinforced.Typings.Fluent;
89

910
namespace Reinforced.Typings.Cli
@@ -40,14 +41,25 @@ public static void Main(string[] args)
4041
Console.WriteLine("No valid parameters found. Exiting.");
4142
Environment.Exit(0);
4243
}
43-
var settings = InstantiateExportSettings();
44+
var settings = InstantiateExportContext();
4445
ResolveFluentMethod(settings);
4546
TsExporter exporter = new TsExporter(settings);
4647
exporter.Export();
48+
foreach (var rtWarning in settings.Warnings)
49+
{
50+
var msg = VisualStudioFriendlyErrorMessage.Create(rtWarning);
51+
Console.WriteLine(msg.ToString());
52+
}
53+
}
54+
catch (RtException rtException)
55+
{
56+
var error = VisualStudioFriendlyErrorMessage.Create(rtException);
57+
Console.WriteLine(error.ToString());
58+
Environment.Exit(1);
4759
}
4860
catch (Exception ex)
4961
{
50-
Console.WriteLine(ex.ToString());
62+
BuildError(ex.Message);
5163
Environment.Exit(1);
5264
}
5365

@@ -84,7 +96,7 @@ private static void ResolveFluentMethod(ExportContext context)
8496
}
8597
}
8698

87-
public static ExportContext InstantiateExportSettings()
99+
public static ExportContext InstantiateExportContext()
88100
{
89101
ExportContext context = new ExportContext
90102
{
@@ -114,7 +126,8 @@ public static void BuildReferencesCache()
114126

115127
public static string LookupAssemblyPath(string assemblyNameOrFullPath, bool storeIfFullName = true)
116128
{
117-
if (!assemblyNameOrFullPath.EndsWith(".dll")) assemblyNameOrFullPath = assemblyNameOrFullPath + ".dll";
129+
if (!assemblyNameOrFullPath.EndsWith(".dll") && !assemblyNameOrFullPath.EndsWith(".exe"))
130+
assemblyNameOrFullPath = assemblyNameOrFullPath + ".dll";
118131
#if DEBUG
119132
Console.WriteLine("Looking up for assembly {0}", assemblyNameOrFullPath);
120133
#endif
@@ -148,7 +161,8 @@ public static string LookupAssemblyPath(string assemblyNameOrFullPath, bool stor
148161
return p;
149162
}
150163

151-
Console.WriteLine("Warning! Probably assembly {0} not found", assemblyNameOrFullPath, p);
164+
BuildWarn("Assembly {0} may be resolved incorrectly", assemblyNameOrFullPath, p);
165+
152166
return assemblyNameOrFullPath;
153167
}
154168

@@ -224,6 +238,20 @@ public static void PrintHelp()
224238
}
225239
}
226240

241+
private static void BuildWarn(string message, params object[] args)
242+
{
243+
var warningMessage = string.Format(message, args);
244+
VisualStudioFriendlyErrorMessage vsm = new VisualStudioFriendlyErrorMessage(99, warningMessage, VisualStudioFriendlyMessageType.Warning, "Build");
245+
Console.WriteLine(vsm.ToString());
246+
}
247+
248+
private static void BuildError(string message, params object[] args)
249+
{
250+
var errorMessage = string.Format(message, args);
251+
VisualStudioFriendlyErrorMessage vsm = new VisualStudioFriendlyErrorMessage(999, errorMessage, VisualStudioFriendlyMessageType.Error, "Unexpected");
252+
Console.WriteLine(vsm.ToString());
253+
}
254+
227255
public static ExporterConsoleParameters ExtractParametersFromArgs(string[] args)
228256
{
229257
var t = typeof(ExporterConsoleParameters);
@@ -234,7 +262,7 @@ public static ExporterConsoleParameters ExtractParametersFromArgs(string[] args)
234262
var kv = trimmed.Split('=');
235263
if (kv.Length != 2)
236264
{
237-
Console.WriteLine("Unrecognized parameter: {0}", s);
265+
BuildWarn("Unrecognized parameter: {0}", s);
238266
continue;
239267
}
240268

@@ -244,7 +272,7 @@ public static ExporterConsoleParameters ExtractParametersFromArgs(string[] args)
244272
var prop = t.GetProperty(key);
245273
if (prop == null)
246274
{
247-
Console.WriteLine("Unrecognized parameter: {0}", key);
275+
BuildWarn("Unrecognized parameter: {0}", key);
248276
continue;
249277
}
250278

@@ -268,7 +296,7 @@ public static ExporterConsoleParameters ExtractParametersFromArgs(string[] args)
268296
continue;
269297
}
270298

271-
Console.WriteLine("Cannot parse parameter for source property {0}", key);
299+
BuildWarn("Cannot parse parameter for source property {0}", key);
272300
}
273301

274302
try
@@ -277,7 +305,7 @@ public static ExporterConsoleParameters ExtractParametersFromArgs(string[] args)
277305
}
278306
catch (Exception ex)
279307
{
280-
Console.WriteLine("Parameters validation error: {0}", ex.Message);
308+
BuildError("Parameters validation error: {0}", ex.Message);
281309
PrintHelp();
282310
return null;
283311
}

Reinforced.Typings.Cli/Reinforced.Typings.Cli.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
<ItemGroup>
4747
<Compile Include="Bootstrapper.cs" />
4848
<Compile Include="ConsoleHelpAttribute.cs" />
49+
<Compile Include="VisualStudioFriendlyMessageType.cs" />
4950
<Compile Include="ExporterConsoleParameters.cs" />
5051
<Compile Include="Properties\AssemblyInfo.cs" />
52+
<Compile Include="VisualStudioFriendlyErrorMessage.cs" />
5153
</ItemGroup>
5254
<ItemGroup>
5355
<None Include="App.config" />
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Reinforced.Typings.Exceptions;
2+
3+
namespace Reinforced.Typings.Cli
4+
{
5+
/// <summary>
6+
/// Class that formats messages in appropriate way to be shown at
7+
/// VisualStudio's errors list
8+
///
9+
/// Explanation is taken from here:
10+
/// http://blogs.msdn.com/b/msbuild/archive/2006/11/03/msbuild-visual-studio-aware-error-messages-and-message-formats.aspx
11+
/// </summary>
12+
class VisualStudioFriendlyErrorMessage
13+
{
14+
public string Origin { get { return "Reinforced.Typings"; } }
15+
16+
public string Subcategory { get; set; }
17+
18+
public VisualStudioFriendlyMessageType Type { get; set; }
19+
20+
public int Code { get; set; }
21+
22+
public string CodeName { get { return string.Format("RT{0:0000}", Code); } }
23+
24+
public string ErrorText { get; set; }
25+
26+
public VisualStudioFriendlyErrorMessage(int code, string errorText, VisualStudioFriendlyMessageType type, string subcategory = "")
27+
{
28+
Code = code;
29+
ErrorText = errorText;
30+
Subcategory = subcategory;
31+
Type = type;
32+
}
33+
34+
public override string ToString()
35+
{
36+
return string.Format("{0} : {1} {2} {3}: {4}", Origin, Subcategory, Type == VisualStudioFriendlyMessageType.Error ? "error" : "warning", CodeName, ErrorText);
37+
}
38+
39+
public static VisualStudioFriendlyErrorMessage Create(RtWarning warning)
40+
{
41+
return new VisualStudioFriendlyErrorMessage(warning.Code,warning.Text,VisualStudioFriendlyMessageType.Warning,warning.Subcategory);
42+
}
43+
44+
public static VisualStudioFriendlyErrorMessage Create(RtException error)
45+
{
46+
return new VisualStudioFriendlyErrorMessage(error.Code, error.Message, VisualStudioFriendlyMessageType.Error, error.Subcategory);
47+
}
48+
}
49+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Reinforced.Typings.Cli
8+
{
9+
public enum VisualStudioFriendlyMessageType
10+
{
11+
Error,
12+
Warning
13+
}
14+
}

Reinforced.Typings/Ast/RtField.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public class RtField : RtMember
1717
/// </summary>
1818
public RtTypeName Type { get; set; }
1919

20+
/// <summary>
21+
/// TypeScript expression to initialize field
22+
/// </summary>
23+
public string InitializationExpression { get; set; }
24+
2025
/// <summary>
2126
/// Child nodes
2227
/// </summary>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Reinforced.Typings.Exceptions
8+
{
9+
class ErrorMessage
10+
{
11+
public int Code { get; private set; }
12+
13+
public string MessageText { get; private set; }
14+
15+
public string Subcategory { get; private set; }
16+
17+
public ErrorMessage(int code, string messageText, string subcategory = "")
18+
{
19+
Code = code;
20+
MessageText = messageText;
21+
Subcategory = subcategory;
22+
}
23+
24+
public void Throw(params object[] formatParameters)
25+
{
26+
throw new RtException(string.Format(MessageText, formatParameters), Code, Subcategory);
27+
}
28+
29+
public RtWarning Warn(params object[] formatParameters)
30+
{
31+
return new RtWarning(Code, text: string.Format(MessageText, formatParameters), subcategory: Subcategory);
32+
}
33+
}
34+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Reinforced.Typings.Exceptions
8+
{
9+
/// <summary>
10+
/// This class contains all RT's error and siagnostic messages.
11+
/// Why didnt I use resources? I dont want to add one more .dll to RT's NuGet package.
12+
/// if localization will be required through issues then I will add one
13+
/// </summary>
14+
class ErrorMessages
15+
{
16+
#region Errors
17+
/// <summary>
18+
/// Could not acuire temorary file {0}: {1}
19+
/// </summary>
20+
public static readonly ErrorMessage RTE0001_TempFileError = new ErrorMessage(0001,"Could not acuire temorary file {0}: {1}","IO");
21+
22+
/// <summary>
23+
/// Could not replace source file {0}: {1}
24+
/// </summary>
25+
public static readonly ErrorMessage RTE0002_DeployingFilesError = new ErrorMessage(0002,"Could not replace source file {0}: {1}","IO");
26+
27+
/// <summary>
28+
/// Could not instantiate code generator {0}: {1}
29+
/// </summary>
30+
public static readonly ErrorMessage RTE0003_GeneratorInstantiate = new ErrorMessage(0003,"Could not instantiate code generator {0}: {1}","Code generation");
31+
32+
/// <summary>
33+
/// Code generator {0} has thrown an error: {1}
34+
/// </summary>
35+
public static readonly ErrorMessage RTE0004_GeneratorError = new ErrorMessage(0004,"Code generator {0} has thrown an error: {1}","Code generation");
36+
37+
/// <summary>
38+
/// Could not resolve type for {0}. An error occured: {1}
39+
/// </summary>
40+
public static readonly ErrorMessage RTE0005_TypeResolvationError = new ErrorMessage(0005, "Could not resolve type for {0}. An error occured: {1}", "Type resolvation");
41+
42+
/// <summary>
43+
/// Exception thrown when applying fluent configuration method for {1} '{2}': {0}
44+
/// </summary>
45+
public static readonly ErrorMessage RTE0006_FluentSingleError = new ErrorMessage(0006, "Exception thrown when applying fluent configuration method for {1} '{2}': {0}", "Fluent configuration");
46+
47+
/// <summary>
48+
/// Exception thrown when applying fluent configuration method for collection of {1}: {0}
49+
/// </summary>
50+
public static readonly ErrorMessage RTE0007_FluentBatchError = new ErrorMessage(0007, "Exception thrown when applying fluent configuration method for collection of {1}: {0}", "Fluent configuration");
51+
52+
/// <summary>
53+
/// MethodCallExpression should be provided for .WithMethod call. Please use only lamba expressions in this place.
54+
/// </summary>
55+
public static readonly ErrorMessage RTE0008_FluentWithMethodError = new ErrorMessage(0008, "MethodCallExpression should be provided for .WithMethod call. Please use only lamba expressions in this place.", "Fluent configuration");
56+
57+
58+
/// <summary>
59+
/// Sorry, but {0} is not very good idea for parameter configuration. Try using simplier lambda expression.
60+
/// </summary>
61+
public static readonly ErrorMessage RTE0009_FluentWithMethodCouldNotParse = new ErrorMessage(0009, "Sorry, but {0} is not very good idea for parameter configuration. Try using simplier lambda expression.", "Fluent configuration");
62+
63+
/// <summary>
64+
/// Property lambda expression expected in {0}
65+
/// </summary>
66+
public static readonly ErrorMessage RTE0010_PropertyLambdaExpected = new ErrorMessage(0010, "Property lambda expression expected in {0}", "Fluent configuration");
67+
68+
/// <summary>
69+
/// Field lambda expression expected in {0}
70+
/// </summary>
71+
public static readonly ErrorMessage RTE0011_FieldLambdaExpected = new ErrorMessage(0011, "Field lambda expression expected in {0}", "Fluent configuration");
72+
73+
/// <summary>
74+
/// NewExpression should be provided for .WithConstructor call. Please use only lamba expressions in this place.
75+
/// </summary>
76+
public static readonly ErrorMessage RTE0012_NewExpressionLambdaExpected = new ErrorMessage(0012, "NewExpression should be provided for .WithConstructor call. Please use only 'new ...' lamba expressions in this place.", "Fluent configuration");
77+
#endregion
78+
79+
#region Warnings
80+
/// <summary>
81+
/// XMLDOC file not supplied
82+
/// </summary>
83+
public static readonly ErrorMessage RTW0001_DocumentationNotSupplied = new ErrorMessage(0001, "XMLDOC file not supplied", "JSDOC");
84+
85+
/// <summary>
86+
/// Could not find XMLDOC file {0}
87+
/// </summary>
88+
public static readonly ErrorMessage RTW0002_DocumentationNotFound = new ErrorMessage(0002, "Could not find XMLDOC file {0}", "JSDOC");
89+
90+
/// <summary>
91+
/// Could not find suitable TypeScript type for {0}. 'any' assumed.
92+
/// </summary>
93+
public static readonly ErrorMessage RTW0003_TypeUnknown = new ErrorMessage(0003, "Could not find suitable TypeScript type for {0}. 'any' assumed.", "Type resolvation");
94+
95+
/// <summary>
96+
/// No suitable base constructor found for {0}. Generating 'super' call with all nulls.
97+
/// </summary>
98+
public static readonly ErrorMessage RTW0004_DefaultSuperCall = new ErrorMessage(0004, "No suitable base constructor found for {0}. Generating 'super' call with all nulls.", "Class code generation");
99+
100+
/// <summary>
101+
/// Class {0} (base for {1}) is exported as interface. It is potentially unsafe facility.
102+
/// </summary>
103+
public static readonly ErrorMessage RTW0005_BaseClassExportingAsInterface = new ErrorMessage(0005, "Class {0} (base for {1}) is exported as interface. It is potentially unsafe facility.", "Class code generation");
104+
105+
#endregion
106+
}
107+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Reinforced.Typings.Exceptions
8+
{
9+
/// <summary>
10+
/// Base class for RT exception.
11+
/// All the RT exceptions will be provided to VisualStudio's errors tab
12+
/// </summary>
13+
public class RtException : Exception
14+
{
15+
/// <summary>
16+
/// Internal error code
17+
/// </summary>
18+
public int Code { get; private set; }
19+
20+
/// <summary>
21+
/// Error subcategory
22+
/// </summary>
23+
public string Subcategory { get; private set; }
24+
25+
/// <summary>
26+
/// Constructs new RT exception
27+
/// </summary>
28+
/// <param name="message">Error message</param>
29+
/// <param name="code">Error code</param>
30+
/// <param name="subcategory">Error subcategory (optional)</param>
31+
public RtException(string message, int code, string subcategory = "") : base(message)
32+
{
33+
Code = code;
34+
Subcategory = subcategory;
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)