I've gone so many directions with this and time to resort to the forums. I have a helper class I use extensively where I've gone from working with DynamicContent to IContent to now IPublishedContent as I've been encountering issues after upgrading from 6.1.6 to 6.2.1. The site is snappy now and I'm happy with everything EXCEPT my custom indexer isn't working cause I need to access UmbracoContext for the UmbracoHelper.
Helper = new UmbracoHelper(UmbracoContext.Current);
I thought I might be able to fake one like the following:
// mock up a context if necessary
if (HttpContext.Current == null)
{
var mockUrl = "http://mydomain.com";
HttpContext.Current = new HttpContext(
new HttpRequest("", mockUrl, ""),
new HttpResponse(new StringWriter())
)
{
User = new GenericPrincipal(
new GenericIdentity("myname"),
new string[0]
)
};
}
if (UmbracoContext.Current == null)
{
UmbracoContext.EnsureContext(new HttpContextWrapper(HttpContext.Current), ApplicationContext.Current);
}
It seems to create one, but later in the indexer I receive an error, Cannot render a macro when UmbracoContext.PageId is null. I have a single instance of Umbraco with several domains bound to a single node structure, it pulls in content specific to the domain and I have a custom indexer to render out and index only the content which would be served for each individual domain's content. This was all working in 6.1.6, but stopped working when I upgraded to 6.2 and later to 6.2.1. Any suggestions on how I mock up a legitemate UmbracoContext?
I didn't. I went a different direction and basically extracted all the information from the macro tags and basically manually generated the output in code enough to index what I needed to satisfy search results. I only had a handful of macros so it wasn't too bad, not ideal, but enough.
Mocking UmbracoContext for Examine Custom Indexer
I've gone so many directions with this and time to resort to the forums. I have a helper class I use extensively where I've gone from working with DynamicContent to IContent to now IPublishedContent as I've been encountering issues after upgrading from 6.1.6 to 6.2.1. The site is snappy now and I'm happy with everything EXCEPT my custom indexer isn't working cause I need to access UmbracoContext for the UmbracoHelper.
I thought I might be able to fake one like the following:
It seems to create one, but later in the indexer I receive an error, Cannot render a macro when UmbracoContext.PageId is null. I have a single instance of Umbraco with several domains bound to a single node structure, it pulls in content specific to the domain and I have a custom indexer to render out and index only the content which would be served for each individual domain's content. This was all working in 6.1.6, but stopped working when I upgraded to 6.2 and later to 6.2.1. Any suggestions on how I mock up a legitemate UmbracoContext?
Link to similar issue I was having which lead me to getting this working to start with until now: http://our.umbraco.org/forum/developers/extending-umbraco/47617-RenderMacro-for-a-Lucene-Index
I've kicked the can down the road a little.
New error: Cannot render a macro when there is no current PublishedContentRequest.
If you figure out how to fake the UmbracoContext, please let me know how you accomplished this.
I didn't. I went a different direction and basically extracted all the information from the macro tags and basically manually generated the output in code enough to index what I needed to satisfy search results. I only had a handful of macros so it wasn't too bad, not ideal, but enough.
is working on a reply...