Esempio n. 1
0
        public JobFactory(JOB_TYPE type)
        {
            this.Messages = new QueueThreadSafe <Message>();

            this.Type  = type;
            JobHandles = new DictionaryThreadSafe <int, IJobHandle>();
        }
Esempio n. 2
0
        public IJobHandle f_createNew(IJob job)
        {
            IJobHandle handle = null;
            JOB_TYPE   type   = job.Type;

            switch (type)
            {
            case JOB_TYPE.NONE:
            case JOB_TYPE.REQUEST_URL:
                // factory
                IJobFactory fac;
                if (this.JobFactories.ContainsKey(type))
                {
                    fac = this.JobFactories[type];
                }
                else
                {
                    fac = new JobFactory(type);
                    this.JobFactories.Add(type, fac);
                }
                handle = fac.f_createNew(job);
                break;

            default:
                // singleton
                if (!this.JobSingletons.ContainsKey(type))
                {
                    handle = new JobHandle(job);
                    this.JobSingletons.Add(type, handle);
                }
                break;
            }
            return(handle);
        }
Esempio n. 3
0
 public JobBaseUrl(IJobContext jobContext, JOB_TYPE type)
 {
     this.JobContext = jobContext;
     this.Id         = jobContext.f_getTotalJob() + 1;
     this.Type       = type;
     this.Status     = 1; /* 1: init */
 }
Esempio n. 4
0
    public void HoverOnCitizen(GameObject go)
    {
        JOB_TYPE jobType = (JOB_TYPE)System.Enum.Parse(typeof(JOB_TYPE), go.name);

        lblCitizenInfo.text = jobType.ToString() + "'s: \n\n";
        for (int i = 0; i < currentDisplayingCityTile.cityAttributes.citizens.Count; i++)
        {
            Citizen currentCitizen = currentDisplayingCityTile.cityAttributes.citizens [i];
            if (currentCitizen.job.jobType == jobType)
            {
                lblCitizenInfo.text += "Name: " + currentCitizen.name + "\n";
                lblCitizenInfo.text += "Level: " + currentCitizen.level.ToString() + "\n";
                lblCitizenInfo.text += "Assigned Tile: " + currentCitizen.assignedTile.name + "\n";
//				lblCitizenInfo.text += "Upgrade Reqs: ";
//				if (jobType != JOB_TYPE.MERCHANT) {
//					for (int j = 0; j < currentCitizen.GetUpgradeRequirements ().resource.Count; j++) {
//						Resource currentResource = currentCitizen.GetUpgradeRequirements ().resource [j];
//						lblCitizenInfo.text += currentResource.resourceType.ToString () + " - " + currentResource.resourceQuantity.ToString () + "\n";
//					}
//					lblCitizenInfo.text += "\n";
//				}
            }
        }
        goCitizenInfo.SetActive(true);
    }
Esempio n. 5
0
 public void CopyData(Job job)
 {
     this._jobType             = job.jobType;
     this._citizen             = job.citizen;
     this._upgradeRequirements = job.upgradeRequirements;
     this._resourcesProduced   = job.resourcesProduced;
     this._residence           = job.residence;
 }
Esempio n. 6
0
    internal void ChangeJob(JOB_TYPE jobType)
    {
        this._job         = GetJob(jobType);
        this._job.citizen = this;
//		if (jobType != JOB_TYPE.PIONEER) {
//			UpdateUpgradeRequirements ();
//		}
    }
Esempio n. 7
0
        public JobWorker(IJobContext jobContext, JOB_TYPE type)
        {
            this.Messages = new QueueThreadSafe <Message>();

            this.JobContext = jobContext;
            this.Id         = jobContext.f_getTotalJob() + 1;
            this.Type       = type;
            this.Status     = 1; /* 1: init */
        }
Esempio n. 8
0
        public JobBase(IJobContext jobContext, JOB_TYPE type)
        {
            this.Messages = new ConcurrentQueue <Message>();

            this.JobContext = jobContext;
            this.Id         = jobContext.f_getTotalJob() + 1;
            this.Type       = type;
            this.Status     = 1; /* 1: init */
        }
Esempio n. 9
0
    public Citizen(JOB_TYPE jobType, CityTest city)
    {
        this._id  = GetID() + 1;
        this.name = "CITIZEN" + this._id;
        this._job = GetJob(jobType);
//		this._job = new Job();
//		this._job.CopyData(GetJob (jobType));
        this._city  = city;
        this._level = 1;
        AssignJobToCitizen();
        SetLastID(this._id);
    }
Esempio n. 10
0
 public void f_sendRequestMessages(JOB_TYPE type, Message[] ms, Func <IJobHandle, Guid, bool> responseCallbackDoneAll)
 {
     foreach (Message m in ms)
     {
         Guid id = m.GetMessageId();
         if (m.f_getTimeOut() > 0)
         {
             long timeOut = DateTime.Now.Ticks / 1000 + m.f_getTimeOut();
             this.MessagesRequestTimeOut.Add(timeOut, id);
         }
         this.MessagesRequest.Add(id, m);
     }
 }
