static void Postfix(Pawn_JobTracker __instance, ref ThinkResult __result) { Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>(); //If a hostile pawn owns an animal, make sure it mounts it whenever possible if (pawn.RaceProps.Humanlike && pawn.Faction != null && pawn.Faction.HostileTo(Faction.OfPlayer) && !pawn.Downed && !pawn.IsBurning() && !pawn.IsPrisoner) { ExtendedPawnData pawnData = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(pawn); if (pawnData.owning == null || pawnData.owning.Faction != pawn.Faction || pawnData.mount != null || pawnData.owning.Downed || pawnData.owning.Dead || !pawnData.owning.Spawned || pawnData.owning.IsBurning()) { return; } QueuedJob qJob = pawn.jobs.jobQueue.FirstOrFallback(null); if (qJob != null && (qJob.job.def == GUC_JobDefOf.Mount)) { return; } if (__result.Job.def == GUC_JobDefOf.Mount) { return; } Job mountJob = new Job(GUC_JobDefOf.Mount, pawnData.owning); mountJob.count = 1; __instance.jobQueue.EnqueueFirst(mountJob); } }
public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams) { JobQueue jobQueue = pawn.jobs.jobQueue; if (pawn.Downed || jobQueue.AnyCanBeginNow(pawn, inBedOnly)) { while (jobQueue.Count > 0 && !jobQueue.Peek().job.CanBeginNow(pawn, inBedOnly)) { QueuedJob queuedJob = jobQueue.Dequeue(); pawn.ClearReservationsForJob(queuedJob.job); if (pawn.jobs.debugLog) { pawn.jobs.DebugLogEvent(" Throwing away queued job that I cannot begin now: " + queuedJob.job); } } } if (jobQueue.Count > 0 && jobQueue.Peek().job.CanBeginNow(pawn, inBedOnly)) { QueuedJob queuedJob2 = jobQueue.Dequeue(); if (pawn.jobs.debugLog) { pawn.jobs.DebugLogEvent(" Returning queued job: " + queuedJob2.job); } return(new ThinkResult(queuedJob2.job, this, queuedJob2.tag, fromQueue: true)); } return(ThinkResult.NoJob); }
public void SetAsQueueable() { QueuedJob = new QueuedJob { AutoSave = true, DateTimeQueued = DateTime.UtcNow }; }
static void Postfix(Pawn_JobTracker __instance, ref ThinkResult __result) { Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>(); if (pawn.IsColonistPlayerControlled || pawn.RaceProps.Animal) { return; } LocalTargetInfo target = DistanceUtility.GetFirstTarget(__result.Job, TargetIndex.A); if (!target.IsValid) { return; } ExtendedDataStorage store = Base.Instance.GetExtendedDataStorage(); if (store == null) { return; } //Log.Message("wrong duty"); ExtendedPawnData PawnData = store.GetExtendedDataFor(pawn); Lord lord = pawn.GetLord(); if (lord == null) { return; } QueuedJob qJob = pawn.jobs.jobQueue.FirstOrFallback(null); if (qJob != null && (qJob.job.def == GUC_JobDefOf.Dismount)) { return; } Log.Message("curLordToil: " + pawn.GetLord().CurLordToil.ToString() + ", pawn name: " + pawn.Name); Log.Message("lordJob: " + pawn.GetLord().LordJob + ", pawn name: " + pawn.Name); Log.Message("lord.CurLordToil.GetType().Name" + lord.CurLordToil.GetType().Name); if (lord.CurLordToil is LordToil_ExitMapAndEscortCarriers) { if (PawnData.owning != null && PawnData.mount == null && !PawnData.owning.Downed && PawnData.owning.Spawned) { mountAnimal(__instance, pawn, PawnData, ref __result); } } else if (lord.CurLordToil.GetType().Name == "LordToil_DefendTraderCaravan" || lord.CurLordToil is LordToil_DefendPoint) //first option is internal class, hence this way of accessing. { if (PawnData.mount != null) { parkAnimal(__instance, pawn, PawnData); } } }
public override IEnumerable <Clue> DoProcess(ExecutionContext context, WebhookDataCommand command) { try { if (ConfigurationManager.AppSettings.GetFlag("Feature.Webhooks.Log.Posts", false)) { context.Log.LogDebug(command.HttpPostData); } var configurationDataStore = context.ApplicationContext.Container.Resolve <IConfigurationRepository>(); if (command.WebhookDefinition.ProviderDefinitionId != null) { var providerDefinition = context.Organization.Providers.GetProviderDefinition(context, command.WebhookDefinition.ProviderDefinitionId.Value); var jobDataCheck = context.ApplicationContext.Container.ResolveAll <IProvider>().FirstOrDefault(providerInstance => providerDefinition != null && providerInstance.Id == providerDefinition.ProviderId); var configStoreData = configurationDataStore.GetConfigurationById(context, command.WebhookDefinition.ProviderDefinitionId.Value); // If you have stopped the provider then don't process the webhooks if (providerDefinition?.WebHooks != null) { if (providerDefinition.WebHooks == false || providerDefinition.IsEnabled == false) { return(new List <Clue>()); } } if (jobDataCheck != null) { var crawlJobData = new SalesforceCrawlJobData(); var clues = new List <Clue>(); IAgentJobProcessorArguments jobArgs = new QueuedJob(new AgentJob(Guid.NewGuid(), AgentJobPriority.Normal, "CluedIn" + SalesforceConstants.ProviderName, ProcessingRestriction.Any, null, null)) { TaskScheduler = TaskScheduler.Default, }; var processorState = new AgentJobProcessorState <SalesforceCrawlJobData>(jobArgs, AppContext) { JobData = crawlJobData, Status = new AgentJobStatus { Statistics = new AgentJobStatusStatistics() } }; throw new NotImplementedException($"TODO: Implement this to populate '{clues.GetType()}' with '{processorState}'"); } } } catch (Exception exception) { using (context.Log.BeginScope(new { command.HttpHeaders, command.HttpQueryString, command.HttpPostData, command.WebhookDefinitionId })) { context.Log.LogError(exception, "Could not process web hook message"); } } return(new List <Clue>()); }
public void Serialize_queued_job_id_with_tenant_id() { QueuedJob job = new QueuedJob(); job.TenantId = new TenantId("TEST_TENANT"); job.Id = new QueuedJobId("some id"); var json = job.ToJson(); Assert.That(json, Text.Contains("some id")); Assert.That(json, Text.Contains("test_tenant")); }
static void Postfix(Pawn_JobTracker __instance, ref ThinkResult __result) { Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>(); if (pawn.Drafted) { ExtendedPawnData pawnData = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(pawn); if (pawnData.SD_enabled && __instance.jobQueue.Count > 0) { QueuedJob qjob = __instance.jobQueue.Last(); __instance.ClearQueuedJobs(); __result = new ThinkResult(qjob.job, __result.SourceNode, null, false); } } }
public static bool Extract(JobQueue __instance, ref QueuedJob __result, Job j) { lock (jobs(__instance)) { int num = jobs(__instance).FindIndex((QueuedJob qj) => qj.job == j); if (num >= 0) { QueuedJob result = jobs(__instance)[num]; jobs(__instance).RemoveAt(num); __result = result; return(false); } } __result = null; return(false); }
public static bool AnyCanBeginNow(JobQueue __instance, ref bool __result, Pawn pawn, bool whileLyingDown) { for (int i = 0; i < jobs(__instance).Count; i++) { QueuedJob queuedJob = jobs(__instance)[i]; if (null != queuedJob) { if (queuedJob.job.CanBeginNow(pawn, whileLyingDown)) { __result = true; return(false); } } } __result = false; return(false); }
public static bool Dequeue(JobQueue __instance, ref QueuedJob __result) { QueuedJob result; lock (jobs(__instance)) { if (jobs(__instance).NullOrEmpty()) { __result = null; return(false); } result = jobs(__instance)[0]; jobs(__instance).RemoveAt(0); } __result = result; return(false); }
public static float TotalPsyfocusCostOfQueuedPsycasts(Pawn pawn) { float num = (pawn.jobs?.curJob?.verbToUse as Verb_CastPsycast)?.Psycast.FinalPsyfocusCost(pawn.jobs.curJob.targetA) ?? 0f; if (pawn.jobs != null) { for (int i = 0; i < pawn.jobs.jobQueue.Count; i++) { QueuedJob queuedJob = pawn.jobs.jobQueue[i]; Verb_CastPsycast verb_CastPsycast; if ((verb_CastPsycast = queuedJob.job.verbToUse as Verb_CastPsycast) != null) { num += verb_CastPsycast.Psycast.FinalPsyfocusCost(queuedJob.job.targetA); } } } return(num); }
static void Postfix(Pawn_JobTracker __instance, ref ThinkResult __result) { Pawn pawn = __instance.pawn; //Remove mount in case the mount somehow isn't mounted by pawn. if (pawn.IsColonist) { ExtendedPawnData pawnData = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(pawn); if (pawnData.mount != null) { if (pawnData.mount.CurJob == null || pawnData.mount.CurJobDef != GUC_JobDefOf.Mounted) { pawnData.reset(); } else if (pawnData.mount.jobs.curDriver is JobDriver_Mounted driver && driver.Rider != pawn) { pawnData.reset(); } } } //If a hostile pawn owns an animal, make sure it mounts it whenever possible if (pawn.RaceProps.Humanlike && pawn.Faction != null && pawn.Faction.HostileTo(Faction.OfPlayer) && !pawn.Downed && !pawn.IsBurning() && !pawn.IsPrisoner) { ExtendedPawnData pawnData = Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(pawn); if (pawnData.owning == null || pawnData.owning.Faction != pawn.Faction || pawnData.mount != null || pawnData.owning.Downed || pawnData.owning.Dead || !pawnData.owning.Spawned || pawnData.owning.IsBurning()) { return; } QueuedJob qJob = pawn.jobs.jobQueue.FirstOrFallback(null); if (qJob != null && (qJob.job.def == GUC_JobDefOf.Mount)) { return; } if (__result.Job.def == GUC_JobDefOf.Mount) { return; } Job mountJob = new Job(GUC_JobDefOf.Mount, pawnData.owning); mountJob.count = 1; __instance.jobQueue.EnqueueFirst(mountJob); } }
public static bool AnyCanBeginNow(JobQueue __instance, ref bool __result, Pawn pawn, bool whileLyingDown) { List <QueuedJob> j = __instance.jobs; for (int i = 0; i < j.Count; i++) { QueuedJob queuedJob = j[i]; if (null == queuedJob) { continue; } if (!queuedJob.job.CanBeginNow(pawn, whileLyingDown)) { continue; } __result = true; return(false); } __result = false; return(false); }
public static bool TryIssueJobPackage(ThinkNode_QueuedJob __instance, ref ThinkResult __result, Pawn pawn, JobIssueParams jobParams) { JobQueue jobQueue = pawn.jobs.jobQueue; if (pawn.Downed || jobQueue.AnyCanBeginNow(pawn, __instance.inBedOnly)) { while (jobQueue.Count > 0 && !jobQueue.Peek().job.CanBeginNow(pawn, __instance.inBedOnly)) { QueuedJob queuedJob = jobQueue.Dequeue(); pawn.ClearReservationsForJob(queuedJob.job); if (pawn.jobs.debugLog) { pawn.jobs.DebugLogEvent(" Throwing away queued job that I cannot begin now: " + queuedJob.job); } } } if (jobQueue.Count > 0) { QueuedJob jqpeek = jobQueue.Peek(); if (jqpeek != null) { if (jqpeek.job.CanBeginNow(pawn, __instance.inBedOnly)) { QueuedJob queuedJob2 = jobQueue.Dequeue(); if (pawn.jobs.debugLog) { pawn.jobs.DebugLogEvent(" Returning queued job: " + queuedJob2.job); } __result = new ThinkResult(queuedJob2.job, __instance, queuedJob2.tag, fromQueue: true); return(false); } } } __result = ThinkResult.NoJob; return(false); }
public async Task <HttpResponseMessage> Compose( TenantId tenantId, Model.ComposeDocumentsModel dto) { QueuedJob job = new QueuedJob(); var id = new QueuedJobId(Guid.NewGuid().ToString()); job.Id = id; job.SchedulingTimestamp = DateTime.Now; job.StreamId = 0; job.TenantId = tenantId; job.Parameters = new Dictionary <string, string>(); job.Parameters.Add("documentList", String.Join <Object>("|", dto.DocumentList)); job.Parameters.Add("resultingDocumentHandle", dto.ResultingDocumentHandle); job.Parameters.Add("resultingDocumentFileName", dto.ResultingDocumentFileName ?? dto.ResultingDocumentHandle); job.Parameters.Add(JobKeys.TenantId, tenantId); _queueDispatcher.QueueJob("pdfComposer", job); return(Request.CreateResponse( HttpStatusCode.OK, new { result = "ok" } )); }
public static void StackFeeder( [QueueTrigger("slackfeed-items", Connection = "slackstackfeed_QueueStorage")] QueuedJob job, [CosmosDB("FeedStateDatabase", "FeedItemsCollection", ConnectionStringSetting = "slackstackfeed_CosmosDB", Id = "state")] SlackStackState state, [CosmosDB("FeedStateDatabase", "FeedItemsCollection", ConnectionStringSetting = "slackstackfeed_CosmosDB", Id = "{team}")] SlackTeam team, DateTime processed, ILogger log) { if (!team.Active || !team.Subscriptions.ContainsKey(job.Feed)) { return; } var feed = state.Feeds[job.Feed]; try { var atom = XDocument.Load(feed.SourceUri.AbsoluteUri).Root; XNamespace bs = "http://www.w3.org/2005/Atom"; DateTime.TryParse(atom.Element(bs + "updated").Value, out var updated); if (updated > processed) { log.LogDebug("Feed recently updated, scanning for entries..."); using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })) { foreach (var entry in atom.Elements(bs + "entry")) { var id = entry.Element(bs + "id")?.Value ?? string.Empty; if (string.IsNullOrEmpty(id) || team.Posted.Contains(id)) { continue; } if (!DateTime.TryParse(entry.Element(bs + "published").Value, out var published)) { log.LogDebug("Invalid entry data -- missing published date."); continue; } var raw = entry.Element(bs + "summary").Value; var post = StackFunctions.Slackify(raw); var userLink = entry.Element(bs + "author").Element(bs + "uri").Value ?? string.Empty; var match = Regex.Match(userLink, $"https://{feed.Site}.stackexchange.com/users/([0-9]+)"); var user = default(StackUser); if (match.Success) { var userData = client.GetStringAsync($"https://api.stackexchange.com/2.2/users/{match.Groups[1].Value}?site={feed.Site}&key=MYe90O9jVj1YJI12XqK0BA((&filter=!)RwdAtHo34gjVfkkY.BZV4L(").Result; var stackData = JsonConvert.DeserializeObject <StackApiResponse <StackUser> >(userData); if (string.IsNullOrEmpty(stackData.ErrorMessage) && stackData.Items.Any()) { user = stackData.Items[0]; } } var attachments = new[] { new { mrkdwn_in = new string[] { "text", "fields" }, title = entry.Element(bs + "title")?.Value ?? string.Empty, title_link = id, text = post, thumb_url = feed.LogoUri.AbsoluteUri, author_name = user?.DisplayName ?? string.Empty, author_link = user?.Link?.AbsoluteUri ?? string.Empty, author_icon = user?.ProfileImage?.AbsoluteUri ?? string.Empty, fields = entry.Elements(bs + "category").Select(tag => new { value = $"`{tag.Attribute("term").Value}`", @short = true }), ts = new DateTimeOffset(published).ToUnixTimeSeconds() } }; foreach (var channel in team.Subscriptions[job.Feed]) { var data = new FormUrlEncodedContent(new Dictionary <string, string> { { "as_user", "false" }, { "username", "Slack Stack Feed" }, { "token", team.BotToken }, { "channel", channel }, { "text", $"New Question Posted to: <{feed.Uri}| *{feed.Name}*>." }, { "unfurl_links", "false" }, { "unfurl_media", "false" }, { "attachments", JsonConvert.SerializeObject(attachments, new JsonSerializerSettings { Formatting = Formatting.Indented }) } }); var response = client.PostAsync("https://slack.com/api/chat.postMessage", data).Result; response.EnsureSuccessStatusCode(); } team.Posted.Add(id); } } } // Only keep the last 30 posts we sent, to avoid filling up DocumentDB storage. team.Posted = team.Posted.Skip(team.Posted.Count - 30).ToList(); } catch (Exception ex) { log.LogDebug(ex.ToString()); } }
static void Postfix(Pawn_JobTracker __instance, ref ThinkResult __result, ref Pawn ___pawn) { if (___pawn.RaceProps.Animal && ___pawn.Faction != Faction.OfPlayer && ___pawn.Faction != null) { if (___pawn.GetLord() != null && (___pawn.GetLord().CurLordToil is LordToil_DefendPoint || ___pawn.GetLord().CurLordToil.GetType().Name == "LordToil_DefendTraderCaravan")) { if (__result.SourceNode is JobGiver_Wander) { JobGiver_Wander jgWander = (JobGiver_Wander)__result.SourceNode; Traverse.Create(__result.SourceNode).Field("wanderRadius").SetValue(5f); } } } if (___pawn.IsColonistPlayerControlled || ___pawn.RaceProps.Animal || ___pawn.Faction.HostileTo(Faction.OfPlayer)) { return; } if (___pawn.IsPrisoner) { return; } LocalTargetInfo target = DistanceUtility.GetFirstTarget(__result.Job, TargetIndex.A); if (!target.IsValid) { return; } ExtendedDataStorage store = Base.GetExtendedDataStorage(); if (store == null) { return; } //Log.Message("wrong duty"); ExtendedPawnData PawnData = store.GetExtendedDataFor(___pawn); Lord lord = ___pawn.GetLord(); if (lord == null) { return; } if (__result.Job.def == GUC_JobDefOf.Dismount || __result.Job.def == GUC_JobDefOf.Mount) { return; } QueuedJob qJob = ___pawn.jobs.jobQueue.FirstOrFallback(null); if (qJob != null && (qJob.job.def == GUC_JobDefOf.Dismount || qJob.job.def == GUC_JobDefOf.Mount)) { return; } if (lord.CurLordToil is LordToil_ExitMapAndEscortCarriers || lord.CurLordToil is LordToil_Travel || lord.CurLordToil is LordToil_ExitMap || lord.CurLordToil is LordToil_ExitMapTraderFighting) { if (PawnData.owning != null && PawnData.owning.Faction == ___pawn.Faction && PawnData.mount == null && !PawnData.owning.Downed && PawnData.owning.Spawned && !___pawn.IsBurning() && !___pawn.Downed) { mountAnimal(__instance, ___pawn, PawnData, ref __result); } } else if (lord.CurLordToil.GetType().Name == "LordToil_DefendTraderCaravan" || lord.CurLordToil is LordToil_DefendPoint) //first option is internal class, hence this way of accessing. { if (PawnData.mount != null) { parkAnimal(__instance, ___pawn, PawnData); } } }