Copied to clipboard

Flag this post as spam?

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

  • Kevin Jump 1701 posts 10914 karma points MVP 4x c-trib
    Oct 08, 2015 @ 12:10
    Kevin Jump

    using the uSync.Core

    uSync.Core is the core of how the new version of usync works, but you can use it in your own code without having to have all of usync.

    you can get it from nuget

    Install-Package uSync.Core

    Once you have it reference the core in code

    using Jumoo.uSync.Core

    then you just need to initialize the core


    once you've done that you can interact with the core serializers

    the serializers take and generate XElement nodes for items inside umbraco. generally

    • Deserailize: takes an item from umbraco and procudes a XElement node
    • Serialize: takes an XElement and puts / syncs it with umbraco
    • IsUpdate: takes an XELement and tells you if uSync thinks it is different than what is already inside umbraco

    Update only by default

    for speed, uSync checks to see if there are any differences between an import file and the contents of the umbraco object. by default if they are the same no import occurs - this is much faster than making changes everytime you are asked as you are not updating the database.

    If you want to force uSync to update, you can pass true in the force parameter of deseralize , and the update will happen regardless.

    Two Pass deserialize

    Most items just follow the serialize / deserialize route, but there are some key elements that 'can' require a two pass deseralize.

    Document types (ContentTypes), MediaTypes and MemberTypes, all have elements and settings that can reference other types.

    when you import a load of content types, one might have Allow Child Types (Structure) pointing to other content types you have yet to import. untill all the types you are importing are in you can't reliably import the structure.

    to get accomodate this - the two pass types also implement

    • DesearlizeSecondPass: which takes the XElement and Item you want to serailize - it then does the parts that need to be done once everything is imported.
    • single pass force if you are 100% sure you don't need to do this you can pass OnePass = true to the Deserialize Method of these serailizers and everything will happen at once.


    All methods return an SyncAttempt object which tells you what has happened:

    the basics of this object are:

    • Success (bool) - did what you just do work?
    • Name (string) - name of what you just did
    • Item (T) - will be either a XElement (for serialize) or the umbraco item you have just imported
    • ChangeType (enum) - what type of change happened
    • Message & Exception - tells you what went wrong.

    example import might look like

    var attempt = uSyncCoreContext.Instance.DataTypeSerializer.DeSerialize(node);
    if (!attempt.Success)
     // something went wrong, check attempt.message / attempt.exception
  • ZNS 60 posts 195 karma points
    Nov 10, 2015 @ 15:29


    Great work on the new version of Usync. I'm wondering if there's an easy way to do a full import of what's on disk? Previously I did this..

    var sync = new jumps.umbraco.usync.uSync(); sync.ReadAllFromDisk();

    How can I achieve this in v3?

  • Kevin Jump 1701 posts 10914 karma points MVP 4x c-trib
    Nov 10, 2015 @ 16:04
    Kevin Jump


    in v3

    using Jumoo.uSync.BackOffice; 
    // you will probably need to initialize uSync first

    the default will import only changes from the ~/usync/data folder.

    you can import from a different folder (you need to map the path before you call import)

    var folder = Umbraco.Core.IO.IOHelper.MapPath("~/app_data/myusyncfolder/");

    by default an import will only import things when they are different then what is inside umbraco (this is the quickest way to do it) - if you want to force the import to import everything even when uSync thinks they are the same for can set force = true.

    uSyncBackOfficeContext.Instance.ImportAll(force: true);

    these calls will also return an list of uSyncActions, which will detail all the things that happened during the import, so you can check if it worked (success = true) and what was imported (change will tell you the type)

  • ZNS 60 posts 195 karma points
    Nov 11, 2015 @ 22:20

    Seems great! Since it's using the backoffice api, will this work even if not logged in?

Please Sign in or register to post replies

Write your reply to: