Showing posts with label Umbraco. Show all posts
Showing posts with label Umbraco. Show all posts

Wednesday, 2 October 2013

Umbraco Links


 Slowly I am getting loads of articles about Umbraco

Here are some I have found usefull


Publishing events using V4 code base in V6 
http://our.umbraco.org/forum/developers/api-questions/38101-V6-ContentService-Publish-Event


MVC

 Custom routing
http://shazwazza.com/category/Umbraco


MVC Umbraco testing
http://dipunm.wordpress.com/2013/06/16/creating-testable-controllers-in-umbraco/


Code UI Automation
http://watin.org/

Tuesday, 10 September 2013

Could not open Source file: Could not find a part of the path Web.config; \umbraco\Xslt\Web.config'


I am using Team city as my build server, and web deploy in order to create my deploy package.

I have received error message:

My error message that is on Build server


[09:31:02]Step 1/1: Publish & Deploy (MSBuild) (47s)
[09:31:05][Step 1/1] Website.Web.UI\Website.Web.UI.csproj.teamcity: Build targets: Build;Package (45s)
[09:31:50][Website.Web.UI\Website.Web.UI.csproj.teamcity] AutoParameterizationWebConfigConnectionStringsCore
[09:31:50][AutoParameterizationWebConfigConnectionStringsCore] ParameterizeTransformXml
[09:31:50][ParameterizeTransformXml] D:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(2352, 5): Could not open Source file: Could not find a part of the path 'D:\41fe9571fcaca9a1\Website.Web.UI\umbraco\Xslt\Web.config;
\umbraco\Xslt\Web.config'.

[09:31:50][Website.Web.UI\Website.Web.UI.csproj.teamcity] Project Website.Web.UI\Website.Web.UI.csproj.teamcity failed.
[09:31:50][Step 1/1] Step Publish & Deploy (MSBuild) failed

I have found 2 cases which cause this error.

This happens because of web.deploy is running web.config transformation changes. By default the web.config is set to build as content.

Solution 1 - Svn issue


Issue has been that I have had 2 sources loading data.
One:Source check out from repository
Second:Artefacts used from previous steps.

Use only one source for build and error goes away.

Solution 2 - Web.config transform


Find the file in your solution(project). in my case it is:"D:\41fe9571fcaca9a1\Website.Web.UI\umbraco\Xslt\Web.config".
Go to the properties of the file (Alt + Enter)

Update your configuration.

Set your "Build Action" to  None or Content

This means that there will be no transform on this config, usual configuration is compile.




 

Monday, 12 August 2013

Umbraco get media id from url

Working with umbraco 6 is great fun.

I am working with images and needed to access image before is served to public.
Hope my solution will  save you some time.

Here is solution


var path = HttpContext.Current.Request.Path.ToLower();

// filter requests that we know are not relevant
if (!path.StartsWith("/media/") || path.StartsWith("/media/temp/") || path.Contains("_thumb.")) return;


// access medisa service
Umbraco.Core.Services.MediaService ms = new Umbraco.Core.Services.MediaService(new Umbraco.Core.Persistence.RepositoryFactory()); 
var item = ms.GetMediaByPath(path);

Thursday, 18 July 2013

Add information about published node to search Umbraco


I needed to add information about published node to search Umbraco. You can do it as follows:


 Examine settings for my code:

Make sure that your indexer does allow

 <add name="AutoCompleteLookupIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
           supportUnpublished="true"
           supportProtected="true"
          analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" />



in [ExamineIndex.config]

Code:



public class ExamineEvents : ApplicationBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ExamineEvents"/> class.
        /// </summary>
        public ExamineEvents()
        {
            // hookup to application
            ExamineManager.Instance.IndexProviderCollection[ExamineIndexers.AutoCompleteLookupIndexer.Name()].GatheringNodeData +=
                InternalExamineEvents_GatheringNodeData;
        }

        /// <summary>
        /// Handles the GatheringNodeData event of the InternalExamineEvents control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="IndexingNodeDataEventArgs"/> instance containing the event data.</param>
        void InternalExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            if (e.IndexType != IndexTypes.Content) return;

            var node = uQuery.GetNode(e.NodeId);
           
            e.Fields.Add("isPublished", node==null?Boolean.TrueString:Boolean.FalseString);
        }
    }


in [your file]

Lucene concrete example

Lucene concrete example

Purpose:


I am building autocomplete search for umbraco. I need to get all pages that are searchable and not hidden from navigation.

Searchable and hiddenFromNavigation are my custom properties.

My seach examine index
  <IndexSet SetName="AutoCompleteLookupIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/AutoCompleteLookupIndexSet/">
    <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName" />
      <add Name="updateDate" />
      <add Name="writerName" />
      <add Name="path" />
      <add Name="nodeTypeAlias" />
      <add Name="parentID" />
    </IndexAttributeFields>
    <IndexUserFields>
      <add Name="description"/>
      <add Name="hideFromNav"/>
      <add Name="searchable"/>
    </IndexUserFields>
    <IncludeNodeTypes>
    </IncludeNodeTypes>
    <ExcludeNodeTypes>
    </ExcludeNodeTypes>
  </IndexSet>

My examine settings:

      <add name="AutoCompleteLookupIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
           supportUnpublished="false"
           supportProtected="true"
          analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" />

 <!-- AutoComplete lookup search-->
      <add name="AutoCompleteLookupSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
           analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net" enableLeadingWildcards="true"/>


My Lucene query

(hideFromNav:"0" AND searchable:"1" AND nodeName:searchTextAsWildCard*)


Thursday, 11 July 2013

Umbraco and MVC tips

 
How to access Umbraco Current Node 
 
public class CommentSurfaceController : SurfaceController
{
    private readonly IUmbracoApplicationContext context;
    public CommentSurfaceController(IUmbracoApplicationContext context)
    {
        this.context = context;
    }
}
 

Implementation surface controller

I have search for which I want to implement autocomplete. 

My json result will be based on AutoCompleteSearchResult:
 
 public class AutoCompleteSearchResult
    {
        public string value { get; set; }
        public string data { get; set; }
    }
 
My controller

  public class SearchController: SurfaceController
    {
        public JsonResult Index(RenderModel model)
        {

            var result = new List<AutoCompleteSearchResult>();

            result.Add(new AutoCompleteSearchResult(){data = "1", value = "test1"});
            result.Add(new AutoCompleteSearchResult(){data = "2", value = "test2"});
            result.Add(new AutoCompleteSearchResult(){data = "3", value = "test3"});


            return new JsonResult(){Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
        }
    }

 
If you are using surface controllers your link has to have prefix:
 
umbraco/surface/ 

 
Access the action on url
 
http://yourserver/umbraco/surface/Search/index/ 
 

Binding tip

If you are binding RenderMvcController to controller make sure that 
DataType and Controller name are the same
 
SearchPage , SearchPageController

Load data using uQuery

umbraco.NodeFactory.Node node = uQuery.GetNodesByName("Page Name")
    .Where(n => n.NodeTypeAlias == "NodeTypeAlias").FirstOrDefault();

if (node != null)
{
    //...
}
GetNodesByType(string or int):
umbraco.NodeFactory.Node node = uQuery.GetNodesByType("NodeTypeAlias")
    .Where(n => n.Name == "Page Name").FirstOrDefault();

if (node != null)
{
    //...
}