added HasValue unit test, removed the default.aspx file from the Web project, it now only exists in the UI project but

the codebehind still exist in the web for backwards compatibility. Updated the logging so that the LogHelper
can now write to a TraceContext specified if debugging which is handy if we want to write to the normal trace.
This commit is contained in:
Shannon Deminick
2012-08-29 07:47:16 +07:00
parent 3cd1592abc
commit 7be4480254
5 changed files with 44 additions and 40 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using log4net;
namespace Umbraco.Core.Logging
@@ -190,7 +191,7 @@ namespace Umbraco.Core.Logging
}
/// <summary>
/// Debugs a message, only generating the message if tracing is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled.
/// Debugs a message, only generating the message if debug is actually enabled. Use this method to avoid calling any long-running methods such as "ToDebugString" if logging is disabled.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="generateMessageFormat">The generate message format.</param>
@@ -200,6 +201,22 @@ namespace Umbraco.Core.Logging
{
Debug(typeof(T), generateMessageFormat, formatItems);
}
/// <summary>
/// Debugs a message and also writes to the TraceContext specified, useful for when you would like the debug
/// output also displayed in the Http trace output.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="generateMessageFormat"></param>
/// <param name="trace"></param>
/// <param name="formatItems"></param>
public static void Debug<T>(string generateMessageFormat, TraceContext trace, params Func<object>[] formatItems)
{
if (trace == null) throw new ArgumentNullException("trace");
trace.Write(string.Format(generateMessageFormat, formatItems.Select(x => x())));
Debug(typeof(T), generateMessageFormat, formatItems);
}
#endregion
}

View File

@@ -59,6 +59,18 @@ namespace Umbraco.Tests.DynamicDocument
}
[Test]
public void HasValue()
{
var asDynamic = GetDynamicNode(1173);
var hasValue = asDynamic.HasValue("umbracoUrlAlias");
var noValue = asDynamic.HasValue("blahblahblah");
Assert.IsTrue(hasValue);
Assert.IsFalse(noValue);
}
[Test]
public void Take()
{

View File

@@ -1,2 +0,0 @@
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="True" Inherits="umbraco.UmbracoDefault" trace="true" validateRequest="false" %>

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading;
using System.Web;
using System.Web.Routing;
@@ -6,6 +6,7 @@ using System.Web.UI;
using System.IO;
using System.Xml;
using System.Text.RegularExpressions;
using Umbraco.Core.Logging;
using Umbraco.Web;
using Umbraco.Web.Routing;
using Umbraco.Core.Configuration;
@@ -16,17 +17,18 @@ using umbraco.cms.businesslogic;
namespace umbraco
{
/// <summary>
/// Summary description for WebForm1.
/// The codebehind class for the main default.aspx page that does the webforms rendering in Umbraco
/// </summary>
///
public partial class UmbracoDefault : Page
/// <remarks>
/// We would move this to the UI project but there is a public API property and some protected properties which people may be using so
/// we cannot move it.
/// </remarks>
public class UmbracoDefault : Page
{
private page _upage = null;
private DocumentRequest _docRequest = null;
bool _validateRequest = true;
const string TraceCategory = "UmbracoDefault";
/// <summary>
/// To turn off request validation set this to false before the PageLoad event. This equivalent to the validateRequest page directive
/// and has nothing to do with "normal" validation controls. Default value is true.
@@ -40,8 +42,7 @@ namespace umbraco
// fixme - switch over to OnPreInit override
void Page_PreInit(Object sender, EventArgs e)
{
Trace.Write(TraceCategory, "Begin PreInit");
//TODO: This still a bunch of routing stuff being handled here, this all needs to be handled in the HttpModule instead
// get the document request
@@ -111,12 +112,10 @@ namespace umbraco
}
// reset the friendly path so it's used by forms, etc.
Trace.Write(TraceCategory, string.Format("Reset url to \"{0}\"", UmbracoContext.Current.RequestUrl));
LogHelper.Debug<UmbracoDefault>(string.Format("Reset url to \"{0}\"", UmbracoContext.Current.RequestUrl));
Context.RewritePath(UmbracoContext.Current.RequestUrl.PathAndQuery);
Context.Items.Add("pageElements", _upage.Elements); // legacy - fixme
Trace.Write(TraceCategory, "End PreInit");
}
void OnPreInitLegacy()
@@ -153,7 +152,7 @@ namespace umbraco
if (cultureAlias != null)
{
UmbracoContext.Current.HttpContext.Trace.Write("default.aspx", "Culture changed to " + cultureAlias);
LogHelper.Debug<UmbracoDefault>("Culture changed to " + cultureAlias, Context.Trace);
var culture = new System.Globalization.CultureInfo(cultureAlias);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = culture;
}
@@ -191,7 +190,7 @@ namespace umbraco
// filter / add preview banner
if (UmbracoContext.Current.InPreviewMode)
{
Trace.Write("Runtime Engine", "Umbraco is running in preview mode.");
LogHelper.Debug<UmbracoDefault>("Umbraco is running in preview mode.", Context.Trace);
if (Response.ContentType == "text/HTML") // ASP.NET default value
{
@@ -200,8 +199,8 @@ namespace umbraco
{
string htmlBadge =
String.Format(UmbracoSettings.PreviewBadge,
umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco),
umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco_client),
IOHelper.ResolveUrl(SystemDirectories.Umbraco),
IOHelper.ResolveUrl(SystemDirectories.UmbracoClient),
Server.UrlEncode(UmbracoContext.Current.HttpContext.Request.Path));
text = text.Substring(0, pos) + htmlBadge + text.Substring(pos, text.Length - pos);

View File

@@ -1,22 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.1434
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace umbraco {
/// <summary>
/// UmbracoDefault class.
/// </summary>
/// <remarks>
/// Auto-generated class.
/// </remarks>
public partial class UmbracoDefault {
}
}