Skip to content

Commit 28dff7f

Browse files
committed
Merge branch 'release/1.0.1' into production
2 parents b09294c + 58b563a commit 28dff7f

27 files changed

Lines changed: 759 additions & 170 deletions

.appveyor.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '{branch}-{build}'
2+
init:
3+
- cmd: git config --global core.autocrlf true
4+
before_build:
5+
- cmd: nuget restore
6+
build:
7+
verbosity: minimal

CSF.Zpt.MVC5/CSF.Zpt.MVC5.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="Rendering\MvcRenderingContextFactory.cs" />
125125
<Compile Include="IZptViewEngineConfiguration.cs" />
126126
<Compile Include="ZptViewEngineConfigurationSection.cs" />
127+
<Compile Include="ErrorPageRenderer.cs" />
127128
</ItemGroup>
128129
<ItemGroup>
129130
<None Include="packages.config" />
@@ -140,6 +141,9 @@
140141
<LogicalName>ExceptionMessages.resx</LogicalName>
141142
<LastGenOutput>ExceptionMessages.Designer.cs</LastGenOutput>
142143
</EmbeddedResource>
144+
<EmbeddedResource Include="Resources\ZptErrorPage.pt">
145+
<LogicalName>ZptErrorPage.pt</LogicalName>
146+
</EmbeddedResource>
143147
</ItemGroup>
144148
<Target Name="BeforeBuild">
145149
<CallTarget Targets="StampAssemblyInfo" />

CSF.Zpt.MVC5/ErrorPageRenderer.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
5+
namespace CSF.Zpt.MVC
6+
{
7+
public class ErrorPageRenderer
8+
{
9+
const string ErrorPageResourceName = "ZptErrorPage.pt";
10+
readonly IZptDocumentFactory factory;
11+
12+
public void Render(TextWriter writer, Exception ex)
13+
{
14+
var template = GetTemplate();
15+
var model = GetModel(ex);
16+
17+
template.Render(model, writer);
18+
}
19+
20+
ErrorModel GetModel(Exception ex)
21+
{
22+
return new ErrorModel
23+
{
24+
Exception = ex,
25+
ZptVersion = Assembly.GetAssembly(typeof(ZptDocument)).GetName().Version.ToSemanticVersion(),
26+
ZptMvcVersion = Assembly.GetExecutingAssembly().GetName().Version.ToSemanticVersion(),
27+
};
28+
}
29+
30+
IZptDocument GetTemplate()
31+
{
32+
var thisAssembly = Assembly.GetExecutingAssembly();
33+
using(var page = thisAssembly.GetManifestResourceStream(ErrorPageResourceName))
34+
{
35+
return factory.CreateDocument(page, RenderingMode.Html);
36+
}
37+
}
38+
39+
internal class ErrorModel
40+
{
41+
public Exception Exception { get; set; }
42+
43+
public string ZptVersion { get; set; }
44+
45+
public string ZptMvcVersion { get; set; }
46+
}
47+
48+
public ErrorPageRenderer()
49+
{
50+
factory = new ZptDocumentFactory();
51+
}
52+
}
53+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>ZPT Error</title>
6+
<style>
7+
body {
8+
margin: 0;
9+
padding: 1em;
10+
font-family: sans-serif;
11+
line-height: 140%;
12+
}
13+
body>header {
14+
border-bottom: 1px solid #DAA;
15+
padding: 0 0 0.8em;
16+
margin: 0 0 1em;
17+
}
18+
h1 {
19+
margin: 0;
20+
color: #600;
21+
font-size: 250%;
22+
line-height: 100%;
23+
}
24+
p {
25+
margin: 0 0 0.4em;
26+
}
27+
.user_message {
28+
font-size: 110%;
29+
line-height: 140%;
30+
font-style: italic;
31+
margin: 2em 0 3em;
32+
}
33+
.tech_info {
34+
background: #F0F0F0;
35+
padding: 1em;
36+
}
37+
h2 {
38+
margin: 0 0 1em;
39+
}
40+
h3 {
41+
white-space: pre-line;
42+
font-size: 110%;
43+
font-style: italic;
44+
color: #600;
45+
line-height: 140%;
46+
}
47+
pre {
48+
padding: 0.4em;
49+
border: 1px solid #DAA;
50+
background: #FFFFF0;
51+
line-height: 110%;
52+
overflow: auto;
53+
max-height: 30em;
54+
}
55+
body>footer {
56+
border-top: 1px solid #DAA;
57+
padding: 0.8em 0 0;
58+
margin: 1em 0 0;
59+
font-size: 90%;
60+
}
61+
</style>
62+
</head>
63+
<body>
64+
<header><h1>ZPT rendering error</h1></header>
65+
<p class="user_message">
66+
Sorry, but an unexpected error occurred whilst getting the web page you requested.
67+
</p>
68+
<section class="tech_info">
69+
<header><h2>Technical information</h2></header>
70+
<p>
71+
Following is technical data about the nature of the error.
72+
If you are filing a bug report with the owner of the website or application,
73+
please consider including this information.
74+
</p>
75+
<h3 tal:content="here/Exception/Message">Unexpected exception whilst rendering a ZPT document as an MVC view.</h3>
76+
<pre tal:content="here/Exception">Exception stack trace
77+
which may occupy
78+
many lines</pre>
79+
</section>
80+
<footer>
81+
<div>
82+
ZPT-Sharp: v<span tal:replace="here/ZptVersion">v1.0.0</span>
83+
</div>
84+
<div>
85+
ZPT-Sharp MVC: v<span tal:replace="here/ZptMvcVersion">v1.0.0</span>
86+
</div>
87+
</footer>
88+
</body>
89+
</html>

CSF.Zpt.MVC5/ZptView.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,19 @@ public System.Text.Encoding ForceInputEncoding
5454
public void Render(ViewContext viewContext, TextWriter writer)
5555
{
5656
var doc = CreateDocument();
57-
doc.Render(writer,
58-
contextConfigurator: ConfigureContext(viewContext),
59-
options: RenderingOptions);
57+
try
58+
{
59+
doc.Render(writer,
60+
contextConfigurator: ConfigureContext(viewContext),
61+
options: RenderingOptions);
62+
}
63+
catch(ZptException ex)
64+
{
65+
var errorPage = new ErrorPageRenderer();
66+
errorPage.Render(writer, ex);
67+
viewContext.HttpContext.Response.StatusCode = (int) System.Net.HttpStatusCode.InternalServerError;
68+
viewContext.HttpContext.Response.StatusDescription = "Internal server error";
69+
}
6070
}
6171

6272
private Action<IModelValueContainer> ConfigureContext(ViewContext viewContext)

CSF.Zpt/CSF.Zpt.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<DependentUpon>SourceAnnotationFormats.resx</DependentUpon>
153153
</Compile>
154154
<Compile Include="DefaultAddOnAssemblyFinder.cs" />
155+
<Compile Include="Metal\DuplicateMacroException.cs" />
155156
</ItemGroup>
156157
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
157158
<ItemGroup>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
namespace CSF.Zpt.Metal
3+
{
4+
/// <summary>
5+
/// Exception raised when there are duplicate METAL macros found within a document.
6+
/// </summary>
7+
[System.Serializable]
8+
public class DuplicateMacroException : Exception
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="T:DuplicateMacroException"/> class
12+
/// </summary>
13+
public DuplicateMacroException()
14+
{
15+
}
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="T:DuplicateMacroException"/> class
19+
/// </summary>
20+
/// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param>
21+
public DuplicateMacroException(string message) : base(message)
22+
{
23+
}
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="T:DuplicateMacroException"/> class
27+
/// </summary>
28+
/// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param>
29+
/// <param name="inner">The exception that is the cause of the current exception. </param>
30+
public DuplicateMacroException(string message, Exception inner) : base(message, inner)
31+
{
32+
}
33+
34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="T:DuplicateMacroException"/> class
36+
/// </summary>
37+
/// <param name="context">The contextual information about the source or destination.</param>
38+
/// <param name="info">The object that holds the serialized object data.</param>
39+
protected DuplicateMacroException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
40+
{
41+
}
42+
}
43+
}

