Пример #1
0
        private static bool Output(long status)
        {
            var previousPosition  = droidPosition;
            var attemptedPosition = Compass.PositionAfterMovement(droidPosition, Attempt);

            if (status == 0)
            {
                // The repair droid hit a wall. Its position has not changed.
                area.Set(attemptedPosition, Day15Cell.Wall);
                Day15Debug.Set(attemptedPosition, Day15Cell.Wall);
                Day15Debug.WriteLine("BLOCKED");
            }
            else
            {
                // The repair droid has moved one step in the requested direction.
                Day15Debug.WriteLine("OK");
                droidPosition = attemptedPosition;
                if (!Backtracking)
                {
                    area.Set(attemptedPosition, Day15Cell.Open);
                    Day15Debug.Set(attemptedPosition, Day15Cell.Open);
                    if (status == 2)
                    {
                        oxygenSystemPosition = attemptedPosition;
                    }
                    EnteredFrom[attemptedPosition] = Attempt;
                    Visited.Add(attemptedPosition);
                    Attempts.Push(Compass.AllDirections);
                }
            }

            return((Attempts.Count() > 1) || (Attempts.Peek().Count > 0));
        }
Пример #2
0
        public bool Attempt(string activityId, bool logAttempt)
        {
            var attemptLimited = false;

            Console.ReadLine();
            var time             = DateTime.UtcNow;
            var blockWindowStart = time - MaxBlockTime; //Used for Queue Cleanup
            var windowStart      = time - Window;       //Used for max block time

            // delete those outside of window

            var  timeLeft = TimeSpan.MaxValue;
            bool isBlocking;

            lock (_syncRoot)
            {
                if (logAttempt)
                {
                    //var time = DateTime.UtcNow;
                    Console.WriteLine($"Attempt logged at {time} details: {this}");
                    Attempts.Enqueue(time);
                }
                //Attempts.RemoveAll(t => t < windowStart);
                //isBlocking = Attempts.Count() == MaxAttempts || timeLeft <= MaxBlockTime;
                timeLeft   = Attempts.Max() - blockWindowStart;
                isBlocking = Attempts.Count() == MaxAttempts;
                if (isBlocking)
                {
                    if (Attempts.Count() > 0)
                    {
                        timeLeft = Attempts.Max() - blockWindowStart;
                    }
                    else
                    {
                        isBlocking = false;
                    }
                }
            }

            if (isBlocking)
            {
                // get last attempts
                if (Block && timeLeft <= MaxBlockTime)
                {
                    Console.WriteLine($"Attempt is blocked for {timeLeft} details: {this}");
                    //Thread.Sleep(timeLeft);
                    //throw new TooManyAttemptsException(ToString());
                }
                else if (AbortIfCantBlock)
                {
                    if (OverrideAttemptLimitationExceptions)
                    {
                        Console.WriteLine($"Attempt TooManyAttemptsException suppressed by setting OverrideAttemptLimitationExceptions in service configuration details: {this}");
                    }
                    else
                    {
                        Console.WriteLine($"Attempt throws TooManyAttemptsException details: {this}");
                        //throw new TooManyAttemptsException(ToString());
                    }
                }
                else
                {
                    Console.WriteLine($"Attempt was limited but neither exception or blocking has taken place details: {this}");
                }

                attemptLimited = true;
            }


            return(attemptLimited);
        }
Пример #3
0
 public override string ToString()
 {
     return($"Count: {Attempts.Count()}, Window: {Window}, MaxAttempts: {MaxAttempts}, Block: {Block}, MaxBlockTime: {MaxBlockTime}, AbortIfCantBlock: {AbortIfCantBlock}");
 }