Beispiel #1
0
        public void DeployIncrementally_Default_CSOM()
        {
            // setup web
            var siteUrl = "";

            // create you models
            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
            });

            var webModel = SPMeta2Model.NewWebModel(web =>
            {
            });

            // setup client context
            using (var clientContext = new ClientContext(siteUrl))
            {
                // deploy site model incrementally
                var provisionService = new StandardCSOMProvisionService();
                provisionService.DeploySiteModelIncrementally(clientContext, siteModel, "MySiteModelId");

                // deploy web model incrementally
                provisionService.DeployWebModelIncrementally(clientContext, webModel, "MyWebModelId");
            }
        }
Beispiel #2
0
        private void InitServices()
        {
            //_provisionService = new CSOMProvisionService();
            _provisionService  = new StandardCSOMProvisionService();
            _validationService = new CSOMValidationService();

            // TODO, setup a high level validation registration
            _provisionService.PreDeploymentServices.Add(new DefaultRequiredPropertiesValidationService());

            var csomStandartAsm = typeof(TaxonomyFieldModelHandler).Assembly;

            foreach (var handlerType in ReflectionUtils.GetTypesFromAssembly <ModelHandlerBase>(csomStandartAsm))
            {
                _provisionService.RegisterModelHandler(Activator.CreateInstance(handlerType) as ModelHandlerBase);
            }

            var csomtandartValidationAsm = typeof(ClientTaxonomyFieldDefinitionValidator).Assembly;

            foreach (var handlerType in ReflectionUtils.GetTypesFromAssembly <ModelHandlerBase>(csomtandartValidationAsm))
            {
                _validationService.RegisterModelHandler(Activator.CreateInstance(handlerType) as ModelHandlerBase);
            }

            _provisionService.OnModelNodeProcessing += (sender, args) =>
            {
                ContainerTraceUtils.WriteLine(
                    string.Format("Processing: [{0}/{1}] - [{2:0} %] - [{3}] [{4}]",
                                  new object[] {
                    args.ProcessedModelNodeCount,
                    args.TotalModelNodeCount,
                    100d * (double)args.ProcessedModelNodeCount / (double)args.TotalModelNodeCount,
                    args.CurrentNode.Value.GetType().Name,
                    args.CurrentNode.Value
                }));
            };

            _provisionService.OnModelNodeProcessed += (sender, args) =>
            {
                ContainerTraceUtils.WriteLine(
                    string.Format("Processed: [{0}/{1}] - [{2:0} %] - [{3}] [{4}]",
                                  new object[] {
                    args.ProcessedModelNodeCount,
                    args.TotalModelNodeCount,
                    100d * (double)args.ProcessedModelNodeCount / (double)args.TotalModelNodeCount,
                    args.CurrentNode.Value.GetType().Name,
                    args.CurrentNode.Value
                }));
            };
        }
Beispiel #3
0
        protected void DeployCSOMModel(ModelNode model)
        {
            // deploy with CSOM
            var csomProvisionService = new StandardCSOMProvisionService();

            using (var context = new ClientContext(CSOMSiteUrl))
            {
                if (model.Value is SiteDefinition)
                {
                    csomProvisionService.DeploySiteModel(context, model);
                }

                if (model.Value is WebDefinition)
                {
                    csomProvisionService.DeployWebModel(context, model);
                }
            }
        }
        public void EnsureStandardCSOMModelHandlers()
        {
            var service = new StandardCSOMProvisionService();

            var modelHandlers         = ReflectionUtils.GetTypesFromAssembly <ModelHandlerBase>(typeof(SPMeta2.CSOM.ModelHandlers.FieldModelHandler).Assembly);
            var standardModelHandlers = ReflectionUtils.GetTypesFromAssembly <ModelHandlerBase>(typeof(SPMeta2.CSOM.Standard.ModelHandlers.Fields.TaxonomyFieldModelHandler).Assembly);

            foreach (var srcHandlerImplType in modelHandlers)
            {
                var dstHandlerImpl = service.ModelHandlers.Values.FirstOrDefault(h => h.GetType() == srcHandlerImplType);
                Assert.IsNotNull(dstHandlerImpl);
            }

            foreach (var srcHandlerImplType in standardModelHandlers)
            {
                var dstHandlerImpl = service.ModelHandlers.Values.FirstOrDefault(h => h.GetType() == srcHandlerImplType);
                Assert.IsNotNull(dstHandlerImpl);
            }
        }
Beispiel #5
0
        public void DeployIncrementally_NormalSetup_CSOM()
        {
            // setup web
            var siteUrl = "";

            // create you models
            var siteModel = SPMeta2Model.NewSiteModel(site =>
            {
            });

            var webModel = SPMeta2Model.NewWebModel(web =>
            {
            });

            // setup client context
            using (var clientContext = new ClientContext(siteUrl))
            {
                var provisionService = new StandardCSOMProvisionService();

                // setup incremental provision settings
                var incrementalProvisionConfig = new IncrementalProvisionConfig();

                // 1 - store model hash in SharePoint
                incrementalProvisionConfig.AutoDetectSharePointPersistenceStorage = true;

                // 2 - set incremental provisio model for the provision service
                provisionService.SetIncrementalProvisionMode(incrementalProvisionConfig);

                // set model id for incremental provision
                siteModel.SetIncrementalProvisionModelId(incrementalModelId);
                webModel.SetIncrementalProvisionModelId(incrementalModelId);


                // deploy incrementally
                provisionService.DeploySiteModel(clientContext, siteModel);
                provisionService.DeployWebModel(clientContext, webModel);

                // revert back to normal provision mode
                provisionService.SetDefaultProvisionMode();
            }
        }
