Example #1
0
        public ActionResult SetFiletypes(List <string> filetypes)
        {
            try
            {
                string cdnFileTypes;

                using (var clientContext = GetClientContext())
                {
                    var tenant = new Office365Tenant(clientContext);

                    var newFileTypes = string.Join(",", filetypes);

                    tenant.SetTenantCdnPolicy(SPOTenantCdnType.Public, SPOTenantCdnPolicyType.IncludeFileExtensions, newFileTypes);

                    var publicCDNPolicies = tenant.GetTenantCdnPolicies(SPOTenantCdnType.Public);

                    clientContext.ExecuteQuery();

                    cdnFileTypes = publicCDNPolicies.Where(s => s.StartsWith(SPOTenantCdnPolicyType.IncludeFileExtensions.ToString())).First();
                }

                return(Json(ConvertToList(cdnFileTypes)));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Json(ex.Message));
            }
        }
Example #2
0
        public ActionResult GetCDNSettings()
        {
            var cdnManagerModel = new CDNManagerModel();

            using (var clientContext = GetClientContext())
            {
                clientContext.Load(clientContext.Web, w => w.Url);

                var tenant            = new Office365Tenant(clientContext);
                var publicCDNEnabled  = tenant.GetTenantCdnEnabled(SPOTenantCdnType.Public);
                var publicCdnOrigins  = tenant.GetTenantCdnOrigins(SPOTenantCdnType.Public);
                var publicCDNPolicies = tenant.GetTenantCdnPolicies(SPOTenantCdnType.Public);

                clientContext.ExecuteQuery();

                cdnManagerModel.PublicCDNEnabled = publicCDNEnabled.Value;
                cdnManagerModel.Origins          = publicCdnOrigins; //Origins will need refactor. It is just a string now, not an object
                var fileTypes = publicCDNPolicies.Where(s => s.StartsWith(SPOTenantCdnPolicyType.IncludeFileExtensions.ToString())).First();
                cdnManagerModel.Filetypes  = ConvertToList(fileTypes);
                cdnManagerModel.SPOSiteUrl = clientContext.Web.Url;
            }

            return(Json(cdnManagerModel, JsonRequestBehavior.AllowGet));
        }