private static IEnumerable<Changeset> FilterChangesetsByOwner(IEnumerable<Changeset> changesets, FilterNode rootFilterNode) { if (rootFilterNode.Count(p => p.Key.Equals("Owner")) > 0) { var ownerParameter = rootFilterNode.SingleOrDefault(p => p.Key.Equals("Owner")); switch (ownerParameter.Sign) { case FilterExpressionType.Equal: changesets = ownerParameter != null ? changesets.Where(c => c.Owner != null && c.Owner.Equals(ownerParameter.Value, StringComparison.OrdinalIgnoreCase)) : changesets.Where(c => c.Owner == null); break; case FilterExpressionType.NotEqual: changesets = ownerParameter != null ? changesets.Where(c => c.Owner == null || !c.Owner.Equals(ownerParameter.Value, StringComparison.OrdinalIgnoreCase)) : changesets.Where(c => c.Owner != null); break; default: throw new NotSupportedException("Changeset Owner can only be filtered with an equal or not equal operator"); } } return changesets; }
private IEnumerable<Build> RequestBuildsByProjectCollection(FilterNode rootFilterNode) { var teamProjects = this.TfsConnection.CatalogNode.QueryChildren( new Guid[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None); IEnumerable<Build> preliminaryResults = null; var buildServer = this.TfsConnection.GetService<TeamFoundation.Build.Client.IBuildServer>(); if (rootFilterNode != null && rootFilterNode.Count(p => p.Key.Equals("Project", StringComparison.OrdinalIgnoreCase)) > 0) { var projectParameter = rootFilterNode.SingleOrDefault(p => p.Key.Equals("Project", StringComparison.OrdinalIgnoreCase)); var spec = CreateBuildDetailSpec(buildServer, projectParameter.Value, rootFilterNode); preliminaryResults = buildServer.QueryBuilds(spec).Builds.Select(b => b.ToModel()); } else { var specs = teamProjects.Select(t => CreateBuildDetailSpec(buildServer, t.Resource.DisplayName, rootFilterNode)); preliminaryResults = specs.Select(s => buildServer.QueryBuilds(s)).SelectMany(r => r.Builds).Select(b => b.ToModel()); } return FilterBuilds(preliminaryResults, rootFilterNode).ToArray(); }
private static IEnumerable<Changeset> FilterChangesetsByCreationDate(IEnumerable<Changeset> changesets, FilterNode rootFilterNode) { if (rootFilterNode.Count(p => p.Key.Equals("CreationDate")) > 0 && rootFilterNode.Count(p => p.Key.Equals("Id")) > 0) { // We could not filter by both parameters using the API. So we filter programmatically var dateParameter = rootFilterNode.SingleOrDefault(p => p.Key.Equals("CreationDate")); var dateValue = default(DateTime); if (DateTime.TryParse(dateParameter.Value, out dateValue)) { switch (dateParameter.Sign) { case FilterExpressionType.Equal: changesets = dateParameter != null ? changesets.Where(c => c.CreationDate != null && RoundDateToSeconds(c.CreationDate).Equals(dateValue)) : changesets.Where(c => c.CreationDate == null); break; case FilterExpressionType.GreaterThan: changesets = dateParameter != null ? changesets.Where(c => c.CreationDate != null && RoundDateToSeconds(c.CreationDate) > dateValue) : changesets.Where(c => c.CreationDate != null); break; case FilterExpressionType.GreaterThanOrEqual: changesets = dateParameter != null ? changesets.Where(c => c.CreationDate != null && RoundDateToSeconds(c.CreationDate) >= dateValue) : changesets.Where(c => c.CreationDate != null); break; case FilterExpressionType.LessThan: changesets = dateParameter != null ? changesets.Where(c => c.CreationDate != null && RoundDateToSeconds(c.CreationDate) < dateValue) : changesets.Where(c => c.CreationDate != null); break; case FilterExpressionType.LessThanOrEqual: changesets = dateParameter != null ? changesets.Where(c => c.CreationDate != null && RoundDateToSeconds(c.CreationDate) <= dateValue) : changesets.Where(c => c.CreationDate != null); break; default: throw new DataServiceException(501, "Not Implemented", "Changeset Creation Date can only be filtered with an equality, greater than, less than, greater than or equal and less than or equal operators", "en-US", null); } } } return changesets; }