Beispiel #1
0
        /// <summary>
        /// Create new library with the specified name.
        /// </summary>
        /// <param name="name">The name of the new library (must be unique)</param>
        /// <returns>The new library if successfully created</returns>
        public static async Task <LibraryLocationItem> CreateLibrary(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }
            var connection = await AppServiceConnectionHelper.Instance;

            if (connection == null)
            {
                return(null);
            }
            var(status, response) = await connection.SendMessageForResponseAsync(new ValueSet
            {
                { "Arguments", "ShellLibrary" },
                { "action", "Create" },
                { "library", name }
            });

            LibraryLocationItem library = null;

            if (status == AppServiceResponseStatus.Success && response.ContainsKey("Create"))
            {
                library = new LibraryLocationItem(JsonConvert.DeserializeObject <ShellLibraryItem>((string)response["Create"]));
            }
            return(library);
        }
Beispiel #2
0
 private async Task AddItemsAsync(LibraryLocationItem library, ObservableCollection <ListedItem> results)
 {
     foreach (var folder in library.Folders)
     {
         await AddItemsAsync(folder, results);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Update library details.
        /// </summary>
        /// <param name="libraryFilePath">Library file path</param>
        /// <param name="defaultSaveFolder">Update the default save folder or null to keep current</param>
        /// <param name="folders">Update the library folders or null to keep current</param>
        /// <param name="isPinned">Update the library pinned status or null to keep current</param>
        /// <returns>The new library if successfully updated</returns>
        public static async Task <LibraryLocationItem> UpdateLibrary(string libraryFilePath, string defaultSaveFolder = null, string[] folders = null, bool?isPinned = null)
        {
            if (string.IsNullOrWhiteSpace(libraryFilePath) || (defaultSaveFolder == null && folders == null && isPinned == null))
            {
                // Nothing to update
                return(null);
            }
            var connection = await AppServiceConnectionHelper.Instance;

            if (connection == null)
            {
                return(null);
            }
            var request = new ValueSet
            {
                { "Arguments", "ShellLibrary" },
                { "action", "Update" },
                { "library", libraryFilePath }
            };

            if (!string.IsNullOrEmpty(defaultSaveFolder))
            {
                request.Add("defaultSaveFolder", defaultSaveFolder);
            }
            if (folders != null)
            {
                request.Add("folders", JsonConvert.SerializeObject(folders));
            }
            if (isPinned != null)
            {
                request.Add("isPinned", isPinned);
            }
            var(status, response) = await connection.SendMessageForResponseAsync(request);

            LibraryLocationItem library = null;

            if (status == AppServiceResponseStatus.Success && response.ContainsKey("Update"))
            {
                library = new LibraryLocationItem(JsonConvert.DeserializeObject <ShellLibraryItem>((string)response["Update"]));
            }
            return(library);
        }