Пример #1
0
 /// <summary>
 /// Add a delegate/method as a handler
 /// </summary>
 /// <typeparam name="TData">Type of data</typeparam>
 /// <param name="handle">Handle delegate/method</param>
 /// <returns>A new Executor</returns>
 public Executor <TDataImplements> AddHandler <TData>(Action <TData> handle)
     where TData : class, TDataImplements
 {
     return(new Executor <TDataImplements>(
                _allHandlers.Add(Handler <TDataImplements> .From(handle))
                ));
 }
Пример #2
0
        static IEnumerable <Segment> GetGraphKeyImpl(ISymbol symbol, IImmutableList <Segment> acc)
        {
            if (symbol == null)
            {
                return(acc.Reverse());
            }

            if (symbol is ITypeSymbol)
            {
                return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "+"))));
            }

            if (symbol is INamespaceSymbol)
            {
                if (((INamespaceSymbol)symbol).IsGlobalNamespace)
                {
                    return(GetGraphKeyImpl(symbol.ContainingSymbol, acc));
                }

                return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "."))));
            }

            if (symbol is IModuleSymbol)
            {
                return(GetGraphKeyImpl(symbol.ContainingSymbol, acc));
            }

            if (symbol is IAssemblySymbol)
            {
                return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "|"))));
            }

            return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "!"))));
        }
Пример #3
0
 void IScopeManager <T> .EnableScope(T domain)
 {
     lock (_sync)
     {
         Entry dm;
         if (_scopeByNames.TryGetValue(domain.Name, out dm))
         {
             dm.Enabled = true;
             if (!(domain is ISchema))
             {
                 Interlocked.Exchange(ref _scopes, _scopes.Add(domain));
             }
         }
     }
 }
Пример #4
0
        //BLOCKING IO READ
        private IImmutableList <ByteString> ReadAhead(int maxChunks, IImmutableList <ByteString> chunks)
        {
            if (chunks.Count <= maxChunks && IsActive)
            {
                try
                {
                    var readBytes = _chan.Read(_buffer, 0, _chunkSize);

                    if (readBytes == 0)
                    {
                        //EOF
                        _eofReachedAtOffset = _chan.Position;
                        _log.Debug($"No more bytes available to read (got 0 from read), marking final bytes of file @ {_eofReachedAtOffset}");
                        return(chunks);
                    }

                    _readBytesTotal += readBytes;
                    var newChunks = chunks.Add(ByteString.Create(_buffer, 0, readBytes));
                    return(ReadAhead(maxChunks, newChunks));
                }
                catch (Exception ex)
                {
                    OnErrorThenStop(ex);
                    //read failed, we're done here
                    return(ImmutableList <ByteString> .Empty);
                }
            }

            return(chunks);
        }
Пример #5
0
        public void Replace(int index, byte opcode)
        {
            var original = this[index];

            this[index] = opcode;
            mutations   = mutations.Add(new Mutation(index, original, opcode));
        }
Пример #6
0
        /// <summary>
        ///  Adds the specified <paramref name="indexer"/> to the <see cref="Indexers"/> list
        /// </summary>
        /// <param name="indexer">An <see cref="Indexer"/> to add</param>
        /// <returns>Returns a reference to the same <paramref name="indexer"/>, allowing other operations to be chained</returns>
        /// <exception cref="ArgumentException">
        ///  Throw when this set already contains an indexer with the same <see cref="Indexer.Source"/>
        ///  property value as the <paramref name="indexer"/> being added
        /// </exception>
        public Indexer Add([NotNull] Indexer indexer)
        {
            if (indexer == null)
            {
                throw new ArgumentNullException("indexer");
            }
            if (ContainsSource(indexer.Source))
            {
                throw new ArgumentException("Source is already included in this IndexerSet", "indexer");
            }

            lock (lockObject)
                indexers = indexers.Add(indexer);

            return(indexer);
        }
Пример #7
0
        public async Task <IImmutableList <PackageResult> > Package(IImmutableList <PackageResource> resources, string version)
        {
            var packageResources = resources
                                   .Add(new PackageResource("main.tf",
                                                            await File.ReadAllBytesAsync(_file.FullName)));

            return(ImmutableList.Create(await PackageResult.FromResources($"{Name}.{version}.zip", packageResources)));
        }
