Copied to clipboard

Flag this post as spam?

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


  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Feb 16, 2012 @ 10:06
    Darren Ferguson
    0

    Programatic invoke of deployment and post deployment event?

    Hi All,

    I'm looking through the latest courier docs and trying to work out how to invoke a deployment (of a Document) using code.

    I'd also like to hook into some form of event on the target server when deployment is complete - and get a reference to all of the items that were updated by the deploy.

    I'm honestly a courier novice - I've read the docs and it seems that courier will supress the default publish events on the target server so I can't hook into those.

    ItemEventProvider looks promising:

     

    ExecutionContext.QueueEvent("TweeTOnDeploy", item.ItemId, null, Umbraco.Courier.Core.Enums.EventManagerSys
    temQueues.DeploymentComplete);

    But I'm not sure when I would register them - in a class deriving from ApplicationBase maybe?

    Also in the following method:

    public override void Execute(ItemIdentifier itemId,SerializableDictionary<string, string> Parameters)
    {
    My.Custom.TweetLibrary("woah, I just deployed some stuff");
    }

    Is the itemId just the id of an Umbraco node that was deployed?

    Finally - any tips for a starting point for invoking deployments? I can't find anything!

    Many Thanks.

     

     

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Feb 16, 2012 @ 10:08
    Darren Ferguson
    0

    Oh - and also - would Courier licensing model allow me to test this all out between two Umbraco instances on .local domains - using an eval license?

  • Claus Jensen 49 posts 157 karma points hq
    Feb 16, 2012 @ 19:48
    Claus Jensen
    0

    You should be covered on the license - I'm pretty sure it works just fine as long as you're using localhost/.local. You will be notified about this when browsing the Courier interface though, if I'm wrong. TBH I haven't really tried much without a license but whenever you use it on a alias domain that isn't covered it tells you so.

    I tried hooking into post deployment events too and doing some automated deployment by code. Seems to be a lot of problems with this though, and I never had complete success. Think we had the most luck using some of the old deprecated methods (the ones mentioned in the Courier documentation). Never really got anywhere close to having the same smooth feeling as when using the original Courier UI in Umbraco backend.

    I think most of what I tried doing was based on trying to figure out how the Tasks namespace in Courier works (which is the new part Per has been working on) and also trying to use some of the old stuff from the documentation at: http://nightly.umbraco.org/UmbracoCourier/

    The Tasks namespace lets you enqueue PackagingTasks and such - you should try looking into that - maybe you have better luck than I did. Please let me know if you actually manage to completely transfer items between two instances - invoked from code. :)

  • Claus Jensen 49 posts 157 karma points hq
    Feb 16, 2012 @ 20:05
    Claus Jensen
    0

    Oh and btw - about hooking into post deployment:

    I made a custom media resolver for doing some stuff when packaging. Have a class derive from ItemDataResolverProvider and you will get some events you can hook into. I overrided the Packaging event - but there's also Extracting and Extracted. This was based on one of the examples from the documentation.

    And you asked about the the ItemId. It is an ItemIdentifier property. It can be found by getting a provider and having it get the item you need based on its umbraco ID and then getting the ItemId property on that object:

    var id = new DocumentItemProvider().FindSystemItem("1000").ItemId;

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Feb 17, 2012 @ 11:28
    Darren Ferguson
    0

    Thanks for all of the details above Claus - I'll have a look into this and post back here if I get any further.

    I plan on spending some time today.

    I got two local instances working fine which works fine.

     

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Feb 18, 2012 @ 11:36
    Darren Ferguson
    0

    So I got a steer from Per and have the following code:

    var now = Regex.Replace(DateTime.Now.ToString(CultureInfo.InvariantCulture), "[^0-9A-Za-z]", "");
    
                var revisionName = "__" + now;
    
                var r = new RepositoryStorage();
    
                var repo = r.GetByAlias("http://cdestdarren-fergusoncomlocal");
    
                var packager = new RevisionPackaging(revisionName);
    
                packager.AddToQueue(new ItemIdentifier(d.UniqueId.ToString(), ProviderIDCollection.documentItemProviderGuid), true, 0);
    
                packager.Package();
                packager.Dispose();
    
                var extractor = new Umbraco.Courier.Core.Extraction.RevisionExtraction(repo, revisionName);
    
                // if you want to trigger an event on the remote system you deployed to
                // extractor.Context.QueueEvent("RefreshCache", null, null, Umbraco.Courier.Core.Enums.EventManagerSystemQueues.DeploymentComplete);
    
                extractor.PopulateGraph();
                extractor.Extract();
                extractor.Dispose();
    

    But it throws an exception:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Courier.Core.Packaging.RevisionPackaging.‚ () +399
       Umbraco.Courier.Core.Packaging.RevisionPackaging.Package() +343

     

    The code is understandably obsfucated so any attempt to dig deeper into this have been fruitless.

    There are a few events on RevisionPackaging which i've hooked into and it does seem to do some work before throwing the exception in the package() method.

    I also tried a vanilla Umbraco install with a single document and got the same exception so I don't think it is anything to do with complex dependencies.

    Any steer from here would be very much appreciated.

    Many Thanks

     

     

  • Claus Jensen 49 posts 157 karma points hq
    Feb 18, 2012 @ 12:03
    Claus Jensen
    0

    That's pretty much what I got to too at some point. It seems its actually packing up the revision, but somehow fails at some point - if you diff a rev from courier interface and one made from invoked code - the only difference I saw was a missing manifest file - maybe we're forgetting to add something to the packaging task and that's why it fails when trying to pack it?

    And yes - its rather hard trying to debug it when it's all obfuscated, but it's understandable they need to do that with the commercial Umbraco packages ;)

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Feb 23, 2012 @ 21:44
    Darren Ferguson
    0

    Through a great deal of persistence our developer has made some progress - I can't claim any credit for the code below.

    We are now able to package and transfer a document programtically but we can't extract on the target server.

    Any help of suggestions are much appreciated:

    var d = new umbraco.cms.businesslogic.web.Document(documentId);
                   var now = Regex.Replace(DateTime.Now.ToString(CultureInfo.InvariantCulture), "[^0-9A-Za-z]", "");
    
                   var revisionName = "__" + now;
                   //first we package
                   var packager = new RevisionPackaging(revisionName);
                   packager.PackagingItem += packager_PackagingItem;
                   //here we add the single document to the graph, no children, and a dependency level = 1, which means only this specific item
                   //0 = Selected items and all dependencies
                   //1 = Selected items only
                   //2 = Selected + 1 Dependency level
                   //3 = Selected + 2 Dependency levels
                   //4 = Selected + 3 Dependency levels1
                   var it = new List();
                   var tt = new SystemItem();
                   var itemIdentifier = new ItemIdentifier(d.UniqueId.ToString(),ProviderIDCollection.documentItemProviderGuid);
                   tt.ItemId = itemIdentifier;
                   tt.Name = revisionName;
                   tt.Description = "rev";
    
                   it.Add(tt);
    
                   var manifest = new Umbraco.Courier.Core.Collections.Manifests.RevisionManifest
                                       {UniqueIdentifier = Guid.NewGuid()};
    
                   packager.AddToQueue(it,false,1);
                   packager.AddToQueue(manifest);
                   packager.GenerateHashes=true;
    
                   packager.Package();
                   //packager.Dispose();
    
    
                   //we then extract the things to somewhere else
                   //for this we need a repo, which are setup in courier.config so we can access it with its alias
    
                   var t=new Transfering();
    
                   t.CommitRevision(@"D:\PROJECTS\Ferguson - moriyama\client\DEVELOPMENT\App_Data\courier\revisions\"+revisionName, "destination");
    
                   using (var r = new RepositoryStorage())
                   {
                        var repo = r.GetByAlias("destination");
                        var extractor = new Umbraco.Courier.Core.Extraction.RevisionExtraction(repo, revisionName);
    
                        //if you want to trigger an event on the remote system you deployed to
                        extractor.Context.QueueEvent("RefreshCache", null, null, Umbraco.Courier.Core.Enums.EventManagerSystemQueues.DeploymentComplete);
                        extractor.PopulateGraph();
    
                        extractor.Extract();
                        extractor.Dispose();
                   }
    
Please Sign in or register to post replies

Write your reply to:

Draft