static void EliminateTinySections(List<Section> list, int minLineLengthPx)
		{
			// Eliminate tiny sections
			Section cur;
			int i;
			while ((cur = list[i = list.IndexOfMin(s => s.LengthPx)]).LengthPx < minLineLengthPx)
			{
				var prev = list.TryGet(i - 1, null);
				var next = list.TryGet(i + 1, null);
				if (PickMerge(ref prev, cur, ref next))
				{
					if (prev != null)
						list[i - 1] = prev;
					if (next != null)
						list[i + 1] = next;
					list.RemoveAt(i);
				}
				else
					break;
			}

			// Merge adjacent sections that now have the same mod-8 angle
			for (i = 1; i < list.Count; i++)
			{
				Section s0 = list[i - 1], s1 = list[i];
				if (s0.AngleMod8 == s1.AngleMod8)
				{
					s0.EndSS = s1.EndSS;
					s0.iEnd = s1.iEnd;
					s0.LengthPx += s1.LengthPx;
					list.RemoveAt(i);
					i--;
				}
			}
		}
Example #2
0
        public static Message Convert(OutgoingMessage message, List<DeliveryConstraint> deliveryConstraints)
        {
            var result = new Message();

            if (message.Body != null)
            {
                result.BodyStream = new MemoryStream(message.Body);
            }


            AssignMsmqNativeCorrelationId(message, result);
            result.Recoverable = !deliveryConstraints.Any(c => c is NonDurableDelivery);

            DiscardIfNotReceivedBefore timeToBeReceived;

            if (deliveryConstraints.TryGet(out timeToBeReceived) && timeToBeReceived.MaxTime < MessageQueue.InfiniteTimeout)
            {
                result.TimeToBeReceived = timeToBeReceived.MaxTime;
            }

            var addCorrIdHeader = !message.Headers.ContainsKey("CorrId");

            using (var stream = new MemoryStream())
            {
                var headers = message.Headers.Select(pair => new HeaderInfo
                {
                    Key = pair.Key,
                    Value = pair.Value
                }).ToList();

                if (addCorrIdHeader)
                {
                    headers.Add(new HeaderInfo
                    {
                        Key = "CorrId",
                        Value = result.CorrelationId
                    });
                }

                headerSerializer.Serialize(stream, headers);
                result.Extension = stream.ToArray();
            }

            var messageIntent = default(MessageIntentEnum);

            string messageIntentString;

            if (message.Headers.TryGetValue(Headers.MessageIntent, out messageIntentString))
            {
                Enum.TryParse(messageIntentString, true, out messageIntent);
            }

            result.AppSpecific = (int)messageIntent;


            return result;
        }
        bool IsCombiningTimeToBeReceivedWithTransactions(TransportTransaction transaction, DispatchConsistency requiredDispatchConsistency, List<DeliveryConstraint> deliveryConstraints)
        {
            if (!settings.UseTransactionalQueues)
            {
                return false;
            }

            if (requiredDispatchConsistency == DispatchConsistency.Isolated)
            {
                return false;
            }

            DiscardIfNotReceivedBefore discardIfNotReceivedBefore;
            var timeToBeReceivedRequested = deliveryConstraints.TryGet(out discardIfNotReceivedBefore) && discardIfNotReceivedBefore.MaxTime < MessageQueue.InfiniteTimeout;

            if (!timeToBeReceivedRequested)
            {
                return false;
            }

            if (Transaction.Current != null)
            {
                return true;
            }

            MessageQueueTransaction activeReceiveTransaction;

            return TryGetNativeTransaction(transaction, out activeReceiveTransaction);
        }