Ejemplo n.º 1
0
        /// <summary>
        /// Try to update this order with a serialization object from the API.
        /// </summary>
        /// <param name="src"></param>
        /// <param name="issuedFor">Whether the order was issued for a corporation or a
        /// character.</param>
        /// <param name="endedOrders"></param>
        /// <returns></returns>
        internal bool TryImport(EsiOrderListItem src, IssuedFor issuedFor,
                                ICollection <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))
            {
                if (Item != null)
                {
                    // If it is a buy order, escrow may have changed
                    var buyOrder = this as BuyOrder;
                    if (src.IsBuyOrder && buyOrder != null)
                    {
                        buyOrder.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)
            {
                LastStateChange = DateTime.UtcNow;
                m_state         = OrderState.Active;
            }
            // Order is from a serialized object, so populate the missing info
            if (Item == null)
            {
                PopulateOrderInfo(src, issuedFor);
            }
            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 false
            // CCP does not actually report any orders with this status any longer
            if (state == OrderState.Expired || state == OrderState.Fulfilled)
            {
                endedOrders.Add(this);
            }
#endif
            return(true);
        }
Ejemplo n.º 2
0
        private IssuedFor AdjustIssuer(IssuedFor issuedFor, EsiOrderListItem srcOrder)
        {
            var         orderFor          = issuedFor;
            const ulong MARKET_ORDER_MASK = (ulong)ESIAPICharacterMethods.MarketOrders;

            // Orders in corporation endpoint are unconditionally for corp, the character
            // endpoint has a special field since *some* are for corp, why...
            if (srcOrder.IsCorporation)
            {
                orderFor = IssuedFor.Corporation;
            }
            // Exclude corporation orders made by a monitored character with ESI market
            // order tracking turned on
            if (issuedFor == IssuedFor.Corporation)
            {
                // Find matching character identity, if any
                var issuer = EveMonClient.CharacterIdentities.FirstOrDefault(character =>
                                                                             character.CharacterID == srcOrder.IssuedBy);
                // If the character is monitored and has access mask to market
                if (issuer != null && (issuer.CCPCharacter?.Monitored ?? false) && issuer.
                    ESIKeys.Any(key => (key.AccessMask & MARKET_ORDER_MASK) != 0UL))
                {
                    orderFor = IssuedFor.None;
                }
            }
            return(orderFor);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="issuedFor">Whether the order was issued for a corporation or a
        /// character.</param>
        /// <param name="character">The owning character.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        protected MarketOrder(EsiOrderListItem src, IssuedFor issuedFor,
                              CCPCharacter character)
        {
            src.ThrowIfNull(nameof(src));

            PopulateOrderInfo(src, issuedFor);
            LastStateChange = DateTime.UtcNow;
            m_character     = character;
            m_state         = GetState(src);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the state of an order.
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        private static OrderState GetState(EsiOrderListItem 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();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Populates the serialization object order with the info from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="ownerID">The owner of this order.</param>
        /// <param name="issuedFor">Whether the order was issued for a corporation or a
        /// character.</param>
        private void PopulateOrderInfo(EsiOrderListItem src, IssuedFor issuedFor)
        {
            OwnerID         = src.IssuedBy;
            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       = issuedFor;
            m_stationID     = src.StationID;
            UpdateStation();

            var buyOrder = this as BuyOrder;

            if (src.IsBuyOrder && buyOrder != null)
            {
                buyOrder.Escrow = src.Escrow;
                buyOrder.Range  = src.Range;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src">The source.</param>
 /// <param name="issuedFor">Whether the order was issued for a corporation or a
 /// character.</param>
 internal BuyOrder(EsiOrderListItem src, IssuedFor issuedFor, CCPCharacter character)
     : base(src, issuedFor, character)
 {
     Escrow = src.Escrow;
     Range  = src.Range;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Checks whether the given API object has been modified.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool IsModified(EsiOrderListItem src) => src.RemainingVolume != 0 &&
 ((src.UnitaryPrice != UnitaryPrice && src.Issued != Issued) || src.
  RemainingVolume != RemainingVolume);
Ejemplo n.º 8
0
 /// <summary>
 /// Checks whether the given API object matches with this order.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool MatchesWith(EsiOrderListItem src) => src.OrderID == ID;
Ejemplo n.º 9
0
 /// <summary>
 /// Constructor from the API.
 /// </summary>
 /// <param name="src">The source.</param>
 /// <param name="issuedFor">Whether the order was issued for a corporation or a
 /// character.</param>
 internal SellOrder(EsiOrderListItem src, IssuedFor issuedFor, CCPCharacter character)
     : base(src, issuedFor, character)
 {
 }