Exemplo n.º 1
0
        public AsyncFactoryPool(IAsyncFactory <T> factory, IPool <T> pool)
            : base(pool)
        {
            Contracts.Requires.That(factory != null);

            this.factory = factory;
        }
Exemplo n.º 2
0
        public ChunkedPhase(
            IStageIdentity stageIdentity,
            IGenerationPhaseIdentity phaseIdentity,
            IReadOnlyLargeCollection <TKey> chunkKeys,
            IAsyncFactory <TKey, IDisposableValue <TChunk> > chunkFactory,
            IChunkProcessor <TChunk> chunkProcessor,
            GenerationOptions options = null)
            : base(options?.CancellationToken ?? DefaultCancellationToken)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(phaseIdentity != null);
            Contracts.Requires.That(chunkKeys != null);
            Contracts.Requires.That(chunkFactory != null);
            Contracts.Requires.That(chunkProcessor != null);

            this.StageIdentity  = stageIdentity;
            this.PhaseIdentity  = phaseIdentity;
            this.chunkKeys      = chunkKeys;
            this.chunkFactory   = chunkFactory;
            this.chunkProcessor = chunkProcessor;

            this.Progress = this.progress.AsObservable();

            var dataflowOptions = new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = options?.MaxDegreeOfParallelism ?? DefaultMaxDegreeOfParallelism,
                CancellationToken      = this.CancellationToken,
            };

            this.processChunks   = new ActionBlock <TKey>(this.ProcessChunk, dataflowOptions);
            this.chunksCompleted = new AsyncLongCountdownEvent(this.ProgressTotalCount);
        }
Exemplo n.º 3
0
 public MemberMetricsCalculator(SemanticModel semanticModel, Solution solution, IAsyncFactory <ISymbol, IMemberDocumentation> documentationFactory)
     : base(semanticModel)
 {
     _solution             = solution;
     _documentationFactory = documentationFactory;
     _nameResolver         = new MemberNameResolver(Model);
 }
Exemplo n.º 4
0
		public MemberMetricsCalculator(SemanticModel semanticModel, Solution solution, IAsyncFactory<ISymbol, IMemberDocumentation> documentationFactory)
			: base(semanticModel)
		{
			_solution = solution;
			_documentationFactory = documentationFactory;
			_nameResolver = new MemberNameResolver(Model);
		}
        public SkyIslandMapImagesPhase(
            IStageIdentity stageIdentity,
            IStageBounds stageBounds,
            IAsyncFactory <ChunkOverheadKey, IDisposableValue <IReadOnlySkyIslandMapChunk> > chunkFactory,
            IKeyValueStore statsStore,
            SkyIslandMapImagesOptions imageOptions = null,
            GenerationOptions generationOptions    = null)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(chunkFactory != null);
            Contracts.Requires.That(statsStore != null);

            var phaseIdentity = new GenerationPhaseIdentity(nameof(SkyIslandMapImagesPhase));
            var chunkKeys     = new ChunkOverheadKeyCollection(stageBounds);

            var chunkProcessor = new SkyIslandMapChunkImagesProcessor(stageBounds, statsStore, imageOptions);

            this.Phase = new ChunkedPhase <ChunkOverheadKey, IReadOnlySkyIslandMapChunk>(
                stageIdentity,
                phaseIdentity,
                chunkKeys,
                chunkFactory,
                chunkProcessor,
                generationOptions);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncEntityFactory{TEntity, TIdentity}"/> class.
 /// </summary>
 /// <param name="keyGenerator">The factory that will be used to generate unique identity values.</param>
 /// <exception cref="ArgumentNullException"><paramref name="keyGenerator"/> is <b>null</b>.</exception>
 public AsyncEntityFactory(IAsyncFactory <TIdentity> keyGenerator)
     : this(() => keyGenerator.CreateNewAsync())
 {
     if (keyGenerator == null)
     {
         throw new ArgumentNullException(nameof(keyGenerator));
     }
 }
Exemplo n.º 7
0
        public BoundedAsyncFactoryPool(IAsyncFactory <T> factory, IPool <T> pool)
            : base(pool)
        {
            Contracts.Requires.That(factory != null);

            this.factory   = factory;
            this.countLeft = BoundedFactoryUtilities.GetRemainingCount(pool);
        }
