Fixes: U4-U4-917

Fixes: U4-821
This commit is contained in:
Shannon Deminick
2012-10-01 23:04:57 +05:00
parent 42da98e020
commit 5c20f4f6ec
5 changed files with 178 additions and 50 deletions

View File

@@ -60,13 +60,7 @@ namespace Umbraco.Core.Logging
}
#endregion
#region Warn
public static void Warn(Type callingType, string message)
{
var logger = LogManager.GetLogger(callingType);
if (logger != null)
logger.Warn(PrefixThreadId(message));
}
#region Warn
public static void Warn(Type callingType, string message, params object[] format)
{
@@ -75,30 +69,44 @@ namespace Umbraco.Core.Logging
logger.WarnFormat(PrefixThreadId(message), format);
}
/// <summary>
/// Adds a warn log
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="message"></param>
public static void Warn<T>(string message)
public static void Warn(Type callingType, TraceContext trace, string message, params object[] format)
{
var logger = LoggerFor<T>();
if (trace != null)
{
trace.Warn(string.Format(message, format));
}
var logger = LogManager.GetLogger(callingType);
if (logger != null)
logger.Warn(PrefixThreadId(message));
logger.WarnFormat(PrefixThreadId(message), format);
}
/// <summary>
/// Adds a warn log
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="format"></param>
/// <param name="message"></param>
/// <param name="items"></param>
public static void Warn<T>(string format, params object[] items)
public static void Warn<T>(string message, params object[] items)
{
var logger = LoggerFor<T>();
if (logger != null)
logger.WarnFormat(PrefixThreadId(format), items);
logger.WarnFormat(PrefixThreadId(message), items);
}
public static void Warn<T>(string message, TraceContext trace, params object[] items)
{
if (trace != null)
{
trace.Warn(string.Format(message, items));
}
var logger = LoggerFor<T>();
if (logger != null)
logger.WarnFormat(PrefixThreadId(message), items);
}
#endregion
#region Info

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using umbraco;
namespace Umbraco.Tests
{
/// <summary>
/// Tests for the legacy library class
/// </summary>
[TestFixture]
public class LibraryTests : BaseRoutingTest
{
public override void Initialize()
{
base.Initialize();
//set the current umbraco context and a published content store
PublishedContentStoreResolver.Current = new PublishedContentStoreResolver(
new DefaultPublishedContentStore());
var routingContext = GetRoutingContext("/test", 1234);
UmbracoContext.Current = routingContext.UmbracoContext;
}
public override void TearDown()
{
base.TearDown();
UmbracoContext.Current = null;
PublishedContentStoreResolver.Reset();
}
protected override bool RequiresDbSetup
{
get { return false; }
}
[Test]
public void Get_Item_User_Property()
{
var val = library.GetItem(1173, "content");
var legacyVal = LegacyGetItem(1173, "content");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("<div>This is some content</div>", val);
}
[Test]
public void Get_Item_Document_Property()
{
//first test a single static val
var val = library.GetItem(1173, "template");
var legacyVal = LegacyGetItem(1173, "template");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("1234", val);
//now test them all to see if they all match legacy
foreach(var s in new[]{"id","parentID","level","writerID","template","sortOrder","createDate","updateDate","nodeName","writerName","path"})
{
val = library.GetItem(1173, s);
legacyVal = LegacyGetItem(1173, s);
Assert.AreEqual(legacyVal, val);
}
}
[Test]
public void Get_Item_Invalid_Property()
{
var val = library.GetItem(1173, "dontfindme");
var legacyVal = LegacyGetItem(1173, "dontfindme");
Assert.AreEqual(legacyVal, val);
Assert.AreEqual("", val);
}
/// <summary>
/// The old method, just using this to make sure we're returning the correct exact data as before.
/// </summary>
/// <param name="nodeId"></param>
/// <param name="alias"></param>
/// <returns></returns>
private string LegacyGetItem(int nodeId, string alias)
{
var umbracoXML = UmbracoContext.Current.GetXml();
string xpath = UmbracoSettings.UseLegacyXmlSchema ? "./data [@alias='{0}']" : "./{0}";
if (umbracoXML.GetElementById(nodeId.ToString()) != null)
if (
",id,parentID,level,writerID,template,sortOrder,createDate,updateDate,nodeName,writerName,path,"
.
IndexOf("," + alias + ",") > -1)
return umbracoXML.GetElementById(nodeId.ToString()).Attributes.GetNamedItem(alias).Value;
else if (
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)) !=
null)
return
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)).ChildNodes[0].
Value; //.Value + "*";
else
return string.Empty;
else
return string.Empty;
}
}
}

