private bool HasEntriesForDefinition(DefinitionItem definition) { lock (_gate) { return(_entries.Any(e => e.DefinitionBucket.DefinitionItem == definition)); } }
private bool HasDeclarationEntries(DefinitionItem definition) { lock (_gate) { return(_entriesWithDeclarations.Any(e => e.DefinitionBucket.DefinitionItem == definition)); } }
public void GetTextFiles() { _fileFinder.DirectoryWrapper = new DirectoryWrapper(); ImmutableList <TextFile> manifestFiles = _fileFinder.GetTextFiles(_fileFinderPath); Assert.AreEqual(3, manifestFiles.Count); string manifestFilePath = Path.Combine("TestFiles", "FileFinder", "AndroidManifest.xml"); Assert.IsTrue(manifestFiles.Any(file => file.FilePath == manifestFilePath)); string examplePath = Path.Combine("TestFiles", "FileFinder", "Example.txt"); Assert.IsTrue(manifestFiles.Any(file => file.FilePath == examplePath)); string exampleCsPath = Path.Combine("TestFiles", "FileFinder", "Example.cs.test"); Assert.IsTrue(manifestFiles.Any(file => file.FilePath == exampleCsPath)); }
internal void RegisterChild(IDataflowDependency childMeta, bool allowDuplicate) { var child = childMeta.Unwrap(); if (m_children.Any(cm => object.ReferenceEquals(cm.Unwrap(), child))) { if (allowDuplicate) { LogHelper.Logger.DebugFormat("Duplicate child registration ignored in {0}: {1}", this.FullName, childMeta.DisplayName); return; } else { throw new ArgumentException("Duplicate child to register in " + this.FullName); } } m_children = m_children.Add(childMeta); if (!m_completionTask.IsValueCreated) { //eagerly initialize completion task //would look better if Lazy<T> provides an EagerEvaluate() method var t = m_completionTask.Value; } }
public ComponentUnionGraphType(Builder builder, FieldInfo fieldInfo, ImmutableList <DomainId>?schemaIds) { Name = fieldInfo.ReferenceType; if (schemaIds?.Any() == true) { foreach (var schemaId in schemaIds) { var contentType = builder.GetComponentType(schemaId); if (contentType != null) { types[schemaId.ToString()] = contentType; } } } if (HasType) { foreach (var type in types) { AddPossibleType(type.Value); } ResolveType = value => { if (value is JsonObject component && component.TryGetValue <JsonString>(Component.Discriminator, out var schemaId)) { return(types.GetOrDefault(schemaId.Value)); } return(null); }; } }
public void GetActionFor_FileItem() { ImmutableList <ActionMapping> actions = _actionRegistry.GetActionForInType(typeof(FileItem)); actions.Count.ShouldEqual(1); actions.Any(x => x.ActionType == typeof(OpenAction)).ShouldBeTrue(); }
public bool AppliesInUiMode(string uiMode) { if (_uiModes.Any()) { return(_uiModes.Contains(uiMode)); } return(!_exceptInUiModes.Contains(uiMode)); }
private static bool IsExemptType(Type type) { if (type.IsConstructedGenericType) { return(IsExemptType(type.GetGenericTypeDefinition())); } return(s_exemptTypes.Contains(type.FullName) || s_exemptNamespaces.Any(n => type.FullName.StartsWith(n))); }
public async Task <VoteFailure?> Vote(string pollCode, string userId, IImmutableList <int> options) { Poll?poll = await FindPoll(pollCode); if (poll == null) { return(new VoteFailure.PollNotFound(pollCode)); } if (!poll.Alive) { return(new VoteFailure.PollNotAlive()); } if (!poll.AllowChangeVote && poll.Voters.Contains(userId)) { return(new VoteFailure.AlreadyVoted()); } if (options.Count == 0) { return(new VoteFailure.CannotVoteForNone()); } if (options.Count > 1 && !poll.MultiChoice) { return(new VoteFailure.NotMultipleChoice()); } ImmutableList <int> invalidOptions = options.Except(poll.PollOptions.Select(p => p.Id)).ToImmutableList(); if (invalidOptions.Any()) { return(new VoteFailure.InvalidOptions(invalidOptions)); } await Collection.UpdateOneAsync( p => p.PollCode == pollCode, Builders <Poll> .Update.AddToSet(p => p.Voters, userId)); // remove any existing votes in case the user has voted before and is changing their vote right now. // no typed support for the $[] (for each in array) operator yet, see https://jira.mongodb.org/browse/CSHARP-2232 foreach (int i in Range(0, poll.PollOptions.Count)) { await Collection.UpdateOneAsync( p => p.PollCode == pollCode, Builders <Poll> .Update.Pull(p => p.PollOptions[i].VoterIds, userId)); } // the MongoDB C# driver's representation for '$', see also https://docs.mongodb.com/manual/reference/operator/update/positional/ const int positionalOperator = -1; foreach (int option in options) { await Collection.UpdateOneAsync( p => p.PollCode == pollCode && p.PollOptions.Any(o => o.Id == option), Builders <Poll> .Update.AddToSet(p => p.PollOptions[positionalOperator].VoterIds, userId)); } return(null); }
private Hash LastHash() { var lastHash = default(Hash); if (_blocks.Any()) { lastHash = Last.Hash; } return(lastHash); }
//TODO: account for Member.MemberId public void AddMember(Member member) { // Avoid adding the same member twice if (_members.Any(x => x.Address == member.Address)) { return; } _members = _members.Add(member); _rdv.UpdateMembers(_members); }
public void OkDialog() { var helper = new MessageBoxHelper(this, true); string name; if (!helper.ValidateNameTextBox(tbxListName, out name)) { return; } if (name != _listDefOriginal.ListName && _existing.Any(listDef => listDef.Name == name)) { helper.ShowTextBoxError(tbxListName, string.Format(Resources.ListDesigner_OkDialog_There_is_already_a_list_named___0___, name)); return; } var propertyNames = new HashSet <string>(); for (int i = 0; i < _listProperties.Count; i++) { if (!propertyNames.Add(_listProperties[i].Name)) { MessageDlg.Show(this, Resources.ListDesigner_OkDialog_Duplicate_property_name); dataGridViewProperties.CurrentCell = dataGridViewProperties.Rows[i].Cells[colPropertyName.Index]; return; } } string idProperty = comboIdProperty.SelectedItem as string; if (!string.IsNullOrEmpty(idProperty) && !propertyNames.Contains(idProperty)) { MessageDlg.Show(this, Resources.ListDesigner_OkDialog_No_such_property); comboIdProperty.Focus(); return; } string displayProperty = comboDisplayProperty.SelectedItem as string; if (!string.IsNullOrEmpty(displayProperty) && !propertyNames.Contains(displayProperty)) { MessageDlg.Show(this, Resources.ListDesigner_OkDialog_No_such_property); comboDisplayProperty.Focus(); return; } try { GetListDef(); } catch (Exception e) { MessageDlg.ShowWithException(this, TextUtil.LineSeparate(Resources.ListDesigner_OkDialog_There_was_an_error_trying_to_apply_this_list_definition_to_the_original_data_, e.Message), e); return; } DialogResult = DialogResult.OK; }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(tbxName, out name)) { return; } if (name != _originalName && _existing.Any(existingRuleSet => existingRuleSet.Name == name)) { helper.ShowTextBoxError(tbxName, string.Format(Resources.MetadataRuleEditor_OkDialog_There_is_already_a_metadata_rule_named___0___, name)); return; } var ruleSet = MetadataRuleSet; for (int rowIndex = 0; rowIndex < ruleSet.Rules.Count; rowIndex++) { var rule = ruleSet.Rules[rowIndex]; if (rule.Source == null) { MessageDlg.Show(this, string.Format(Resources.MetadataRuleEditor_OkDialog__0__cannot_be_blank, colSource.HeaderText)); SelectCell(dataGridViewRules, colSource, rowIndex); return; } if (!string.IsNullOrEmpty(rule.Pattern)) { try { var _ = new Regex(rule.Pattern); } catch (Exception exception) { MessageDlg.ShowWithException(this, Resources.MetadataRuleEditor_OkDialog_This_is_not_a_valid_regular_expression_, exception); SelectCell(dataGridViewRules, colPattern, rowIndex); return; } } if (rule.Target == null) { MessageDlg.Show(this, string.Format(Resources.MetadataRuleEditor_OkDialog__0__cannot_be_blank, colTarget.HeaderText)); SelectCell(dataGridViewRules, colTarget, rowIndex); return; } } DialogResult = DialogResult.OK; }
public async Task <PlayerInfo?> Register(PlayerInfo myInfo) { using var _ = await Lock(); if (_playerlist.Any(ps => ps.PlayerInfo.Name.Equals(myInfo.Name) || ps.PlayerInfo.Token.Equals(myInfo.Token))) { return(null); } _playerlist = _playerlist.Add(new PlayerState(myInfo, 0)); OnPlayerlistChanged?.Invoke(this, _playerlist); Logger.LogInformation($"Player {myInfo.Name} joined; {_playerlist.Count} in list"); return(myInfo); }
public ParsedContent(ImmutableList <IType> types, IReadStringContent reader) { if (types == null) { throw new ArgumentNullException(nameof(types)); } if (types.Any(t => t == null)) { throw new ArgumentException("Null reference encountered in set", nameof(types)); } Types = types; Reader = reader; }
public override async Task <Shopping> Act(object cmd) { switch (cmd) { default: throw new CommandInvalidException(cmd); case ChooseProduct c: _products.Any(p => p == c.ProductId).ShouldBeFalse("Product already added"); return(Apply(new ProductChosen( c.CustomerId, c.ProductId ))); } }
public FFmpegColorChannelMixer( double rr = 1, double rg = 0, double rb = 0, double ra = 0, double gr = 0, double gg = 1, double gb = 0, double ga = 0, double br = 0, double bg = 0, double bb = 1, double ba = 0, double ar = 0, double ag = 0, double ab = 0, double aa = 1, ImmutableList <FFmpegFilterOption> options = null ) : base( "colorchannelmixer", (options ?? ImmutableList.Create <FFmpegFilterOption>()) .AddRange( new[] { new FFmpegFilterOption("rr", rr), new FFmpegFilterOption("rg", rg), new FFmpegFilterOption("rb", rb), new FFmpegFilterOption("ra", ra), new FFmpegFilterOption("gr", gr), new FFmpegFilterOption("gg", gg), new FFmpegFilterOption("gb", gb), new FFmpegFilterOption("ga", ga), new FFmpegFilterOption("br", br), new FFmpegFilterOption("bg", bg), new FFmpegFilterOption("bb", bb), new FFmpegFilterOption("ba", ba), new FFmpegFilterOption("ar", ar), new FFmpegFilterOption("ag", ag), new FFmpegFilterOption("ab", ab), new FFmpegFilterOption("aa", aa) }.Where(x => options?.Any(o => o.Name == x.Name) != true) // ^ Let colour mix settings in 'options' take priority ) ) { ErrorUtils.ThrowIfArgOutsideRange(rr, -2.0, 2.0, nameof(rr)); ErrorUtils.ThrowIfArgOutsideRange(rg, -2.0, 2.0, nameof(rg)); ErrorUtils.ThrowIfArgOutsideRange(rb, -2.0, 2.0, nameof(rb)); ErrorUtils.ThrowIfArgOutsideRange(ra, -2.0, 2.0, nameof(ra)); ErrorUtils.ThrowIfArgOutsideRange(gr, -2.0, 2.0, nameof(gr)); ErrorUtils.ThrowIfArgOutsideRange(gg, -2.0, 2.0, nameof(gg)); ErrorUtils.ThrowIfArgOutsideRange(gb, -2.0, 2.0, nameof(gb)); ErrorUtils.ThrowIfArgOutsideRange(ga, -2.0, 2.0, nameof(ga)); ErrorUtils.ThrowIfArgOutsideRange(br, -2.0, 2.0, nameof(br)); ErrorUtils.ThrowIfArgOutsideRange(bg, -2.0, 2.0, nameof(bg)); ErrorUtils.ThrowIfArgOutsideRange(bb, -2.0, 2.0, nameof(bb)); ErrorUtils.ThrowIfArgOutsideRange(ba, -2.0, 2.0, nameof(ba)); ErrorUtils.ThrowIfArgOutsideRange(ar, -2.0, 2.0, nameof(ar)); ErrorUtils.ThrowIfArgOutsideRange(ag, -2.0, 2.0, nameof(ag)); ErrorUtils.ThrowIfArgOutsideRange(ab, -2.0, 2.0, nameof(ab)); ErrorUtils.ThrowIfArgOutsideRange(aa, -2.0, 2.0, nameof(aa)); }
internal bool HasDefaultTypeReader(Type type) { if (_defaultTypeReaders.ContainsKey(type)) { return(true); } var typeInfo = type.GetTypeInfo(); if (typeInfo.IsEnum) { return(true); } return(_entityTypeReaders.Any(x => type == x.Item1 || typeInfo.ImplementedInterfaces.Contains(x.Item2))); }
public RemoveOperation(RemoveOperationBuilder builder, LazyItemEvaluator <P, I, M, D> lazyEvaluator) : base(builder, lazyEvaluator) { _matchOnMetadata = builder.MatchOnMetadata.ToImmutable(); ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile( _matchOnMetadata.IsEmpty || _itemSpec.Fragments.All(f => f is ItemSpec <P, I> .ItemExpressionFragment), new BuildEventFileInfo(string.Empty), "OM_MatchOnMetadataIsRestrictedToReferencedItems"); if (_matchOnMetadata.Any()) { _metadataSet = new MetadataTrie <P, I>(builder.MatchOnMetadataOptions, _matchOnMetadata, _itemSpec); } }
public void AddMember(Member member) { // Avoid adding the same member twice if (_members.Any(x => x.Address == member.Address)) { return; } if (member.Address.Equals(_cluster.System.Address)) { _me = member; } _members = _members.Add(member); _rdv.UpdateMembers(_members); }
public void Commit() { var currentValue = _property.GetValue(_object); var isChanged = _candidates.Any( c => c.Value == null && currentValue == null || currentValue != null && !currentValue.Equals(c.Value) ); if (isChanged || _isDraft) { SetTo(currentValue); } _isDraft = false; }
public string ToDescriptiveString(int depth = 0) { string indent = Strings.Indent(depth); string pathLines = paths .Select(path => path.ToDescriptiveString(depth + 1) + conditionals .Where(condition => condition.Start == path.Target) .Select(condition => condition.ToDescriptiveString(depth + 1)) .Join("") ) .Join(""); string strStarts = starts.Any() ? starts.Join(", ") + " " : ""; return($"{indent}{strStarts}{{\r\n{pathLines}{indent}}}\r\n"); }
public override PointStatus GetPointStatus(Vertex3 vt) { if (faces.Any(x => x.Plane.Excludes(vt))) { return(PointStatus.Outside); } foreach (CH_Polygon f in faces) { PointStatus ps = f.GetPointStatus(vt); if (ps != PointStatus.Outside) { return(ps); } } return(PointStatus.Inside); }
protected override void ApplyImpl(OrderedItemDataCollection.Builder listBuilder, ImmutableHashSet <string> globsToIgnore) { if (!_conditionResult) { return; } bool matchingOnMetadata = _matchOnMetadata.Any(); if (!matchingOnMetadata) { if (ItemspecContainsASingleBareItemReference(_itemSpec, _itemElement.ItemType)) { // Perf optimization: If the Remove operation references itself (e.g. <I Remove="@(I)"/>) // then all items are removed and matching is not necessary listBuilder.Clear(); return; } if (listBuilder.Count >= Traits.Instance.DictionaryBasedItemRemoveThreshold) { // Perf optimization: If the number of items in the running list is large, construct a dictionary, // enumerate all items referenced by the item spec, and perform dictionary look-ups to find items // to remove. IList <string> matches = _itemSpec.IntersectsWith(listBuilder.Dictionary); listBuilder.RemoveAll(matches); return; } } // todo Perf: do not match against the globs: https://github.com/dotnet/msbuild/issues/2329 HashSet <I> items = null; foreach (ItemData item in listBuilder) { bool isMatch = matchingOnMetadata ? MatchesItemOnMetadata(item.Item) : _itemSpec.MatchesItem(item.Item); if (isMatch) { items ??= new HashSet <I>(); items.Add(item.Item); } } if (items is not null) { listBuilder.RemoveAll(items); } }
public InterfaceDetails( IdentifierDetails name, ImmutableList <GenericTypeParameterDetails> genericTypeParams, ImmutableList <NamedTypeDetails> baseTypes, ImmutableList <PropertyDetails> contents, SourceRangeDetails source) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (genericTypeParams == null) { throw new ArgumentNullException(nameof(genericTypeParams)); } if (genericTypeParams.Any(t => t == null)) { throw new ArgumentException("Null reference encountered in set", nameof(genericTypeParams)); } if (baseTypes == null) { throw new ArgumentNullException(nameof(baseTypes)); } if (baseTypes.Any(t => t == null)) { throw new ArgumentException("Null reference encountered in set", nameof(baseTypes)); } if (contents == null) { throw new ArgumentNullException(nameof(contents)); } if (contents.Any(p => p == null)) { throw new ArgumentException("Null reference encountered in set", nameof(contents)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } Name = name; GenericTypeParams = genericTypeParams; BaseTypes = baseTypes; Contents = contents; SourceRange = source; }
public Task(Guid uuid, TaskStatus status, string description, Timestamp entered, Timestamp lastModified, ImmutableList <string> tags, ImmutableDictionary <string, Json.IJsonValue> additionalAttributes) { if (description == "") { throw new System.ArgumentException("description must not be empty", "description"); } if (tags.Any(tag => tag.Any(char.IsWhiteSpace))) { throw new System.ArgumentException("tag must not contain whitespace", "tags"); } this.uuid = uuid; this.status = status; this.description = description; this.entered = entered; this.lastModified = lastModified; this.tags = tags; this.additionalAttributes = additionalAttributes; }
private static ImmutableList <int> Sort(ImmutableList <int> source) { if (!source.Any()) { return(source); } var first = source.First(); var(left, right) = source .Skip(1) .Partition(x => x <= first); var leftSorted = Sort(left); var rightSorted = Sort(right); return(leftSorted .Add(first) .AddRange(rightSorted)); }
public ReferenceUnionGraphType(Builder builder, FieldInfo fieldInfo, ImmutableList <DomainId>?schemaIds) { Name = fieldInfo.ReferenceType; if (schemaIds?.Any() == true) { foreach (var schemaId in schemaIds) { var contentType = builder.GetContentType(schemaId); if (contentType != null) { types[schemaId] = contentType; } } } else { foreach (var(key, value) in builder.GetAllContentTypes()) { types[key.Schema.Id] = value; } } if (HasType) { foreach (var type in types) { AddPossibleType(type.Value); } ResolveType = value => { if (value is IContentEntity content) { return(types.GetOrDefault(content.SchemaId.Id)); } return(null); }; } }
public VisualizerNode( IInspectedObject obj, ImmutableList <VisualizerNode> children, bool expanded, bool selected, int level, ImmutableDictionary <ILogSource, string> annotationsMap ) { this.obj = obj; this.key = $"{obj?.GetHashCode():x08}"; this.children = children; this.annotationsMap = annotationsMap; this.text = GetNodeText(obj, level, annotationsMap); this.expanded = expanded; this.selected = selected; this.level = level; children.ForEach(c => c.parent = this); this.hasSelectedNodes = selected || children.Any(c => c.HasSelectedNodes); }
public async Task <bool> Unlink(DocumentModel model) { await dataLock.WaitAsync(); try { linkedModels = linkedModels.Remove(model); if (!linkedModels.Any(m => m.RepresentationType == model.RepresentationType)) { // Last model referencing its representation. Get rid of it. if (representations.TryGetValue(model.RepresentationType, out var rep)) { await RemoveRepresentation(model.RepresentationType, rep); rep.OnDispose().Ignore(); } } return(linkedModels.Count == 0); } finally { dataLock.Release(); } }
private void NavigatePageStack(ImmutableList<Type> pageStack, ImmutableList<Type> priorPageStack) { var priorTop = priorPageStack?.LastOrDefault(); var priorSecond = priorPageStack != null && priorPageStack.Any() ? priorPageStack.Reverse().Skip(1).FirstOrDefault() : null; var currentTop = pageStack.LastOrDefault(); var currentSecond = pageStack.Any() ? pageStack.Reverse().Skip(1).FirstOrDefault() : null; if (currentTop == priorTop) { // All set. } else if (currentTop == priorSecond) { if (_rootFrame.CanGoBack) _rootFrame.GoBack(); } else if (currentSecond == priorTop) { _rootFrame.Navigate(currentTop); } if (_rootFrame.CurrentSourcePageType != currentTop) { while (_rootFrame.CanGoBack) _rootFrame.GoBack(); if (currentTop != null) _rootFrame.Navigate(currentTop); } }
public void JoinSeedNodes(ImmutableList<Address> seedNodes) { if (seedNodes.Any()) { StopSeedNodeProcess(); if (seedNodes.SequenceEqual(ImmutableList.Create(_cluster.SelfAddress))) { Self.Tell(new ClusterUserAction.JoinTo(_cluster.SelfAddress)); _seedNodeProcess = null; } else { // use unique name of this actor, stopSeedNodeProcess doesn't wait for termination _seedNodeProcessCounter += 1; if (seedNodes.Head().Equals(_cluster.SelfAddress)) { _seedNodeProcess = Context.ActorOf(Props.Create(() => new FirstSeedNodeProcess(seedNodes)), "firstSeedNodeProcess-" + _seedNodeProcessCounter); } else { _seedNodeProcess = Context.ActorOf(Props.Create(() => new JoinSeedNodeProcess(seedNodes)).WithDispatcher(_cluster.Settings.UseDispatcher), "joinSeedNodeProcess-" + _seedNodeProcessCounter); } } } }
protected override void OnReceive(object message) { if (message is InternalClusterAction.JoinSeenNode) { if (_timeout.HasTimeLeft) { // send InitJoin to remaining seed nodes (except myself) foreach ( var seed in _remainingSeeds.Select( x => Context.ActorSelection(Context.Parent.Path.ToStringWithAddress(x)))) seed.Tell(new InternalClusterAction.InitJoin()); } else { // no InitJoinAck received, initialize new cluster by joining myself Context.Parent.Tell(new ClusterUserAction.JoinTo(_selfAddress)); Context.Stop(Self); } } else if (message is InternalClusterAction.InitJoinAck) { // first InitJoinAck reply, join existing cluster var initJoinAck = (InternalClusterAction.InitJoinAck)message; Context.Parent.Tell(new ClusterUserAction.JoinTo(initJoinAck.Address)); Context.Stop(Self); } else if (message is InternalClusterAction.InitJoinNack) { var initJoinNack = (InternalClusterAction.InitJoinNack)message; _remainingSeeds = _remainingSeeds.Remove(initJoinNack.Address); if (!_remainingSeeds.Any()) { // initialize new cluster by joining myself when nacks from all other seed nodes Context.Parent.Tell(new ClusterUserAction.JoinTo(_selfAddress)); Context.Stop(Self); } } else { Unhandled(message); } }
public JoinSeedNodeProcess(ImmutableList<Address> seeds) { _selfAddress = Cluster.Get(Context.System).SelfAddress; _seeds = seeds; if (!seeds.Any() || seeds.Head() == _selfAddress) throw new ArgumentException("Join seed node should not be done"); Context.SetReceiveTimeout(Cluster.Get(Context.System).Settings.SeedNodeTimeout); }