public static async Task <OneDriveInfoResult> GetFolderInFolder(this LiveConnectClient client, string desiredFolderName, string rootFolderId, CancellationToken cancellationToken)
        {
            try
            {
                var result = await client.GetItemsInFolderAsync(rootFolderId, cancellationToken);

                if (!result.IsSuccessful)
                {
                    OneDriveItem empty = new OneDriveFolder();
                    return(new OneDriveInfoResult(false, empty));
                }
                var items         = result.Items;
                var existedFolder = items.FirstOrDefault(item => item.Name.ToUpper() == desiredFolderName.ToUpper() && item.ItemType.HasFlag(OneDriveItemType.Folder));
                if (existedFolder != null)
                {
                    return(new OneDriveInfoResult(true, existedFolder));
                }
                return(await CreateFolderInFolderAsync(client, desiredFolderName, rootFolderId, cancellationToken));
            }
            catch (TaskCanceledException e)
            {
                Debug.WriteLine(e.Message);
                OneDriveItem empty = new OneDriveFolder();
                return(new OneDriveInfoResult(false, empty));
            }
        }
Example #2
0
        private static OneDriveItem GetItem(IDictionary <string, object> properties)
        {
            OneDriveItem result = null;

            if (properties.ContainsKey("type"))
            {
                var type = properties["type"].ToString().ToLower();
                switch (type)
                {
                case "notebook":
                    result = new OneDriveNoteBook();
                    break;

                case "folder":
                    result = new OneDriveFolder();
                    break;

                case "album":
                    result = new OneDriveAlbum();
                    break;

                case "file":
                    result = new OneDriveFile();
                    break;

                case "photo":
                    result = new OneDrivePhoto();
                    break;

                case "audio":
                    result = new OneDriveAudio();
                    break;

                case "video":
                    result = new OneDriveVideo();
                    break;

                default:
                    foreach (var property in properties)
                    {
                        Debug.WriteLine("{0}  :  {1}", property.Key, property.Value);
                    }
                    result = new OneDriveItem();
                    break;
                }
                OneDriveReflector.ReflectProperties(ref result, properties);
            }
            return(result);
        }