Copied to clipboard

Flag this post as spam?

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


  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 23, 2011 @ 14:50
    Morten Bock
    0

    Creating Courier packages in a console app

    I just downloaded the 2.5 hotfix version, and the sample console apps, and I am trying to create a console app to package up my items for me.

    I started out witht the first sample in the manual: http://nightly.umbraco.org/UmbracoCourier/Developer%20Docs.pdf

    The problem is, that it seems that I am not getting any providers what so ever. My code so far is:

    class Program
    {
        static readonly string _application = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
    
        static void Main(string[] args)
        {
            Console.WriteLine("Ready set go!");
    
            Context.Current.SettingsFilePath = Path.Combine(_application, "courier.config");
            Context.Current.BaseDirectory = Directory.GetCurrentDirectory();
            Context.Current.HasHttpContext = false;
    
    
            List<ItemProvider> itemProviders = ItemProviderCollection.Instance.GetProviders();
    
            foreach (ItemProvider itemProvider in itemProviders)
            {
                Console.WriteLine(itemProvider.Name);
            }
    
            Console.ReadLine();
        }
    }
    
    I added the config file from the hotfix zip file. I'm guessing that is the one it needs? Or is there a separate config file for the console app things?
    What am I missing here? I'm not getting any exception, just no prviders...


  • Per Ploug 865 posts 3491 karma points MVP admin
    Sep 23, 2011 @ 14:52
    Per Ploug
    0

    Hi Morten

    You need to load the dlls into the appdomain for courier to actually pick up on them, (not needed in a web application, but is in console apps)

    Umbraco.Courier.Core.Helpers.TypeResolver.LoadAssembliesIntoAppDomain(plugins, "*.dll");
  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 23, 2011 @ 14:53
    Morten Bock
    0

    Even if there is nothing in the plugins folder? (Which dll's would I need there?)

  • Per Ploug 865 posts 3491 karma points MVP admin
    Sep 23, 2011 @ 14:54
    Per Ploug
    0

    And a bit more detail :) 

    Yes, config file is the same, no matter if it runs on web or console. 

    The LoadAssemblies method is used to load all the providers courier has, item providers and repository providers, so those dlls should be put in a seperate folder

    Download the console app source on nightly to see how the initial wirering is done

    /per

  • Per Ploug 865 posts 3491 karma points MVP admin
    Sep 23, 2011 @ 14:55
    Per Ploug
    0

    umbraco.courier.providers and repositoryproviders.dll

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 23, 2011 @ 15:09
    Morten Bock
    0

    Ok, that helped a bit. But I only get one provider from the collection: "Tag Relations". Shouldn't I be getting a few more? Or is it because I am not yet connecting to a webservice?

    The idea is to loop through the providers one by one, and picking the items we want to transfer, and then create the package. Im' thinking I don't need the webservice until I start loping through the actual items using provider.AvailableSystemItems()? Or am I mistaken? :)

  • Per Ploug 865 posts 3491 karma points MVP admin
    Sep 23, 2011 @ 15:16
    Per Ploug
    0

    This piece of code, gives me a full list of item providers, you shouldn't need to connect to any source to get the providers

    //To init our app, we need to load all provider dlls from our plugins dir
                //The application needs the DLL umbraco.courier.providers.dll to work with the build-in providers
                //you can add any dll in there to load your own
                Umbraco.Courier.Core.Helpers.TypeResolver.LoadAssembliesIntoAppDomain(plugins, "*.dll");
                
                //we also need to tell it where to get it's config xml
                //this is the standard courier file which contains settings for the engines and providers
                Umbraco.Courier.Core.Context.Current.SettingsFilePath = Path.Combine(application, "courier.config");

                //finally we need to redirect the revisions root for correct mapping
                Umbraco.Courier.Core.Context.Current.BaseDirectory = directory;
                Umbraco.Courier.Core.Context.Current.HasHttpContext = false;

                foreach (var q in Umbraco.Courier.Core.ProviderModel.ItemProviderCollection.Instance.GetProviders())
                {
                    Console.WriteLine(q.Name);
                }
  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 23, 2011 @ 15:32
    Morten Bock
    0

    Hmm. I must be doing something wrong then :-)

    Is it looking in the config for them, or is it pure reflection?

    And this is 2.5 code right? Or is it for 2.1?

  • Per Ploug 865 posts 3491 karma points MVP admin
    Sep 23, 2011 @ 15:36
    Per Ploug
    0

    It's pure reflection, but it might look in the config file for settings required by each provider

    tested on 2.5

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 23, 2011 @ 16:48
    Morten Bock
    0

    Could it be a licensing thing?

    I'm able to get some providers if I do this:

    List<Type> findClassesOfType = Umbraco.Courier.Core.Helpers.TypeFinder.FindClassesOfType<ItemProvider>(false);

    Do I need a license to write the cmd app, or is only when connection to an umbraco instance?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Sep 26, 2011 @ 10:09
    Morten Bock
    0

    Hmm, I'm having no luck it seems.

    I noticed in one of the samples that there was a log.txt file in the bin folder, but I can't seem to find any info on it in the docs. Can I explicitly enable logging?

    I think the next step is to try and connect to a local website, and see if I can get any connection/exceptions.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies