SubPointSolutions / spmeta2

SharePoint artifact provision for .NET platform. Supports SharePoint Online, SharePoint 2019, 2016 and 2013 via CSOM/SSOM.
http://subpointsolutions.com/spmeta2
134 stars 56 forks source link

Docs - Doom switch for incremental updates #1051

Closed andreasblueher closed 5 years ago

andreasblueher commented 7 years ago

Hey guys,

while trying to chase the calcuated field issues I had to redeploy my fields many, many times. Having implemented incremetal updates, I was wondering what's the fastest way to ensure full deployment? I found the propertybags and deleting them using a powershell script did it for me, but I was wondering if you got another (maybe easier) way to do so.

SubPointSupport commented 7 years ago

There is a bunch of extension methods for provision services, such as:

provisionService.SetDefaultProvisionMode();

Here are more scenarios:

var incrementalProvisionConfig = new IncrementalProvisionConfig();

// in that case M2 auto-detect runtime/api and stored model hash in Property Bag at web, web app or farm level after successful provision
incrementalProvisionConfig.AutoDetectSharePointPersistenceStorage = true;

// configure incremental provision as per options
provisionService.SetIncrementalProvisionMode(incrementalProvisionConfig);

// assign ID, model should have that ID so that SPMeta2 would be able to find/save model hash using that key
// use "my-model", "my.model" or something like that
model.SetIncrementalProvisionModelId(incrementalModelId);

// deploy model as usual
 provisionService.DeployModel(host, model)

// get back to normal provision
provisionService.SetDefaultProvisionMode();

https://github.com/SubPointSolutions/spmeta2/issues/553#issuecomment-283891350

Let us know if that works fine.

sergeisnitko commented 7 years ago

we have some extention functions for Model Deploying and we use the parameter in function to change Incremental provision to Full provision. Like this:

public static void DeployModel(this ClientContext Ctx, WebModelNode model)
{
    DeployModel(Ctx, model, true);
}

public static void DeployModel(this ClientContext Ctx, SiteModelNode model)
{
    DeployModel(Ctx, model, true);
}

public static void DeployModel(this ClientContext Ctx, WebModelNode model, bool Incremental)
{
    BeforeDeployModel(Incremental, x =>
    {
        x.DeployModel(SPMeta2.CSOM.ModelHosts.WebModelHost.FromClientContext(Ctx), model);
    });
}
public static void DeployModel(this ClientContext Ctx, SiteModelNode model, bool Incremental)
{
    BeforeDeployModel(Incremental, x =>
    {
        x.DeployModel(SPMeta2.CSOM.ModelHosts.SiteModelHost.FromClientContext(Ctx), model);
    });

}
public static void BeforeDeployModel(bool Incremental, Action<CSOMProvisionService> Deploy)
{
    var StartedDate = DateTime.Now;
    var provisionService = new CSOMProvisionService();
    if (Incremental)
    {
        var IncProvisionConfig = new IncrementalProvisionConfig();
        IncProvisionConfig.AutoDetectSharePointPersistenceStorage = true;
        provisionService.SetIncrementalProvisionMode(IncProvisionConfig);
    }
    provisionService.OnModelNodeProcessed += (sender, args) =>
    {
        ModelNodeProcessed(sender, args, Incremental);
    };

    Deploy(provisionService);
    provisionService.SetDefaultProvisionMode();

}

public static void ModelNodeProcessed(object sender, ModelProcessingEventArgs args, bool Incremental)
{
    var ModelId = args.Model.GetPropertyBagValue(DefaultModelNodePropertyBagValue.Sys.IncrementalProvision.PersistenceStorageModelId);

    bool shouldDeploy = args.CurrentNode.GetIncrementalRequireSelfProcessingValue();

    var NodeName = args.CurrentNode.Value.ToString();
    if (NodeName.Length > 20)
    {
        NodeName = NodeName.Substring(0, 20) + "...";
    }
    if (!Incremental)
    {
        shouldDeploy = true;
    }

    Console.WriteLine(
    string.Format("{5}[{6}] [{0}/{1}] - [{2}%] - [{3}] [{4}]",
    new object[] {
            args.ProcessedModelNodeCount.AddZeros(4),
            args.TotalModelNodeCount.AddZeros(4),
            Math.Round(100d * (double)args.ProcessedModelNodeCount / (double)args.TotalModelNodeCount).AddSpacesBefore(3),
            args.CurrentNode.Value.GetType().Name,
            NodeName,
            (shouldDeploy == true) ? "[+]" : "[-]",
            ModelId
   }));

}
SubPointSupport commented 7 years ago

@andreasblueher, would you please let us know how it works for you? All good or you need additional help here?

andreasblueher commented 7 years ago

@sergeisnitko Thank you for your methods, I think I'll use a few of them.

@SubPointSupport Sorry for having you wait here and for not being specific enough with my first question. I have a SharePoint solution which is being packaged and copied to the customer system. I don't have access to Visual Studio there, so changing code is not an option.

It just came to my mind that I could do something like if (web.GetProperty("DefaultProvision") { provisionService.SetDefaultProvisionMode(); web.DeleteProperty("DefaultProvision"); }

This way I could simply add a propertybag value to the web and have default provisioning activated and without this, incremental deployment would be default. This is the kind of doom switch I was looking for. What do you think about it, since changing code is not an option for me.

SubPointSupport commented 7 years ago

@andreasblueher, from what we see, such logic is to be implemented by developers rather than opinionated within the library itself.

Library provides APIs for choosing provision mode, a few persistence storages for storing model state, methods and API for additional extensibility. The high-level orchestration better be tailored by developers to fit the solution requirement and design.

SubPointSupport commented 7 years ago

Hey @andreasblueher, just checking on the status of this ticket.

So far, such feature does not seem to have a great fit within the library. Having said that, we still open for a discussion. Looking forward for your feedback as well as @sergeisnitko feedback so that we would be able to either come up with a better solution or close this one.

As for the incremental provision, how did it go, @sergeisnitko? Anything we can improve on out side to make incremental provision usage?

andreasblueher commented 7 years ago

I agree it's not a fit for the library, but maybe it could be part of some tutorial or documentation to guide people. I'll implement my idea and you can go ahead and close this issue.

SubPointSupport commented 7 years ago

Locked on https://github.com/SubPointSolutions/spmeta2/issues/1053