Пример #8
0
        public GradientColorBuilder Add(GradientColorByValue gradientColor)
        {
            if (_gradientColorList.Any(item => item.Value == gradientColor.Value))
            {
                throw new InvalidOperationException($"Gradient color value ({gradientColor.Value}) is already defined");
            }

            return(ShallowClone(_gradientColorList.Add(gradientColor)));
        }
Пример #9
0
            IImmutableList <RowModel> UpdateRows(
                IImmutableList <RowModel> visibleRows,
                Dictionary <ILiveElement, Action <RowModel> > updates)
            {
                //while (visibleRows.Count < 30)
                //	visibleRows = visibleRows.Add(new RowModel(_tree));

                // First update all rows currently attached to an element
                Queue <RowModel> freeRows = new Queue <RowModel>();

                foreach (var rowModel in visibleRows)
                {
                    var rowModelLocal = rowModel;                     // Shouldn't be necesarry in C# 5 or higher, doing it just to be safe.
                    rowModel.Element.Do(
                        el =>
                    {
                        Action <RowModel> update;
                        if (updates.TryGetValue(el, out update))
                        {
                            update(rowModelLocal);
                            updates.Remove(el);
                        }
                        else
                        {
                            freeRows.Enqueue(rowModelLocal);
                        }
                    },
                        () => { freeRows.Enqueue(rowModelLocal); });
                }

                // Now update all remaining elements
                foreach (var update in updates.Values)
                {
                    RowModel rowModel;
                    if (freeRows.Count > 0)
                    {
                        rowModel = freeRows.Dequeue();
                    }
                    else
                    {
                        rowModel    = new RowModel(_tree);
                        visibleRows = visibleRows.Add(rowModel);
                    }
                    update(rowModel);
                }

                // And then detach any leftover rows
                // (we don't free row templates if tree is resized smaller)
                while (freeRows.Count > 0)
                {
                    freeRows.Dequeue().Detach();
                }
                return(visibleRows);
            }
Пример #10
0
        public void RemoveTest()
        {
            ImmutableList <int> list = ImmutableList <int> .Empty;

            for (int i = 1; i <= 10; i++)
            {
                list = list.Add(i * 10);
            }

            list = list.Remove(30);
            Assert.Equal(9, list.Count);
            Assert.False(list.Contains(30));

            list = list.Remove(100);
            Assert.Equal(8, list.Count);
            Assert.False(list.Contains(100));

            list = list.Remove(10);
            Assert.Equal(7, list.Count);
            Assert.False(list.Contains(10));

            var removeList = new int[] { 20, 70 };

            list = list.RemoveAll(removeList.Contains);
            Assert.Equal(5, list.Count);
            Assert.False(list.Contains(20));
            Assert.False(list.Contains(70));

            IImmutableList <int> list2 = ImmutableList <int> .Empty;

            for (int i = 1; i <= 10; i++)
            {
                list2 = list2.Add(i * 10);
            }

            list2 = list2.Remove(30);
            Assert.Equal(9, list2.Count);
            Assert.False(list2.Contains(30));

            list2 = list2.Remove(100);
            Assert.Equal(8, list2.Count);
            Assert.False(list2.Contains(100));

            list2 = list2.Remove(10);
            Assert.Equal(7, list2.Count);
            Assert.False(list2.Contains(10));

            list2 = list2.RemoveAll(removeList.Contains);
            Assert.Equal(5, list2.Count);
            Assert.False(list2.Contains(20));
            Assert.False(list2.Contains(70));
        }
Пример #11
0
        /// <summary>
        /// Sets the item in the given index.
        /// </summary>
        /// <param name="index">The index in which the item would be replaced.</param>
        /// <param name="item">The item to replace with item in the given index.</param>
        /// <returns>New list with the item in the given index replaced with the given one.</returns>
        public IImmutableList <T> SetItem(int index, T item)
        {
            if (index < 0 || index >= this.Count)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            ImmutableList <T>  notToCopy = ListAt(index + 1) as ImmutableList <T>;
            IImmutableList <T> newList   = notToCopy.ListAt(index - 1);

            newList = newList.Add(item);

            return(CopyDifferntial(newList, this, notToCopy));
        }
