예제 #1
0
        public override async Task <CloudProviderResponse <List <CloudStorageProviderFileBase> > > ListFiles()
        {
            try
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "DropboxStorageProvider ListFiles.");

                List <CloudStorageProviderFileBase> files = new List <CloudStorageProviderFileBase>();
                ListFolderArg    arg = new ListFolderArg(String.Empty, true);
                ListFolderResult listFolderResult = await _client.Files.ListFolderAsync(arg);

                foreach (Metadata curFile in listFolderResult.Entries)
                {
                    DropboxStorageProviderFile file = DropboxStorageProviderFile.FromMetadata(curFile);
                    if (!file.IsFolder)
                    {
                        if (file.Path.ToLower().EndsWith(".vault"))
                        {
                            files.Add(file);
                        }
                    }
                }
                return(new CloudProviderResponse <List <CloudStorageProviderFileBase> >(files));
            }
            catch (AuthException ae)
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An authorisation error occurred whilst attempting to list files from DropboxStorageProvider. {0}", ae.Message);
                return(new CloudProviderResponse <List <CloudStorageProviderFileBase> >(CloudProviderResponse <List <CloudStorageProviderFileBase> > .Response.AuthenticationError, ae));
            }
            catch (DropboxException de)
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An error occurred whilst attempting to list files from DropboxStorageProvider. {0}", de.Message);
                if (de.Message.ToLower().Contains("not_found"))
                {
                    return(new CloudProviderResponse <List <CloudStorageProviderFileBase> >(CloudProviderResponse <List <CloudStorageProviderFileBase> > .Response.NotFound, de));
                }
                else
                {
                    return(new CloudProviderResponse <List <CloudStorageProviderFileBase> >(CloudProviderResponse <List <CloudStorageProviderFileBase> > .Response.UnknownError, de));
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An unknown error occurred whilst attempting to list files from DropboxStorageProvider. {1}", ex.Message);
                return(new CloudProviderResponse <List <CloudStorageProviderFileBase> >(CloudProviderResponse <List <CloudStorageProviderFileBase> > .Response.UnknownError, ex));
            }
        }
예제 #2
0
        //Need to change this to return a response object that contains the result
        //as a property if successful
        public override async Task <CloudProviderResponse <CloudStorageProviderFileBase> > GetFileInfo(string path)
        {
            try
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "DropboxStorageProvider GetFileInfo '{0}'.", path);

                Metadata fileMetaData = await _client.Files.GetMetadataAsync(path,
                                                                             false,
                                                                             false,
                                                                             false);

                DropboxStorageProviderFile file = DropboxStorageProviderFile.FromMetadata(fileMetaData);
                return(new CloudProviderResponse <CloudStorageProviderFileBase>(file));
            }
            catch (AuthException ae)
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An authorisation error occurred whilst attempting to get file info for '{0}' from DropboxStorageProvider. {1}", path, ae.Message);
                return(new CloudProviderResponse <CloudStorageProviderFileBase>(CloudProviderResponse <CloudStorageProviderFileBase> .Response.AuthenticationError, ae));
            }
            catch (DropboxException e)
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An error occurred whilst attempting to get file info for '{0}' from DropboxStorageProvider. {1}", path, e.Message);
                if (e.Message.ToLower().Contains("not_found"))
                {
                    return(new CloudProviderResponse <CloudStorageProviderFileBase>(CloudProviderResponse <CloudStorageProviderFileBase> .Response.NotFound, e));
                }
                else
                {
                    return(new CloudProviderResponse <CloudStorageProviderFileBase>(CloudProviderResponse <CloudStorageProviderFileBase> .Response.UnknownError, e));
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LoggerMessageType.Information | LoggerMessageType.VerboseHigh, "An unknown error occurred whilst attempting to get file info for '{0}' from DropboxStorageProvider. {1}", path, ex.Message);
                return(new CloudProviderResponse <CloudStorageProviderFileBase>(CloudProviderResponse <CloudStorageProviderFileBase> .Response.UnknownError, ex));
            }
        }