Example #1
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);
        }
Example #2
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;
Example #3
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();
            }
        }
Example #4
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;
Example #5
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;
        }
Example #6
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();
        }
Example #7
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, List<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)
            {
                // Update state
                m_state = state;

                // Update modified info
                UpdateContractInfo(src);
            }

            // Should we notify it to the user ?
            if (NeedsAttention || state == ContractState.Finished)
                endedContracts.Add(this);

            return true;
        }