/// <summary>
 /// Add a <see cref="AuctionCreate" /> item to the queue of items to sell. The queue will be handled automatically.
 /// </summary>
 /// <param name="auctionInfo">The auction info.</param>
 public static void AddSell(AuctionCreate auctionInfo)
 {
     SellQueue.Enqueue(auctionInfo);
     if (!_selling && IsVisible)
         Sell(SellQueue.Dequeue());
 }
 private static void Sell(AuctionCreate auctionInfo)
 {
     Logging.Write("Selling {0} ({1}) x {2}", auctionInfo.Name, auctionInfo.StackSize, auctionInfo.Stacks);
     if (Helpers.InBagCount(auctionInfo.Id) < auctionInfo.StackSize)
     {
         Logging.Write("Not enough items to post {0}. StackSize is {1} and I only have {2}", auctionInfo.Name, auctionInfo.StackSize, Helpers.InBagCount(auctionInfo.Id));
         SellQueueHandler();
         return;
     }
     if (Helpers.InBagCount(auctionInfo.Id) < auctionInfo.StackSize * auctionInfo.Stacks)
     {
         auctionInfo.Stacks = (int) Math.Floor((decimal) Helpers.InBagCount(auctionInfo.Id)/auctionInfo.StackSize);
     }
     _selling = true;
     var addItemLua =
         "for b=0,4 do " +
         "  for s=1,GetContainerNumSlots(b) do " +
         "   local id=GetContainerItemID(b,s) " +
         "	if id=={0} then " +
         "	  PickupContainerItem(b,s) " +
         "	  ClickAuctionSellItemButton() " +
         "     AuctionFrameAuctions.duration={1} " +
         "	  ClearCursor() " +
         "	  return 1 " +
         "	end " +
         "  end " +
         "end " +
         "return 0";
     //                                                  int values of the enum are 12,24,48. The lua takes 1,2,3 as arguments.
     addItemLua = string.Format(addItemLua, auctionInfo.Id, (int) auctionInfo.Duration/12);
     var sellItemLua = string.Format("StartAuction({0},{1},{2},{3},{4})", auctionInfo.MinBid.TotalCopper,
                                     auctionInfo.BuyoutPrice.TotalCopper, (int) auctionInfo.Duration/12,
                                     auctionInfo.StackSize, auctionInfo.Stacks);
     UseAuctionMultisellUpdated = false;
     UseAuctionMultisellFailed = false;
     //Lua.Events.DetachEvent("AUCTION_MULTISELL_UPDATE", AuctionMultisellUpdated);
     //Lua.Events.DetachEvent("AUCTION_MULTISELL_FAILURE", AuctionMultisellFailed);
     //Lua.Events.DetachEvent("AUCTION_OWNED_LIST_UPDATE", AuctionOwnedListUpdated);
     if (auctionInfo.Stacks > 1)
     {
         UseAuctionMultisellUpdated = true;
         UseAuctionMultisellFailed = true;
         //Lua.Events.AttachEvent("AUCTION_MULTISELL_UPDATE", AuctionMultisellUpdated);
         //Lua.Events.AttachEvent("AUCTION_MULTISELL_FAILURE", AuctionMultisellFailed);
     }
     if (auctionInfo.Stacks == 1)
     {
         sellDelay.Restart();
         UseAuctionMultisellFailed = true;
         //Lua.Events.AttachEvent("AUCTION_OWNED_LIST_UPDATE", AuctionOwnedListUpdated);
     }
     Lua.DoString(addItemLua);
     Lua.DoString(sellItemLua);
 }