public override async Task <IList <IEntryModel> > ListAsync(IEntryModel entry, CancellationToken ct, Func <IEntryModel, bool> filter = null, bool refresh = false) { await checkLoginAsync(); if (filter == null) { filter = e => true; } GoogleDriveItemModel dirModel = (GoogleDriveItemModel)entry; if (dirModel != null) { if (!refresh) { var cachedChild = ModelCache.GetChildModel(dirModel); if (cachedChild != null) { return(cachedChild.Where(m => filter(m)).Cast <IEntryModel>().ToList()); } } var listRequest = _driveService.Files.List(); listRequest.Q = String.Format("'{0}' in parents", dirModel.UniqueId); var listResult = (await listRequest.ExecuteAsync().ConfigureAwait(false)); var listResultItems = listResult.Items.ToList(); var outputModels = listResultItems.Select(f => new GoogleDriveItemModel(this, f, dirModel.FullPath)).ToArray(); ModelCache.RegisterChildModels(dirModel, outputModels); return(outputModels.Where(m => filter(m)).Cast <IEntryModel>().ToList()); } return(new List <IEntryModel>()); }
public override void NotifySelectionChanged(IEntryModel[] appliedModels) { List <ICommandModel> subItemList = new List <ICommandModel>(); if (appliedModels.Count() == 1) { GoogleDriveItemModel model = appliedModels[0] as GoogleDriveItemModel; if (model != null && model.Metadata != null && model.Metadata.ExportLinks != null) { foreach (var mimeType in model.Metadata.ExportLinks.Keys) { string url = model.Metadata.ExportLinks[mimeType]; string ext = null; var match = Regex.Match(url, "[&]exportFormat=(?<ext>[\\w]*)$", RegexOptions.IgnoreCase); if (match.Success) { ext = "." + match.Groups["ext"].Value; } else { ext = ShellUtils.MIMEType2Extension(mimeType); } string filter = String.Format("{0} ({1})|*{1}", mimeType, ext); string defaultName = System.IO.Path.ChangeExtension(appliedModels[0].Name, ext); if (ext != null) { subItemList.Add( new CommandModel( //SaveFile --> ParseOrCreatePath -> ShowProgress -> Download -> HideProgress // --> OK (If cancel) WPFScriptCommands.SaveFilePicker(WindowManager, Events, _rootModelFunc(), filter, defaultName, (fi) => WPFScriptCommands.ParseOrCreatePath(fi.Profile as IDiskProfile, fi.FileName, false, (m) => WPFScriptCommands.ShowProgress(WindowManager, "Saving", WPFScriptCommands.Download(url, m, (appliedModels[0].Profile as GoogleDriveProfile) .HttpClientFunc(), new HideProgress()))), ResultCommand.OK) ) { Header = String.Format("{0} ({1})", mimeType, ext), IsEnabled = true, IsVisibleOnMenu = true }); } } } } SubCommands = subItemList; this.IsEnabled = subItemList.Count() > 0; }
public override IEnumerable <IModelIconExtractor <IEntryModel> > GetIconExtractSequence(IEntryModel entry) { foreach (var extractor in base.GetIconExtractSequence(entry)) { yield return(extractor); } GoogleDriveItemModel model = entry as GoogleDriveItemModel; string ext = Path.GetExtension(model.Name); if (model.ImageUrl != null && isImage(ext)) { yield return(new GetUriIcon(e => new Uri((e as GoogleDriveItemModel).ImageUrl), HttpClientFunc)); } //else if (model.Name.IndexOf('.') != -1) yield return(GetFromSystemImageListUsingExtension.Instance); if (entry.FullPath.Equals(Alias)) { yield return(EntryModelIconExtractors.ProvideValue(ProfileIcon)); } }
public override async Task <IEntryModel> CreateAsync(string fullPath, bool isDirectory, CancellationToken ct) { if (isDirectory) { string parentPath = _profile.Path.GetDirectoryName(fullPath); string name = _profile.Path.GetFileName(fullPath); GoogleDriveItemModel parentDir = await _profile.ParseAsync(parentPath) as GoogleDriveItemModel; if (parentDir == null) { throw new DirectoryNotFoundException(parentPath); } var newFolder = new Google.Apis.Drive.v2.Data.File() { Title = name, MimeType = GoogleMimeTypeManager.FolderMimeType }; if (parentDir.UniqueId != "root") { if (newFolder.Parents == null) { newFolder.Parents = new List <ParentReference>(); } newFolder.Parents.Add(new ParentReference() { Id = parentDir.UniqueId }); } var insertedFolder = (await _profile.DriveService.Files.Insert(newFolder).ExecuteAsync()); return(new GoogleDriveItemModel(_profile, insertedFolder, parentDir.FullPath)); } else { return(new GoogleDriveItemModel(_profile, fullPath, false)); } }