private async Task RunInitialQuery(CancellationToken cancellationToken) { var startReferences = initialAnchor.GetFactReferences().ToImmutableList(); var products = await factManager.Query(startReferences, specification, cancellationToken); var productAnchorProjections = await factManager.ComputeProjections(specification.Projection, products, typeof(TProjection), observation, initialAnchor, string.Empty, cancellationToken); var removals = await observation.NotifyAdded(productAnchorProjections); lock (this) { removalsByProduct = removalsByProduct.AddRange(removals); } }
public ExtensionData(IReadOnlyDictionary <string, object?> extensionData) { ImmutableDictionary <string, object?> .Builder builder = ImmutableDictionary.CreateBuilder <string, object?>(); builder.AddRange(extensionData); _dict = builder.ToImmutableDictionary(); }
public Task <ImmutableList <Fact> > Save(FactGraph graph, CancellationToken cancellationToken) { var newFacts = graph.FactReferences .Where(reference => !factsByReference.ContainsKey(reference)) .Select(reference => graph.GetFact(reference)) .ToImmutableList(); factsByReference = factsByReference.AddRange(newFacts .Select(fact => new KeyValuePair <FactReference, Fact>(fact.Reference, fact)) ); var newPredecessors = newFacts .Select(fact => ( factReference: fact.Reference, edges: fact.Predecessors .SelectMany(predecessor => CreateEdges(fact, predecessor)) .ToImmutableList() )) .ToImmutableList(); edges = edges.AddRange(newPredecessors .SelectMany(pair => pair.edges) ); foreach (var(factReference, edges) in newPredecessors) { ancestors = ancestors.Add( factReference, edges .SelectMany(edge => ancestors[edge.Predecessor]) .Append(factReference) .Distinct() .ToImmutableList() ); } return(Task.FromResult(newFacts)); }
public void StartBatchBuild(IDictionary <string, string>?globalProperties = null) { if (_batchBuildStarted) { throw new InvalidOperationException(); } globalProperties = globalProperties ?? ImmutableDictionary <string, string> .Empty; var allProperties = s_defaultGlobalProperties.AddRange(globalProperties); _batchBuildProjectCollection = new MSB.Evaluation.ProjectCollection(allProperties); _batchBuildLogger = new MSBuildDiagnosticLogger() { Verbosity = MSB.Framework.LoggerVerbosity.Normal }; var buildParameters = new MSB.Execution.BuildParameters(_batchBuildProjectCollection) { Loggers = _msbuildLogger is null ? (new MSB.Framework.ILogger[] { _batchBuildLogger }) : (new MSB.Framework.ILogger[] { _batchBuildLogger, _msbuildLogger }) }; MSB.Execution.BuildManager.DefaultBuildManager.BeginBuild(buildParameters); _batchBuildStarted = true; }
public void StartBatchBuild(IDictionary <string, string> globalProperties = null) { if (_batchBuildStarted) { throw new InvalidOperationException(); } globalProperties = globalProperties ?? ImmutableDictionary <string, string> .Empty; var allProperties = s_defaultGlobalProperties.AddRange(globalProperties); _batchBuildProjectCollection = new ErgonProjectCollection(allProperties); //_batchBuildLogger = new ErgonDiagnosticLogger() //{ // Verbosity = MSB.Framework.LoggerVerbosity.Normal //}; //var buildParameters = new MSB.Execution.BuildParameters(_batchBuildProjectCollection) //{ // Loggers = new MSB.Framework.ILogger[] { _batchBuildLogger } //}; //MSB.Execution.BuildManager.DefaultBuildManager.BeginBuild(buildParameters); _batchBuildStarted = true; }
public ImmutableDictionary <string, ImmutableArray <DiagnosticDescriptor> > GetDiagnosticDescriptorsPerReference(DiagnosticAnalyzerInfoCache infoCache, Project project) { var descriptorPerReference = CreateDiagnosticDescriptorsPerReference(infoCache, CreateDiagnosticAnalyzersPerReference(project)); var map = _hostAnalyzerReferencesMap.AddRange(CreateProjectAnalyzerReferencesMap(project.AnalyzerReferences)); return(ConvertReferenceIdentityToName(descriptorPerReference, map)); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="id"> /// The identifier. /// </param> /// <param name="schemaId"> /// Identifier for the meta class. /// </param> /// <param name="nodetype"> /// The type of the node. /// </param> /// <param name="start"> /// (Optional) the start. /// </param> /// <param name="end"> /// (Optional) the end. /// </param> /// <param name="value"> /// (Optional) The value. /// </param> /// <param name="version"> /// (Optional) The version. /// </param> /// <param name="outgoings"> /// (Optional) The outgoings. /// </param> /// <param name="incomings"> /// (Optional) The incomings. /// </param> ///------------------------------------------------------------------------------------------------- internal GraphNode(Identity id, Identity schemaId, NodeType nodetype, Identity start = null, Identity end = null, object value = null, long?version = null, IEnumerable <EdgeInfo> outgoings = null, IEnumerable <EdgeInfo> incomings = null ) : base(id, schemaId, end) { DebugContract.Requires(id, "id"); DebugContract.Requires(schemaId, "schemaId"); DebugContract.Requires(start == null || end != null, "start/end"); StartId = start; Value = value; Version = version ?? DateTime.UtcNow.Ticks; NodeType = nodetype; if (outgoings != null) { _outgoings = _outgoings.AddRange(outgoings.ToDictionary(e => e.Id)); } if (incomings != null) { _incomings = _incomings.AddRange(incomings.ToDictionary(e => e.Id)); } }
public IImmutableDictionary <TKey, TValue> AddRange(IEnumerable <KeyValuePair <TKey, TValue> > pairs) { return(new ImmutableDictionaryKeepOrder <TKey, TValue>( _dictionary.AddRange(pairs), _items.AddRange(pairs) )); }
private static Diagnostic CreateWithLocationTags( DiagnosticDescriptor descriptor, Location location, ReportDiagnostic effectiveSeverity, IEnumerable <Location> additionalLocations, IDictionary <string, IEnumerable <int> > tagIndices, ImmutableDictionary <string, string> properties, params object[] messageArgs ) { Contract.ThrowIfTrue(additionalLocations.IsEmpty()); Contract.ThrowIfTrue(tagIndices.IsEmpty()); properties ??= ImmutableDictionary <string, string> .Empty; properties = properties.AddRange( tagIndices.Select( kvp => new KeyValuePair <string, string>( kvp.Key, EncodeIndices(kvp.Value, additionalLocations.Count()) ) ) ); return(Create( descriptor, location, effectiveSeverity, additionalLocations, properties, messageArgs ));
public void SetAddressSharedEntities(ImmutableDictionary <AnalysisEntity, CopyAbstractValue> addressSharedEntitiesOpt) { _addressSharedEntitiesBuilder.Clear(); if (addressSharedEntitiesOpt != null) { _addressSharedEntitiesBuilder.AddRange(addressSharedEntitiesOpt); } }
public GangStateEventMap Add <TStateData>() where TStateData : class { return(new GangStateEventMap( _map.AddRange( GangState <TStateData> .ApplyMethods.Keys .ToImmutableDictionary(GetName <TStateData>) ))); }
protected override ImmutableDictionary <TKey, TValue> AddRange(ImmutableDictionary <TKey, TValue> values, ref ArraySegment <KeyValuePair <TKey, TValue> > newValues, ISerializationContext context) { if (newValues.Count == 1) { var pair = newValues.Singleton(); return(values.Add(pair.Key, pair.Value)); } return(values.AddRange(newValues)); }
public SpecificationResult Compose(SpecificationResult other) { return(new SpecificationResult( this.SymbolValue, SetDefinitions.AddRange(other.SetDefinitions), Targets.AddRange(other.Targets), labelByTarget.AddRange(other.labelByTarget) )); }
/// <summary> /// Clear out the project's construction model and add a simple SDK-based project to get a baseline. /// We need to use the same name as the original csproj and same path so that all the default that derive /// from name\path get the right values (there are a lot of them). /// </summary> private BaselineProject CreateSdkBaselineProject(string projectFilePath, IProject project, ImmutableDictionary <string, string> globalProperties, ImmutableDictionary <string, ImmutableDictionary <string, string> > configurations, ImmutableDictionary <string, string> targetProjectProperties) { var projectStyle = GetProjectStyle(ProjectRootElement); var rootElement = Microsoft.Build.Construction.ProjectRootElement.Open(projectFilePath); rootElement.RemoveAllChildren(); switch (projectStyle) { case ProjectStyle.Default: rootElement.Sdk = "Microsoft.NET.Sdk"; break; case ProjectStyle.DefaultWithCustomTargets: var imports = ProjectRootElement.Imports; void CopyImport(ProjectImportElement import) { var newImport = rootElement.AddImport(import.Project); newImport.Condition = import.Condition; } CopyImport(imports.First()); CopyImport(imports.Last()); break; default: throw new NotSupportedException("This project has custom imports in a manner that's not supported."); } var propGroup = rootElement.AddPropertyGroup(); propGroup.AddProperty("TargetFramework", project.GetTargetFramework()); propGroup.AddProperty("OutputType", project.GetPropertyValue("OutputType") ?? throw new InvalidOperationException("OutputType is not set!")); var newGlobalProperties = globalProperties.AddRange(targetProjectProperties); // Create a new collection because a project with this name has already been loaded into the global collection. var pc = new ProjectCollection(newGlobalProperties); var newProject = new UnconfiguredProject(configurations); newProject.LoadProjects(pc, newGlobalProperties, rootElement); // If the original project had the TargetFramework property don't touch it during conversion. var propertiesInTheBaseline = ImmutableArray.Create("OutputType"); if (project.GetProperty("TargetFramework") != null) { propertiesInTheBaseline = propertiesInTheBaseline.Add("TargetFramework"); } return(new BaselineProject(newProject, propertiesInTheBaseline, targetProjectProperties, projectStyle)); }
public void Setup() { var content = Enumerable.Range(0, N).Select(i => new KeyValuePair <string, int>(i.ToString(), i)); dictionary = new Dictionary <string, int>(content); immutableDictionary = ImmutableDictionary.CreateBuilder <string, int>(); immutableTrieDictionary = ImmutableTrieDictionary.CreateBuilder <string, int>(); immutableDictionary.AddRange(content); immutableTrieDictionary.AddRange(content); }
private void UpdateContextData( IResolverContext context, IReadOnlyQueryResult result, DelegateDirective delegateDirective) { if (result.ContextData.Count > 0) { ImmutableDictionary <string, object> .Builder builder = ImmutableDictionary.CreateBuilder <string, object>(); builder.AddRange(context.ScopedContextData); builder[WellKnownProperties.SchemaName] = delegateDirective.Schema; builder.AddRange(result.ContextData); context.ScopedContextData = builder.ToImmutableDictionary(); } else { context.ModifyScopedContext(c => c.SetItem( WellKnownProperties.SchemaName, delegateDirective.Schema)); } }
public void LoadProjects(ProjectCollection collection, ImmutableDictionary <string, string> globalProperties, string projectFilePath) { var projectBuilder = ImmutableDictionary.CreateBuilder <string, IProject>(); foreach (var config in Configurations) { var globalPropertiesWithDimensions = globalProperties.AddRange(config.Value); var project = new MSBuildProject(collection.LoadProject(projectFilePath, globalPropertiesWithDimensions, toolsVersion: null)); projectBuilder.Add(config.Key, project); } ConfiguredProjects = projectBuilder.ToImmutable(); }
internal MSBuildProjectLoader( HostWorkspaceServices workspaceServices, DiagnosticReporter diagnosticReporter, ProjectFileLoaderRegistry projectFileLoaderRegistry, ImmutableDictionary <string, string> properties) { _workspaceServices = workspaceServices; _diagnosticReporter = diagnosticReporter; _pathResolver = new PathResolver(_diagnosticReporter); _projectFileLoaderRegistry = projectFileLoaderRegistry ?? new ProjectFileLoaderRegistry(workspaceServices, _diagnosticReporter); _properties = ImmutableDictionary.Create <string, string>(StringComparer.OrdinalIgnoreCase); if (properties != null) { _properties = _properties.AddRange(properties); } }
private TypeDoc ConvertTypeToDocForm(Type type, IncludeKind includeKind) { NameInfo typeName = ConvertTypeToNameInfo(type); IEnumerable <TypeParameterDoc> typeParameters = ExtractTypeParameters(type); ImmutableDictionary <string, FieldDoc> fields = ExtractFields(type, typeName, includeKind); ImmutableDictionary <string, PropertyDoc> properties = ExtractProperties(type, typeName, includeKind); ImmutableDictionary <string, EventDoc> events = ExtractEvents(type, typeName, includeKind); ImmutableDictionary <string, MethodDoc> methods = ExtractMethods(type, typeName, includeKind); ImmutableDictionary <string, MethodDoc> constructors = ExtractConstructors(type, typeName, includeKind); methods = methods.AddRange(constructors); TypeDoc typeDoc = new TypeDoc(typeName, null, typeParameters, fields, properties, events, methods); return(typeDoc); }
internal ErgonProjectLoader( Workspace workspace, DiagnosticReporter diagnosticReporter, ProjectFileLoaderRegistry projectFileLoaderRegistry, ImmutableDictionary <string, string> properties) { _workspace = workspace; _diagnosticReporter = diagnosticReporter ?? new DiagnosticReporter(workspace); _pathResolver = new PathResolver(_diagnosticReporter); _projectFileLoaderRegistry = projectFileLoaderRegistry ?? new ProjectFileLoaderRegistry(workspace, _diagnosticReporter); _properties = ImmutableDictionary.Create <string, string>(StringComparer.OrdinalIgnoreCase); if (properties != null) { _properties = _properties.AddRange(properties); } }
private protected override void AddAsFallbackToSnapshot( ImmutableDictionary <Type, StackedDependency> .Builder snapshotBuilder ) { snapshotBuilder.AddRange(enumerateAddableDependencies()); IEnumerable <KeyValuePair <Type, StackedDependency> > enumerateAddableDependencies() { foreach (var kvp in _dependencyStacks) { if (kvp.Value.Count != 0 && !snapshotBuilder.ContainsKey(kvp.Key)) { yield return(new KeyValuePair <Type, StackedDependency>( kvp.Key, kvp.Value.Peek().RunOnSnapshot() )); } } } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private static void AddClrBoundTypeMembers(IEnumerable <Type> clrTypes) { TypeMember GetOrCreateNewTypeMember(Type clrType) { if (_s_typeMemberByClrType.TryGetValue(clrType, out TypeMember existing)) { return(existing); } return(new TypeMember(clrType)); } var boundClrTypeMemberPairs = clrTypes .Select(t => new KeyValuePair <Type, TypeMember>(t, GetOrCreateNewTypeMember(t))) .ToList(); _s_typeMemberByClrType = _s_typeMemberByClrType.AddRange( boundClrTypeMemberPairs .Where(kvp => !_s_typeMemberByClrType.ContainsKey(kvp.Key))); }
/// <summary> /// Adds a set of tags to the message. /// </summary> /// <param name="tags">The tags to add.</param> /// <returns>The same <see cref="IRCMessageBuilder"/> instance.</returns> /// <exception cref="ArgumentNullException"><paramref name="tags"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"> /// <para>One or more keys in <paramref name="tags"/> are <c>null</c>, empty, or contain whitespace.</para> /// <para>-or-</para> /// <para>One of the values in <paramref name="tags"/> is <c>null</c>.</para> /// </exception> public IRCMessageBuilder AddTags(IEnumerable <KeyValuePair <string, string> > tags) { if (tags is null) { throw new ArgumentNullException(nameof(tags)); } foreach (var kvp in tags) { if (kvp.Key is null || kvp.Key == "" || Regex.IsMatch(kvp.Key, "\\s")) { throw new ArgumentException("Tag keys may not be null, empty, or contain whitespace."); } if (kvp.Value is null) { throw new ArgumentException("Tag values may not be null."); } } tagsBuilder.AddRange(tags); return(this); }
private ImmutableDictionary <string, DiagnosticDescriptor> LoadDiagnosticsById() { ImmutableDictionary <string, DiagnosticDescriptor> .Builder diagnosticsById = ImmutableDictionary.CreateBuilder <string, DiagnosticDescriptor>(); diagnosticsById.AddRange(Analyzers .SelectMany(f => f.SupportedDiagnostics) .Distinct(DiagnosticDescriptorComparer.Id) .OrderBy(f => f, DiagnosticDescriptorComparer.Id) .Select(f => new KeyValuePair <string, DiagnosticDescriptor>(f.Id, f))); foreach (CodeFixProvider fixer in Fixers) { foreach (string diagnosticId in fixer.FixableDiagnosticIds) { if (!diagnosticsById.ContainsKey(diagnosticId)) { diagnosticsById[diagnosticId] = null; } } } return(diagnosticsById.ToImmutable()); }
public DependenciesSnapshot SetTargets( ImmutableArray <ITargetFramework> targetFrameworks, ITargetFramework activeTargetFramework) { bool activeChanged = !activeTargetFramework.Equals(ActiveTargetFramework); ImmutableDictionary <ITargetFramework, TargetedDependenciesSnapshot> map = DependenciesByTargetFramework; var diff = new SetDiff <ITargetFramework>(map.Keys, targetFrameworks); map = map.RemoveRange(diff.Removed); map = map.AddRange( diff.Added.Select( added => new KeyValuePair <ITargetFramework, TargetedDependenciesSnapshot>( added, TargetedDependenciesSnapshot.CreateEmpty(added, null)))); if (activeChanged || !ReferenceEquals(map, DependenciesByTargetFramework)) { return(new DependenciesSnapshot(activeTargetFramework, map)); } return(this); }
internal CompilerAnalyzerConfigOptionsProvider WithAdditionalTreeOptions(ImmutableDictionary<object, AnalyzerConfigOptions> treeDict) => new CompilerAnalyzerConfigOptionsProvider(_treeDict.AddRange(treeDict), GlobalOptions);
/// <summary> /// Register a config override for a specific participant. /// </summary> public void NodeConfig(IEnumerable <RoleName> roles, IEnumerable <Config> configs) { var c = configs.Aggregate((a, b) => a.WithFallback(b)); _nodeConf = _nodeConf.AddRange(roles.Select(r => new KeyValuePair <RoleName, Config>(r, c))); }
public TypeRegistry AddSymbols(IEnumerable <KeyValuePair <string, Expression> > symbols) { return(new TypeRegistry(registry.AddRange(symbols), resolvers)); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void OnBackendProductsLoaded(TypeFactoryProduct <TArtifact>[] products) { var newKeyValuePairs = products.Select(p => new KeyValuePair <TypeKey, TypeFactoryProduct <TArtifact> >(p.Key, p)); _productByKey = _productByKey.AddRange(newKeyValuePairs); }
private async Task HandleAsync( IProjectVersionedValue <Tuple <IProjectSubscriptionUpdate, IProjectCatalogSnapshot, IProjectCapabilitiesSnapshot> > e, RuleHandlerType handlerType) { AggregateCrossTargetProjectContext currentAggregateContext = await _host.GetCurrentAggregateProjectContext().ConfigureAwait(false); if (currentAggregateContext == null || _currentProjectContext != currentAggregateContext) { return; } IProjectSubscriptionUpdate update = e.Value.Item1; IProjectCatalogSnapshot catalogs = e.Value.Item2; IEnumerable <ICrossTargetRuleHandler <T> > handlers = Handlers.Select(h => h.Value) .Where(h => h.SupportsHandlerType(handlerType)); // We need to process the update within a lock to ensure that we do not release this context during processing. // TODO: Enable concurrent execution of updates themeselves, i.e. two separate invocations of HandleAsync // should be able to run concurrently. using (await _gate.DisposableWaitAsync().ConfigureAwait(true)) { // Get the inner workspace project context to update for this change. ITargetedProjectContext projectContextToUpdate = currentAggregateContext .GetInnerProjectContext(update.ProjectConfiguration, out bool isActiveContext); if (projectContextToUpdate == null) { return; } // Broken design time builds sometimes cause updates with no project changes and sometimes // cause updates with a project change that has no difference. // We handle the former case here, and the latter case is handled in the CommandLineItemHandler. if (update.ProjectChanges.Count == 0) { if (handlerType == RuleHandlerType.DesignTimeBuild) { projectContextToUpdate.LastDesignTimeBuildSucceeded = false; } return; } T ruleChangeContext = CreateRuleChangeContext( currentAggregateContext.ActiveProjectContext.TargetFramework, catalogs); foreach (ICrossTargetRuleHandler <T> handler in handlers) { ImmutableDictionary <string, IProjectChangeDescription> .Builder builder = ImmutableDictionary.CreateBuilder <string, IProjectChangeDescription>(StringComparers.RuleNames); ImmutableHashSet <string> handlerRules = handler.GetRuleNames(handlerType); builder.AddRange(update.ProjectChanges.Where( x => handlerRules.Contains(x.Key))); ImmutableDictionary <string, IProjectChangeDescription> projectChanges = builder.ToImmutable(); if (handler.ReceiveUpdatesWithEmptyProjectChange || projectChanges.Any(x => x.Value.Difference.AnyChanges)) { await handler.HandleAsync(e, projectChanges, projectContextToUpdate, isActiveContext, ruleChangeContext) .ConfigureAwait(true); } } await CompleteHandleAsync(ruleChangeContext).ConfigureAwait(false); // record all the rules that have occurred _treeTelemetryService.ObserveTargetFrameworkRules(projectContextToUpdate.TargetFramework, update.ProjectChanges.Keys); } }