コード例 #1
0
 public void GetTenantAdminCenterUrlForRegularTenants()
 {
     Assert.AreEqual(new Uri("https://bertonline-admin.sharepoint.com"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://bertonline.sharepoint.com")));
     Assert.AreEqual(new Uri("https://bertonline-admin.sharepoint.com"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://bertonline-my.sharepoint.com")));
     Assert.AreEqual(new Uri("https://bertonline-admin.sharepoint.com"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://bertonline-admin.sharepoint.com")));
     Assert.AreEqual(new Uri("https://BertOnline-admin.sharepoint.com"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://BertOnline.sharepoint.com")));
     Assert.AreEqual(new Uri("https://BertOnline-admin.sharepoint.com"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://BertOnline-my.sharepoint.com")));
     Assert.AreEqual(new Uri("https://BertOnline-admin.sharepoint.com"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://BertOnline-admin.sharepoint.com")));
     Assert.AreEqual(new Uri("https://bertonline-admin.sharepoint.us"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://bertonline.sharepoint.us")));
     Assert.AreEqual(new Uri("https://bertonline-admin.sharepoint.us"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://bertonline-my.sharepoint.us")));
     Assert.AreEqual(new Uri("https://bertonline-admin.sharepoint.us"), SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri("https://bertonline-admin.sharepoint.us")));
 }
コード例 #2
0
        public async Task <List <IGeoLocationInformation> > GetMultiGeoLocationsAsync()
        {
            var result = await(context.Web as Web).RawRequestAsync(new ApiCall("sites?filter=siteCollection/root%20ne%20null&select=webUrl,siteCollection", ApiType.Graph), HttpMethod.Get).ConfigureAwait(false);

            #region Json responses

            /* Response if not multi-geo
             *
             * {
             *  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
             *  "value": [
             *      {
             *          "webUrl": "https://bertonline.sharepoint.com/",
             *          "siteCollection": {
             *              "hostname": "bertonline.sharepoint.com",
             *              "root": {}
             *          }
             *      }
             *  ]
             * }
             *
             * response if multi geo
             *
             * {
             *  "@odata.context": "https://graph.microsoft.com/beta/$metadata#sites",
             *  "value": [
             *      {
             *          "webUrl": "https://contoso.sharepoint.com/",
             *          "siteCollection": {
             *              "dataLocationCode":"NAM",
             *              "hostname": "contoso.sharepoint.com"
             *          }
             *      },
             *      {
             *          "webUrl": "https://contosoeur.sharepoint.com/",
             *          "siteCollection": {
             *              "dataLocationCode":"EUR",
             *              "hostname": "contosoeur.sharepoint.com"
             *          }
             *      },
             *      {
             *          "webUrl": "https://contosoapc.sharepoint.com/",
             *          "siteCollection": {
             *              "dataLocationCode":"APC",
             *              "hostname": "contosoapc.sharepoint.com"
             *          }
             *      }
             *  ]
             * }
             */
            #endregion

            var root = JsonDocument.Parse(result.Json).RootElement.GetProperty("value");

            List <IGeoLocationInformation> dataLocations = null;

            if (root.ValueKind == JsonValueKind.Array)
            {
                foreach (var siteInformation in root.EnumerateArray())
                {
                    if (siteInformation.TryGetProperty("siteCollection", out JsonElement siteCollection))
                    {
                        if (siteCollection.TryGetProperty("dataLocationCode", out JsonElement dataLocationCode))
                        {
                            if (dataLocationCode.ValueKind == JsonValueKind.String && !string.IsNullOrEmpty(dataLocationCode.GetString()))
                            {
                                if (dataLocations == null)
                                {
                                    dataLocations = new List <IGeoLocationInformation>();
                                }

                                var geoLocation = new GeoLocationInformation()
                                {
                                    DataLocationCode    = (GeoLocation)Enum.Parse(typeof(GeoLocation), dataLocationCode.GetString()),
                                    SharePointPortalUrl = siteInformation.GetProperty("webUrl").GetString(),
                                    SharePointAdminUrl  = SharePointAdmin.GetTenantAdminCenterUriForStandardTenants(new Uri(siteInformation.GetProperty("webUrl").GetString())).ToString(),
                                    SharePointMySiteUrl = SharePointAdmin.GetTenantMySiteHostUriForStandardTenants(new Uri(siteInformation.GetProperty("webUrl").GetString())).ToString()
                                };

                                if (dataLocations.FirstOrDefault(p => p.DataLocationCode == geoLocation.DataLocationCode) == null)
                                {
                                    dataLocations.Add(geoLocation);
                                }
                            }
                        }
                    }
                }
            }

            return(dataLocations);
        }