CSF.Zpt/Metal/MacroExpander.cs

Lines changed: 0 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -174,149 +174,6 @@ public IRenderingContext GetFullyExtendedContext(IRenderingContext macroContext,
174174
return ExtendAndSubstitute(macroContext, extendedMacro, ref macroStack, _extensionSubstitutor);
175175
}
176176

177-
178-
179-
180-
181-
182-
183-
184-
185-
186-
187-
188-
189-
//
190-
// /// <summary>
191-
// /// Expands the given macro and uses it to replace the element exposed by the given context.
192-
// /// </summary>
193-
// /// <param name="context">The context to expand.</param>
194-
// /// <param name="macro">The macro element to replace the original.</param>
195-
// public virtual IRenderingContext ExpandAndReplace(IRenderingContext context, IZptElement macro)
196-
// {
197-
// if(context == null)
198-
// {
199-
// throw new ArgumentNullException(nameof(context));
200-
// }
201-
// if(macro == null)
202-
// {
203-
// throw new ArgumentNullException(nameof(macro));
204-
// }
205-
// if(macro.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute) == null)
206-
// {
207-
// string message = String.Format(ExceptionMessages.MetalMacroMustBeDefined,
208-
// ZptConstants.Metal.DefineMacroAttribute,
209-
// ZptConstants.Metal.Namespace);
210-
// throw new ArgumentException(message, "macro");
211-
// }
212-
//
213-
// var macroContext = context.CreateSiblingContext(macro);
214-
//
215-
// macroContext = this.ApplyMacroExtension(macroContext);
216-
// var extendedMacro = context.Element.ReplaceWith(macroContext.Element);
217-
//
218-
// this.FillSlots(context, extendedMacro);
219-
//
220-
// return context.CreateSiblingContext(extendedMacro);
221-
// }
222-
//
223-
// /// <summary>
224-
// /// Fills slots defined in the <paramref name="macro"/> with content defined in the <paramref name="sourceContext"/>.
225-
// /// </summary>
226-
// /// <param name="sourceContext">Source rendering context.</param>
227-
// /// <param name="macro">The macro providing the slots to fill.</param>
228-
// private void FillSlots(IRenderingContext sourceContext, IZptElement macro)
229-
// {
230-
// if(sourceContext == null)
231-
// {
232-
// throw new ArgumentNullException(nameof(sourceContext));
233-
// }
234-
// if(macro == null)
235-
// {
236-
// throw new ArgumentNullException(nameof(macro));
237-
// }
238-
//
239-
// var slotsToHandle = (from defineSlot in this.GetElementsByValue(macro, ZptConstants.Metal.DefineSlotAttribute)
240-
// join fillSlot in this.GetElementsByValue(sourceContext.Element, ZptConstants.Metal.FillSlotAttribute)
241-
// on defineSlot.Key equals fillSlot.Key
242-
// select new { Slot = sourceContext.CreateSiblingContext(defineSlot.Value),
243-
// Filler = sourceContext.CreateSiblingContext(fillSlot.Value) });
244-
//
245-
// foreach(var replacement in slotsToHandle)
246-
// {
247-
// var replacementElement = replacement.Slot.Element.ReplaceWith(replacement.Filler.Element);
248-
// var replacementContext = replacement.Filler.CreateSiblingContext(replacementElement);
249-
// _annotator.ProcessAnnotation(replacementContext,
250-
// originalContext: replacement.Slot,
251-
// replacementContext: replacement.Filler);
252-
// LogSlotFilling(replacement.Slot.Element, replacement.Filler.Element);
253-
// }
254-
// }
255-
//
256-
// /// <summary>
257-
// /// Applies METAL macro extension, recursively extending the given macro where applicable.
258-
// /// </summary>
259-
// /// <returns>A rendering context, exposing the METAL macro element, after all required extension has been applied.</returns>
260-
// /// <param name="context">The context exposing the macro element to expand.</param>
261-
// private IRenderingContext ApplyMacroExtension(IRenderingContext context)
262-
// {
263-
// if(context == null)
264-
// {
265-
// throw new ArgumentNullException(nameof(context));
266-
// }
267-
//
268-
// var extended = _macroFinder.GetExtendedMacro(context);
269-
// IRenderingContext output;
270-
//
271-
// if(extended != null)
272-
// {
273-
// LogMacroExtension(context.Element, extended);
274-
// output = ExpandAndReplace(context, extended);
275-
// }
276-
// else
277-
// {
278-
// output = context;
279-
// }
280-
//
281-
// return output;
282-
// }
283-
//
284-
// private void LogMacroUsage(IZptElement defineMacro, IZptElement useMacro)
285-
// {
286-
// ZptConstants.TraceSource.TraceEvent(System.Diagnostics.TraceEventType.Verbose,
287-
// 4,
288-
// Resources.LogMessageFormats.MacroUsage,
289-
// defineMacro.GetMetalAttribute(ZptConstants.Metal.DefineMacroAttribute).Value,
290-
// useMacro.GetFullFilePathAndLocation(),
291-
// defineMacro.GetFullFilePathAndLocation(),
292-
// nameof(MacroExpander),
293-
// nameof(LogMacroUsage));
294-
// }
295-
//
296-
// private void LogMacroExtension(IZptElement defineMacro, IZptElement extendedMacro)
297-
// {
298-
// ZptConstants.TraceSource.TraceEvent(System.Diagnostics.TraceEventType.Verbose,
299-
// 4,
300-
// Resources.LogMessageFormats.MacroExtension,
301-
// defineMacro.GetMetalAttribute(ZptConstants.Metal.ExtendMacroAttribute).Value,
302-
// extendedMacro.GetFullFilePathAndLocation(),
303-
// defineMacro.GetFullFilePathAndLocation(),
304-
// nameof(MacroExpander),
305-
// nameof(LogMacroExtension));
306-
// }
307-
//
308-
// private void LogSlotFilling(IZptElement defineSlot, IZptElement fillSlot)
309-
// {
310-
// ZptConstants.TraceSource.TraceEvent(System.Diagnostics.TraceEventType.Verbose,
311-
// 4,
312-
// Resources.LogMessageFormats.SlotFilling,
313-
// fillSlot.GetMetalAttribute(ZptConstants.Metal.FillSlotAttribute).Value,
314-
// defineSlot.GetFullFilePathAndLocation(),
315-
// fillSlot.GetFullFilePathAndLocation(),
316-
// nameof(MacroExpander),
317-
// nameof(LogSlotFilling));
318-
// }
319-
320177
#endregion
321178

322179
#region constructor

0 commit comments

Comments
 (0)