// Get the items that are shared with the current user.
        public async Task <List <ResultsItem> > GetSharedWithMe(GraphServiceClient graphClient)
        {
            List <ResultsItem> items = new List <ResultsItem>();

            // Get shared items.
            IDriveSharedWithMeCollectionPage driveItems = await graphClient.Me.Drive.SharedWithMe().Request().GetAsync();

            if (driveItems?.Count > 0)
            {
                foreach (DriveItem driveItem in driveItems)
                {
                    // Get item properties.
                    string type = driveItem.RemoteItem.File?.ToString() ?? driveItem.RemoteItem.Folder?.ToString();
                    items.Add(new ResultsItem
                    {
                        Properties = new Dictionary <string, object>
                        {
                            { Resource.Prop_Name, driveItem.RemoteItem.Name + " (" + type?.Replace("Microsoft.Graph.", "") + ")" },
                            { Resource.Prop_Id, driveItem.RemoteItem.Id }
                        }
                    });
                }
            }
            return(items);
        }
Ejemplo n.º 2
0
        public async Task <List <CachedDrive> > GetDrivesFromGraph()
        {
            // Compile a list of drives, straight from Graph
            List <DriveItem> localDriveList = new List <DriveItem>();

            localDriveList.Add(await Graph.GetUserRootDrive());

            IDriveSharedWithMeCollectionPage sharedDrivesCollection = await Graph.GetSharedDrivesAsync();

            foreach (DriveItem drive in sharedDrivesCollection)
            {
                if (drive.Folder != null)
                {
                    localDriveList.Add(drive);
                }
            }

            // Convert the Graph format
            List <CachedDrive> newlyCachedDrives = new List <CachedDrive>();

            foreach (DriveItem graphDrive in localDriveList)
            {
                CachedDrive driveToAdd = new CachedDrive
                {
                    Id            = graphDrive.Id,
                    ChildrenCount = graphDrive.Folder.ChildCount
                };
                // Check if the current graphDrive in the localDriveList is the personal graphDrive
                if (graphDrive.RemoteItem is null)
                {
                    // this is the personal drive
                    driveToAdd.DriveName      = "Your Drive";
                    driveToAdd.DriveId        = graphDrive.ParentReference.DriveId;
                    driveToAdd.IsSharedFolder = false;
                }
                else
                {
                    driveToAdd.DriveName      = graphDrive.Name;
                    driveToAdd.DriveId        = graphDrive.RemoteItem.ParentReference.DriveId;
                    driveToAdd.IsSharedFolder = true;
                }
                newlyCachedDrives.Add(driveToAdd);
            }
            return(newlyCachedDrives);
        }
Ejemplo n.º 3
0
        private async Task <List <FileDescription> > ListShares(OneDrive2ItemLocation <OneDrive2PrefixContainerType> parentPath, IGraphServiceClient client)
        {
            List <FileDescription> result = new List <FileDescription>();


            DriveItem root = await client.Me.Drive.Root.Request().GetAsync();

            FileDescription myEntry = GetFileDescription(parentPath.BuildShare("me", "me", "me", root.ParentReference?.DriveId), root);

            myEntry.DisplayName = MyOneDriveDisplayName;

            result.Add(myEntry);

            if (!CanListShares)
            {
                return(result);
            }



            IDriveSharedWithMeCollectionPage sharedWithMeCollectionPage = await client.Me.Drive.SharedWithMe().Request().GetAsync();

            while (true)
            {
                IList <DriveItem> sharedWithMeItems = sharedWithMeCollectionPage.CurrentPage;
                if (!sharedWithMeItems.Any())
                {
                    break;
                }

                foreach (DriveItem i in sharedWithMeItems)
                {
                    FileDescription sharedFileEntry = GetFileDescription(parentPath.BuildShare(i.Id, i.Name, i.WebUrl, i.ParentReference?.DriveId), i);
                    result.Add(sharedFileEntry);
                }
                var b = sharedWithMeCollectionPage.NextPageRequest;
                if (b == null)
                {
                    break;
                }
                sharedWithMeCollectionPage = await b.GetAsync();
            }
            return(result);
        }