/// <summary> /// Enumerate infos of all cloud service schedules. /// </summary> public List <CloudServiceSchedulingInfo> GetSchedules() { // TODO: Redesign to make it self-contained (so that we don't need to pass the name as well) return(_blobs.ListBlobNames(ScheduledServiceStateName.GetPrefix()) .Select(name => Tuple.Create(name, _blobs.GetBlob(name, _runtimeSerializer))) .Where(pair => pair.Item2.HasValue) .Select(pair => { var state = pair.Item2.Value; var info = new CloudServiceSchedulingInfo { ServiceName = pair.Item1.ServiceName, TriggerInterval = state.TriggerInterval, LastExecuted = state.LastExecuted, WorkerScoped = state.SchedulePerWorker, LeasedBy = Maybe <string> .Empty, LeasedSince = Maybe <DateTimeOffset> .Empty, LeasedUntil = Maybe <DateTimeOffset> .Empty }; if (state.Lease != null) { info.LeasedBy = state.Lease.Owner; info.LeasedSince = state.Lease.Acquired; info.LeasedUntil = state.Lease.Timeout; } return info; }) .ToList()); }
/// <summary> /// Lazily enumerate all logs of the specified level or higher, ordered with the newest entry first. /// </summary> public IEnumerable <CloudLogEntry> GetLogsOfLevelOrHigher(LogLevel levelThreshold, int skip = 0) { // We need to sort by date (desc), but want to do it lazily based on // the guarantee that the enumerators themselves are ordered alike. // To do that we always select the newest value, move next, and repeat. var enumerators = Enum.GetValues(typeof(LogLevel)).OfType <LogLevel>() .Where(l => l >= levelThreshold && l <LogLevel.Max && l> LogLevel.Min) .Select(level => { var containerName = LevelToContainer(level); return(_blobs.ListBlobNames(containerName, string.Empty) .Select(blobName => Tuple.Create(containerName, blobName)) .GetEnumerator()); }) .ToList(); for (var i = enumerators.Count - 1; i >= 0; i--) { if (!enumerators[i].MoveNext()) { enumerators.RemoveAt(i); } } // Skip for (var i = skip; i > 0 && enumerators.Count > 0; i--) { var max = enumerators.Aggregate((left, right) => String.CompareOrdinal(left.Current.Item2, right.Current.Item2) < 0 ? left : right); if (!max.MoveNext()) { enumerators.Remove(max); } } // actual iterator while (enumerators.Count > 0) { var max = enumerators.Aggregate((left, right) => String.CompareOrdinal(left.Current.Item2, right.Current.Item2) < 0 ? left : right); var blob = _blobs.GetBlob <string>(max.Current.Item1, max.Current.Item2, _runtimeSerializer); if (blob.HasValue) { yield return(ParseLogEntry(blob.Value)); } if (!max.MoveNext()) { enumerators.Remove(max); } } }
/// <summary> /// Enumerate infos of all cloud services. /// </summary> public List <CloudServiceInfo> GetServices() { // TODO: Redesign to make it self-contained (so that we don't need to pass the name as well) return(_blobs.ListBlobNames(CloudServiceStateName.GetPrefix()) .Select(name => System.Tuple.Create(name, _blobs.GetBlob(name, _runtimeSerializer))) .Where(pair => pair.Item2.HasValue) .Select(pair => new CloudServiceInfo { ServiceName = pair.Item1.ServiceName, IsStarted = pair.Item2.Value == CloudServiceState.Started }) .ToList()); }
public void ListBlobNames() { var prefix = Guid.NewGuid().ToString("N"); var prefixed = Range.Array(10).Select(i => prefix + Guid.NewGuid().ToString("N")).ToArray(); var unprefixed = Range.Array(13).Select(i => Guid.NewGuid().ToString("N")).ToArray(); foreach (var n in prefixed) { BlobStorage.PutBlob(ContainerName, n, n); } foreach (var n in unprefixed) { BlobStorage.PutBlob(ContainerName, n, n); } var list = BlobStorage.ListBlobNames(ContainerName, prefix).ToArray(); Assert.AreEqual(prefixed.Length, list.Length, "#A00"); foreach (var n in list) { Assert.IsTrue(prefixed.Contains(n), "#A01"); Assert.IsFalse(unprefixed.Contains(n), "#A02"); } }
/// <summary> /// List the blob locations (with the provided type) of all blobs matching the provided blob name prefix. /// </summary> /// <remarks> /// <para>This method is sideeffect-free, except for infrastructure effects like thread pool usage.</para> /// </remarks> public static IEnumerable <IBlobLocationAndType <T> > ListBlobLocations <T>(this IBlobStorageProvider provider, IBlobLocationAndType <T> blobLocationPrefix) { return(provider.ListBlobNames(blobLocationPrefix.ContainerName, blobLocationPrefix.Path) .Select(name => new BlobLocationAndType <T>(blobLocationPrefix.ContainerName, name))); }
/// <summary> /// List the blob locations (with the provided type) of all blobs matching the provided blob name prefix. /// </summary> /// <remarks> /// <para>This method is sideeffect-free, except for infrastructure effects like thread pool usage.</para> /// </remarks> public static IEnumerable <IBlobLocationAndType <T> > ListBlobLocations <T>(this IBlobStorageProvider provider, string containerName, string blobNamePrefix = null) { return(provider.ListBlobNames(containerName, blobNamePrefix) .Select(name => new BlobLocationAndType <T>(containerName, name))); }
/// <summary> /// List the blob names of all blobs matching the provided blob name prefix. /// </summary> /// <remarks> /// <para>This method is sideeffect-free, except for infrastructure effects like thread pool usage.</para> /// </remarks> public static IEnumerable <T> ListBlobNames <T>(this IBlobStorageProvider provider, IBlobLocation locationPrefix) where T : UntypedBlobName { return(provider.ListBlobNames(locationPrefix.ContainerName, locationPrefix.Path) .Select(UntypedBlobName.Parse <T>)); }
/// <summary> /// List the blob names of all blobs matching the provided blob name prefix. /// </summary> /// <remarks> /// <para>This method is sideeffect-free, except for infrastructure effects like thread pool usage.</para> /// </remarks> public static IEnumerable <T> ListBlobNames <T>(this IBlobStorageProvider provider, T blobNamePrefix) where T : UntypedBlobName { return(provider.ListBlobNames(blobNamePrefix.ContainerName, blobNamePrefix.ToString()) .Select(UntypedBlobName.Parse <T>)); }