Beispiel #1
0
        /// <summary>
        /// Try to update this contract with a serialization object from the API.
        /// </summary>
        /// <param name="src">The serializable source.</param>
        /// <param name="endedContracts">The ended contracts.</param>
        /// <returns>True if import successful otherwise, false.</returns>
        internal bool TryImport(SerializableContractListItem src, ICollection <Contract> endedContracts)
        {
            // Note that, before a match is found, all contracts have been marked for deletion:
            // m_markedForDeletion == true
            // Checks whether ID is the same
            if (!MatchesWith(src))
            {
                return(false);
            }
            // Prevent deletion
            MarkedForDeletion = false;
            // Contract is from a serialized object, so populate the missing info
            if (string.IsNullOrEmpty(Issuer))
            {
                PopulateContractInfo(src);
            }
            // Update if modified
            ContractState state = GetState(src);

            if (state == m_state && !NeedsAttention)
            {
                return(true);
            }
            if (state != m_state || Overdue)
            {
                m_state = state;
                UpdateContractInfo(src);
            }
            // Should we notify it to the user ?
            if (NeedsAttention || state == ContractState.Finished)
            {
                endedContracts.Add(this);
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Try to update this contract with a serialization object from the API.
        /// </summary>
        /// <param name="src">The serializable source.</param>
        /// <param name="endedContracts">The ended contracts.</param>
        /// <returns>True if import successful otherwise, false.</returns>
        internal bool TryImport(SerializableContractListItem src, ICollection <Contract> endedContracts)
        {
            // Note that, before a match is found, all contracts have been marked for deletion:
            // m_markedForDeletion == true
            bool matches = MatchesWith(src);

            if (matches)
            {
                // Prevent deletion
                MarkedForDeletion = false;
                // Contract is from a serialized object, so populate the missing info
                if (IssuerID == 0L || Issuer.IsEmptyOrUnknown())
                {
                    PopulateContractInfo(src);
                }
                // Update if modified
                ContractState state = GetState(src);
                if (state != m_state || NeedsAttention)
                {
                    if (state != m_state || Overdue)
                    {
                        m_state = state;
                        UpdateContractInfo(src);
                    }
                    // If the contract has just finished or expired, add it to the ended list
                    if (NeedsAttention || state == ContractState.Finished)
                    {
                        endedContracts.Add(this);
                    }
                }
            }
            return(matches);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor from the API.
        /// </summary>
        /// <param name="ccpCharacter">The CCP character.</param>
        /// <param name="src">The source.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        internal Contract(CCPCharacter ccpCharacter, SerializableContractListItem src)
        {
            src.ThrowIfNull(nameof(src));

            Character = ccpCharacter;
            PopulateContractInfo(src);
            m_state = GetState(src);
        }
Beispiel #4
0
        /// <summary>
        /// Populates the serialization object contract with the info from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        private void PopulateContractInfo(SerializableContractListItem src)
        {
            ContractAvailability avail;
            ContractType         type;

            src.ThrowIfNull(nameof(src));

            m_method = src.APIMethod;

            ID               = src.ContractID;
            IssuerID         = src.IssuerID;
            AssigneeID       = src.AssigneeID;
            Description      = string.IsNullOrWhiteSpace(src.Title) ? "(None)" : src.Title;
            IssuedFor        = src.ForCorp ? IssuedFor.Corporation : IssuedFor.Character;
            Issued           = src.DateIssued;
            Expiration       = src.DateExpired;
            Duration         = (int)Math.Round(src.DateExpired.Subtract(src.DateIssued).TotalDays);
            DaysToComplete   = src.NumDays;
            Price            = src.Price;
            Reward           = src.Reward;
            Collateral       = src.Collateral;
            Buyout           = src.Buyout;
            Volume           = src.Volume;
            m_startStationID = src.StartStationID;
            m_endStationID   = src.EndStationID;
            UpdateStation();
            UpdateContractInfo(src);

            // Parse availability and contract type
            if (!Enum.TryParse(src.Availability, true, out avail))
            {
                avail = ContractAvailability.None;
            }
            Availability = avail;
            if (!Enum.TryParse(src.Type, true, out type))
            {
                type = ContractType.None;
            }
            ContractType = type;
            // Issuer and assignee
            m_issuer = src.ForCorp ? Character.Corporation.Name : EveIDToName.GetIDToName(
                src.IssuerID);
            m_assignee = EveIDToName.GetIDToName(src.AssigneeID);

            /*
             * // Retrieve items
             * if (ContractType != ContractType.Courier)
             *  GetContractData<EsiAPIContractItems>(OnContractItemsDownloaded,
             *      ESIAPICorporationMethods.CorporationContractItems,
             *      ESIAPICharacterMethods.ContractItems);
             * // Retrieve bids
             * if (ContractType == ContractType.Auction)
             *  GetContractData<EsiAPIContractBids>(OnContractBidsUpdated,
             *      ESIAPICorporationMethods.CorporationContractBids,
             *      ESIAPICharacterMethods.ContractBids);
             */
        }
Beispiel #5
0
        /// <summary>
        /// Gets the contract status.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <returns></returns>
        private static CCPContractStatus GetStatus(SerializableContractListItem src)
        {
            CCPContractStatus status;

            if (!Enum.TryParse(src.Status ?? string.Empty, true, out status))
            {
                status = CCPContractStatus.None;
            }
            return(status);
        }
Beispiel #6
0
        /// <summary>
        /// Constructor from the API.
        /// </summary>
        /// <param name="ccpCharacter">The CCP character.</param>
        /// <param name="src">The source.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        internal Contract(CCPCharacter ccpCharacter, SerializableContractListItem src)
        {
            src.ThrowIfNull(nameof(src));

            m_bidsResponse = m_itemsResponse = null;
            Character      = ccpCharacter;
            PopulateContractInfo(src);
            m_state = GetState(src);
            m_bids  = new LinkedList <ContractBid>();
        }
Beispiel #7
0
 /// <summary>
 /// Updates the contract info.
 /// </summary>
 /// <param name="src">The source.</param>
 private void UpdateContractInfo(SerializableContractListItem src)
 {
     Accepted   = src.DateAccepted;
     Completed  = src.DateCompleted;
     AcceptorID = src.AcceptorID;
     m_acceptor = EveIDToName.GetIDToName(src.AcceptorID);
     Status     = GetStatus(src);
     if (Overdue)
     {
         Status = CCPContractStatus.Overdue;
     }
 }
Beispiel #8
0
        /// <summary>
        /// Populates the serialization object contract with the info from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        private void PopulateContractInfo(SerializableContractListItem src)
        {
            src.ThrowIfNull(nameof(src));

            m_method = src.APIMethod;

            ID               = src.ContractID;
            IssuerID         = src.IssuerID;
            AssigneeID       = src.AssigneeID;
            Description      = String.IsNullOrWhiteSpace(src.Title) ? "(None)" : src.Title;
            IssuedFor        = src.ForCorp ? IssuedFor.Corporation : IssuedFor.Character;
            Issued           = src.DateIssued;
            Expiration       = src.DateExpired;
            Duration         = Convert.ToInt32(src.DateExpired.Subtract(src.DateIssued).TotalDays);
            DaysToComplete   = src.NumDays;
            Price            = src.Price;
            Reward           = src.Reward;
            Collateral       = src.Collateral;
            Buyout           = src.Buyout;
            Volume           = src.Volume;
            m_startStationID = src.StartStationID;
            m_endStationID   = src.EndStationID;
            UpdateStation();
            UpdateContractInfo(src);

            Availability = Enum.IsDefined(typeof(ContractAvailability), src.Availability)
                ? (ContractAvailability)Enum.Parse(typeof(ContractAvailability), src.Availability)
                : ContractAvailability.None;

            ContractType = Enum.IsDefined(typeof(ContractType), src.Type)
                ? (ContractType)Enum.Parse(typeof(ContractType), src.Type)
                : ContractType.None;

            m_issuer = src.ForCorp
                ? Character.Corporation.Name
                : src.IssuerID == Character.CharacterID
                    ? Character.Name
                    : EveIDToName.GetIDToName(src.IssuerID);


            m_assignee = src.AssigneeID == Character.CharacterID
                ? Character.Name
                : src.AssigneeID == Character.CorporationID
                    ? Character.Corporation.Name
                    : EveIDToName.GetIDToName(src.AssigneeID);


            if (ContractType != ContractType.Courier)
            {
                GetContractItems();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Updates the contract info.
        /// </summary>
        /// <param name="src">The source.</param>
        private void UpdateContractInfo(SerializableContractListItem src)
        {
            Accepted   = src.DateAccepted;
            Completed  = src.DateCompleted;
            AcceptorID = src.AcceptorID;
            m_acceptor = src.AcceptorID == Character.CharacterID ? Character.Name :
                         (src.AcceptorID == Character.CorporationID ? Character.Corporation.Name :
                          EveIDToName.GetIDToName(src.AcceptorID));

            Status = GetStatus(src);

            if (Overdue)
            {
                Status = CCPContractStatus.Overdue;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Populates the serialization object contract with the info from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        private void PopulateContractInfo(SerializableContractListItem src)
        {
            ContractAvailability avail;
            ContractType         type;

            src.ThrowIfNull(nameof(src));

            m_method         = src.APIMethod;
            ID               = src.ContractID;
            IssuerID         = src.IssuerID;
            AssigneeID       = src.AssigneeID;
            Description      = src.Title.IsEmptyOrUnknown() ? "(None)" : src.Title;
            IssuedFor        = src.ForCorp ? IssuedFor.Corporation : IssuedFor.Character;
            Issued           = src.DateIssued;
            Expiration       = src.DateExpired;
            Duration         = (int)Math.Round(src.DateExpired.Subtract(src.DateIssued).TotalDays);
            DaysToComplete   = src.NumDays;
            Price            = src.Price;
            Reward           = src.Reward;
            Collateral       = src.Collateral;
            Buyout           = src.Buyout;
            Volume           = src.Volume;
            m_startStationID = src.StartStationID;
            m_endStationID   = src.EndStationID;
            UpdateStation();
            UpdateContractInfo(src);

            // Parse availability and contract type
            if (!Enum.TryParse(src.Availability, true, out avail))
            {
                avail = ContractAvailability.None;
            }
            Availability = avail;
            if (!Enum.TryParse(src.Type, true, out type))
            {
                type = ContractType.None;
            }
            ContractType = type;
            // Issuer and assignee
            m_issuer = src.ForCorp ? Character.Corporation.Name : EveIDToName.GetIDToName(
                src.IssuerID);
            m_assignee = EveIDToName.GetIDToName(src.AssigneeID);
        }
Beispiel #11
0
        /// <summary>
        /// Gets the state of a contract.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <returns></returns>
        private ContractState GetState(SerializableContractListItem src)
        {
            CCPContractStatus status = GetStatus(src);

            if (status == CCPContractStatus.Outstanding && IsExpired)
            {
                return(ContractState.Expired);
            }

            switch (status)
            {
            case CCPContractStatus.Failed:
                return(ContractState.Failed);

            case CCPContractStatus.Canceled:
                return(ContractState.Canceled);

            case CCPContractStatus.Overdue:
            case CCPContractStatus.Outstanding:
            case CCPContractStatus.InProgress:
                return(IssuerID != Character.CharacterID ? ContractState.Assigned : ContractState.Created);

            case CCPContractStatus.Completed:
            case CCPContractStatus.CompletedByContractor:
            case CCPContractStatus.CompletedByIssuer:
                return(ContractState.Finished);

            case CCPContractStatus.Rejected:
                return(ContractState.Rejected);

            case CCPContractStatus.Deleted:
                return(ContractState.Deleted);

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #12
0
 /// <summary>
 /// Checks whether the given API object matches with this contract.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool MatchesWith(SerializableContractListItem src) => src.ContractID == ID;
Beispiel #13
0
 /// <summary>
 /// Gets the contract status.
 /// </summary>
 /// <param name="src">The source.</param>
 /// <returns></returns>
 private static CCPContractStatus GetStatus(SerializableContractListItem src)
 => Enum.IsDefined(typeof(CCPContractStatus), src.Status)
         ? (CCPContractStatus)Enum.Parse(typeof(CCPContractStatus), src.Status)
         : CCPContractStatus.None;