/// <summary> /// If an email embeds an email inline in its html, that embedded image won't display correctly unless we modify the html. /// This method does that, given information about email's known attachments /// </summary> public static string UpdateEmbeddedImageLinks(string originalHtml, System.Collections.Generic.IReadOnlyCollection <MessageAttachmentInfo> attachments) { if (attachments == null || attachments.Count == 0) { return(originalHtml); } CQ dom = originalHtml; foreach (var attachment in attachments) { string originalImgSrc = $"cid:{attachment.ContentId}"; var matchingImgLinks = dom[$"img[src$='{originalImgSrc}']"]; // This may point to the file on the local file-system if we haven't yet uploaded the attachment // However, the work item APIs seem to magically 'just work' with this and update the URI to point to the uploaded location // If for some reason that stops working, we'd need to either infer the uploaded URI or upload first and mutate the html afterward var newSrc = new Uri(attachment.FilePath); foreach (IDomObject img in matchingImgLinks) { img.SetAttribute("src", newSrc.AbsoluteUri); } } return(dom.Render()); }
/// <summary> /// Initializes a new instance of the <see cref="SetReadOnlyCollectionAdapter{T}"/> class. /// </summary> /// <param name="collection"> /// The set to adapt. /// </param> /// <param name="comparer"> /// The comparer to use when comparing equality of instances contained by <paramref name="collection"/>. This /// comparer is used when the methods on the <see cref="ISet{T}"/> interface are called. If /// <see langword="null"/>, the default equality comparer for the type <typeparamref name="T"/> will be used. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown when <paramref name="collection"/> is <see langword="null"/>. /// </exception> public SetReadOnlyCollectionAdapter( System.Collections.Generic.IReadOnlyCollection <T> collection, IEqualityComparer <T>?comparer = null) { this.collection = collection ?? throw new ArgumentNullException(nameof(collection)); this.comparer = comparer ?? EqualityComparer <T> .Default; }
private bool AnyChanges( IDependency updatedDependency, GraphNode dependencyGraphNode, out IReadOnlyList <DependencyNodeInfo> nodesToAdd, out IReadOnlyList <DependencyNodeInfo> nodesToRemove, out System.Collections.Generic.IReadOnlyCollection <IDependency> updatedChildren, out string dependencyProjectPath) { ITargetedDependenciesSnapshot snapshot = GetSnapshot(updatedDependency); if (snapshot == null) { nodesToAdd = default; nodesToRemove = default; updatedChildren = default; dependencyProjectPath = default; return(false); } dependencyProjectPath = updatedDependency.FullPath; updatedChildren = snapshot.TopLevelDependencies; IReadOnlyList <DependencyNodeInfo> existingChildren = GetExistingChildren(dependencyGraphNode); IReadOnlyList <DependencyNodeInfo> updatedChildrenInfo = updatedChildren.Select(x => DependencyNodeInfo.FromDependency(x)).ToList(); return(AnyChanges(existingChildren, updatedChildrenInfo, out nodesToAdd, out nodesToRemove)); }
public RangeTreeLookup(System.Collections.Generic.IReadOnlyCollection <ExecutionPathGroup> executionPathGroups, ExecutionPathGroup emptyGroup) { _emptyGroup = emptyGroup; foreach (var executionPathGroup in executionPathGroups) { var range = CreateRange(executionPathGroup.Match); _minValue = Math.Min(_minValue, range.Minimum); _maxValue = Math.Max(_maxValue, range.Maximum); } _intervalTree = IntervalTree.Build(executionPathGroups, e => CreateRange(e.Match)); }
/// <inheritdoc/> public bool Equals(System.Collections.Generic.IReadOnlyCollection <T> other) { return(this.collection.Equals(other)); }
/// <summary> /// Generates search graph containing nodes matching search criteria in Solution Explorer /// and attaches it to correct top level node. /// </summary> private void Search(IGraphContext graphContext) { string searchParametersTypeName = typeof(ISolutionSearchParameters).GUID.ToString(); ISolutionSearchParameters searchParameters = graphContext.GetValue <ISolutionSearchParameters>(searchParametersTypeName); string searchTerm = searchParameters?.SearchQuery.SearchString?.ToLowerInvariant(); if (searchTerm == null) { return; } var cachedDependencyToMatchingResultsMap = new Dictionary <string, HashSet <IDependency> >(StringComparer.OrdinalIgnoreCase); var searchResultsPerContext = new Dictionary <string, HashSet <IDependency> >(StringComparer.OrdinalIgnoreCase); System.Collections.Generic.IReadOnlyCollection <IDependenciesSnapshotProvider> snapshotProviders = AggregateSnapshotProvider.GetSnapshotProviders(); foreach (IDependenciesSnapshotProvider snapshotProvider in snapshotProviders) { IDependenciesSnapshot snapshot = snapshotProvider.CurrentSnapshot; if (snapshot == null) { continue; } searchResultsPerContext[snapshotProvider.ProjectFilePath] = SearchFlat( searchTerm.ToLowerInvariant(), snapshot); } foreach (IDependenciesSnapshotProvider snapshotProvider in snapshotProviders) { IDependenciesSnapshot snapshot = snapshotProvider.CurrentSnapshot; if (snapshot == null) { continue; } IEnumerable <IDependency> allTopLevelDependencies = snapshot.GetFlatTopLevelDependencies(); HashSet <IDependency> matchedDependencies = searchResultsPerContext[snapshotProvider.ProjectFilePath]; using (var scope = new GraphTransactionScope()) { foreach (IDependency topLevelDependency in allTopLevelDependencies) { ITargetedDependenciesSnapshot targetedSnapshot = snapshot.Targets[topLevelDependency.TargetFramework]; if (!cachedDependencyToMatchingResultsMap .TryGetValue(topLevelDependency.Id, out HashSet <IDependency> topLevelDependencyMatches)) { IDependenciesGraphViewProvider viewProvider = ViewProviders .FirstOrDefaultValue((x, d) => x.SupportsDependency(d), topLevelDependency); if (viewProvider == null) { continue; } bool processed = viewProvider.MatchSearchResults( snapshotProvider.ProjectFilePath, topLevelDependency, searchResultsPerContext, out topLevelDependencyMatches); if (!processed) { if (matchedDependencies.Count == 0) { continue; } topLevelDependencyMatches = GetMatchingResultsForDependency( topLevelDependency, targetedSnapshot, matchedDependencies, cachedDependencyToMatchingResultsMap); } cachedDependencyToMatchingResultsMap[topLevelDependency.Id] = topLevelDependencyMatches; } if (topLevelDependencyMatches.Count == 0) { continue; } GraphNode topLevelNode = Builder.AddTopLevelGraphNode(graphContext, snapshotProvider.ProjectFilePath, topLevelDependency.ToViewModel(targetedSnapshot)); foreach (IDependency matchedDependency in topLevelDependencyMatches) { GraphNode matchedDependencyNode = Builder.AddGraphNode(graphContext, snapshotProvider.ProjectFilePath, topLevelNode, matchedDependency.ToViewModel(targetedSnapshot)); graphContext.Graph.Links.GetOrCreate(topLevelNode, matchedDependencyNode, label: null, GraphCommonSchema.Contains); } if (topLevelNode != null) { // 'node' is a GraphNode for top level dependency (which is part of solution explorer tree) // Setting ProjectItem category (and correct GraphNodeId) ensures that search graph appears // under right solution explorer hierarchy item topLevelNode.AddCategory(CodeNodeCategories.ProjectItem); } } scope.Complete(); } } graphContext.OnCompleted(); }
/// <summary> /// Initializes a new instance of the <see cref="SetAdapter{T}"/> class, wrapping the specified /// <see cref="System.Collections.Generic.IReadOnlyCollection{T}"/> <paramref name="collection"/>. It is /// assumed that the contents of the collection represent a valid set, where "valid" is determined by the /// caller. /// </summary> /// <param name="collection"> /// The collection to wrap. /// </param> /// <param name="comparer"> /// The comparer to use when comparing equality of instances contained by <paramref name="collection"/>. This /// comparer is used when the methods on the <see cref="ISet{T}"/> interface are called. If /// <see langword="null"/>, the default equality comparer for the type <typeparamref name="T"/> will be used. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown when <paramref name="collection"/> is <see langword="null"/>. /// </exception> public SetAdapter( System.Collections.Generic.IReadOnlyCollection <T> collection, IEqualityComparer <T>?comparer = null) { this.adapter = new SetReadOnlyCollectionAdapter <T>(collection, comparer); }
/// <inheritdoc/> public bool Equals(System.Collections.Generic.IReadOnlyCollection <T> other) => this.adapter.Equals(other);
/// <summary> /// Script the objects matching the provided list of names. /// </summary> /// <param name="connectionString">Connection to database to find objects in.</param> /// <param name="objectNames">Names of objects to script.</param> /// <param name="infoMessageCallback">Optional callback to capture information messages sent on connection.</param> /// <param name="scrubScript">Value indicating whether or not to scrub the script to make it more readable and remove issues that prvent running.</param> /// <returns>Collection of scripted objects matching the provided names.</returns> public static System.Collections.Generic.IReadOnlyList <ScriptedObject> ScriptObjectsFromDatabase(string connectionString, System.Collections.Generic.IReadOnlyCollection <string> objectNames, SqlInfoMessageEventHandler infoMessageCallback = null, bool scrubScript = true) { var ret = new List <ScriptedObject>(); void Logic(Database database) { var allScriptableObjects = database.GetAllScriptableObjects(); var filtered = allScriptableObjects.Where(_ => objectNames.Contains(_.Name)).ToList(); ret = filtered.Select(_ => SqlObjectScripter.ScriptToObject(_, scrubScript)).ToList(); } SqlServerSmoDatabaseManager.RunOperationOnSmoDatabase(Logic, connectionString, infoMessageCallback); return(ret); }