public static async Task <Tuple <IEnumerable <IStorageBlob>, DateTime> > PollNewBlobsAsync( IStorageBlobContainer container, DateTime previousTimestamp, CancellationToken cancellationToken) { DateTime updatedTimestamp = previousTimestamp; IList <IStorageListBlobItem> currentBlobs; try { currentBlobs = (await container.ListBlobsAsync(prefix: null, useFlatBlobListing: true, cancellationToken: cancellationToken)).ToList(); } catch (StorageException exception) { if (exception.IsNotFound()) { return(new Tuple <IEnumerable <IStorageBlob>, DateTime>( Enumerable.Empty <IStorageBlob>(), updatedTimestamp)); } else { throw; } } List <IStorageBlob> newBlobs = new List <IStorageBlob>(); // Type cast to IStorageBlob is safe due to useFlatBlobListing: true above. foreach (IStorageBlob currentBlob in currentBlobs) { cancellationToken.ThrowIfCancellationRequested(); IStorageBlobProperties properties = currentBlob.Properties; DateTime lastModifiedTimestamp = properties.LastModified.Value.UtcDateTime; if (lastModifiedTimestamp > updatedTimestamp) { updatedTimestamp = lastModifiedTimestamp; } if (lastModifiedTimestamp > previousTimestamp) { newBlobs.Add(currentBlob); } } return(new Tuple <IEnumerable <IStorageBlob>, DateTime>(newBlobs, updatedTimestamp)); }
public static async Task<Tuple<IEnumerable<IStorageBlob>, DateTime>> PollNewBlobsAsync( IStorageBlobContainer container, DateTime previousTimestamp, CancellationToken cancellationToken) { DateTime updatedTimestamp = previousTimestamp; IList<IStorageListBlobItem> currentBlobs; try { currentBlobs = (await container.ListBlobsAsync(prefix: null, useFlatBlobListing: true, cancellationToken: cancellationToken)).ToList(); } catch (StorageException exception) { if (exception.IsNotFound()) { return new Tuple<IEnumerable<IStorageBlob>, DateTime>( Enumerable.Empty<IStorageBlob>(), updatedTimestamp); } else { throw; } } List<IStorageBlob> newBlobs = new List<IStorageBlob>(); // Type cast to IStorageBlob is safe due to useFlatBlobListing: true above. foreach (IStorageBlob currentBlob in currentBlobs) { cancellationToken.ThrowIfCancellationRequested(); try { await currentBlob.FetchAttributesAsync(cancellationToken); } catch (StorageException exception) { if (exception.IsNotFound()) { continue; } else { throw; } } IStorageBlobProperties properties = currentBlob.Properties; DateTime lastModifiedTimestamp = properties.LastModified.Value.UtcDateTime; if (lastModifiedTimestamp > updatedTimestamp) { updatedTimestamp = lastModifiedTimestamp; } if (lastModifiedTimestamp > previousTimestamp) { newBlobs.Add(currentBlob); } } return new Tuple<IEnumerable<IStorageBlob>, DateTime>(newBlobs, updatedTimestamp); }