/// <summary>
        /// Loads the items shared with the user in the "Shared with me" overview
        /// </summary>
        /// <param name="parentItem">OneDriveItem to display the child folders and items of. If not provided or NULL, the root folder will be used.</param>
        public async Task LoadSharedWithMeItems(OneDriveItem parentItem = null)
        {
            SharedWithMePicker.Items.Clear();

            if (parentItem == null)
            {
                // Get the root of the shared with me items
                var itemCollection = await _oneDriveApi.GetSharedWithMe();

                SharedWithMeUpButton.Enabled    = false;
                CurrentSharedWithMeOneDriveItem = null;
                GoToSharedWithMeRootTtoolStripMenuItem.Enabled = false;
                SharedWithMePath.Text = string.Empty;

                foreach (var listViewItem in itemCollection.Collection.OrderBy(i => i.Name).OrderBy(i => i.Folder == null).OrderBy(i => i.RemoteItem.Folder == null).Select(oneDriveItem => new ListViewItem
                {
                    Text = oneDriveItem.Name,
                    Tag = oneDriveItem,
                    ImageKey = (oneDriveItem.RemoteItem != null && oneDriveItem.RemoteItem.Folder != null) || oneDriveItem.Folder != null ? "RemoteFolder" : "File"
                }))
                {
                    SharedWithMePicker.Items.Add(listViewItem);
                }
            }
            else
            {
                // Parent folder provided, get its children
                var itemCollection = await _oneDriveApi.GetAllChildrenFromDriveByFolderId(parentItem.RemoteItem != null?parentItem.RemoteItem.ParentReference.DriveId : parentItem.ParentReference.DriveId, parentItem.RemoteItem != null?parentItem.RemoteItem.ParentReference != null?string.IsNullOrEmpty(parentItem.RemoteItem.ParentReference.Id)?parentItem.RemoteItem.Id : parentItem.RemoteItem.ParentReference.Id : parentItem.RemoteItem.Id : parentItem.Id);

                SharedWithMeUpButton.Tag = parentItem.Name == "root" || parentItem.ParentReference.Id == null || (parentItem.ParentReference.Path != null && parentItem.ParentReference.Path.EndsWith("root:")) ? null : await _oneDriveApi.GetItemFromDriveById(parentItem.ParentReference.Id, parentItem.ParentReference.DriveId);

                CurrentSharedWithMeOneDriveItem = parentItem;
                GoToSharedWithMeRootTtoolStripMenuItem.Enabled = true;
                SharedWithMeUpButton.Enabled = CurrentSharedWithMeOneDriveItem.ParentReference != null;

                if (CurrentSharedWithMeOneDriveItem.ParentReference.Path != null)
                {
                    var rootLocation = CurrentSharedWithMeOneDriveItem.ParentReference.Path.IndexOf("root:");
                    SharedWithMePath.Text = ((rootLocation == -1 ? CurrentSharedWithMeOneDriveItem.ParentReference.Path : CurrentSharedWithMeOneDriveItem.ParentReference.Path.Remove(0, rootLocation + 5).TrimStart(new[] { '/' })) + "/" + CurrentSharedWithMeOneDriveItem.Name).TrimStart(new[] { '/' });
                }
                else
                {
                    SharedWithMePath.Text = CurrentSharedWithMeOneDriveItem.Name;
                }

                foreach (var listViewItem in itemCollection.Select(oneDriveItem => new ListViewItem
                {
                    Text = oneDriveItem.Name,
                    Tag = oneDriveItem,
                    ImageKey = oneDriveItem.Folder != null ? "RemoteFolder" : "File"
                }))
                {
                    SharedWithMePicker.Items.Add(listViewItem);
                }
            }

            // Define if the OK button should be enabled
            FileNameTextBox_TextChanged(null, null);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the items shared with the user in the "Shared with me" overview
        /// </summary>
        /// <param name="parentItem">OneDriveItem to display the child folders and items of. If not provided or NULL, the root folder will be used.</param>
        public async Task LoadSharedWithMeItems(OneDriveItem parentItem = null)
        {
            SharedWithMePicker.Items.Clear();

            if (parentItem == null)
            {
                // Get the root of the shared with me items
                var itemCollection = await _oneDriveApi.GetSharedWithMe();

                var sortedItemCollection = itemCollection.Collection.OrderBy(i => i.Name).OrderBy(i => i.Folder == null).OrderBy(i => i.RemoteItem.Folder == null);
                SharedWithMeUpButton.Enabled    = false;
                CurrentSharedWithMeOneDriveItem = null;
                GoToSharedWithMeRootTtoolStripMenuItem.Enabled = false;
                SharedWithMePath.Text = string.Empty;

                foreach (var oneDriveItem in sortedItemCollection)
                {
                    var oneDriveListViewItem = new ListViewItem
                    {
                        Text     = oneDriveItem.Name,
                        Tag      = oneDriveItem,
                        ImageKey = (oneDriveItem.RemoteItem != null && oneDriveItem.RemoteItem.Folder != null) || oneDriveItem.Folder != null ? "RemoteFolder" : "File",
                    };

                    OneDriveIdentity sharedInfo = null;
                    if (oneDriveItem.RemoteItem != null && oneDriveItem.RemoteItem.Shared != null && oneDriveItem.RemoteItem.Shared.Owner != null && oneDriveItem.RemoteItem.Shared.Owner.User != null)
                    {
                        sharedInfo = oneDriveItem.RemoteItem.Shared.Owner.User;
                    }
                    else if (oneDriveItem.Shared != null && oneDriveItem.Shared.Owner != null && oneDriveItem.Shared.Owner.User != null)
                    {
                        sharedInfo = oneDriveItem.Shared.Owner.User;
                    }
                    if (sharedInfo != null)
                    {
                        oneDriveListViewItem.ToolTipText = string.Format("Shared by {0} ({1})", sharedInfo.DisplayName, sharedInfo.Id);
                    }
                    else
                    {
                        oneDriveListViewItem.ToolTipText = "Shared by information not available";
                    }
                    if (oneDriveItem.Size > 0)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Size: {0:n0} bytes", oneDriveItem.Size);
                    }
                    else if (oneDriveItem.RemoteItem != null && oneDriveItem.RemoteItem.Size > 0)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Size: {0:n0} bytes", oneDriveItem.RemoteItem.Size);
                    }
                    if (oneDriveItem.CreatedDateTime != null)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Created: {0:d MMMM yyyy HH:mm:ss}", oneDriveItem.CreatedDateTime);
                    }
                    if (oneDriveItem.LastModifiedDateTime != null)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Last modified: {0:d MMMM yyyy HH:mm:ss}", oneDriveItem.LastModifiedDateTime);
                    }

                    SharedWithMePicker.Items.Add(oneDriveListViewItem);
                }
            }
            else
            {
                // Parent folder provided, get its children
                var itemCollection = await _oneDriveApi.GetAllChildrenFromDriveByFolderId(parentItem.RemoteItem != null?parentItem.RemoteItem.ParentReference.DriveId : parentItem.ParentReference.DriveId,
                                                                                          parentItem.RemoteItem != null?parentItem.RemoteItem.ParentReference != null?string.IsNullOrEmpty(parentItem.RemoteItem.ParentReference.Id) || parentItem.RemoteItem.Folder != null?parentItem.RemoteItem.Id : parentItem.RemoteItem.ParentReference.Id : parentItem.RemoteItem.Id : parentItem.Id);

                SharedWithMeUpButton.Tag = parentItem.Name == "root" || parentItem.ParentReference == null || parentItem.ParentReference.Id == null || (parentItem.ParentReference.Path != null && parentItem.ParentReference.Path.EndsWith("root:")) ? null : await _oneDriveApi.GetItemFromDriveById(parentItem.ParentReference.Id, parentItem.ParentReference.DriveId);

                CurrentSharedWithMeOneDriveItem = parentItem;
                GoToSharedWithMeRootTtoolStripMenuItem.Enabled = true;
                SharedWithMeUpButton.Enabled = true;

                if (CurrentSharedWithMeOneDriveItem.ParentReference != null && CurrentSharedWithMeOneDriveItem.ParentReference.Path != null)
                {
                    var rootLocation = CurrentSharedWithMeOneDriveItem.ParentReference.Path.IndexOf("root:");
                    SharedWithMePath.Text = ((rootLocation == -1 ? CurrentSharedWithMeOneDriveItem.ParentReference.Path : CurrentSharedWithMeOneDriveItem.ParentReference.Path.Remove(0, rootLocation + 5).TrimStart(new[] { '/' })) + "/" + CurrentSharedWithMeOneDriveItem.Name).TrimStart(new[] { '/' });
                }
                else
                {
                    SharedWithMePath.Text = CurrentSharedWithMeOneDriveItem.Name;
                }

                foreach (var oneDriveItem in itemCollection)
                {
                    var oneDriveListViewItem = new ListViewItem
                    {
                        Text     = oneDriveItem.Name,
                        Tag      = oneDriveItem,
                        ImageKey = oneDriveItem.Folder != null ? "RemoteFolder" : "File",
                    };

                    OneDriveIdentity sharedInfo = null;
                    if (oneDriveItem.RemoteItem != null && oneDriveItem.RemoteItem.Shared != null && oneDriveItem.RemoteItem.Shared.Owner != null && oneDriveItem.RemoteItem.Shared.Owner.User != null)
                    {
                        sharedInfo = oneDriveItem.RemoteItem.Shared.Owner.User;
                    }
                    else if (oneDriveItem.Shared != null && oneDriveItem.Shared.Owner != null && oneDriveItem.Shared.Owner.User != null)
                    {
                        sharedInfo = oneDriveItem.Shared.Owner.User;
                    }
                    if (sharedInfo != null)
                    {
                        oneDriveListViewItem.ToolTipText = string.Format("Shared by {0} ({1})", sharedInfo.DisplayName, sharedInfo.Id);
                    }
                    else
                    {
                        oneDriveListViewItem.ToolTipText = "Shared by information not available";
                    }
                    if (oneDriveItem.Size > 0)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Size: {0} bytes", oneDriveItem.Size);
                    }
                    else if (oneDriveItem.RemoteItem != null && oneDriveItem.RemoteItem.Size > 0)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Size: {0} bytes", oneDriveItem.RemoteItem.Size);
                    }
                    if (oneDriveItem.CreatedDateTime != null)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Created: {0:d MMMM yyyy HH:mm:ss}", oneDriveItem.CreatedDateTime);
                    }
                    if (oneDriveItem.LastModifiedDateTime != null)
                    {
                        oneDriveListViewItem.ToolTipText += Environment.NewLine + string.Format("Last modified: {0:d MMMM yyyy HH:mm:ss}", oneDriveItem.LastModifiedDateTime);
                    }

                    SharedWithMePicker.Items.Add(oneDriveListViewItem);
                }
            }

            // Define if the OK button should be enabled
            FileNameTextBox_TextChanged(null, null);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets all items in OneDrive that have been shared with the current user
        /// </summary>
        private async void SharedWithMeButton_Click(object sender, EventArgs e)
        {
            var data = await OneDriveApi.GetSharedWithMe();

            JsonResultTextBox.Text = data.OriginalJson;
        }