Exemplo n.º 8
0
        public AsyncCompletableChunkFactory(IAsyncFactory <TKey, TChunk> factory, IAsyncCompletable completable)
        {
            Contracts.Requires.That(factory != null);
            Contracts.Requires.That(completable != null);

            this.factory     = factory;
            this.completable = completable;
        }
        public CacheStashedChunkFactory(
            IAsyncFactory <TKey, IDisposableValue <TChunk> > factory, IExpiryStash <TKey> stash)
        {
            Contracts.Requires.That(factory != null);
            Contracts.Requires.That(stash != null);

            this.factory = factory;
            this.stash   = stash;
        }
 public void AddAsyncFactory <TFactoryContext, TModel>(IAsyncFactory <TFactoryContext, TModel> factory)
     where TFactoryContext : class, IFactoryContext, new()
     where TModel : class, new()
 => this.factoryInfos.Add(new FactoryInfo
 {
     FactoryContextType = typeof(TFactoryContext),
     FactoryType        = factory.GetType(),
     IsAsync            = true
 });
Exemplo n.º 11
0
        public PersistableChunkFactory(
            IAsyncFactory <TKey, IDisposableValue <TChunk> > factory,
            IChunkPersister <TChunk, TPersistable> converter)
        {
            Contracts.Requires.That(factory != null);
            Contracts.Requires.That(converter != null);

            this.factory   = factory;
            this.converter = converter;
        }
        public SerializeMeshChunkFactory(
            IAsyncFactory <ChunkKey, IDisposableValue <IDivisibleMesh <NormalColorTextureVertex> > > meshFactory,
            ISerializerDeserializer <IDivisibleMesh <NormalColorTextureVertex> > serializer)
        {
            Contracts.Requires.That(meshFactory != null);
            Contracts.Requires.That(serializer != null);

            this.meshFactory = meshFactory;
            this.serializer  = serializer;
        }
        public AsyncCache(
            IAsyncFactory <TKey, TState, ICacheValue <TKey, TValue> > factory,
            IEqualityComparer <TKey> comparer)
        {
            Contracts.Requires.That(factory != null);
            Contracts.Requires.That(comparer != null);

            this.factory = factory;
            this.entries = new ConcurrentDictionary <TKey, AsyncLazy <CacheEntry> >(comparer);
        }
        public AsyncCache(
            IAsyncFactory <TKey, ICacheValue <TKey, TValue> > factory,
            IEqualityComparer <TKey> comparer)
        {
            Contracts.Requires.That(factory != null);
            Contracts.Requires.That(comparer != null);

            this.cache = new AsyncCache <TKey, VoidStruct, TValue>(
                Factory.FromAsync((TKey key, VoidStruct unused) => factory.CreateAsync(key)),
                comparer);
        }
        public void Constructor_ShouldThrowException_WhenAbstractFactoryIsNull()
        {
            // Arrange
            IAsyncFactory <int> factory = null;

            // Act
            Action action = () => new AsyncEntityFactory <FakeEntity <int>, int>(factory);

            // Assert
            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 16
0
        public StageBoundaryChunkOverheadFactory(
            IStageBounds bounds,
            IAsyncFactory <ChunkOverheadKey, TChunk> interiorFactory,
            IFactory <ChunkOverheadKey, TChunk> exteriorFactory)
        {
            Contracts.Requires.That(bounds != null);
            Contracts.Requires.That(interiorFactory != null);
            Contracts.Requires.That(exteriorFactory != null);

            this.minKey          = bounds.InOverheadChunks.LowerBounds;
            this.maxKey          = bounds.InOverheadChunks.UpperBounds;
            this.interiorFactory = interiorFactory;
            this.exteriorFactory = exteriorFactory;
        }
        public ChunkedBatchingPhase(
            IStageIdentity stageIdentity,
            IGenerationPhaseIdentity phaseIdentity,
            IReadOnlyLargeCollection <TKey> chunkKeys,
            IAsyncFactory <TKey, TPersistable> chunkFactory,
            IChunkStore <TKey, TPersistable> chunkStore,
            int maxBatchedChunks,
            BatchGenerationOptions options = null)
            : base(options?.CancellationToken ?? DefaultCancellationToken)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(phaseIdentity != null);
            Contracts.Requires.That(chunkKeys != null);
            Contracts.Requires.That(chunkFactory != null);
            Contracts.Requires.That(chunkStore != null);
            Contracts.Requires.That(maxBatchedChunks > 0);

            this.StageIdentity = stageIdentity;
            this.PhaseIdentity = phaseIdentity;
            this.chunkKeys     = chunkKeys;
            this.chunkFactory  = chunkFactory;
            this.chunkStore    = chunkStore;

            this.Progress = this.progress.AsObservable();

            var dataflowOptions = new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = options?.MaxDegreeOfParallelism ?? DefaultMaxDegreeOfParallelism,
                BoundedCapacity        = maxBatchedChunks,
                CancellationToken      = this.CancellationToken,
            };

            this.generateChunks = new TransformBlock <TKey, TPersistable>(
                chunkIndex => this.chunkFactory.CreateAsync(chunkIndex), dataflowOptions);

            this.saveChunks = BatchActionBlock.Create <TPersistable>(
                this.SaveChunks,
                maxBatchedChunks,
                options?.Batching ?? DefaultBatching,
                dataflowOptions);

            var linkOptions = new DataflowLinkOptions()
            {
                PropagateCompletion = true
            };

            this.generateChunks.LinkTo(this.saveChunks, linkOptions);

            this.chunksCompleted = new AsyncLongCountdownEvent(this.ProgressTotalCount);
        }
        public SkyIslandVoxelGridChunkPopulator(
            SkyIslandVoxelPopulatorConfig config,
            IAsyncFactory <ChunkOverheadKey, IDisposableValue <IReadOnlySkyIslandMapChunk> > chunkFactory,
            IFactory <int, INoise3D> multiNoise)
        {
            Contracts.Requires.That(config != null);
            Contracts.Requires.That(chunkFactory != null);
            Contracts.Requires.That(multiNoise != null);

            this.config           = config;
            this.chunkFactory     = chunkFactory;
            this.environmentNoise = multiNoise.Create(SkyIslandNoiseSubSeed.Environment);
            this.caveNoise1       = multiNoise.Create(SkyIslandNoiseSubSeed.Cave1);
            this.caveNoise2       = multiNoise.Create(SkyIslandNoiseSubSeed.Cave2);
        }
