Пример #1
0
        /// <summary>
        /// Constructor from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <exception cref="System.ArgumentNullException">src</exception>
        internal IndustryJob(SerializableJobListItem src)
        {
            src.ThrowIfNull(nameof(src));

            PopulateJobInfo(src);
            State = GetState(src);
            LastStateChange = DateTime.UtcNow;
            ActiveJobState = GetActiveJobState();
        }
Пример #2
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(SerializableJobListItem src)
        {
            //if (src.CompletedDate != DateTime.MinValue)
            //    return JobState.Active;

            switch ((CCPJobCompletedStatus)src.Status)
            {
                // Active States
                case CCPJobCompletedStatus.Installed:
                    return JobState.Active;
                // Canceled States
                case CCPJobCompletedStatus.Canceled:
                    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();
            }
        }
Пример #3
0
        /// <summary>
        /// Populates the serialization object job with the info from the API.
        /// </summary>
        /// <param name="src">The source.</param>
        private void PopulateJobInfo(SerializableJobListItem src)
        {
            ID = src.JobID;
            InstallerID = src.InstallerID;
            InstalledItem = StaticBlueprints.GetBlueprintByID(src.BlueprintTypeID);
            Runs = src.Runs;
            SolarSystem = StaticGeography.GetSolarSystemByID(src.SolarSystemID);
            Cost = src.Cost;
            Probability = src.Probability;
            SuccessfulRuns = src.SuccessfulRuns;
            //InstalledTime = src.InstallTime;
            //InstalledME = src.InstalledItemMaterialLevel;
            //InstalledPE = src.InstalledItemProductivityLevel;
            StartDate = src.StartDate;
            EndDate = src.EndDate;
            PauseDate = src.PauseDate;
            IssuedFor = src.IssuedFor;
            m_installedItemLocationID = src.StationID;

            UpdateInstallation();

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

            OutputItem = GetOutputItem(src.ProductTypeID);

            //if (Enum.IsDefined(typeof(BlueprintType), src.InstalledItemCopy))
            //    BlueprintType = (BlueprintType)Enum.ToObject(typeof(BlueprintType), src.InstalledItemCopy);
        }
Пример #4
0
        /// <summary>
        /// Try to update this job with a serialization object from the API.
        /// </summary>
        /// <param name="src">The serializable source.</param>
        /// <returns>True if import sucessful otherwise, false.</returns>
        internal bool TryImport(SerializableJobListItem src)
        {
            // Note that, before a match is found, all jobs have been marked for deletion : m_markedForDeletion == true

            // Checks whether ID is the same
            if (!MatchesWith(src))
                return false;

            // Prevent deletion
            MarkedForDeletion = false;

            // Update infos (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);
                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);

            // Update state
            JobState state = GetState(src);
            if (State == JobState.Paused || state == State)
                return true;

            State = state;
            LastStateChange = DateTime.UtcNow;

            return true;
        }
Пример #5
0
 /// <summary>
 /// Checks whether the given API object has been modified.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool IsModified(SerializableJobListItem src) => src.EndDate != EndDate
                                                         || src.PauseDate != PauseDate;
Пример #6
0
 /// <summary>
 /// Checks whether the given API object matches with this job.
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 private bool MatchesWith(SerializableJobListItem src) => src.JobID == ID;