/// <summary> /// Return an item that represents a special named folder from the service. /// </summary> /// <param name="folder"></param> /// <returns></returns> public async Task <OneDriveItem> GetNamedFolderProperties(NamedFolder folder) { string pathToNamedFolder = string.Concat("/me" + FolderPathAttribute.FolderPathForValue(folder)); return(await GetObjectFromRequest <OneDriveItem>(pathToNamedFolder, (json) => OneDriveItem.CreateFromRawJson(json, this))); }
/// <summary> /// Return an item from a particular identifier /// </summary> /// <param name="fileResourceIdentifier"></param> /// <returns></returns> public async Task <OneDriveItem> GetItemFromIdentifier(string fileResourceIdentifier) { string pathForFileProperties = string.Format("/{0}", fileResourceIdentifier); return(await GetObjectFromRequest <OneDriveItem>(pathForFileProperties, (json) => OneDriveItem.CreateFromRawJson(json, this))); }
internal static OneDriveItem CreateFromRawJson(string rawJsonData, OneDriveClient sourceClient) { OneDriveItem item = JsonConvert.DeserializeObject <OneDriveItem>(rawJsonData); item.Client = sourceClient; return(item); }
/// <summary> /// Retrieve a reference to the root of the OneDrive namespace /// </summary> /// <returns></returns> public async Task <OneDriveItem> GetOneDriveRootAsync() { OneDriveItem rootItem = await GetObjectFromRequest <OneDriveItem>("/me/skydrive", (json) => OneDriveItem.CreateFromRawJson(json, this)); rootItem.Name = "OneDrive"; // Force the name to OneDrive, since the service returns SkyDrive return(rootItem); }
/// <summary> /// Moves the current item to a new parent item. Can move a folder to a new parent, or move a file into a new folder. /// </summary> /// <param name="parentItem"></param> /// <returns></returns> public async Task<bool> MoveToNewParentAsync(OneDriveItem parentItem) { throw new NotImplementedException(); }
private void AddFolderToHierarchy(OneDriveItem item, bool isFirstItem = false) { LinkLabel label = new LinkLabel(); if (!isFirstItem) { label.Text = "> " + item.Name; label.LinkArea = new LinkArea(2, item.Name.Length); } else { label.Text = item.Name; flowPanelHierarchy.Controls.Clear(); } label.AutoSize = true; label.Tag = item; label.LinkClicked += (sender, args) => { flowPanelHierarchy.SuspendLayout(); int index = flowPanelHierarchy.Controls.IndexOf((Control)sender); for (int i = flowPanelHierarchy.Controls.Count - 1; i > index; i--) { flowPanelHierarchy.Controls.RemoveAt(i); } flowPanelHierarchy.ResumeLayout(); LoadContentsOfFolder(((Control)sender).Tag as OneDriveItem); }; flowPanelHierarchy.Controls.Add(label); }
private void OnSelectFile(OneDriveItem file) { // TODO: Do something when the user selects a file. }
private void OnSelectFolder(OneDriveItem folder) { if (folder == this.CurrentFolder) return; AddFolderToHierarchy(folder); LoadContentsOfFolder(folder); }
private Label CreateLabelForItem(OneDriveItem item) { Label itemLabel = new Label(); itemLabel.Text = item.Name; itemLabel.Font = new Font("Segoe UI", 9.75f); itemLabel.TextAlign = ContentAlignment.BottomLeft; itemLabel.ForeColor = Color.White; itemLabel.BackColor = Color.RoyalBlue; itemLabel.AutoSize = false; itemLabel.Size = new Size(150, 100); itemLabel.Margin = new Padding(10); itemLabel.Padding = new Padding(3); itemLabel.Tag = item; itemLabel.Cursor = Cursors.Hand; itemLabel.Click += (sender, args) => { OneDriveItem selectedItem = ((Control)sender).Tag as OneDriveItem; if (null == selectedItem) return; if (selectedItem.ItemType == OneDriveItemType.Album || selectedItem.ItemType == OneDriveItemType.Folder) { OnSelectFolder(selectedItem); } else { OnSelectFile(selectedItem); } }; return itemLabel; }
private void PopulateContents(OneDriveItem[] contentsOfFolder) { bool waitCursor = this.UseWaitCursor; this.UseWaitCursor = true; flowPanelItems.SuspendLayout(); flowPanelItems.Controls.Clear(); foreach (OneDriveItem item in contentsOfFolder.OrderBy(odi => odi.Name)) { Label itemLabel = CreateLabelForItem(item); flowPanelItems.Controls.Add(itemLabel); } flowPanelItems.ResumeLayout(); this.UseWaitCursor = waitCursor; }
private async Task LoadContentsOfFolder(OneDriveItem parentItem) { if (!IsLoggedIn()) return; if (null == parentItem) return; this.CurrentFolder = parentItem; this.UseWaitCursor = true; OneDriveItem[] contentsOfFolder = await parentItem.GetChildItemsAsync(); PopulateContents(contentsOfFolder); this.UseWaitCursor = false; }
/// <summary> /// Moves the current item to a new parent item. Can move a folder to a new parent, or move a file into a new folder. /// </summary> /// <param name="parentItem"></param> /// <returns></returns> public async Task <bool> MoveToNewParentAsync(OneDriveItem parentItem) { throw new NotImplementedException(); }