コード例 #1
0
        private static async Task BuildUserLookupDictionary()
        {
            try
            {
                userLookupIds = new Dictionary <string, string>();

                // Get the root site
                var rootSite = await appClient.Sites["root"].Request().GetAsync();

                // Get the flight admin site
                var adminSite = await appClient
                                .Sites[$"{rootSite.SiteCollection.Hostname}:/sites/{flightAdminSite}"]
                                .Request().GetAsync();

                // Get all lists including the "system" lists
                // This is needed to see the User Information List
                var lists = await appClient.Sites[adminSite.Id].Lists.Request()
                            .Select(x => new { x.System, x.DisplayName, x.Id }).GetAsync();

                // Find the User Information List
                Microsoft.Graph.List userList = null;
                foreach (var list in lists.CurrentPage)
                {
                    if (string.Compare(list.DisplayName, "User Information List", true) == 0)
                    {
                        userList = list;
                        break;
                    }
                }

                if (userList == null)
                {
                    return;
                }

                var users = await appClient.Sites[adminSite.Id].Lists[userList.Id].Items.Request()
                            .Expand(x => new { x.Fields }).GetAsync();

                foreach (var user in users)
                {
                    object email = null;
                    if (user.Fields.AdditionalData.TryGetValue("EMail", out email))
                    {
                        if (!userLookupIds.TryAdd((email as string).ToLower(), user.Id))
                        {
                            Console.WriteLine($"Duplicate entry for {email}, ignored.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                userLookupIds = null;
            }
        }
コード例 #2
0
        //private async Task CopyFlightLogToTeamFilesAsync(GraphService graphClient, string groupId)
        //{
        //    // Upload flight log to team files
        //    // Get root site to determine SP host name
        //    var rootSite = await HttpGet<Site>($"/sites/root");

        //    // Get flight admin site
        //    var adminSite = await HttpGet<Site>($"{rootSite.SiteCollection.Hostname}:/sites/{flightAdminSite}");

        //    // Get the flight log document
        //    var flightLog = await HttpGet<DriveItem>($"/sites/{adminSite.Id}/drive/root:/{flightLogFile}");

        //    // Get the files folder in the team OneDrive
        //    var teamDrive = await HttpGet<DriveItem>($"/groups/{groupId}/drive/root:/General", retries: 4);
        //    // Retry this call if it fails
        //    // There seems to be a delay between creating a Team and the drives being
        //    // fully created/enabled

        //    // Copy the file from SharePoint to team drive
        //    var teamDriveReference = new ItemReference
        //    {
        //        DriveId = teamDrive.ParentReference.DriveId,
        //        Id = teamDrive.Id
        //    };

        //    await graphClient.CopySharePointFileAsync(adminSite.Id, flightLog.Id, teamDriveReference);
        //}

        //public async Task CopySharePointFileAsync(string siteId, string itemId, ItemReference target)
        //{
        //    var copyPayload = new DriveItem
        //    {
        //        ParentReference = target
        //    };

        //    var response = await HttpPost($"/sites/{siteId}/drive/items/{itemId}/copy",
        //        copyPayload);
        //}

        // Posting messages is supported in beta but will not GA in 2018.
        // Post a message to that channel
        //await HttpPost($"/teams/{teamId}/channels/{channel.Id}/chatThreads",
        //        new PostMessage()
        //{
        //    rootMessage = new RootMessage()
        //    {
        //        body = new MessageBody()
        //        {
        //            content = $"Welcome to Flight {flight.number}!"
        //        }
        //    }
        //        });


        public async Task <Microsoft.Graph.List> CreateSharePointListAsync(string siteId, Microsoft.Graph.List list)
        {
            var response = await HttpPost($"/sites/{siteId}/lists", list);

            return(JsonConvert.DeserializeObject <Microsoft.Graph.List>(response));
        }