Ejemplo n.º 1
0
        public override Job JobOnThing(Pawn pawn, Thing thing)
        {
            if (!thing.def.mineable)
            {
                return(null);
            }

            if (!DesignationDefOf.Mine.IsDefinedAt(thing.Position))
            {
                return(null);
            }

            if (!IsMiningResearched())
            {
                return(null);
            }

            Log.Message("jobonthing for " + pawn.Nickname + ", " + thing);

            var mineverb = pawn.GetVerbOnEquipment(typeof(Verb_MineWithTool));

            if (mineverb == null)
            {
                Log.Message("wanted to mine, but no equipment with proper verb");
                // TODO get a tool
                return(null);
            }

            if (!pawn.CanReserve(thing, ReservationType.Total))
            {
                Log.Message("couldn't reserve");
                return(null);
            }

            Job job;
            var standable = JobUtilities.CanStandBy(pawn, thing, out job);

            if (standable)
            {
                Log.Message("standable beside, returning jobdefof mine, target " + thing + ", verb mineverb");
                return(new Job(JobDefOf.Mine, new TargetInfo(thing))
                {
                    verbToUse = mineverb
                });
            }
            else
            {
                Log.Message("not standable beside, returning " + job);
                // haul job
                return(job);
            }
        }
        ////////////////////////////////////////////////////////////////////////
        // METHOD: CreateDependencyOnParentJob
        private void CreateDependencyOnParentJob(IJTXJobDependencies dependencyManager, IJTXJob2 pParentJob, int childJobID)
        {
            IJTXJobDependency dependency = dependencyManager.CreateDependency(pParentJob.ID);

            dependency.DepJobID  = childJobID;
            dependency.DepOnType = jtxDependencyType.jtxDependencyTypeStatus;

            IJTXStatus statusType = null;

            if (!m_paramHasStatusType)
            {
                statusType = m_ipDatabase.ConfigurationManager.GetStatus("Closed");
            }
            else
            {
                statusType = m_ipDatabase.ConfigurationManager.GetStatus(m_paramStatusType);
            }

            dependency.DepOnValue = statusType.ID;
            dependency.HeldOnType = jtxDependencyType.jtxDependencyTypeStep;

            IJTXWorkflowExecution parentWorkflow = pParentJob as IJTXWorkflowExecution;

            int[] currentSteps  = parentWorkflow.GetCurrentSteps();
            int   dependentStep = currentSteps[0];

            if (m_paramDependNextStep)
            {
                IJTXWorkflowConfiguration workflowConf = pParentJob as IJTXWorkflowConfiguration;
                try
                {
                    dependentStep = workflowConf.GetAllNextSteps(currentSteps[0])[0];
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show(Properties.Resources.NoNextStep, Properties.Resources.Error,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            dependency.HeldOnValue = dependentStep;
            dependency.Store();

            IPropertySet props = new PropertySetClass();

            props.SetProperty("[DEPENDENCY]", dependency.ID);
            JobUtilities.LogJobAction(m_ipDatabase, pParentJob, Constants.ACTTYPE_ADD_DEPENDENCY, "", props);
        }
        ////////////////////////////////////////////////////////////////////////
        // METHOD: CreateExtendedPropertyRecord
        private bool CreateExtendedPropertyRecord(IJTXJob job, ExtendedPropertyIdentifier child)
        {
            IJTXAuxProperties pAuxProps = (IJTXAuxProperties)job;

            IJTXAuxRecordContainer pAuxContainer = pAuxProps.GetRecordContainer(child.LongTableName);

            if (!string.IsNullOrEmpty(m_paramExtendedProperties) && pAuxContainer == null)
            {
                string msg = string.Format(
                    "Unable to set extended property for child job {0}. Unable to find child job's extended property table: {1}",
                    job.ID, child.LongTableName);
                m_ipDatabase.LogMessage(3, 2000, msg);
            }

            System.Array contNames = pAuxProps.ContainerNames;
            System.Collections.IEnumerator contNamesEnum = contNames.GetEnumerator();
            contNamesEnum.Reset();
            while (contNamesEnum.MoveNext())
            {
                try
                {
                    string strContainerName = (string)contNamesEnum.Current;
                    if (!string.IsNullOrEmpty(m_paramExtendedProperties) && (strContainerName.ToUpper()).Equals(child.LongTableName.ToUpper()))
                    {
                        pAuxContainer = pAuxProps.GetRecordContainer(strContainerName);

                        if (pAuxContainer.RelationshipType != esriRelCardinality.esriRelCardinalityOneToOne)
                        {
                            throw new Exception("The table relationship is not one-to-one.");
                        }
                        IJTXAuxRecord childRecord = pAuxContainer.GetRecords().get_Item(0);//pAuxContainer.CreateRecord();


                        SetExtendedPropertyValues(childRecord, child);
                        JobUtilities.LogJobAction(m_ipDatabase, job, Constants.ACTTYPE_UPDATE_EXT_PROPS, "", null);
                    }
                }
                catch (Exception ex)
                {
                    string msg = string.Format(
                        "Unable to create extended property {0} in record for jobid {1}. ERROR: {2}",
                        child.FieldName, job.ID, ex.Message);
                    m_ipDatabase.LogMessage(3, 2000, msg);
                }
            }

            return(true);
        }
        ////////////////////////////////////////////////////////////////////////
        // METHOD: CreateChildVersion
        private bool CreateChildVersion(ref IJTXJob pJob)
        {
            IVersion pNewVersion = null;

            try
            {
                string strVersionName = pJob.VersionName;
                int    index          = strVersionName.IndexOf(".", 0);
                if (index >= 0)
                {
                    strVersionName = strVersionName.Substring(index + 1);
                }
                pJob.VersionName = strVersionName;

                pNewVersion = pJob.CreateVersion(esriVersionAccess.esriVersionAccessPublic);

                if (pNewVersion == null)
                {
                    m_ipDatabase.LogMessage(3, 1000, "Unable to create version for child job ID: " + pJob.ID);
                }
                else
                {
                    IPropertySet pOverrides = new PropertySetClass();
                    pOverrides.SetProperty("[VERSION]", pNewVersion.VersionName);
                    JobUtilities.LogJobAction(m_ipDatabase, pJob, Constants.ACTTYPE_CREATE_VERSION, "", pOverrides);
                    JTXUtilities.SendNotification(Constants.NOTIF_VERSION_CREATED, m_ipDatabase, pJob, pOverrides);
                }
            }
            catch (Exception ex)
            {
                m_ipDatabase.LogMessage(3, 1000, "Unable to create version for child job ID: " + pJob.ID + ". ERROR: " + ex.Message);
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pNewVersion);
            }

            return(true);
        }