View File

@@ -56,6 +56,7 @@
<Compile Include="ContentStores\PublishMediaStoreTests.cs" />
<Compile Include="DynamicDocument\DocumentTests.cs" />
<Compile Include="HtmlHelperExtensionMethodsTests.cs" />
<Compile Include="LibraryTests.cs" />
<Compile Include="Resolvers\ActionsResolverTests.cs" />
<Compile Include="AsynchronousRollingFileAppenderTests.cs" />
<Compile Include="BusinessLogic\ApplicationTest.cs" />

View File

@@ -1,6 +1,8 @@
using System;
using System.Dynamic;
using System.Globalization;
using System.Web;
using Umbraco.Core.Logging;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.language;
@@ -22,10 +24,10 @@ namespace Umbraco.Web.Dictionary
{
return new global::umbraco.cms.businesslogic.Dictionary.DictionaryItem(key).Value(Language.id);
}
catch (Exception)
catch (Exception e)
{
//NOTE: SD: I'm not sure why this is here but was copied from the UmbracoCultureDictionary in the macroEngines project
// which previously seems to have worked so I'm leaving it for now.
var trace = UmbracoContext.Current != null ? UmbracoContext.Current.HttpContext.Trace : null;
LogHelper.Warn<DefaultCultureDictionary>("Error returning dictionary item '" + key + "'", trace, e);
return string.Empty;
}
}

View File

@@ -434,26 +434,46 @@ namespace umbraco
/// <returns>Returns a string with the data from the given element of a node</returns>
public static string GetItem(int nodeID, String alias)
{
XmlDocument umbracoXML = UmbracoContext.Current.GetXml();
var doc = PublishedContentStoreResolver.Current.PublishedContentStore.GetDocumentById(
Umbraco.Web.UmbracoContext.Current,
nodeID);
string xpath = UmbracoSettings.UseLegacyXmlSchema ? "./data [@alias='{0}']" : "./{0}";
if (doc == null)
return string.Empty;
switch (alias)
{
case "id":
return doc.Id.ToString();
case "version":
return doc.Version.ToString();
case "parentID":
return doc.Parent.Id.ToString();
case "level":
return doc.Level.ToString();
case "writerID":
return doc.WriterId.ToString();
case "template":
return doc.TemplateId.ToString();
case "sortOrder":
return doc.SortOrder.ToString();
case "createDate":
return doc.CreateDate.ToString("yyyy-MM-dd'T'HH:mm:ss");
case "updateDate":
return doc.UpdateDate.ToString("yyyy-MM-dd'T'HH:mm:ss");
case "nodeName":
return doc.Name;
case "writerName":
return doc.WriterName;
case "path":
return doc.Path;
case "creatorName":
return doc.CreatorName;
}
var prop = doc.GetProperty(alias);
return prop == null ? string.Empty : prop.Value.ToString();
if (umbracoXML.GetElementById(nodeID.ToString()) != null)
if (
",id,version,parentID,level,writerID,editDataType,template,sortOrder,createDate,updateDate,nodeName,writerName,path,"
.
IndexOf("," + alias + ",") > -1)
return umbracoXML.GetElementById(nodeID.ToString()).Attributes.GetNamedItem(alias).Value;
else if (
umbracoXML.GetElementById(nodeID.ToString()).SelectSingleNode(string.Format(xpath, alias)) !=
null)
return
umbracoXML.GetElementById(nodeID.ToString()).SelectSingleNode(string.Format(xpath, alias)).ChildNodes[0].
Value; //.Value + "*";
else
return string.Empty;
else
return string.Empty;
}
/// <summary>
@@ -1492,17 +1512,7 @@ namespace umbraco
/// <returns>A dictionary items value as a string.</returns>
public static string GetDictionaryItem(string Key)
{
try
{
Language l = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name);
return new Dictionary.DictionaryItem(Key).Value(l.id);
//return new Dictionary.DictionaryItem(Key).Value(GetCurrentLanguageId());
}
catch (Exception errDictionary)
{
HttpContext.Current.Trace.Warn("library", "Error returning dictionary item '" + Key + "'", errDictionary);
return string.Empty;
}
return GetUmbracoHelper().GetDictionaryValue(Key);
}
/// <summary>