protected void RemoveOrphanVehicles() { foreach (var orphanVehicle in VehiclesSet.Where(x => x.CanBeRemoved).ToArray()) { VehiclesSet = VehiclesSet.Remove(orphanVehicle); } }
private static void Write(Node root, ImmutableHashSet <Edge> edges, TextWriter writer, IDictionary <Node, int> ranks, ISet <Edge> visited = null, int depth = 0) { if (visited == null) { visited = new HashSet <Edge>(); } if (ranks.TryGetValue(root, out var currentRank)) { ranks[root] = Math.Min(depth, currentRank); } else { ranks[root] = depth; } foreach (var edge in edges.Where(x => x.Start.Equals(root)).OrderBy(x => x.End.Type)) { if (!visited.Add(edge)) { continue; } writer.WriteLine(edge.End is PackageReferenceNode ? $"\"{edge.Start.Id}\" -> \"{edge.End.Id}\" [label=\"{edge.Label}\" color=\"blue\"];" : $"\"{edge.Start.Id}\" -> \"{edge.End.Id}\""); Write(edge.End, edges.Remove(edge), writer, ranks, visited, depth + 1); } }
protected override void EscapeValueForParameterPointsToLocationOnExit(IParameterSymbol parameter, AnalysisEntity analysisEntity, ImmutableHashSet <AbstractLocation> escapedLocations) { Debug.Assert(!escapedLocations.IsEmpty); Debug.Assert(parameter.RefKind != RefKind.None); var escapedDisposableLocations = escapedLocations.Where(l => l.LocationTypeOpt?.IsDisposable(WellKnownTypeProvider.IDisposable) == true); SetAbstractValue(escapedDisposableLocations, ValueDomain.UnknownOrMayBeValue); }
static IReadOnlyDictionary <Point4d, ImmutableHashSet <Point4d> > GetNeighbours(ImmutableHashSet <Point4d> points) { return(points .Select(point => ( Source: point, Neighbours: points.Where(p => p != point && p.DistanceTo(point) <= 3).ToImmutableHashSet() )) .ToDictionary(k => k.Source, v => v.Neighbours)); }
void IXmlSerializable.WriteXml(XmlWriter writer) { new XElement("listeners", registrations .Where(i => i.Listener.GetType().IsPublic) .Where(i => i.Listener.GetType().GetConstructor(new Type[0]) != null) .GroupBy(i => i.Listener).Select(i => new XElement("item", SerializeListener(i.Key), i.Select(j => new XElement("registration", new XAttribute("event", j.EventType), new XAttribute("capture", j.Capture)))))) .WriteTo(writer); }
static ImmutableList<string> GetNamespacesToReallyAdd(SyntaxNode relativeToNode, SemanticModel semanticModel, ImmutableHashSet<string> namespaceQualifiedStrings) { var alreadyInScope = semanticModel .GetUsingNamespacesInScope(relativeToNode) .Select(ns => ns.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)) .ToImmutableHashSet(); var toReallyAdd = namespaceQualifiedStrings .Where(ns => !alreadyInScope.Contains(ns)) .ToImmutableList(); return toReallyAdd; }
public void ClusterClient_must_reestablish_connection_to_receptionist_after_partition() { Within(30.Seconds(), () => { RunOn(() => { var c = Sys.ActorOf(ClusterClient.Props(ClusterClientSettings.Create(Sys).WithInitialContacts(InitialContacts)), "client3"); c.Tell(new ClusterClient.Send("/user/service2", "bonjour2", localAffinity: true)); var reply = ExpectMsg <ClusterClientSpecConfig.Reply>(); reply.Msg.Should().Be("bonjour2-ack"); RoleName receptionistRoleName = GetRoleName(reply.Node); if (receptionistRoleName == null) { throw new Exception("Unexpected missing role name: " + reply.Node); } // shutdown all but the one that the client is connected to _remainingServerRoleNames.Where(r => !r.Equals(receptionistRoleName)).ForEach(r => { TestConductor.Exit(r, 0).Wait(); }); _remainingServerRoleNames = ImmutableHashSet.Create(receptionistRoleName); // network partition between client and server TestConductor.Blackhole(_config.Client, receptionistRoleName, ThrottleTransportAdapter.Direction.Both).Wait(); c.Tell(new ClusterClient.Send("/user/service2", "ping", localAffinity: true)); // if we would use remote watch the failure detector would trigger and // connection quarantined ExpectNoMsg(5.Seconds()); TestConductor.PassThrough(_config.Client, receptionistRoleName, ThrottleTransportAdapter.Direction.Both).Wait(); var expectedAddress = GetAddress(receptionistRoleName); AwaitAssert(() => { var probe = CreateTestProbe(); c.Tell(new ClusterClient.Send("/user/service2", "bonjour3", localAffinity: true), probe.Ref); var reply2 = probe.ExpectMsg <ClusterClientSpecConfig.Reply>(1.Seconds()); reply2.Msg.Should().Be("bonjour3-ack"); reply2.Node.Should().Be(expectedAddress); }); Sys.Stop(c); }, _config.Client); EnterBarrier("after-5"); }); }
protected override void EscapeValueForParameterPointsToLocationOnExit(IParameterSymbol parameter, AnalysisEntity analysisEntity, ImmutableHashSet <AbstractLocation> escapedLocations) { // Mark parameters as validated if they are non-null at all non-exception return paths and null at one of the unhandled throw operations. var notValidatedLocations = escapedLocations.Where(IsNotOrMaybeValidatedLocation); if (notValidatedLocations.Any()) { if (TryGetNullAbstractValueAtCurrentBlockEntry(analysisEntity, out NullAbstractValue nullAbstractValue) && nullAbstractValue == NullAbstractValue.NotNull && TryGetMergedNullAbstractValueAtUnhandledThrowOperationsInGraph(analysisEntity, out NullAbstractValue mergedValueAtUnhandledThrowOperations) && mergedValueAtUnhandledThrowOperations != NullAbstractValue.NotNull) { SetAbstractValue(notValidatedLocations, ParameterValidationAbstractValue.Validated); } } }
public BicepTelemetryEvent?GetTelemetryAboutSourceFiles(SemanticModel semanticModel, Uri uri, ImmutableHashSet <ISourceFile> sourceFiles, IEnumerable <Diagnostic> diagnostics) { var mainFile = sourceFiles.First(x => x.FileUri == uri) as BicepFile; if (mainFile is null) { return(null); } Dictionary <string, string> properties = GetTelemetryPropertiesForMainFile(semanticModel, mainFile, diagnostics); var referencedFiles = sourceFiles.Where(x => x.FileUri != uri); var propertiesFromReferencedFiles = GetTelemetryPropertiesForReferencedFiles(referencedFiles); properties = properties.Concat(propertiesFromReferencedFiles).ToDictionary(s => s.Key, s => s.Value); return(BicepTelemetryEvent.CreateBicepFileOpen(properties)); }
private bool CheckRowFull(ImmutableHashSet<Cell> allCells, int row) { return allCells.Where(c => c.Y == row). ToImmutableHashSet(). SetEquals(Enumerable.Range(0, width).Select(i => new Cell(i, row))); }
public IDiagnoser GetCompositeDiagnoser(BenchmarkCase benchmarkCase, RunMode runMode) { var diagnosersForGivenMode = diagnosers.Where(diagnoser => diagnoser.GetRunMode(benchmarkCase) == runMode).ToImmutableHashSet(); return(diagnosersForGivenMode.Any() ? new CompositeDiagnoser(diagnosersForGivenMode) : null); }
protected virtual DependenciesChange ProcessDependenciesChanges( IProjectSubscriptionUpdate projectSubscriptionUpdate, IProjectCatalogSnapshot catalogs) { var changes = projectSubscriptionUpdate.ProjectChanges; var resolvedReferenceChanges = ResolvedReferenceRuleNames.Where(x => changes.Keys.Contains(x)) .Select(ruleName => changes[ruleName]).ToImmutableHashSet(); var unresolvedReferenceSnapshots = changes.Values .Where(cd => !ResolvedReferenceRuleNames.Any(ruleName => string.Equals(ruleName, cd.After.RuleName, StringComparison.OrdinalIgnoreCase))) .ToDictionary(d => d.After.RuleName, d => d, StringComparer.OrdinalIgnoreCase); var rootTreeNodes = new HashSet <IDependencyNode>(RootNode.Children); var dependenciesChange = new DependenciesChange(); foreach (var unresolvedChange in unresolvedReferenceSnapshots.Values) { if (!unresolvedChange.Difference.AnyChanges) { continue; } var itemType = GetItemTypeFromRuleName(unresolvedChange.After.RuleName, catalogs, true); if (itemType == null) { // We must be missing that rule. Skip it. continue; } foreach (string removedItemSpec in unresolvedChange.Difference.RemovedItems) { var node = rootTreeNodes.FindNode(removedItemSpec, itemType); if (node != null) { dependenciesChange.RemovedNodes.Add(node); } } foreach (string addedItemSpec in unresolvedChange.Difference.AddedItems) { var node = rootTreeNodes.FindNode(addedItemSpec, itemType); if (node == null) { var properties = GetProjectItemProperties(unresolvedChange.After, addedItemSpec); node = CreateDependencyNode(addedItemSpec, itemType, properties: properties, resolved: false); dependenciesChange.AddedNodes.Add(node); } } } var updatedUnresolvedSnapshots = unresolvedReferenceSnapshots.Values.Select(cd => cd.After); foreach (var resolvedReferenceRuleChanges in resolvedReferenceChanges) { if (!resolvedReferenceRuleChanges.Difference.AnyChanges) { continue; } // if resolved reference appears in Removed list, it means that it is either removed from // project or can not be resolved anymore. In case when it can not be resolved, // we must remove old "resolved" node and add new unresolved node with corresponding // properties changes (rules, icon, etc) // Note: removed resolved node is not added to "added unresolved diff", which we process // above, thus we need to do this properties update here. It is just cleaner to re-add node // instead of modifying properties. foreach (string removedItemSpec in resolvedReferenceRuleChanges.Difference.RemovedItems) { string unresolvedItemSpec = resolvedReferenceRuleChanges.Before .Items[removedItemSpec][OriginalItemSpecPropertyName]; IProjectRuleSnapshot unresolvedReferenceSnapshot = null; string unresolvedItemType = GetUnresolvedReferenceItemType(unresolvedItemSpec, updatedUnresolvedSnapshots, catalogs, out unresolvedReferenceSnapshot); var node = rootTreeNodes.FindNode(removedItemSpec, unresolvedItemType); if (node != null) { dependenciesChange.RemovedNodes.Add(node); IImmutableDictionary <string, string> properties = null; if (unresolvedReferenceSnapshot != null) { properties = GetProjectItemProperties(unresolvedReferenceSnapshot, unresolvedItemSpec); } node = CreateDependencyNode(unresolvedItemSpec, unresolvedItemType, properties: properties, resolved: false); dependenciesChange.AddedNodes.Add(node); } } foreach (string addedItemSpec in resolvedReferenceRuleChanges.Difference.AddedItems) { var properties = GetProjectItemProperties(resolvedReferenceRuleChanges.After, addedItemSpec); if (properties == null || !properties.Keys.Contains(OriginalItemSpecPropertyName)) { // if there no OriginalItemSpec, we can not associate item with the rule continue; } var originalItemSpec = properties[OriginalItemSpecPropertyName]; IProjectRuleSnapshot unresolvedReferenceSnapshot = null; var itemType = GetUnresolvedReferenceItemType(originalItemSpec, updatedUnresolvedSnapshots, catalogs, out unresolvedReferenceSnapshot); if (string.IsNullOrEmpty(itemType)) { // Note: design time build resolves not only our unresolved assemblies, but also // all transitive assembly dependencies, which ar enot direct references and // we should not show them. If reference does not have an unresolved reference // corresponded to it, i.e. itemType = null here - we skip it. continue; } // avoid adding unresolved dependency along with resolved one var existingUnresolvedNode = dependenciesChange.AddedNodes.FindNode(originalItemSpec, itemType); if (existingUnresolvedNode != null) { dependenciesChange.AddedNodes.Remove(existingUnresolvedNode); } // if unresolved dependency was added earlier, remove it, since it will be substituted by resolved one existingUnresolvedNode = rootTreeNodes.FindNode(originalItemSpec, itemType); if (existingUnresolvedNode != null) { dependenciesChange.RemovedNodes.Add(existingUnresolvedNode); } var newNode = CreateDependencyNode(originalItemSpec, itemType: itemType, properties: properties); dependenciesChange.AddedNodes.Add(newNode); } } return(dependenciesChange); }
public static IEnumerable <CachedDecor> GetDecor(string name) { return(decorLookup .Where(d => d.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase)) .OrderBy(d => d.Id)); }
public IEnumerable <IIncrementalAnalyzer> GetApplicableAnalyzers(ImmutableArray <IIncrementalAnalyzer> allAnalyzers) => SpecificAnalyzers?.Count > 0 ? SpecificAnalyzers.Where(allAnalyzers.Contains) : allAnalyzers;
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { if (!_autoDeployConfiguration.Enabled) { return; } await Task.Delay(TimeSpan.FromSeconds(_autoDeployConfiguration.StartupDelayInSeconds), stoppingToken); while (!stoppingToken.IsCancellationRequested) { ImmutableArray <DeploymentTarget> deploymentTargets; using (var targetsTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(_autoDeployConfiguration.DefaultTimeoutInSeconds))) { using (CancellationTokenSource linked = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken, targetsTokenSource.Token)) { deploymentTargets = (await _deploymentTargetReadService.GetDeploymentTargetsAsync(linked.Token)) .Where(target => target.Enabled && target.AutoDeployEnabled) .ToImmutableArray(); } } if (deploymentTargets.IsDefaultOrEmpty) { _logger.Verbose("Found no deployment targets with auto deployment enabled, waiting {DelayInSeconds} seconds", _autoDeployConfiguration.EmptyTargetsDelayInSeconds); await Task.Delay(TimeSpan.FromSeconds(_autoDeployConfiguration.EmptyTargetsDelayInSeconds), stoppingToken); continue; } ImmutableArray <DeploymentTarget> targetsWithUrl = deploymentTargets.Where(target => target.Url.HasValue()).ToImmutableArray(); if (targetsWithUrl.IsDefaultOrEmpty) { _logger.Verbose("Found no deployment targets with auto deployment enabled and URL defined, waiting {DelayInSeconds} seconds", _autoDeployConfiguration.EmptyTargetsDelayInSeconds); await Task.Delay(TimeSpan.FromSeconds(_autoDeployConfiguration.EmptyTargetsDelayInSeconds), stoppingToken); continue; } AppVersion[] appVersions; using (var cancellationTokenSource = new CancellationTokenSource( TimeSpan.FromSeconds(_autoDeployConfiguration.MetadataTimeoutInSeconds))) { using (CancellationTokenSource linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationTokenSource.Token, stoppingToken)) { CancellationToken cancellationToken = linkedCancellationTokenSource.Token; IEnumerable <Task <AppVersion> > tasks = targetsWithUrl.Select(target => _monitoringService.GetAppMetadataAsync(target, cancellationToken)); appVersions = await Task.WhenAll(tasks); } } foreach (DeploymentTarget deploymentTarget in targetsWithUrl) { AppVersion appVersion = appVersions.SingleOrDefault(v => v.Target.Id.Equals(deploymentTarget.Id, StringComparison.OrdinalIgnoreCase)); if (appVersion?.SemanticVersion is null || appVersion.PackageId.IsNullOrWhiteSpace()) { continue; } ImmutableHashSet <PackageVersion> packageVersions; using (var packageVersionCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(_autoDeployConfiguration.DefaultTimeoutInSeconds))) { using (CancellationTokenSource linked = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken, packageVersionCancellationTokenSource.Token)) { packageVersions = (await _packageService.GetPackageVersionsAsync(deploymentTarget.PackageId, cancellationToken: linked.Token, logger: _logger)).ToImmutableHashSet(); } } if (packageVersions.IsEmpty) { continue; } ImmutableHashSet <PackageVersion> filteredPackages = !deploymentTarget.AllowPreRelease ? packageVersions.Where(p => !p.Version.IsPrerelease).ToImmutableHashSet() : packageVersions; if (filteredPackages.IsEmpty) { continue; } ImmutableHashSet <PackageVersion> newerPackages = filteredPackages .Where(package => package.PackageId.Equals(appVersion.PackageId, StringComparison.OrdinalIgnoreCase) && package.Version > appVersion.SemanticVersion) .ToImmutableHashSet(); PackageVersion packageToDeploy = newerPackages .OrderByDescending(package => package.Version) .FirstOrDefault(); if (packageToDeploy != null) { var task = new DeploymentTask(packageToDeploy, deploymentTarget.Id, Guid.NewGuid()); _logger.Information("Auto-deploying package {Package} to target {TargetId}", packageToDeploy, deploymentTarget.Id); _deploymentWorker.Enqueue(task); } } await Task.Delay(TimeSpan.FromSeconds(_autoDeployConfiguration.AfterDeployDelayInSeconds), stoppingToken); } }