Пример #12
0
    static IEnumerable<Segment> GetGraphKeyImpl(ISymbol symbol, IImmutableList<Segment> acc)
    {
      if (symbol == null)
        return acc.Reverse();

      if (symbol is ITypeSymbol)
        return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "+")));

      if (symbol is INamespaceSymbol)
      {
        if (((INamespaceSymbol)symbol).IsGlobalNamespace)
          return GetGraphKeyImpl(symbol.ContainingSymbol, acc);

        return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, ".")));
      }

      if (symbol is IModuleSymbol)
        return GetGraphKeyImpl(symbol.ContainingSymbol, acc);

      if (symbol is IAssemblySymbol)
        return GetGraphKeyImpl(symbol.ContainingSymbol, acc);

      return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "!")));
    }
Пример #13
0
        private void AddSubjectUnderCategory(ISubject subject)
        {
            subjects = subjects.Add(subject);

            foreach (string keyword in subject.Keywords)
            {
                if (map.TryGetValue(keyword, out var keywordSet))
                {
                    map = map.SetItem(keyword, keywordSet.Add(subject));
                }
                else
                {
                    map = map.SetItem(keyword, ImmutableHashSet <ISubject> .Empty.Add(subject));
                }
            }
        }
Пример #14
0
            public Logic(SeqStage <T> stage, TaskCompletionSource <IImmutableList <T> > promise) : base(stage.Shape)
            {
                _stage = stage;

                SetHandler(stage._in, onPush: () =>
                {
                    _buf = _buf.Add(Grab(stage._in));
                    Pull(stage._in);
                }, onUpstreamFinish: () =>
                {
                    promise.TrySetResult(_buf);
                    CompleteStage();
                }, onUpstreamFailure: ex =>
                {
                    promise.TrySetException(ex);
                    FailStage(ex);
                });
            }
Пример #15
0
 protected override bool Receive(object message)
 {
     return(message.Match()
            .With <int>(i =>
     {
         if (_buffer.Count == 0 && TotalDemand > 0)
         {
             OnNext(i);
         }
         else
         {
             _buffer = _buffer.Add(i);
             DeliverBuffer();
         }
     })
            .With <Request>(DeliverBuffer)
            .With <Cancel>(() => Context.Stop(Self))
            .WasHandled);
 }
        public InferenceState Unify(out IImmutableList <InferenceState> states)
        {
            var state = this;

            states = ImmutableList.Create(state);
            while (state.Context.Any(e => e is IConstraint))
            {
                var prefix      = state.Context.TakeWhile(e => !(e is IConstraint));
                var eqAndSuffix = state.Context.SkipWhile(e => !(e is IConstraint));
                if (eqAndSuffix.First() is IConstraint constraint)
                {
                    state = constraint.Solve(state.Fresh, prefix.ToImmutableList(), eqAndSuffix.Skip(1).ToImmutableList());
                }
                else
                {
                    throw new Exception("Should never get here: said there was a constraint, but then didn't find it.");
                }
                states = states.Add(state);
            }
            return(state);
        }
Пример #17
0
        /// <inheritdoc />
        protected override bool Receive(object message)
        {
            switch (message)
            {
            case int wordCount:
                _results = _results.Add(wordCount);
                if (_results.Count == _expectedResults)
                {
                    var meanWordLength = _results.Sum() * 1.0 / _results.Count;
                    _replyTo.Tell(new StatsResult(meanWordLength));
                    Context.Stop(Self);
                }
                return(true);

            case ReceiveTimeout _:
                _replyTo.Tell(new JobFailed("Service unavailable, try again later"));
                Context.Stop(Self);
                return(true);
            }

            return(false);
        }
        private static IEnumerable <CircularReferenceError> Analyse(string assemblyName, IImmutableList <string> parent, IDictionary <string, AssemblyCheck> context)
        {
            var hasCycle    = parent.Contains(assemblyName);
            var currentPath = parent.Add(assemblyName);

            if (hasCycle)
            {
                yield return(new CircularReferenceError(currentPath));

                yield break;
            }

            var assembly = context[assemblyName];

            foreach (var child in assembly.AssembliesReferenced)
            {
                foreach (var result in Analyse(child, currentPath, context).ToList())
                {
                    yield return(result);
                }
            }
        }
