Esempio n. 1
0
        public override IEnumerable <IModelIconExtractor <IEntryModel> > GetIconExtractSequence(IEntryModel entry)
        {
            checkLogin();

            foreach (var extractor in base.GetIconExtractSequence(entry))
            {
                yield return(extractor);
            }

            DropBoxItemModel model = entry as DropBoxItemModel;

            //if (model.ImageUrl != null)
            //    yield return new GetUriIcon(e => new Uri((e as SkyDriveItemModel).ImageUrl));
            //else
            //if (model.Name.IndexOf('.') != -1)
            yield return(GetFromSystemImageListUsingExtension.Instance);

            if (model.FullPath == Alias)
            {
                yield return(EntryModelIconExtractors.ProvideValue(ProfileIcon));
            }

            else if (model.Metadata != null && model.Metadata.Thumb_Exists)
            {
                yield return(_thumbnailExtractor);
            }
        }
        public override async Task DeleteAsync(IEntryModel entryModel, CancellationToken ct)
        {
            DropBoxItemModel entry = entryModel as DropBoxItemModel;
            var profile            = entry.Profile as DropBoxProfile;

            await profile.GetClient().DeleteTask(entry.RemotePath);
        }
        public override async Task <IEntryModel> CreateAsync(string fullPath, bool isDirectory, CancellationToken ct)
        {
            _profile.checkLogin();
            string parentPath       = _profile.Path.GetDirectoryName(fullPath);
            string parentRemotePath = _profile.ConvertRemotePath(parentPath);
            string name             = _profile.Path.GetFileName(fullPath);
            string remotePath       = _profile.Path.Combine(parentRemotePath, name);

            if (isDirectory)
            {
                DropBoxItemModel parentDir = await _profile.ParseAsync(parentPath)
                                             as DropBoxItemModel;

                if (parentDir == null)
                {
                    throw new DirectoryNotFoundException(parentPath);
                }


                var addedFolder = await _profile.GetClient().CreateFolderTask(remotePath, m => { }, e => { });

                ct.ThrowIfCancellationRequested();
                return(new DropBoxItemModel(_profile, addedFolder, parentDir.FullPath));
            }
            else
            {
                return(new DropBoxItemModel(_profile, name, parentRemotePath));
            }
        }
        public override async Task <IEntryModel> RenameAsync(IEntryModel entryModel, string newName, CancellationToken ct)
        {
            DropBoxItemModel entry = entryModel as DropBoxItemModel;
            var    profile         = entry.Profile as DropBoxProfile;
            string newRemotePath   = profile.Path.Combine(
                profile.Path.GetDirectoryName(entry.RemotePath), newName);
            string newPath = profile.Path.Combine(
                profile.Path.GetDirectoryName(entry.FullPath), newName);
            await profile.GetClient().MoveTask(entry.RemotePath, newRemotePath);

            return(await profile.ParseAsync(newPath));
        }
Esempio n. 5
0
        public override async Task <IList <IEntryModel> > ListAsync(IEntryModel entry, CancellationToken ct,
                                                                    Func <IEntryModel, bool> filter = null, bool refresh = false)
        {
            checkLogin();

            if (filter == null)
            {
                filter = em => true;
            }

            List <IEntryModel>      retList   = new List <IEntryModel>();
            List <DropBoxItemModel> cacheList = new List <DropBoxItemModel>();

            var dirModel = (entry as DropBoxItemModel);

            if (dirModel != null)
            {
                if (!refresh)
                {
                    var cachedChild = ModelCache.GetChildModel(dirModel);
                    if (cachedChild != null)
                    {
                        return(cachedChild.Where(m => filter(m)).Cast <IEntryModel>().ToList());
                    }
                }
                ct.ThrowIfCancellationRequested();

                var fetchedMetadata = await GetClient().GetMetaDataTask(ConvertRemotePath(entry.FullPath));

                foreach (var metadata in fetchedMetadata.Contents)
                {
                    var retVal = new DropBoxItemModel(this, metadata, dirModel.FullPath);
                    cacheList.Add(ModelCache.RegisterModel(retVal));
                    if (filter(retVal))
                    {
                        retList.Add(retVal);
                    }
                }
                ModelCache.RegisterChildModels(dirModel, cacheList.ToArray());
            }
            return(retList);
        }