コード例 #1
0
        public async Task <LocalFileAccess> BeginLocalAccess()
        {
            if (IsDirectory)
            {
                throw new InvalidOperationException("Only files permit local access");
            }

            var docsDir   = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var cachesDir = System.IO.Path.GetFullPath(System.IO.Path.Combine(docsDir, "../Library/Caches"));

            var tmpDir = System.IO.Path.Combine(cachesDir, "DropboxTemp");

            var filename = Path;

            var lp = System.IO.Path.Combine(tmpDir, filename);

            FileSystemManager.EnsureDirectoryExists(System.IO.Path.GetDirectoryName(lp));

            await FileSystem.DropboxLoadFileAsync(DropboxPath, lp);

            var data = await Task.Run(() => File.ReadAllText(lp, Encoding.UTF8));

            return(new DropboxLocal(this, lp, data));
        }
コード例 #2
0
        public async Task <LocalFileAccess> BeginLocalAccess()
        {
            if (IsDirectory)
            {
                throw new InvalidOperationException("Only files permit local access");
            }

            string data = "";

            await fileLock.WaitAsync();

            DBFile file = null;

            try {
                //
                // Sometimes we get informed of new files before the files
                // are actually ready to be read. If that's the case then
                // the modified times are different. We try for up to 10 seconds
                // to get the new file.
                //
                var expectedTime = (DateTime)fileInfo.ModifiedTime;

                for (int i = 0; i < 10; i++)
                {
                    file = await fileSystem.OpenFileAsync(fileInfo.Path);

                    data = await file.ReadStringAsync();

                    var modTime = (DateTime)file.Info.ModifiedTime;

                    if (modTime < expectedTime)
                    {
                        file.Close();
                        file = null;
                        await Task.Delay(i *100);
                    }
                    else
                    {
                        break;
                    }
                }
            } finally {
                if (file != null)
                {
                    file.Close();
                }
                fileLock.Release();
            }

            var docsDir   = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var cachesDir = System.IO.Path.GetFullPath(System.IO.Path.Combine(docsDir, "../Library/Caches"));

            var tmpDir = System.IO.Path.Combine(cachesDir, "DropboxTemp");

            FileSystemManager.EnsureDirectoryExists(tmpDir);

            var filename = fileInfo.Path.Name;
            var lp       = System.IO.Path.Combine(tmpDir, filename);

            File.WriteAllText(lp, data, Encoding.UTF8);

            return(new DropboxLocal(this, lp, data));
        }