Example #1
0
        public static void ProcessOrigins(Tenant tenant, CdnSettings cdnSettings, SPOTenantCdnType cdnType, TokenParser parser, PnPMonitoredScope scope)
        {
            if (cdnSettings.Origins != null && cdnSettings.Origins.Any())
            {
                var origins = tenant.GetTenantCdnOrigins(cdnType);
                tenant.Context.ExecuteQueryRetry();
                foreach (var origin in cdnSettings.Origins)
                {
                    switch (origin.Action)
                    {
                    case OriginAction.Add:
                    {
                        var parsedOriginUrl = parser.ParseString(origin.Url);
                        if (!origins.Contains(parsedOriginUrl))
                        {
                            scope.LogInfo($"Adding {parsedOriginUrl} to {cdnType} CDN");
                            tenant.AddTenantCdnOrigin(cdnType, parsedOriginUrl);
                        }
                        break;
                    }

                    case OriginAction.Remove:
                    {
                        var parsedOriginUrl = parser.ParseString(origin.Url);
                        if (origins.Contains(parsedOriginUrl))
                        {
                            scope.LogInfo($"Removing {parsedOriginUrl} to {cdnType} CDN");
                            tenant.RemoveTenantCdnOrigin(cdnType, parsedOriginUrl);
                        }
                        break;
                    }
                    }
                    tenant.Context.ExecuteQueryRetry();
                }
            }
        }
 protected override void ExecuteCmdlet()
 {
     Tenant.AddTenantCdnOrigin(CdnType, OriginUrl);
     ClientContext.ExecuteQueryRetry();
 }