Esempio n. 11
0
 public bool f_sendRequestMessages(JOB_TYPE type, Message[] ms,
                                   Func <IJobHandle, Guid, bool> responseCallbackDoneAll)
 {
     if (this.JobFactories.ContainsKey(type))
     {
         if (responseCallbackDoneAll != null)
         {
             if (this.MessageContext != null)
             {
                 this.MessageContext.f_sendRequestMessages(type, ms, responseCallbackDoneAll);
             }
         }
         this.JobFactories[type].f_sendRequests(ms);
     }
     else if (this.JobSingletons.ContainsKey(type))
     {
         //this.JobSingletons[type].f_sendMessages(ms);
     }
     return(false);
 }
Esempio n. 12
0
    public Job GetJob(JOB_TYPE jobType)
    {
        switch (jobType)
        {
        case JOB_TYPE.ALCHEMIST:
            return(new Alchemist());

//		case JOB_TYPE.ARCHER:
//			return new Archer ();
//		case JOB_TYPE.BRAWLER:
//			return new Brawler ();
        case JOB_TYPE.FARMER:
            return(new Farmer());

        case JOB_TYPE.HUNTER:
            return(new Hunter());

        case JOB_TYPE.MINER:
            return(new Miner());

        case JOB_TYPE.QUARRYMAN:
            return(new Quarryman());

        case JOB_TYPE.WOODSMAN:
            return(new Woodsman());

        case JOB_TYPE.PIONEER:
            return(new Pioneer());

        case JOB_TYPE.MERCHANT:
            return(new Merchant());

        default:
            return(new Job());
        }
    }
Esempio n. 13
0
    public int GetRelevantResourceValueByJobType(JOB_TYPE jobType)
    {
        switch (jobType)
        {
        case JOB_TYPE.FARMER:
            return(farmingValue);

        case JOB_TYPE.HUNTER:
            return(huntingValue);

        case JOB_TYPE.WOODSMAN:
            return(woodValue);

        case JOB_TYPE.QUARRYMAN:
            return(stoneValue);

        case JOB_TYPE.MINER:
            return(metalValue);

        case JOB_TYPE.ALCHEMIST:
            return(manaValue);
        }
        return(-1);
    }
Esempio n. 14
0
 public JobNeeds(JOB_TYPE jobType, Resource resource)
 {
     this.jobType  = jobType;
     this.resource = resource;
 }
Esempio n. 15
0
 public JobFactoryBase(JOB_TYPE type)
 {
     this.JobHandles = new ConcurrentDictionary <int, IJobHandle>();
     this.Messages   = new ConcurrentQueue <Message>();
     this.Type       = type;
 }
Esempio n. 16
0
        public static string create_job(JOB_TYPE type, string group_name, Dictionary <string, object> para = null, string schedule = null)
        {
            if (para == null)
            {
                para = new Dictionary <string, object>()
                {
                }
            }
            ;
            group_name = group_name.ToLower();
            string name = group_name + "." + DateTime.Now.ToString("yyMMdd-HHmmss-fff");

            if (!string.IsNullOrEmpty(schedule))
            {
                name += "." + schedule;
            }

            JobDataMap m = new JobDataMap();

            m.Put("ID___", name);
            m.Put("SCHEDULE___", schedule);
            m.Put("TYPE___", type);
            m.Put("CURRENT_ID___", 0);
            m.Put("COUNTER___", new ConcurrentDictionary <long, bool>());
            m.Put("PARA___", para);

            JobBuilder     job     = null;
            TriggerBuilder trigger = null;

            switch (type)
            {
            case JOB_TYPE.CRAWLER_NET:
            case JOB_TYPE.CRAWLER_CURL:
                job = JobBuilder.Create <JobCrawler>();
                break;

            case JOB_TYPE.API_JS:
                job = JobBuilder.Create <JobApiJS>();
                break;
            }

            if (job != null)
            {
                job     = job.WithIdentity(name, group_name).UsingJobData(m);
                trigger = TriggerBuilder.Create();

                if (!string.IsNullOrEmpty(schedule))
                {
                    trigger = trigger.WithSchedule(CronScheduleBuilder.CronSchedule(schedule));
                }
                trigger = trigger.StartNow();

                var j = job.Build();
                var t = trigger.Build();

                m_scheduler.ScheduleJob(j, t);

                m_job.TryAdd(name, j);
                m_trigger.TryAdd(name, t);

                m_scheduler.ScheduleJob(j, t).Wait();
                return(name);
            }

            return(string.Empty);
        }
Esempio n. 17
0
 public JobFactoryUrl(JOB_TYPE type) : base(type)
 {
 }