Exemplo n.º 19
0
        public ContourPhase(
            IStageIdentity stageIdentity,
            IStageBounds stageBounds,
            IRasterChunkConfig <Index3D> voxelChunkConfig,
            IAsyncFactory <ChunkKey, IDisposableValue <IReadOnlyVoxelGridChunk> > voxelChunkFactory,
            IDualContourer <TerrainVoxel, TSurfaceData, NormalColorTextureVertex> contourer,
            IChunkStore <ChunkKey, SerializedMeshChunk> meshChunkStore,
            int maxBufferedChunks,
            BatchSerializeGenerationOptions options = null)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(voxelChunkConfig != null);
            Contracts.Requires.That(voxelChunkFactory != null);
            Contracts.Requires.That(contourer != null);
            Contracts.Requires.That(meshChunkStore != null);
            Contracts.Requires.That(maxBufferedChunks > 0);

            var phaseIdentity = new GenerationPhaseIdentity(nameof(ContourPhase <TSurfaceData>));
            var chunkKeys     = new ChunkKeyCollection(stageBounds);

            var poolOptions = new PoolOptions <IMutableDivisibleMesh <NormalColorTextureVertex> >()
            {
                ResetAction = mesh => mesh.Clear(),
            };

            this.pool = Pool.WithFactory.New(
                Factory.From <IMutableDivisibleMesh <NormalColorTextureVertex> >(
                    () => new MutableDivisibleMesh <NormalColorTextureVertex>()),
                poolOptions);

            var chunkFactory = new ContourMeshFactory <TSurfaceData>(
                voxelChunkConfig, voxelChunkFactory, this.pool, contourer);
            var serializer = DivisibleMeshSerializer.NormalColorTextureVertices.WithColorAlpha[
                options?.SerializationEndianness ?? DefaultSerializationEndianness];
            var persistableFactory = new SerializeMeshChunkFactory(chunkFactory, serializer);

            this.Phase = new ChunkedBatchingPhase <ChunkKey, SerializedMeshChunk>(
                stageIdentity,
                phaseIdentity,
                chunkKeys,
                persistableFactory,
                meshChunkStore,
                maxBufferedChunks,
                options);

            this.Completion = this.CompleteAsync();
        }
        public ContourMeshFactory(
            IRasterChunkConfig <Index3D> voxelChunkConfig,
            IAsyncFactory <ChunkKey, IDisposableValue <IReadOnlyVoxelGridChunk> > voxelChunkFactory,
            IPool <IMutableDivisibleMesh <NormalColorTextureVertex> > meshBuilderPool,
            IDualContourer <TerrainVoxel, TSurfaceData, NormalColorTextureVertex> contourer)
        {
            Contracts.Requires.That(voxelChunkConfig != null);
            Contracts.Requires.That(voxelChunkFactory != null);
            Contracts.Requires.That(meshBuilderPool != null);
            Contracts.Requires.That(contourer != null);

            this.voxelChunkDimensionsInVoxels = voxelChunkConfig.Bounds.Dimensions;
            this.meshBuilderPool = meshBuilderPool;
            this.contourer       = contourer;

            this.chunkConglomerator = new ChunkConglomerator <IReadOnlyVoxelGridChunk>(
                async index => await voxelChunkFactory.CreateAsync(
                    new ChunkKey(index - new Index3D(1))).DontMarshallContext(),
                new Index3D(3));
        }
