Copied to clipboard

Flag this post as spam?

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


  • ssougnez 93 posts 319 karma points c-trib
    Sep 19, 2018 @ 17:24
    ssougnez
    0

    Running a full import from a class library

    Hi,

    I'm using uSync along with Umbraco 7 and I have a class library that contains some migration code (using the migration system of Umbraco). The first version is supposed to create content, however, I cannot do so until uSync has run.

    I searched how to run the import with code and I saw that it's possible with uSync.BackOffice. However, I cannot really install this package in my class library as it will install Umbraco as well...

    I tried with uSync.Core but with no luck. How could I run a full import from a class library?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 20, 2018 @ 06:47
    Dave Woestenborghs
    0

    Hi

    Because both you uSync and your migration run from ApplicationEventHandlers there is no way of specifying their run order.

    So it could be that usync runs first, but it also could be that your migrations run first.

    What we did once is run uSync from our migration that depends on it.

    This is the code we have in the project. It's a few years old so things might have changed :

    // Make sure that uSync has run before moving content so all properties exist.
    var uSyncBackOffice = Jumoo.uSync.BackOffice.uSyncBackOfficeContext.Instance;
    
    uSyncBackOffice.Init();
    
                        var settings = uSyncBackOffice.Configuration.Settings;
    
                        if (settings.Import)
                        {
                            uSyncBackOffice.ImportAll();
                        }
    

    Dave

  • ssougnez 93 posts 319 karma points c-trib
    Sep 20, 2018 @ 06:52
    ssougnez
    0

    Excuse me but did you read my original question ? That’s exactly what I want to do but as I said I can’t because I’m in a class library where I can’t install uSync.BackOffice...

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 20, 2018 @ 06:55
    Dave Woestenborghs
    0

    Why can't you install uSync in the class library ?

    Dave

  • ssougnez 93 posts 319 karma points c-trib
    Sep 20, 2018 @ 06:58
    ssougnez
    0

    Because it depends on uSync that depends on Umbraco, so the whole Umbraco web site ends up in the class library when the goal is specifically to keep the site appart from the this project

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 20, 2018 @ 07:01
    Dave Woestenborghs
    0

    Ha..i see some comments in our code about that.

    We just referenced the uSync dll

    And from git log I see after the migration had run on all servers we removed the reference and commented the migration code.

    Dave

  • ssougnez 93 posts 319 karma points c-trib
    Sep 20, 2018 @ 07:06
    ssougnez
    0

    I’m sorry but I don’t see what I can do with your answer :-D

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 20, 2018 @ 07:48
    Dave Woestenborghs
    0

    Sorry just trying to help out !

    Instead of installing usync into your class library using nuget, you should reference the uSync dlls in your class libray (from the packages folder where nuget installs them).

    Than you can use the code snippet I posted before in your migration.

    If you don't want to keep the reference in your project you can delete it after the migration has run on all your servers. And ofcourse comment the code I just posted.

    Dave

  • ssougnez 93 posts 319 karma points c-trib
    Sep 20, 2018 @ 07:55
    ssougnez
    0

    You'll think I'm picky but I really like code separation. For now, I have a project "MyProject" that contains the Umbraco site. Views and Macro are the only custom elements that I have in this project. This way, when I update the Umbraco NuGet package, I really have few risk of collisions or issues.

    Then I have a class library "MyProject.Core" that is reference by "MyProject". This project also uses "UmbracoCms.Core" to "talk" with Umbraco and that's really nice. I want the reference to be unidirectional. Meaning that I'm okay with "MyProject" referencing "MyProject.Core" but not the other way around. I understand that you're not saying to reference "MyProject" from "MyProject.Core" but rather a DLL of "MyProject" but still, I don't like the idea (even though it's not a bad one) :-$

    That's why I thought that it's awesome that uSync came with "uSync.Core". In my mind, it was the same purpose of "UmbracoCms.Core", but apparently, not exactly...

    So basically, you're saying that I can't do exactly what I want?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 20, 2018 @ 07:58
    Dave Woestenborghs
    100

    Hi,

    You probably have installed uSync using nuget,

    So that means the dll's are also availabe in the nuget "packages" folder. So you can reference it from there. No need to reference it from your website bin folder.

    We use the same approach in set up by the way. So it isn't the most clean way, but a very pratical and temporary solution,

    Dave

  • ssougnez 93 posts 319 karma points c-trib
    Sep 20, 2018 @ 08:20
    ssougnez
    0

    Yep, in the "packages" folder of "MyProject" project (I didn't install the packages at solution level).

    But anyway, I see your point. I guess that's how I'll do if there is not a cleaner way :-)

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Sep 20, 2018 @ 08:44
    Dave Woestenborghs
    0

    Yep,

    Package developers (me included) should have better separation between "Web" and "Core".

    I'm planning to do this for new packages.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft