private void ProcessWatchedFile(DbxFile file) { try { Tracing.Log("AndroidDropboxService - OnFileChange - path: {0} syncStatus: {1} bytesTransfered: {2} bytesTotal: {3} isCached: {4} isLatest: {5}", file.Path.Name, file.SyncStatus.Pending, file.SyncStatus.BytesTransferred, file.SyncStatus.BytesTotal, file.SyncStatus.IsCached, file.SyncStatus.IsLatest); if (file.NewerStatus != null) { Tracing.Log("AndroidDropboxService - OnFileChange - path: {0} newerStatus: {1} bytesTransfered: {2} bytesTotal: {3} isCached: {4} isLatest: {5}", file.Path.Name, file.NewerStatus.Pending, file.NewerStatus.BytesTransferred, file.NewerStatus.BytesTotal, file.NewerStatus.IsCached, file.NewerStatus.IsLatest); if (file.NewerStatus.IsLatest) { Tracing.Log("AndroidDropboxService - OnFileChange - Finished downloading! Updating file..."); file.Update(); // TODO: Maybe add a lock so ReadFully isn't called twice for the same file byte[] bytes = ReadFully(file.ReadStream); Tracing.Log("AndroidDropboxService - OnFileChange - Finished downloading! (2)"); if (OnCloudFileDownloaded != null) { Tracing.Log("AndroidDropboxService - OnFileChange - Finished downloading! (3)"); OnCloudFileDownloaded(string.Format("/Devices/{0}", file.Path.Name), bytes); Tracing.Log("AndroidDropboxService - OnFileChange - Finished downloading! (4)"); } Tracing.Log("AndroidDropboxService - OnFileChange - Finished downloading! (5)"); } } } catch (Exception ex) { // Ignore file close exceptions Tracing.Log("AndroidDropboxService - OnFileChanged - Exception: {0}", ex); } }
public void OnFileChange(DbxFile file) { Tracing.Log("AndroidDropboxService - OnFileChange"); if (file == null) return; Task.Factory.StartNew(() => { ProcessWatchedFile(file); }); }