Exemplo n.º 21
0
 public TypeMetricsCalculator(SemanticModel semanticModel, Solution solution, IAsyncFactory <ISymbol, ITypeDocumentation> documentationFactory)
     : base(semanticModel)
 {
     _solution             = solution;
     _documentationFactory = documentationFactory;
 }
Exemplo n.º 22
0
 public static TrackingPool <T> New <T>(IAsyncFactory <T> factory, TrackingPoolOptions <T> options) =>
 new TrackingPool <T>(Pool.WithFactory.Bounded.New(factory, options), options);
Exemplo n.º 23
0
 public static TrackingPool <T> New <T>(IAsyncFactory <T> factory) =>
 New(factory, new TrackingPoolOptions <T>());
Exemplo n.º 24
0
 public static IPool <T> New <T>(IAsyncFactory <T> factory, IPoolOptions <T> options = null) =>
 new BoundedAsyncFactoryPool <T>(factory, new Pool <T>(options));
Exemplo n.º 25
0
		public TypeMetricsCalculator(SemanticModel semanticModel, Solution solution, IAsyncFactory<ISymbol, ITypeDocumentation> documentationFactory)
			: base(semanticModel)
		{
			_solution = solution;
			_documentationFactory = documentationFactory;
		}
Exemplo n.º 26
0
		public CodeMetricsCalculator(IAsyncFactory<ISymbol, ITypeDocumentation> typeDocumentationFactory, IAsyncFactory<ISymbol, IMemberDocumentation> memberDocumentationFactory)
		{
			_typeDocumentationFactory = typeDocumentationFactory;
			_memberDocumentationFactory = memberDocumentationFactory;
		}
Exemplo n.º 27
0
 public HttpClientAsyncFactory(IAsyncFactory <IAuthService> factory, HttpMessageHandler handler, Api api)
 {
     _factory = factory;
     _handler = handler;
     _api     = api;
 }
Exemplo n.º 28
0
 public static IAsyncFactory <TKey, TPersistable> Create <TKey, TChunk, TPersistable>(
     IAsyncFactory <TKey, IDisposableValue <TChunk> > factory,
     IChunkPersister <TChunk, TPersistable> converter) =>
 new PersistableChunkFactory <TKey, TChunk, TPersistable>(factory, converter);
Exemplo n.º 29
0
 public static IAsyncFactory <TKey, ICacheValue <TKey, TChunk> > CreateStashed <TKey, TChunk>(
     IAsyncFactory <TKey, IDisposableValue <TChunk> > factory, IExpiryStash <TKey> stash) =>
 new CacheStashedChunkFactory <TKey, TChunk>(factory, stash);
Exemplo n.º 30
0
 public UserEndPoint(DataServiceContext context, IAsyncFactory <HttpClient> factory, string uri)
     : base(context, factory, uri)
 {
 }
 public AsyncCache(IAsyncFactory <TKey, ICacheValue <TKey, TValue> > factory)
     : this(factory, EqualityComparer <TKey> .Default)
 {
 }
Exemplo n.º 32
0
 public CodeMetricsCalculator(IAsyncFactory <ISymbol, ITypeDocumentation> typeDocumentationFactory, IAsyncFactory <ISymbol, IMemberDocumentation> memberDocumentationFactory)
 {
     _typeDocumentationFactory   = typeDocumentationFactory;
     _memberDocumentationFactory = memberDocumentationFactory;
 }
Exemplo n.º 33
0
 public static IAsyncFactory <ChunkKey, TChunk> Create <TChunk>(
     IStageBounds bounds,
     IAsyncFactory <ChunkKey, TChunk> interiorFactory,
     IFactory <ChunkKey, TChunk> exteriorFactory) =>
 new StageBoundaryChunkFactory <TChunk>(bounds, interiorFactory, exteriorFactory);