예제 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="plane">Plane</param>
        /// <param name="normal">Normal</param>
        protected BSPTree(BSPTree <T> parent, ICollection <T> items, PartitionHandler partitionHandler)
        {
            this.parent = parent;
            bounds      = GetBounds(items);
            partition   = DeterminePartition(items, bounds, partitionHandler);

            if (items.Count == 1)
            {
                this.items.AddRange(items);
            }
            else
            {
                var backItems  = new List <T>();
                var frontItems = new List <T>();

                foreach (var item in items)
                {
                    Add(item, backItems, frontItems);
                }

                if (backItems.Count > 0)
                {
                    back = new BSPTree <T>(this, backItems, partitionHandler);
                }
                if (frontItems.Count > 0)
                {
                    front = new BSPTree <T>(this, frontItems, partitionHandler);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="plane">Plane</param>
        /// <param name="normal">Normal</param>
        protected BSPTree(BSPTree parent, IList <IBSPItem> items, PartitionHandler partitionHandler)
        {
            this.parent = parent;
            bounds      = GetBounds(items);
            partition   = DeterminePartition(items, bounds, partitionHandler);

            if (items.Count == 1)
            {
                this.items.Add(items[0]);
            }
            else
            {
                List <IBSPItem> backItems  = new List <IBSPItem>();
                List <IBSPItem> frontItems = new List <IBSPItem>();

                foreach (IBSPItem item in items)
                {
                    Add(item, backItems, frontItems);
                }

                if (backItems.Count > 0)
                {
                    back = new BSPTree(this, backItems, partitionHandler);
                }
                if (frontItems.Count > 0)
                {
                    front = new BSPTree(this, frontItems, partitionHandler);
                }
            }
        }
 public PartitioningInterceptor(IApplicationContext applicationContext, IBindingOptions bindingOptions, IPartitionKeyExtractorStrategy partitionKeyExtractorStrategy, IPartitionSelectorStrategy partitionSelectorStrategy)
 {
     _bindingOptions   = bindingOptions;
     _partitionHandler = new PartitionHandler(
         applicationContext,
         _bindingOptions.Producer,
         partitionKeyExtractorStrategy,
         partitionSelectorStrategy);
 }
예제 #4
0
 public PartitioningInterceptor(IExpressionParser expressionParser, IEvaluationContext evaluationContext, IBindingOptions bindingOptions, IPartitionKeyExtractorStrategy partitionKeyExtractorStrategy, IPartitionSelectorStrategy partitionSelectorStrategy)
 {
     _bindingOptions   = bindingOptions;
     _partitionHandler = new PartitionHandler(
         expressionParser,
         evaluationContext,
         _bindingOptions.Producer,
         partitionKeyExtractorStrategy,
         partitionSelectorStrategy);
 }
예제 #5
0
        /// <summary>
        /// Delegates execution to the provided <see cref="IPartitionHandler"/>. The
        /// <see cref="StepExecution"/> passed in here becomes the parent or master
        /// execution for the partition, summarising the status on exit of the
        /// logical grouping of work carried out by the PartitionHandler. The
        /// individual step executions and their input parameters (through
        /// ExecutionContext) for the partition elements are provided by the
        /// StepExecutionSplitter.
        /// </summary>
        /// <param name="stepExecution">the master step execution for the partition</param>
        /// <exception cref="Exception">&nbsp;</exception>
        protected override void DoExecute(StepExecution stepExecution)
        {
            stepExecution.ExecutionContext.Put(StepConstants.StepTypeKey, GetType().Name);

            // Wait for task completion and then aggregate the results
            ICollection <StepExecution> executions = PartitionHandler.Handle(StepExecutionSplitter, stepExecution);

            stepExecution.UpgradeStatus(BatchStatus.Completed);
            StepExecutionAggregator.Aggregate(stepExecution, executions);

            // If anything failed or had a problem we need to crap out
            if (stepExecution.BatchStatus.IsUnsuccessful())
            {
                throw new JobExecutionException("Partition handler returned an unsuccessful step");
            }
        }
예제 #6
0
        public async ValueTask ExecuteAsync(IConsole console)
        {
            var            tcs                = new TaskCompletionSource <bool>();
            EventHubClient client             = EventHubClient.CreateFromConnectionString($"Endpoint=sb://{Namespace}.servicebus.windows.net;EntityPath={EventHub};SharedAccessKeyName={SasKeyName};SharedAccessKey={SasKeyValue}");
            var            runtimeInformation = await client.GetRuntimeInformationAsync();

            var partitionReceivers = runtimeInformation.PartitionIds.Select(partitionId => client.CreateReceiver("$Default", partitionId, ShouldReadFromStart ? EventPosition.FromStart() : EventPosition.FromEnd())).ToList();
            Channel <string> queue = Channel.CreateBounded <string>(10000);
            PartitionHandler pr    = new PartitionHandler(queue);

            Task readerTask = Task.Run(async() =>
            {
                while (await queue.Reader.WaitToReadAsync())
                {
                    await foreach (string s in queue.Reader.ReadAllAsync())
                    {
                        await console.Output.WriteLineAsync(s);
                    }
                }
            });

            foreach (var partitionReceiver in partitionReceivers)
            {
                partitionReceiver.SetReceiveHandler(pr);
            }

            Console.CancelKeyPress += async(s, e) =>
            {
                await client.CloseAsync();

                queue.Writer.TryComplete();
                await readerTask;
                tcs.TrySetResult(true);
            };

            await tcs.Task;
        }
예제 #7
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="plane">Plane</param>
		/// <param name="normal">Normal</param>
		protected BSPTree( BSPTree parent, IList<IBSPItem> items, PartitionHandler partitionHandler )
		{
			this.parent = parent;
			bounds = GetBounds( items );
			partition = DeterminePartition( items, bounds, partitionHandler );

			if ( items.Count == 1 )
			{
				this.items.Add( items[ 0 ] );
			}
			else
			{
				List<IBSPItem> backItems = new List<IBSPItem>();
				List<IBSPItem> frontItems = new List<IBSPItem>();

				foreach ( IBSPItem item in items )
				{
					Add( item, backItems, frontItems );
				}

				if ( backItems.Count > 0 ) back = new BSPTree( this, backItems, partitionHandler );
				if ( frontItems.Count > 0 ) front = new BSPTree( this, frontItems, partitionHandler );
			}
		}
예제 #8
0
        /// <summary>
        /// Determine partition
        /// </summary>
        /// <param name="items">Items</param>
        /// <param name="bounds">Bounds</param>
        /// <returns>Partition</returns>
        protected virtual Plane DeterminePartition(IEnumerable <T> items, BoundingBox bounds, PartitionHandler partitionHandler)
        {
            Vector3D size = bounds.Max - bounds.Min;
            double   length;
            Vector3D normal;

            if (size.Z >= size.X && size.Z >= size.Y)
            {
                length = size.Z;
                normal = new Vector3D(0, 0, 1);
            }
            else if (size.X >= size.Y && size.X >= size.Z)
            {
                length = size.X;
                normal = new Vector3D(1, 0, 0);
            }
            else
            {
                length = size.Y;
                normal = new Vector3D(0, 1, 0);
            }

            float position = (float)((partitionHandler != null) ? partitionHandler(length, normal) : 0.5);

            return(new Plane((Vector3D)(bounds.Min + (size * position)), normal));
        }
예제 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="normal">Normal</param>
 public BSPTree(ICollection <T> items, PartitionHandler partitionHandler)
     : this(null, items, partitionHandler)
 {
 }
예제 #10
0
		/// <summary>
		/// Determine partition
		/// </summary>
		/// <param name="items">Items</param>
		/// <param name="bounds">Bounds</param>
		/// <returns>Partition</returns>
		protected virtual Plane DeterminePartition( IList<IBSPItem> items, BoundingBox bounds, PartitionHandler partitionHandler )
		{
			Vector3D size = bounds.Max - bounds.Min;
			double length;
			Vector3D normal;

			if ( size.Z >= size.X && size.Z >= size.Y )
			{
				length = size.Z;
				normal = new Vector3D( 0, 0, 1 );
			}
			else if ( size.X >= size.Y && size.X >= size.Z )
			{
				length = size.X;
				normal = new Vector3D( 1, 0, 0 );
			}
			else
			{
				length = size.Y;
				normal = new Vector3D( 0, 1, 0 );
			}

			double position = ( partitionHandler != null ) ? partitionHandler( length, normal ) : 0.5;

			return new Plane( bounds.Min + ( size * position ), normal );
		}
예제 #11
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="normal">Normal</param>
		public BSPTree( IList<IBSPItem> items, PartitionHandler partitionHandler ) : this( null, items, partitionHandler )
		{
		}
예제 #12
0
        /// <summary>
        /// Determine partition
        /// </summary>
        /// <param name="items">Items</param>
        /// <param name="bounds">Bounds</param>
        /// <returns>Partition</returns>
        protected virtual Plane DeterminePartition(IList <IBSPItem> items, BoundingBox bounds, PartitionHandler partitionHandler)
        {
            Vector3D size = bounds.Max - bounds.Min;
            double   length;
            Vector3D normal;

            if (size.Z >= size.X && size.Z >= size.Y)
            {
                length = size.Z;
                normal = new Vector3D(0, 0, 1);
            }
            else if (size.X >= size.Y && size.X >= size.Z)
            {
                length = size.X;
                normal = new Vector3D(1, 0, 0);
            }
            else
            {
                length = size.Y;
                normal = new Vector3D(0, 1, 0);
            }

            double position = (partitionHandler != null) ? partitionHandler(length, normal) : 0.5;

            return(new Plane(bounds.Min + (size * position), normal));
        }
예제 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="normal">Normal</param>
 public BSPTree(IList <IBSPItem> items, PartitionHandler partitionHandler) : this(null, items, partitionHandler)
 {
 }