diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs
index cf58f420ca..77a9fd2dba 100644
--- a/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs
+++ b/src/Umbraco.Tests/UmbracoExamine/IndexTest.cs
@@ -142,12 +142,15 @@ namespace Umbraco.Tests.UmbracoExamine
{
var s = (IndexSearcher)_searcher.GetSearcher();
+
+
//first delete all 'Content' (not media). This is done by directly manipulating the index with the Lucene API, not examine!
- var r = IndexReader.Open(s.GetIndexReader().Directory(), false);
+
var contentTerm = new Term(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content);
- var delCount = r.DeleteDocuments(contentTerm);
- r.Commit();
- r.Close();
+ var writer = _indexer.GetIndexWriter();
+ writer.DeleteDocuments(contentTerm);
+ writer.Commit();
+
//make sure the content is gone. This is done with lucene APIs, not examine!
var collector = new AllHitsCollector(false, true);
diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
index 6edb9d7960..f47c280d6d 100644
--- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
+++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs
@@ -145,18 +145,24 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var eMgr = GetExamineManagerSafe();
if (eMgr != null)
{
- try
- {
- //by default use the InternalSearcher
- return eMgr.SearchProviderCollection["InternalSearcher"];
- }
- catch (FileNotFoundException)
- {
- //Currently examine is throwing FileNotFound exceptions when we have a loadbalanced filestore and a node is published in umbraco
- //See this thread: http://examine.cdodeplex.com/discussions/264341
- //Catch the exception here for the time being, and just fallback to GetMedia
- //TODO: Need to fix examine in LB scenarios!
- }
+ try
+ {
+ //by default use the InternalSearcher
+ return eMgr.SearchProviderCollection["InternalSearcher"];
+ }
+ catch (FileNotFoundException)
+ {
+ //Currently examine is throwing FileNotFound exceptions when we have a loadbalanced filestore and a node is published in umbraco
+ //See this thread: http://examine.cdodeplex.com/discussions/264341
+ //Catch the exception here for the time being, and just fallback to GetMedia
+ //TODO: Need to fix examine in LB scenarios!
+ }
+ catch (NullReferenceException)
+ {
+ //This will occur when the search provider cannot be initialized. In newer examine versions the initialization is lazy and therefore
+ // the manager will return the singleton without throwing initialization errors, however if examine isn't configured correctly a null
+ // reference error will occur because the examine settings are null.
+ }
}
return null;
}
diff --git a/src/UmbracoExamine/BaseUmbracoIndexer.cs b/src/UmbracoExamine/BaseUmbracoIndexer.cs
index aa0a5c0b63..48fcb85699 100644
--- a/src/UmbracoExamine/BaseUmbracoIndexer.cs
+++ b/src/UmbracoExamine/BaseUmbracoIndexer.cs
@@ -202,8 +202,9 @@ namespace UmbracoExamine
//if temp local storage is configured use that, otherwise return the default
if (_localTempStorageHelper.LuceneDirectory != null)
{
- return new IndexWriter(GetLuceneDirectory(), IndexingAnalyzer,
- DeletePolicyTracker.Current.GetPolicy(IndexSetName),
+ var directory = GetLuceneDirectory();
+ return new IndexWriter(directory, IndexingAnalyzer,
+ DeletePolicyTracker.Current.GetPolicy(directory),
IndexWriter.MaxFieldLength.UNLIMITED);
}
diff --git a/src/UmbracoExamine/DeletePolicyTracker.cs b/src/UmbracoExamine/DeletePolicyTracker.cs
index d002cc108d..3edcd12a24 100644
--- a/src/UmbracoExamine/DeletePolicyTracker.cs
+++ b/src/UmbracoExamine/DeletePolicyTracker.cs
@@ -14,9 +14,9 @@ namespace UmbracoExamine
get { return Instance; }
}
- public IndexDeletionPolicy GetPolicy(string indexSetName)
+ public IndexDeletionPolicy GetPolicy(Lucene.Net.Store.Directory directory)
{
- var resolved = _directories.GetOrAdd(indexSetName, s => new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()));
+ var resolved = _directories.GetOrAdd(directory.GetLockID(), s => new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()));
return resolved;
}
}
diff --git a/src/UmbracoExamine/UmbracoExamineSearcher.cs b/src/UmbracoExamine/UmbracoExamineSearcher.cs
index 437e5c5220..7d5c8b7776 100644
--- a/src/UmbracoExamine/UmbracoExamineSearcher.cs
+++ b/src/UmbracoExamine/UmbracoExamineSearcher.cs
@@ -170,9 +170,10 @@ namespace UmbracoExamine
protected override IndexReader OpenNewReader()
{
+ var directory = GetLuceneDirectory();
return IndexReader.Open(
- GetLuceneDirectory(),
- DeletePolicyTracker.Current.GetPolicy(IndexSetName),
+ directory,
+ DeletePolicyTracker.Current.GetPolicy(directory),
true);
}
diff --git a/src/umbraco.businesslogic/ui.cs b/src/umbraco.businesslogic/ui.cs
index e6bfbb2435..5f2579d9ec 100644
--- a/src/umbraco.businesslogic/ui.cs
+++ b/src/umbraco.businesslogic/ui.cs
@@ -38,6 +38,8 @@ namespace umbraco
[Obsolete("Get the current culture/language from the currently logged in IUser, the IUser object is available on most Umbraco base classes and on the UmbracoContext")]
public static string Culture(User u)
{
+ if (ApplicationContext.Current == null) return string.Empty;
+
var found = UserExtensions.GetUserCulture(u.Language, ApplicationContext.Current.Services.TextService);
return found == null ? string.Empty : found.Name;
}
@@ -46,6 +48,8 @@ namespace umbraco
[Obsolete("Get the current culture/language from the currently logged in IUser, the IUser object is available on most Umbraco base classes and on the UmbracoContext")]
internal static string Culture(IUser u)
{
+ if (ApplicationContext.Current == null) return string.Empty;
+
var found = u.GetUserCulture(ApplicationContext.Current.Services.TextService);
return found == null ? string.Empty : found.Name;
}
@@ -94,11 +98,15 @@ namespace umbraco
///
public static string Text(string Key, User u)
{
+ if (ApplicationContext.Current == null) return "[" + Key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(Key, GetCultureFromUserLanguage(GetLanguage(u)));
}
internal static string Text(string key, IUser u)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(key, GetCultureFromUserLanguage(GetLanguage(u)));
}
@@ -109,6 +117,8 @@ namespace umbraco
///
public static string Text(string Key)
{
+ if (ApplicationContext.Current == null) return "[" + Key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(Key, GetCultureFromUserLanguage(GetLanguage()));
}
@@ -121,6 +131,8 @@ namespace umbraco
///
public static string Text(string Area, string Key, User u)
{
+ if (ApplicationContext.Current == null) return "[" + Key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", Area, Key),
GetCultureFromUserLanguage(GetLanguage(u)));
@@ -128,6 +140,8 @@ namespace umbraco
public static string Text(string area, string key, IUser u)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage(u)));
@@ -141,6 +155,8 @@ namespace umbraco
///
public static string Text(string Area, string Key)
{
+ if (ApplicationContext.Current == null) return "[" + Key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", Area, Key),
GetCultureFromUserLanguage(GetLanguage()));
@@ -156,6 +172,8 @@ namespace umbraco
///
public static string Text(string Area, string Key, string[] Variables, User u)
{
+ if (ApplicationContext.Current == null) return "[" + Key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", Area, Key),
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -164,6 +182,8 @@ namespace umbraco
internal static string Text(string area, string key, string[] variables)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage()),
@@ -172,6 +192,8 @@ namespace umbraco
internal static string Text(string area, string key, string[] variables, IUser u)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -188,6 +210,8 @@ namespace umbraco
///
public static string Text(string Area, string Key, string Variable, User u)
{
+ if (ApplicationContext.Current == null) return "[" + Key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", Area, Key),
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -196,6 +220,8 @@ namespace umbraco
internal static string Text(string area, string key, string variable)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage()),
@@ -204,6 +230,8 @@ namespace umbraco
internal static string Text(string area, string key, string variable, IUser u)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -228,6 +256,8 @@ namespace umbraco
///
public static string GetText(string area, string key)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage()));
@@ -242,6 +272,8 @@ namespace umbraco
///
public static string GetText(string area, string key, string[] variables)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage()),
@@ -257,6 +289,8 @@ namespace umbraco
///
public static string GetText(string area, string key, string variable)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage()),
@@ -274,6 +308,8 @@ namespace umbraco
/// This is the underlying call for all Text/GetText method calls
public static string GetText(string area, string key, string[] variables, string language)
{
+ if (ApplicationContext.Current == null) return "[" + key + "]";
+
return ApplicationContext.Current.Services.TextService.Localize(
string.Format("{0}/{1}", area, key),
GetCultureFromUserLanguage(GetLanguage()),