Example #1
0
        /// <summary>
        /// Populates the serialization object order with the info from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        private void PopulateOrderInfo(SerializableOrderListItem src)
        {
            OwnerID         = src.OwnerID;
            ID              = src.OrderID;
            Item            = StaticItems.GetItemByID(src.ItemID);
            UnitaryPrice    = src.UnitaryPrice;
            InitialVolume   = src.InitialVolume;
            RemainingVolume = src.RemainingVolume;
            MinVolume       = src.MinVolume;
            Duration        = src.Duration;
            Issued          = src.Issued;
            IssuedFor       = src.IssuedFor;
            m_stationID     = src.StationID;
            UpdateStation();

            if (src.IsBuyOrder == 0)
            {
                return;
            }

            BuyOrder buyOrder = (BuyOrder)this;

            buyOrder.Escrow = src.Escrow;
            buyOrder.Range  = src.Range;
        }
Example #2
0
        /// <summary>
        /// Constructor from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        protected MarketOrder(SerializableOrderListItem src)
        {
            src.ThrowIfNull(nameof(src));

            PopulateOrderInfo(src);
            LastStateChange = DateTime.UtcNow;
            m_state         = GetState(src);
        }
Example #3
0
        /// <summary>
        /// Try to update this order with a serialization object from the API.
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        internal bool TryImport(SerializableOrderListItem src, List <MarketOrder> endedOrders)
        {
            // Note that, before a match is found, all orders have been marked for deletion : m_markedForDeletion == true

            // Checks whether ID is the same (IDs can be recycled ?)
            if (!MatchesWith(src))
            {
                return(false);
            }

            // Prevent deletion
            m_markedForDeletion = false;

            // Update infos (if ID is the same it may have been modified either by the market
            // or by the user [modify order] so we update the orders info that are changeable)
            if (IsModified(src))
            {
                // If it's a buying order, escrow may have changed
                if (src.IsBuyOrder != 0)
                {
                    ((BuyOrder)this).Escrow = src.Escrow;
                }

                m_unitaryPrice    = src.UnitaryPrice;
                m_remainingVolume = src.RemainingVolume;
                m_issued          = src.Issued;
                m_state           = OrderState.Modified;
            }
            else if (m_state == OrderState.Modified)
            {
                m_state = OrderState.Active;
            }

            // Update state
            OrderState state = GetState(src);

            if (m_state != OrderState.Modified && state != m_state) // it has either expired or fulfilled
            {
                m_state           = state;
                m_lastStateChange = DateTime.UtcNow;

                // Should we notify it to the user ?
                if ((state == OrderState.Expired || state == OrderState.Fulfilled) && !Ignored)
                {
                    endedOrders.Add(this);
                }
            }

            return(true);
        }
Example #4
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 protected MarketOrder(SerializableOrderListItem src)
 {
     m_state           = GetState(src);
     m_orderID         = src.OrderID;
     m_itemID          = src.ItemID;
     m_item            = StaticItems.GetItemByID(src.ItemID);
     m_station         = GetStationByID(src.StationID);
     m_unitaryPrice    = src.UnitaryPrice;
     m_initialVolume   = src.InitialVolume;
     m_remainingVolume = src.RemainingVolume;
     m_lastStateChange = DateTime.UtcNow;
     m_minVolume       = src.MinVolume;
     m_duration        = src.Duration;
     m_issued          = src.Issued;
     m_issuedFor       = src.IssuedFor;
 }
Example #5
0
        /// <summary>
        /// Gets the state of an order.
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        private static OrderState GetState(SerializableOrderListItem src)
        {
            switch ((APIEnumerations.CCPOrderState)src.State)
            {
            case APIEnumerations.CCPOrderState.Closed:
            case APIEnumerations.CCPOrderState.Canceled:
            case APIEnumerations.CCPOrderState.CharacterDeleted:
                return(OrderState.Canceled);

            case APIEnumerations.CCPOrderState.Pending:
            case APIEnumerations.CCPOrderState.Opened:
                return(OrderState.Active);

            case APIEnumerations.CCPOrderState.ExpiredOrFulfilled:
                return(src.RemainingVolume == 0 ? OrderState.Fulfilled : OrderState.Expired);

            default:
                throw new NotImplementedException();
            }
        }
Example #6
0
 /// <summary>
 /// Checks whether the given API object matches with this order.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 internal bool IsModified(SerializableOrderListItem src)
 {
     return(src.RemainingVolume != 0 &&
            ((src.UnitaryPrice != m_unitaryPrice && src.Issued != m_issued) ||
             src.RemainingVolume != m_remainingVolume));
 }
Example #7
0
 /// <summary>
 /// Checks whether the given API object matches with this order.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 internal bool MatchesWith(SerializableOrderListItem src)
 {
     return(src.OrderID == m_orderID);
 }
Example #8
0
 /// <summary>
 /// Checks whether the given API object has been modified.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool IsModified(SerializableOrderListItem src) => src.RemainingVolume != 0 &&
 ((src.UnitaryPrice != UnitaryPrice && src.Issued != Issued) ||
  src.RemainingVolume != RemainingVolume);
Example #9
0
 /// <summary>
 /// Checks whether the given API object matches with this order.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool MatchesWith(SerializableOrderListItem src) => src.OrderID == ID;
Example #10
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal BuyOrder(SerializableOrderListItem src)
     : base(src)
 {
     Escrow  = src.Escrow;
     m_range = src.Range;
 }
Example #11
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal SellOrder(SerializableOrderListItem src)
     : base(src)
 {
 }
Example #12
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal SellOrder(SerializableOrderListItem src, CCPCharacter character)
     : base(src, character)
 {
 }
Example #13
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal BuyOrder(SerializableOrderListItem src, CCPCharacter character)
     : base(src, character)
 {
     Escrow = src.Escrow;
     Range  = src.Range;
 }