Beispiel #1
0
        /// <summary>
        /// Gets the state of a job.
        /// </summary>
        /// <param name="src">The serializable source.</param>
        /// <returns>State of the seriallzable job.</returns>
        private static JobState GetState(EsiJobListItem src)
        {
            switch (src.Status)
            {
            // Active States
            case CCPJobCompletedStatus.Active:
                return(JobState.Active);

            // Cancelled States
            case CCPJobCompletedStatus.Cancelled:
                return(JobState.Canceled);

            // Failed States
            case CCPJobCompletedStatus.Reverted:
                return(JobState.Failed);

            // Delivered States
            case CCPJobCompletedStatus.Delivered:
                return(JobState.Delivered);

            // Paused States
            case CCPJobCompletedStatus.Paused:
                return(JobState.Paused);

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Populates the serialization object job with the info from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="issuedFor">Whether this jobs was issued for the corporation or
        /// character.</param>
        /// <param name="character">The character owning this job.</param>
        private void PopulateJobInfo(EsiJobListItem src, IssuedFor issuedFor,
                                     CCPCharacter character = null)
        {
            ID                        = src.JobID;
            InstallerID               = src.InstallerID;
            InstalledItem             = StaticBlueprints.GetBlueprintByID(src.BlueprintTypeID);
            Runs                      = src.Runs;
            Cost                      = src.Cost;
            Probability               = src.Probability;
            SuccessfulRuns            = src.SuccessfulRuns;
            StartDate                 = src.StartDate;
            EndDate                   = src.EndDate;
            PauseDate                 = src.PauseDate;
            IssuedFor                 = issuedFor;
            m_installedItemLocationID = src.FacilityID;

            UpdateLocation(character);
            UpdateInstallation(character);

            if (Enum.IsDefined(typeof(BlueprintActivity), src.ActivityID))
            {
                Activity = (BlueprintActivity)Enum.ToObject(typeof(BlueprintActivity),
                                                            src.ActivityID);
            }

            OutputItem = GetOutputItem(src.ProductTypeID);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="issuedFor">Whether this jobs was issued for the corporation or
        /// character.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        internal IndustryJob(EsiJobListItem src, IssuedFor issuedFor)
        {
            src.ThrowIfNull(nameof(src));

            PopulateJobInfo(src, issuedFor);
            State           = GetState(src);
            LastStateChange = DateTime.UtcNow;
            ActiveJobState  = GetActiveJobState();
        }
Beispiel #4
0
        /// <summary>
        /// Try to update this job with a serialization object from the API.
        /// </summary>
        /// <param name="src">The serializable source.</param>
        /// <param name="issuedFor">Whether this jobs was issued for the corporation or
        /// character.</param>
        /// <param name="character">The character owning this job.</param>
        /// <returns>True if import sucessful otherwise, false.</returns>
        internal bool TryImport(EsiJobListItem src, IssuedFor issuedFor, CCPCharacter character)
        {
            bool matches = MatchesWith(src);

            // Note that, before a match is found, all jobs have been marked for deletion:
            // m_markedForDeletion == true
            if (matches)
            {
                MarkedForDeletion = false;
                // Update information (if ID is the same it may have been modified)
                if (IsModified(src))
                {
                    // Job is from a serialized object, so populate the missing info
                    if (InstalledItem == null)
                    {
                        PopulateJobInfo(src, issuedFor);
                    }
                    else
                    {
                        EndDate   = src.EndDate;
                        PauseDate = src.PauseDate;
                    }
                    State = (PauseDate == DateTime.MinValue) ? JobState.Active : JobState.
                            Paused;
                    ActiveJobState  = GetActiveJobState();
                    LastStateChange = DateTime.UtcNow;
                }
                // Job is from a serialized object, so populate the missing info
                if (InstalledItem == null)
                {
                    PopulateJobInfo(src, issuedFor, character);
                }
                var state = GetState(src);
                if (state != State)
                {
                    State           = state;
                    LastStateChange = DateTime.UtcNow;
                }
            }
            return(matches);
        }
Beispiel #5
0
 /// <summary>
 /// Checks whether the given API object has been modified.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool IsModified(EsiJobListItem src) => src.EndDate != EndDate ||
 src.PauseDate != PauseDate;
Beispiel #6
0
 /// <summary>
 /// Checks whether the given API object matches with this job.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool MatchesWith(EsiJobListItem src) => src.JobID == ID;