Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • nojaf 91 posts 300 karma points
    Apr 23, 2014 @ 12:29
    nojaf
    0

    Get a list of all the aliases

    Hello,

    I would like to obtain a list of all the ContentType aliases and the propertyAliases on those ContentTypes. What would be the easiest way to get this?

    I'm not afraid to query the database myself. However it would be nice to have a solution that works without database specifics.

  • nojaf 91 posts 300 karma points
    Apr 23, 2014 @ 15:37
    nojaf
    0

    Ok, I think I have an idea to solve my own question.

    But it raises a new question.

    The simplest way would be to query the ContentTypeService and parse all properties on the found contentTypes. However I would want to try and create a T4 file with all my aliases printed. How can I use create an ApplicationContext in a T4 file snippet?

    Or if that's not possible, how would one do this inside a console application?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Apr 24, 2014 @ 08:05
    Aaron Powell
    0

    You shouldn't need the `ApplicationContext`, if you're running outside of the Umbraco WebApp (which T4 would be).

    My deployment tool Chauffeur just uses the services directly - https://github.com/aaronpowell/Chauffeur/blob/master/Chauffeur/Deliverables/ContentTypeDeliverable.cs#L30

    To get the interface you can just create a new instance of the `ContentTypeService` class as well as new-ing up all of the dependencies which it takes into itself. But be aware that if you're doing this without the Umbraco WebApp things get nasty quickly as a internally Umbraco services use a mix of constructor-provided dependencies and `ApplicationContext` provided dependencies. In the narrow use-case of getting content types + their aliases you _should_ be fine to not setup `ApplicationContext`. You'll probably need to ensure your connection string is in the `*.config` used by the console application as Umbraco expects it to exist (and I had problems injecting it), as for T4 I have no idea how you create a "`*.config`" file.

    Chauffeur now uses an IoC container to resolve dependencies so I don't really know what the dependency chain is any more, but looking at the earlier implementation (pre-IoC) you'll find https://github.com/aaronpowell/Chauffeur/blob/fbdc2c897bc3264a5f849f6ed74ba8ae8721f77f/Chauffeur/Deliverables/ContentTypeDeliverable.cs#L152-L216 which just bootstraps all the services itself.

  • nojaf 91 posts 300 karma points
    Apr 24, 2014 @ 08:50
    nojaf
    0

    Thanks for the quick response. The config files are a pain indeed, getting errors like

    Could not load the Umbraco.Core.Configuration.UmbracoSettings.IUmbracoSettingsSection from config file, ensure the web.config and umbracoSettings.config files are formatted correctly at Umbraco.Core.Configuration.UmbracoConfig.UmbracoSettings()

    Which makes sense though. Maybe I should just create an ApiController that fills in the template at runtime.

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Apr 24, 2014 @ 08:55
    Aaron Powell
    0

    Do you have the full stack-trace? I hit the problem with not being able to load the settings section but in the end I didn't need to use it be skipping around the dependencies.

    Hey, you could always just write a Chauffeur Deliverable to do it ;)

  • nojaf 91 posts 300 karma points
    Apr 24, 2014 @ 09:30
    nojaf
    0

    Hmm, this should actually already work with the existing Deliverables I think.

    umbraco> content-type get <id or alias> gives everything back that I need, so it's matter of string parsing then.

    I'll try it out some time and let you know how it goes.

  • nojaf 91 posts 300 karma points
    Apr 24, 2014 @ 23:55
    nojaf
    0

    What am I missing here?

        public string Rock()
        {
            string chauffeurExe = HttpContext.Current.Server.MapPath("~/bin/Chauffeur.Runner.exe");
            Process compiler = new Process();
            compiler.StartInfo.FileName = chauffeurExe;
            compiler.StartInfo.Arguments = "ct get-all";
            compiler.StartInfo.UseShellExecute = false;
            compiler.StartInfo.RedirectStandardOutput = true;
            compiler.Start();
            string output = compiler.StandardOutput.ReadToEnd();
            compiler.WaitForExit();
            return output;
        }`
    
  • Aaron Powell 1708 posts 3046 karma points c-trib
    Apr 25, 2014 @ 00:57
    Aaron Powell
    0

    Probably, no idea what it'd be though, Chauffeur isn't designed to be used like that so I've got no idea how it would react.

Please Sign in or register to post replies

Write your reply to:

Draft