/// <summary> /// Init Local with the System drives /// </summary> public void InitLocal() { LocalPath = null; LocalItems.Clear(); var drives = DriveInfo.GetDrives(); foreach (var drive in drives) { LocalItems.Add(new ProtocolItem(drive.Name, drive.Name, 0, DateTime.Today, FolderType.Instance)); } }
/// <summary> /// Method for get all files and folders in a folder /// </summary> /// <param name="destination"></param> /// <param name="path"></param> public void GetLocalFilesAndFolders(ObservableCollection <ProtocolItem> destination, string path) { destination.Clear(); var directories = Directory.GetDirectories(path); foreach (var entry in directories) { var di = new DirectoryInfo(entry); LocalItems.Add(new ProtocolItem(Path.GetFileName(entry), entry, 0, di.LastWriteTime, FolderType.Instance)); } var files = Directory.GetFiles(path); foreach (var file in files) { var fi = new FileInfo(file); LocalItems.Add(new ProtocolItem(Path.GetFileName(file), file, fi.Length, fi.LastWriteTime, FileType.Instance)); } }
private async void ItemDownloaderOnDownloadComplete(object sender, AsyncCompletedEventArgs asyncCompletedEventArgs) { var id = ((DownloadProgress)asyncCompletedEventArgs.UserState).Id; var url = ((DownloadProgress)asyncCompletedEventArgs.UserState).Url; var willRetryOnError = ((DownloadProgress)asyncCompletedEventArgs.UserState).WillRetryOnError; var localFilePath = ((DownloadProgress)asyncCompletedEventArgs.UserState).LocalFilePath; var title = ((DownloadProgress)asyncCompletedEventArgs.UserState).Title; var isCustomError = ((DownloadProgress)asyncCompletedEventArgs.UserState).IsCustomError; if (!asyncCompletedEventArgs.Cancelled && asyncCompletedEventArgs.Error != null && willRetryOnError) { return; } LibraryItem itemBeingDownloaded = null; if (CloudItems != null) { itemBeingDownloaded = CloudItems.FirstOrDefault(item => item.ID == id || item.DownloadUrl == url); } if (itemBeingDownloaded != null) { if (asyncCompletedEventArgs.Cancelled) { itemBeingDownloaded.DownloadStatus = DownloadStatus.Canceled; } else if (asyncCompletedEventArgs.Error != null) { itemBeingDownloaded.DownloadStatus = DownloadStatus.Failed; } else { itemBeingDownloaded.DownloadStatus = DownloadStatus.Completed; } itemBeingDownloaded.DownloadProgress = null; } if (!asyncCompletedEventArgs.Cancelled) { if (asyncCompletedEventArgs.Error != null) { var message = "There was a problem downloading your recording of \"" + title + "\". Please try again!"; if (isCustomError) { message = asyncCompletedEventArgs.Error.Message; } await RemoteNotificationsService.Instance.TriggerLocalNotification(new AppNotificationMessage { ID = id, Text = message, Type = AppNotificationType.DownloadFailed }); } else { await RemoteNotificationsService.Instance.TriggerLocalNotification(new AppNotificationMessage { ID = id, Text = "Your recording of \"" + title + "\" was downloaded successfully!", Type = AppNotificationType.DownloadComplete }); var downloadedItem = new LibraryItem { ID = id, Storage = LibraryItemStorage.AppLocal, LocalFilePath = localFilePath }; if (LocalLibraryService.Instance.CreateMediaItem(downloadedItem, true)) { if (itemBeingDownloaded != null) { itemBeingDownloaded.LocalItem = downloadedItem; } if (LocalItems != null) { var itemsToDelete = LocalItems.Where( item => item.LocalFilePath == downloadedItem.LocalFilePath && item.Storage == downloadedItem.Storage).ToArray(); foreach (var itemToDelete in itemsToDelete) { LocalItems.Remove(itemToDelete); } LocalItems.Add(downloadedItem); await sort(librarySort); OnPropertyChanged(nameof(LocalItemsCount)); } } else { LoggerService.Instance.Log( "Library.ItemDownloaderOnDownloadComplete: Unable to create media item"); } } } if (itemBeingDownloaded != null) { try { SuspendOnSelectedItemDetailsChangedEvent = true; Download.ChangeCanExecute(); CancelDownload.ChangeCanExecute(); Delete.ChangeCanExecute(); Play.ChangeCanExecute(); SuspendOnSelectedItemDetailsChangedEvent = false; } catch { } } }