Beispiel #6
0
        public void Deploy_WebModel_CSOM()
        {
            // setup url
            var webUrl = "";

            // create you model
            var webModel = SPMeta2Model.NewWebModel(web =>
            {
            });

            // setup client context
            using (var clientContext = new ClientContext(webUrl))
            {
                // deploy web model with SharePoint Foundation CSOM API
                var foundationProvisionService = new CSOMProvisionService();
                foundationProvisionService.DeployWebModel(clientContext, webModel);

                // deploy web model with SharePoint Standard CSOM API
                var standardProvisionService = new StandardCSOMProvisionService();
                standardProvisionService.DeployWebModel(clientContext, webModel);
            }
        }
Beispiel #7
0
        private void DeployModel(ModelNode model)
        {
            WithCSOMContext(context =>
            {
                var provisionService = new StandardCSOMProvisionService();

                if (model.Value.GetType() == typeof(FarmDefinition))
                {
                    throw new SPMeta2NotImplementedException(
                        string.Format("Runner does not support model of type: [{0}]", model.Value.GetType()));
                }
                else if (model.Value.GetType() == typeof(WebApplicationDefinition))
                {
                    throw new SPMeta2NotImplementedException(
                        string.Format("Runner does not support model of type: [{0}]", model.Value.GetType()));
                }
                else if (model.Value.GetType() == typeof(SiteDefinition))
                {
                    provisionService.DeployModel(SiteModelHost.FromClientContext(context), model);
                }
                else if (model.Value.GetType() == typeof(WebDefinition))
                {
                    provisionService.DeployModel(WebModelHost.FromClientContext(context), model);
                }
                else if (model.Value.GetType() == typeof(ListDefinition))
                {
                    throw new SPMeta2NotImplementedException(
                        string.Format("Runner does not support model of type: [{0}]", model.Value.GetType()));
                }
                else
                {
                    throw new SPMeta2NotImplementedException(
                        string.Format("Runner does not support model of type: [{0}]", model.Value.GetType()));
                }
            });
        }
Beispiel #8
0
        public void Deploy(ClientContext clientContext, SiteModelNode model)
        {
            var csomProvisionService = new StandardCSOMProvisionService();

            csomProvisionService.DeploySiteModel(clientContext, model);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            try
            {
                ReadSettings();
                using (ClientContext ctx = GetAuthenticatedContext())
                {
                    TraceHelper.TraceInformation("Configuring managed metadata");

                    var provisioningService = new StandardCSOMProvisionService();
                    var siteModel           = SiteModel.BuildTaxonomyModel();

                    Console.WriteLine(siteModel.ToPrettyPrint());

                    provisioningService.RegisterModelHandlers(typeof(TaxonomyGroupModelHandler).Assembly);
                    provisioningService.DeployModel(SiteModelHost.FromClientContext(ctx), siteModel);
                }
                using (ClientContext ctx = GetAuthenticatedContext())
                {
                    TraceHelper.TraceInformation("Building site features");

                    var provisioningService = new CSOMProvisionService();
                    var siteModel           = SiteModel.BuildSiteFeaturesModel();
                    Console.WriteLine(siteModel.ToPrettyPrint());

                    provisioningService.DeployModel(SiteModelHost.FromClientContext(ctx), siteModel);
                }
                using (ClientContext ctx = GetAuthenticatedContext())
                {
                    TraceHelper.TraceInformation("Building site fields");

                    var provisioningService = new StandardCSOMProvisionService();
                    var siteModel           = SiteModel.BuildFieldsModel();
                    Console.WriteLine(siteModel.ToPrettyPrint());

                    provisioningService.DeployModel(SiteModelHost.FromClientContext(ctx), siteModel);
                }
                using (ClientContext ctx = GetAuthenticatedContext())
                {
                    TraceHelper.TraceInformation("Building site content types");

                    var provisioningService = new StandardCSOMProvisionService();
                    var siteModel           = SiteModel.BuildContentTypesModel();
                    Console.WriteLine(siteModel.ToPrettyPrint());

                    provisioningService.DeployModel(SiteModelHost.FromClientContext(ctx), siteModel);
                }
                using (ClientContext ctx = GetAuthenticatedContext())
                {
                    TraceHelper.TraceInformation("Building web root model ");

                    var provisioningService = new StandardCSOMProvisionService();
                    var webModel            = SiteModel.BuildWebRootModel();
                    Console.WriteLine(webModel.ToPrettyPrint());

                    provisioningService.DeployModel(SiteModelHost.FromClientContext(ctx), webModel);
                }
                using (ClientContext ctx = GetAuthenticatedContext())
                {
                    TraceHelper.TraceInformation("Building web root files and modules");

                    var provisioningService = new StandardCSOMProvisionService();
                    var webModel            = Model.FIles.BuildFilesModel();
                    Console.WriteLine(webModel.ToPrettyPrint());

                    provisioningService.DeployModel(WebModelHost.FromClientContext(ctx), webModel);
                }
                using (ClientContext ctx = GetAuthenticatedContext())
                {
                    TraceHelper.TraceInformation("Building pages");

                    var provisioningService = new StandardCSOMProvisionService();
                    var webModel            = Model.Pages.BuildPagesModel();
                    Console.WriteLine(webModel.ToPrettyPrint());

                    provisioningService.DeployModel(WebModelHost.FromClientContext(ctx), webModel);
                }
            }
            catch (Exception ex)
            {
                TraceHelper.TraceError("an error has occured, message:{0}", ex);
            }
        }