Пример #1
0
        protected override void ProcessRecord()
        {
            var site = new TeamNoGroupSubSite()
            {
                Url                            = Url,
                Language                       = (int)Language,
                QuickLaunchEnabled             = !QuickLaunchDisabled.IsPresent,
                UseSamePermissionsAsParentSite = !UseDifferentPermissionsFromParentSite.IsPresent,
                TimeZoneId                     = (int)TimeZoneId,
                Description                    = Description,
                Title                          = Title
            };

            if (TemplateIds != null)
            {
                site.Templates.AddRange(TemplateIds.ToList());
            }
            WriteObject(site);
        }
        private SubSite ParseSubsiteSequences(Web subweb, ref ProvisioningHierarchy tenantTemplate, ExtractConfiguration configuration, int currentDepth, int maxDepth)
        {
            subweb.EnsureProperties(sw => sw.Url, sw => sw.Title, sw => sw.QuickLaunchEnabled, sw => sw.Description, sw => sw.Language, sw => sw.RegionalSettings.TimeZone, sw => sw.Webs, sw => sw.HasUniqueRoleAssignments);

            var subwebTemplate = subweb.GetProvisioningTemplate(configuration.ToCreationInformation(subweb));
            var uniqueid       = subweb.Id.ToString("N");

            subwebTemplate.Id = $"TEMPLATE-{uniqueid}";

            tenantTemplate.Templates.Add(subwebTemplate);

            tenantTemplate.Parameters.Add($"SUBSITE_{uniqueid}_URL", subweb.Url.Substring(subweb.Url.LastIndexOf("/")));
            tenantTemplate.Parameters.Add($"SUBSITE_{uniqueid}_TITLE", subweb.Title);
            var subSiteCollection = new TeamNoGroupSubSite()
            {
                Url   = $"{{parameter:SUBSITE_{uniqueid}_URL}}",
                Title = $"{{parameter:SUBSITE_{uniqueid}_TITLE}}",
                QuickLaunchEnabled             = subweb.QuickLaunchEnabled,
                Description                    = subweb.Description,
                Language                       = (int)subweb.Language,
                TimeZoneId                     = subweb.RegionalSettings.TimeZone.Id,
                UseSamePermissionsAsParentSite = !subweb.HasUniqueRoleAssignments,
                Templates                      = { subwebTemplate.Id }
            };
            bool traverse = true;

            if (maxDepth != 0)
            {
                currentDepth++;
                traverse = currentDepth <= maxDepth;
            }
            if (traverse && subweb.Webs.AreItemsAvailable)
            {
                currentDepth++;
                foreach (var subsubweb in subweb.Webs)
                {
                    subSiteCollection.Sites.Add(ParseSubsiteSequences(subsubweb, ref tenantTemplate, configuration, currentDepth, maxDepth));
                }
            }
            return(subSiteCollection);
        }
        protected override void ProcessRecord()
        {
            if (MyInvocation.InvocationName.ToLower() == "new-pnpprovisioningteamnogroupsubsite")
            {
                WriteWarning("New-PnPProvisioningTeamNoGroupSubSite has been deprecated. Use New-PnPTenantSequenceTeamNoGroupSubSite instead.");
            }

            var site = new TeamNoGroupSubSite()
            {
                Url                            = Url,
                Language                       = (int)Language,
                QuickLaunchEnabled             = !QuickLaunchDisabled.IsPresent,
                UseSamePermissionsAsParentSite = !UseDifferentPermissionsFromParentSite.IsPresent,
                TimeZoneId                     = (int)TimeZoneId,
                Description                    = Description,
                Title                          = Title
            };

            if (TemplateIds != null)
            {
                site.Templates.AddRange(TemplateIds.ToList());
            }
            WriteObject(site);
        }
        private TokenParser ApplySubSiteTemplates(ProvisioningHierarchy hierarchy, TokenParser tokenParser, Model.SiteCollection sitecollection, ClientContext siteContext, Web web, TeamNoGroupSubSite subSiteObject, ProvisioningTemplateApplyingInformation provisioningTemplateApplyingInformation)
        {
            var url = tokenParser.ParseString(subSiteObject.Url);

            var subweb = web.Webs.FirstOrDefault(t => t.ServerRelativeUrl.Equals(UrlUtility.Combine(web.ServerRelativeUrl, "/", url.Trim(new char[] { '/' }))));

            foreach (var templateRef in sitecollection.Templates)
            {
                var provisioningTemplate = hierarchy.Templates.FirstOrDefault(t => t.Id == templateRef);
                if (provisioningTemplate != null)
                {
                    provisioningTemplate.Connector = hierarchy.Connector;
                    if (tokenParser == null)
                    {
                        tokenParser = new TokenParser(subweb, provisioningTemplate);
                    }
                    else
                    {
                        tokenParser.Rebase(subweb, provisioningTemplate);
                    }
                    new SiteToTemplateConversion().ApplyRemoteTemplate(subweb, provisioningTemplate, provisioningTemplateApplyingInformation, true, tokenParser);
                }
                else
                {
                    WriteMessage($"Referenced template ID {templateRef} not found", ProvisioningMessageType.Error);
                }
            }

            if (subSiteObject.Sites.Any())
            {
                foreach (var subsubSite in subSiteObject.Sites)
                {
                    var subsubSiteObject = (TeamNoGroupSubSite)subsubSite;
                    tokenParser = ApplySubSiteTemplates(hierarchy, tokenParser, sitecollection, siteContext, subweb, subsubSiteObject, provisioningTemplateApplyingInformation);
                }
            }

            return(tokenParser);
        }
        private TokenParser CreateSubSites(ProvisioningHierarchy hierarchy, TokenParser tokenParser, Model.SiteCollection sitecollection, ClientContext siteContext, Web web, TeamNoGroupSubSite subSiteObject)
        {
            var url = tokenParser.ParseString(subSiteObject.Url);

            var subweb = web.Webs.FirstOrDefault(t => t.ServerRelativeUrl.Equals(UrlUtility.Combine(web.ServerRelativeUrl, "/", url.Trim(new char[] { '/' }))));

            if (subweb == null)
            {
                subweb = web.Webs.Add(new WebCreationInformation()
                {
                    Language    = subSiteObject.Language,
                    Url         = url,
                    Description = tokenParser.ParseString(subSiteObject.Description),
                    Title       = tokenParser.ParseString(subSiteObject.Title),
                    UseSamePermissionsAsParentSite = subSiteObject.UseSamePermissionsAsParentSite,
                    WebTemplate = "STS#3"
                });
                WriteMessage($"Creating Sub Site with no Office 365 group at {url}", ProvisioningMessageType.Progress);
                siteContext.Load(subweb);
                siteContext.ExecuteQueryRetry();
            }
            else
            {
                WriteMessage($"Using existing Sub Site with no Office 365 group at {url}", ProvisioningMessageType.Progress);
            }

            if (subSiteObject.Sites.Any())
            {
                foreach (var subsubSite in subSiteObject.Sites)
                {
                    var subsubSiteObject = (TeamNoGroupSubSite)subsubSite;
                    tokenParser = CreateSubSites(hierarchy, tokenParser, sitecollection, siteContext, subweb, subsubSiteObject);
                }
            }

            return(tokenParser);
        }
        public void ProvisionTenantTemplate()
        {
            if (TestCommon.AppOnlyTesting())
            {
                Assert.Inconclusive("This test does not yet work with app-only due to group connected site creation");
            }


            var resourceFolder           = string.Format(@"{0}\..\..\Resources\Templates", AppDomain.CurrentDomain.BaseDirectory);
            XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(resourceFolder, "");

            var existingTemplate = provider.GetTemplate("ProvisioningSchema-2018-07-FullSample-01.xml");

            Guid siteGuid = Guid.NewGuid();
            int  siteId   = siteGuid.GetHashCode();
            var  template = new ProvisioningTemplate();

            template.Id = "TestTemplate";
            template.Lists.Add(new ListInstance()
            {
                Title        = "Testlist",
                TemplateType = 100,
                Url          = "lists/testlist"
            });

            template.TermGroups.AddRange(existingTemplate.TermGroups);

            ProvisioningHierarchy hierarchy = new ProvisioningHierarchy();

            hierarchy.Templates.Add(template);

            hierarchy.Parameters.Add("CompanyName", "Contoso");

            var sequence = new ProvisioningSequence
            {
                ID = Guid.NewGuid().ToString(),

                TermStore = new ProvisioningTermStore()
            };

            var termGroup = new TermGroup()
            {
                Name = "Contoso TermGroup"
            };
            var termSet = new TermSet()
            {
                Name = "Projects", Id = Guid.NewGuid(), IsAvailableForTagging = true, Language = 1033
            };
            var term = new Term()
            {
                Name = "Contoso Term"
            };

            termSet.Terms.Add(term);
            // termGroup.TermSets.Add(termSet);

            var existingTermSet = existingTemplate.TermGroups[0].TermSets[0];

            termGroup.TermSets.Add(existingTermSet);

            // sequence.TermStore.TermGroups.Add(termGroup);

            var teamSite1 = new TeamSiteCollection()
            {
                //  Alias = $"prov-1-{siteId}",
                Alias       = "prov-1",
                Description = "prov-1",
                DisplayName = "prov-1",
                IsHubSite   = false,
                IsPublic    = false,
                Title       = "prov-1",
            };

            teamSite1.Templates.Add("TestTemplate");

            var subsite = new TeamNoGroupSubSite()
            {
                Description = "Test Sub",
                Url         = "testsub1",
                Language    = 1033,
                TimeZoneId  = 4,
                Title       = "Test Sub",
                UseSamePermissionsAsParentSite = true
            };

            subsite.Templates.Add("TestTemplate");
            teamSite1.Sites.Add(subsite);

            sequence.SiteCollections.Add(teamSite1);

            var teamSite2 = new TeamSiteCollection()
            {
                Alias       = $"prov-2-{siteId}",
                Description = "prov-2",
                DisplayName = "prov-2",
                IsHubSite   = false,
                IsPublic    = false,
                Title       = "prov-2"
            };

            teamSite2.Templates.Add("TestTemplate");

            sequence.SiteCollections.Add(teamSite2);

            hierarchy.Sequences.Add(sequence);


            using (var tenantContext = TestCommon.CreateTenantClientContext())
            {
                var applyingInformation = new ProvisioningTemplateApplyingInformation();
                applyingInformation.ProgressDelegate = (message, step, total) =>
                {
                    if (message != null)
                    {
                    }
                };

                var tenant = new Tenant(tenantContext);

                tenant.ApplyProvisionHierarchy(hierarchy, sequence.ID, applyingInformation);
            }
        }