Example #1
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 #2
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 #3
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 #4
0
 /// <summary>
 /// Gets the state of an order.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private static OrderState GetState(SerializableOrderListItem src)
 {
     switch ((CCPOrderState)src.State)
     {
         case CCPOrderState.Closed:
         case CCPOrderState.Canceled:
         case CCPOrderState.CharacterDeleted:
             return OrderState.Canceled;
         case CCPOrderState.Pending:
         case CCPOrderState.Opened:
             return OrderState.Active;
         case CCPOrderState.ExpiredOrFulfilled:
             return src.RemainingVolume == 0 ? OrderState.Fulfilled : OrderState.Expired;
         default:
             throw new NotImplementedException();
     }
 }
Example #5
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 #6
0
        /// <summary>
        /// Try to update this order with a serialization object from the API.
        /// </summary>
        /// <param name="src"></param>
        /// <param name="endedOrders"></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
            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))
            {
                // Order is from a serialized object, so populate the missing info
                if (Item == null)
                    PopulateOrderInfo(src);
                else
                {
                    // If it's a buying order, escrow may have changed
                    if (src.IsBuyOrder != 0)
                        ((BuyOrder)this).Escrow = src.Escrow;

                    UnitaryPrice = src.UnitaryPrice;
                    RemainingVolume = src.RemainingVolume;
                    Issued = src.Issued;
                }

                LastStateChange = DateTime.UtcNow;
                m_state = OrderState.Modified;
            }
            else if (m_state == OrderState.Modified)
            {
                // Order is from a serialized object, so populate the missing info
                if (Item == null)
                    PopulateOrderInfo(src);

                LastStateChange = DateTime.UtcNow;
                m_state = OrderState.Active;
            }

            // Order is from a serialized object, so populate the missing info
            if (Item == null)
                PopulateOrderInfo(src);

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

            if (m_state == OrderState.Modified || state == m_state)
                return true;

            // It has either expired or fulfilled
            m_state = state;
            LastStateChange = DateTime.UtcNow;

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

            return true;
        }
Example #7
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal SellOrder(SerializableOrderListItem src)
     : base(src)
 {
 }
Example #8
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src"></param>
 internal BuyOrder(SerializableOrderListItem src)
     : base(src)
 {
     Escrow = src.Escrow;
     Range = src.Range;
 }