Пример #1
0
        public override AddResult Add(ItemSurrogate newItem)
        {
            List <ItemSlot> emptySlots = new List <ItemSlot> (Items.Count);

            //bool partiallyComplete = false;

            for (int i = 0; i < Items.Count; i++)
            {
                ItemSlot slot = Items[i];

                if (slot.Item == null)
                {
                    emptySlots.Add(slot);
                    continue;
                }

                AddResult result = slot.Add(newItem);

                if (result == AddResult.Complete)
                {
                    if (OnAddItem != null)
                    {
                        OnAddItem();
                    }

                    return(AddResult.Complete);
                }
                //else if (result == AddResult.Partial)
                //	partiallyComplete = true;
            }

            /*for (int i = 0; i < emptySlots.Count; i++)
             * {
             *      ItemSlot slot = emptySlots [i];
             *
             *      AddResult result = slot.Add (newItem);
             *
             *      if (result == AddResult.Complete)
             *      {
             *              if (OnAddItem != null)
             *                      OnAddItem ();
             *
             *              return AddResult.Complete;
             *      }
             *      else if (result == AddResult.Partial)
             *              partiallyComplete = true;
             * }*/


            AddResult lastAddResult = AddResult.None;

            while (lastAddResult != AddResult.Complete)
            {
                ItemSlot newSlot = AddSlot();

                lastAddResult = newSlot.Add(newItem);

                if (OnAddItem != null)
                {
                    OnAddItem();
                }
            }

            return(AddResult.Complete);

            /*if (partiallyComplete)
            *  {
            *       if (OnAddItem != null)
            *               OnAddItem ();
            *
            *       return AddResult.Partial;
            *  }
            *  else
            *       return AddResult.None;*/
        }
Пример #2
0
 public TransferResult(Schedule s, DeleteResult d, AddResult a) : base(s)
 {
     this.d = d;
     this.a = a;
 }
Пример #3
0
        public override AddResult Add(ItemSurrogate newItem)
        {
            List <ItemSlot> emptySlots = new List <ItemSlot> (Items.Count);

            bool partiallyComplete = false;

            for (int i = 0; i < Items.Count; i++)
            {
                ItemSlot slot = Items[i];

                if (slot.Item == null)
                {
                    emptySlots.Add(slot);
                    continue;
                }

                AddResult result = slot.Add(newItem);

                if (result == AddResult.Complete)
                {
                    if (OnAddItem != null)
                    {
                        OnAddItem();
                    }

                    return(AddResult.Complete);
                }
                else if (result == AddResult.Partial)
                {
                    partiallyComplete = true;
                }
            }

            for (int i = 0; i < emptySlots.Count; i++)
            {
                ItemSlot slot = emptySlots[i];

                AddResult result = slot.Add(newItem);

                if (result == AddResult.Complete)
                {
                    if (OnAddItem != null)
                    {
                        OnAddItem();
                    }

                    return(AddResult.Complete);
                }
                else if (result == AddResult.Partial)
                {
                    partiallyComplete = true;
                }
            }

            if (partiallyComplete)
            {
                if (OnAddItem != null)
                {
                    OnAddItem();
                }

                return(AddResult.Partial);
            }
            else
            {
                return(AddResult.None);
            }
        }
Пример #4
0
        /// <summary>Reads a new operation from the given lexer.</summary>
        /// <param name="sr">The lexer to read the operation from.</param>
        /// <param name="parent">The fragment to parent the operation to.</param>
        public OperationFragment(CodeLexer sr, CodeFragment parent)
        {
            ParentFragment = parent;
            LineNumber     = sr.LineNumber;
            bool localMode = false;

            while (true)
            {
                char peek = sr.Peek();

                if (peek == StringReader.NULL)
                {
                    return;
                }

                if (peek == ';' || peek == ',')
                {
                    // Read it off:
                    sr.Read();
                    return;
                }

                Handler handler = Handlers.Find(peek);

                if (handler == Handler.Stop)
                {
                    return;
                }

                // Handle the fragment:
                CodeFragment fragment;

                try{
                    // Try to get the code fragment:
                    fragment = Handlers.Handle(handler, sr);
                }catch (CompilationException e) {
                    if (e.LineNumber == -1)
                    {
                        // Setup line number:
                        e.LineNumber = LineNumber;
                    }

                    // Rethrow:
                    throw e;
                }

                if (localMode)
                {
                    // Should always be a VariableFragment:

                    if (fragment.GetType() == typeof(VariableFragment))
                    {
                        VariableFragment local = (VariableFragment)fragment;
                        local.AfterVar = true;
                    }

                    localMode = false;
                }

                // Try adding the fragment to the operation:
                AddResult status = fragment.AddTo(this, sr);

                // What was the outcome?
                switch (status)
                {
                case AddResult.Stop:
                    // Halt.
                    return;

                case AddResult.Local:
                    // Local next:
                    localMode = true;
                    break;
                    // Ok otherwise.
                }
            }
        }
Пример #5
0
 private AddInfo CreateAddInfo(AddResult result, Entry <TKey, TValue> targetEntry, int startIndex, int targetIndex)
 {
     return(new AddInfo(result, targetEntry, ArrayMath.CalculateNumberOfSlotsBetween(startIndex, targetIndex, Capacity)));
 }
Пример #6
0
 public AddInfo(AddResult operationResult, Entry <TKey, TValue> targetEntry, int reprobingCount)
 {
     OperationResult = operationResult;
     TargetEntry     = targetEntry;
     ReprobingCount  = reprobingCount;
 }
        public void passing_a_null_object_as_a_success_result_is_not_a_valid_use()
        {
            var act = (Action)(() => AddResult <object> .WasSuccess(null));

            Assert.Throws <ArgumentNullException>(act);
        }