Пример #19
0
        private void OnSpawnpointDiscovered(Spawnpoint s)
        {
            s.IsDiscovered = true;

            _discoveredSpawnpoints = _discoveredSpawnpoints.Add(s.Id);
            _fileWriterScheduler.Schedule(_discoveredSpawnpoints, SerializeDiscoveredSpawnpoints);

            var spawnpointsDiscovered = 0;

            for (int i = 0; i < _spawnpoints.Count; i++)
            {
                var spawnpoint = _spawnpoints[i];
                if (spawnpoint.IsDiscovered)
                {
                    spawnpointsDiscovered++;
                }
            }

            _coroutineScheduler.Run(_announcerUi.Introduce(
                                        "Spawnpoint discovered:",
                                        _challengeColor,
                                        s.Name,
                                        spawnpointsDiscovered + "/" + _spawnpoints.Count + " spawnpoints discovered"));
        }
Пример #20
0
 private static IEnumerable <KeyValuePair <string, string?> > VisitArray(IImmutableList <string> keys, JArray array)
 {
     return(Enumerable.Range(0, array.Count)
            .SelectMany(i => VisitToken(keys.Add(i.ToString(CultureInfo.InvariantCulture)), array[i])));
 }
Пример #21
0
 public IProcessBuilder AddArgument(string argument)
 => ShallowClone(arguments: Option.Some(_arguments.Add(argument)));
Пример #22
0
 internal Builder AddQuery(IWittyerSimpleVariant variant)
 {
     _query = _query.Add(variant);
     return this;
 }
Пример #23
0
 public override void OnPush()
 {
     _buf = _buf.Add(Grab(_stage.In));
     Pull(_stage.In);
 }
Пример #24
0
            private IEither <ParsingException, IPartialParse <IImmutableList <OutputType> > > RepeatParse
            (
                int currentCount,
                string remainingInput,
                IImmutableList <OutputType> outputs
            )
            {
                if (currentCount <= 0)
                {
                    return(Either.Create <ParsingException> .Right(new PartialParse <IImmutableList <OutputType> >(outputs, remainingInput)));
                }

                return(m_outer.Parse(remainingInput)
                       .Match(
                           error => Either.Create <IPartialParse <IImmutableList <OutputType> > > .Left(ParsingFailure(remainingInput, error)),
                           success => RepeatParse(currentCount - 1, success.RemainingInput, outputs.Add(success.Output))
                           ));
            }
Пример #25
0
 public GlobalJsonModificationBuilder AddMsBuildSdk(MsBuildSdk sdk)
 => ShallowClone(sdksToAdd: Option.Some(_msBuildSdksToAdd.Add(sdk)));
Пример #26
0
 private static IEnumerable <KeyValuePair <string, string?> > VisitJObject(IImmutableList <string> keys, JObject jObject)
 {
     return(jObject.Properties()
            .SelectMany(property => VisitToken(keys.Add(property.Name), property.Value)));
 }
Пример #27
0
 public Graph Add(Statement statement)
 {
     return(new Graph(graphKind, name, statements.Add(statement)));
 }
Пример #28
0
 public static IImmutableList <T> add <T>(IImmutableList <T> list, T value) =>
 list.Add(value);
Пример #29
0
 public void AddCondition(ICondition <TValue> condition)
 {
     conditions = conditions.Add(condition);
 }
Пример #30
0
 public State AddParameter(object?parameter)
 {
     return(new State(parameters.Add(parameter), argumentExtractor, postValidations, assignmentOperators));
 }
Пример #31
0
 internal Builder AddNonSupported(IVcfVariant variant)
 {
     _notSupported = _notSupported.Add(variant);
     return this;
 }