public void CanCreateEntities()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var template = new ProvisioningTemplate();
                template = new ObjectPropertyBagEntry().CreateEntities(ctx.Web, template, null);

                Assert.IsTrue(template.PropertyBagEntries.Any());
            }
        }
Exemplo n.º 2
0
        public void CanCreateEntities()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var template = new ProvisioningTemplate();
                template = new ObjectPropertyBagEntry().CreateEntities(ctx.Web, template, null);

                Assert.IsTrue(template.PropertyBagEntries.Any());
            }
        }
        public void CanCreateEntities()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                // Load the base template which will be used for the comparison work
                var creationInfo = new ProvisioningTemplateCreationInformation(ctx.Web) { BaseTemplate = ctx.Web.GetBaseTemplate() };

                var template = new ProvisioningTemplate();
                template = new ObjectPropertyBagEntry().CreateEntities(ctx.Web, template, creationInfo);

                Assert.IsTrue(template.PropertyBagEntries.Any());
            }
        }
Exemplo n.º 4
0
        public void CanCreateEntities()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                // Load the base template which will be used for the comparison work
                var creationInfo = new ProvisioningTemplateCreationInformation(ctx.Web)
                {
                    BaseTemplate = ctx.Web.GetBaseTemplate()
                };

                var template = new ProvisioningTemplate();
                template = new ObjectPropertyBagEntry().CreateEntities(ctx.Web, template, creationInfo);

                Assert.IsTrue(template.PropertyBagEntries.Any());
            }
        }
        public void CanProvisionObjects()
        {
            var template = new ProvisioningTemplate();

            var propbagEntry = new Core.Framework.Provisioning.Model.PropertyBagEntry();
            propbagEntry.Key = key;
            propbagEntry.Value = "Unit Test";

            template.PropertyBagEntries.Add(propbagEntry);

            using (var ctx = TestCommon.CreateClientContext())
            {
                var parser = new TokenParser(ctx.Web, template);
                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                var value = ctx.Web.GetPropertyBagValueString(key, "default");
                Assert.IsTrue(value == "Unit Test");

                // Create same entry, but don't overwrite.
                template = new ProvisioningTemplate();

                var propbagEntry2 = new PropertyBagEntry();
                propbagEntry2.Key = key;
                propbagEntry2.Value = "Unit Test 2";
                propbagEntry2.Overwrite = false;

                template.PropertyBagEntries.Add(propbagEntry2);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                value = ctx.Web.GetPropertyBagValueString(key, "default");
                Assert.IsTrue(value == "Unit Test");


                // Create same entry, but overwrite
                template = new ProvisioningTemplate();

                var propbagEntry3 = new PropertyBagEntry();
                propbagEntry3.Key = key;
                propbagEntry3.Value = "Unit Test 3";
                propbagEntry3.Overwrite = true;

                template.PropertyBagEntries.Add(propbagEntry3);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                value = ctx.Web.GetPropertyBagValueString(key, "default");
                Assert.IsTrue(value == "Unit Test 3");

                // Create entry with system key. We don't specify to overwrite system keys, so the key should not be created.
                template = new ProvisioningTemplate();

                var propbagEntry4 = new PropertyBagEntry();
                propbagEntry4.Key = systemKey;
                propbagEntry4.Value = "Unit Test System Key";
                propbagEntry4.Overwrite = true;

                template.PropertyBagEntries.Add(propbagEntry4);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                value = ctx.Web.GetPropertyBagValueString(systemKey, "default");
                Assert.IsTrue(value == "default");

                // Create entry with system key. We _do_ specify to overwrite system keys, so the key should be created.
                template = new ProvisioningTemplate();

                var propbagEntry5 = new PropertyBagEntry();
                propbagEntry5.Key = systemKey;
                propbagEntry5.Value = "Unit Test System Key 5";
                propbagEntry5.Overwrite = true;

                template.PropertyBagEntries.Add(propbagEntry5);

                parser = new  ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation() { OverwriteSystemPropertyBagValues = true});

                value = ctx.Web.GetPropertyBagValueString(systemKey, "default");
                Assert.IsTrue(value == "Unit Test System Key 5");

                // Create entry with system key. We _do not_ specify to overwrite system keys, so the key should not be created.
                template = new ProvisioningTemplate();

                var propbagEntry6 = new PropertyBagEntry();
                propbagEntry6.Key = systemKey;
                propbagEntry6.Value = "Unit Test System Key 6";
                propbagEntry6.Overwrite = true;

                template.PropertyBagEntries.Add(propbagEntry6);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation() { OverwriteSystemPropertyBagValues = false });

                value = ctx.Web.GetPropertyBagValueString(systemKey, "default");
                Assert.IsFalse(value == "Unit Test System Key 6");
            }
        }
        /// <summary>
        /// Actual implementation of extracting configuration from existing site.
        /// </summary>
        /// <param name="web"></param>
        /// <param name="baseTemplate"></param>
        /// <returns></returns>
        internal ProvisioningTemplate GetRemoteTemplate(Web web, ProvisioningTemplateCreationInformation creationInfo)
        {
            // Create empty object
            ProvisioningTemplate template = new ProvisioningTemplate();

            // Hookup connector, is handy when the generated template object is used to apply to another site
            template.Connector = creationInfo.FileConnector;

            // Get Security
            template = new ObjectSiteSecurity().CreateEntities(web, template, creationInfo);
            // Site Fields
            template = new ObjectField().CreateEntities(web, template, creationInfo);
            // Content Types
            template = new ObjectContentType().CreateEntities(web, template, creationInfo);
            // Get Lists
            template = new ObjectListInstance().CreateEntities(web, template, creationInfo);
            // Get custom actions
            template = new ObjectCustomActions().CreateEntities(web, template, creationInfo);
            // Get features
            template = new ObjectFeatures().CreateEntities(web, template, creationInfo);
            // Get composite look
            //template = new ObjectComposedLook().CreateEntities(web, template, creationInfo);
            // Get files
            template = new ObjectFiles().CreateEntities(web, template, creationInfo);
            // Get Property Bag Entries
            template = new ObjectPropertyBagEntry().CreateEntities(web, template, creationInfo);
            // In future we could just instantiate all objects which are inherited from object handler base dynamically

            // Set default values for Template ID and Version
            template.ID = String.Format("TEMPLATE-{0:N}", Guid.NewGuid()).ToUpper();
            template.Version = 1;

            // Retrieve original Template ID and remove it from Property Bag Entries
            int provisioningTemplateIdIndex = template.PropertyBagEntries.FindIndex(f => f.Key.Equals("_PnP_ProvisioningTemplateId"));
            if (provisioningTemplateIdIndex > -1)
            {
                var templateId = template.PropertyBagEntries[provisioningTemplateIdIndex].Value;
                if (!String.IsNullOrEmpty(templateId))
                {
                    template.ID = templateId;
                }
                template.PropertyBagEntries.RemoveAt(provisioningTemplateIdIndex);
            }

            // Retrieve original Template Info and remove it from Property Bag Entries
            int provisioningTemplateInfoIndex = template.PropertyBagEntries.FindIndex(f => f.Key.Equals("_PnP_ProvisioningTemplateInfo"));
            if (provisioningTemplateInfoIndex > -1)
            {
                var jsonInfo = template.PropertyBagEntries[provisioningTemplateInfoIndex].Value;

                var s = new JavaScriptSerializer();
                ProvisioningTemplateInfo info = s.Deserialize<ProvisioningTemplateInfo>(jsonInfo);

                // Override any previously defined Template ID, Version, and SitePolicy
                // with the one stored in the Template Info, if any
                if (!String.IsNullOrEmpty(info.TemplateID))
                {
                    template.ID = info.TemplateID;
                }
                if (!String.IsNullOrEmpty(info.TemplateSitePolicy))
                {
                    template.SitePolicy = info.TemplateSitePolicy;
                }
                if (info.TemplateVersion > 0)
                {
                    template.Version = info.TemplateVersion;
                }

                template.PropertyBagEntries.RemoveAt(provisioningTemplateInfoIndex);
            }

            return template;
        }
        public void CanProvisionObjects()
        {
            var template = new ProvisioningTemplate();

            var propbagEntry = new PnP.Framework.Provisioning.Model.PropertyBagEntry
            {
                Key   = key,
                Value = "Unit Test"
            };

            template.PropertyBagEntries.Add(propbagEntry);

            using (var ctx = TestCommon.CreateClientContext())
            {
                var parser = new TokenParser(ctx.Web, template);
                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                var value = ctx.Web.GetPropertyBagValueString(key, "default");
                Assert.IsTrue(value == "Unit Test");

                // Create same entry, but don't overwrite.
                template = new ProvisioningTemplate();

                var propbagEntry2 = new PropertyBagEntry
                {
                    Key       = key,
                    Value     = "Unit Test 2",
                    Overwrite = false
                };

                template.PropertyBagEntries.Add(propbagEntry2);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                value = ctx.Web.GetPropertyBagValueString(key, "default");
                Assert.IsTrue(value == "Unit Test");


                // Create same entry, but overwrite
                template = new ProvisioningTemplate();

                var propbagEntry3 = new PropertyBagEntry
                {
                    Key       = key,
                    Value     = "Unit Test 3",
                    Overwrite = true
                };

                template.PropertyBagEntries.Add(propbagEntry3);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                value = ctx.Web.GetPropertyBagValueString(key, "default");
                Assert.IsTrue(value == "Unit Test 3");

                // Create entry with system key. We don't specify to overwrite system keys, so the key should not be created.
                template = new ProvisioningTemplate();

                var propbagEntry4 = new PropertyBagEntry
                {
                    Key       = systemKey,
                    Value     = "Unit Test System Key",
                    Overwrite = true
                };

                template.PropertyBagEntries.Add(propbagEntry4);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());

                value = ctx.Web.GetPropertyBagValueString(systemKey, "default");
                Assert.IsTrue(value == "default");

                // Create entry with system key. We _do_ specify to overwrite system keys, so the key should be created.
                template = new ProvisioningTemplate();

                var propbagEntry5 = new PropertyBagEntry
                {
                    Key       = systemKey,
                    Value     = "Unit Test System Key 5",
                    Overwrite = true
                };

                template.PropertyBagEntries.Add(propbagEntry5);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation()
                {
                    OverwriteSystemPropertyBagValues = true
                });

                value = ctx.Web.GetPropertyBagValueString(systemKey, "default");
                Assert.IsTrue(value == "Unit Test System Key 5");

                // Create entry with system key. We _do not_ specify to overwrite system keys, so the key should not be created.
                template = new ProvisioningTemplate();

                var propbagEntry6 = new PropertyBagEntry
                {
                    Key       = systemKey,
                    Value     = "Unit Test System Key 6",
                    Overwrite = true
                };

                template.PropertyBagEntries.Add(propbagEntry6);

                parser = new ObjectPropertyBagEntry().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation()
                {
                    OverwriteSystemPropertyBagValues = false
                });

                value = ctx.Web.GetPropertyBagValueString(systemKey, "default");
                Assert.IsFalse(value == "Unit Test System Key 6");
            }
        }