protected override GatherResult TargetGather(List <Scenario> list, ref bool random) { GatherResult result = base.TargetGather(list, ref random); if ((Target == null) && (result == GatherResult.Failure)) { if (SimTypes.IsSpecial(Sim)) { IncStat("Special Failure"); } else if (!Sim.YoungAdultOrAbove) { IncStat("Teen Love-Loss"); } else if (Sim.Elder) { IncStat("Elder Love-Loss"); } else if (Sim.Partner != null) { IncStat("Partnered Love-Loss"); } else { list.Add(new CannotFindLoveScenario(Sim)); } } return(result); }
/// <summary> /// range 重试,解决range字段找不到,但又必须提供的问题 /// </summary> /// <param name="func"></param> /// <param name="paramModel"></param> /// <param name="retryNum"></param> /// <returns></returns> private GatherResult Retry(Func <ParamModel, GatherResult> func, ParamModel paramModel, int retryNum) { GatherResult result = default(GatherResult); try { result = func(paramModel); return(result); } catch (Exception) { for (int i = 1; i <= retryNum; i++) { try { paramModel.Range = $"{DateTime.Now.Year - i}"; result = func(paramModel); return(result); } catch (Exception) { } } return(result); } }
/// <summary> /// GENERATE IMAGE TASKS /// Given a list of raw camera images, generate a list of associated published images. /// </summary> /// <param name="gatherResult"></param> /// <param name="token"></param> /// <returns></returns> public List <Task> GenerateImageTasks(GatherResult gatherResult, CancellationToken token) { var processor = new ImageProcessor(); var pubImages = DbRepo.ListPubImages(gatherResult); var items = new List <Task>(); foreach (var pubImage in pubImages) { items.Add(Task <GenerateImageResult> .Factory.StartNew(() => processor.GeneratePubImage(pubImage), token, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith(taskInfo => { try { token.ThrowIfCancellationRequested(); var pubImageResult = (GenerateImageResult)taskInfo.Result; Logit.LogGenerateImageResult(pubImageResult); var publishTasks = GeneratePublishTasks(pubImageResult, token); Parallel.ForEach(publishTasks, publishResult => { }); Task.WaitAll(publishTasks.ToArray()); } catch (Exception exc) { Logit.LogError(exc); } }) ); } return(items); }
protected override GatherResult TargetGather(List <Scenario> list, ref bool random) { GatherResult result = base.TargetGather(list, ref random); if ((Target == null) && (result == GatherResult.Failure)) { Lots.IncreaseImmigrationPressure(Pregnancies, GetValue <ImmigrantRequirementScenario.PressureOption, int>()); } return(result); }
protected override GatherResult TargetGather(List <Scenario> list, ref bool random) { if (Target == null) { if (Lot == null) { if (RandomUtil.RandomChance(ChanceOfHomeLot)) { Lot = Sim.LotHome; } if (Lot == null) { Lot = Lots.GetCommunityLot(Sim.CreatedSim, null, false); if (Lot == null) { return(GatherResult.Failure); } } } } GatherResult result = base.TargetGather(list, ref random); if (result == GatherResult.Success) { RandomUtil.RandomizeListOfObjects(list); int count = 0; foreach (Scenario choice in list) { GatheringScenario guest = choice as GatheringScenario; if (guest == null) { continue; } count++; mGuests.Add(guest.Target); if (count >= TargetMaximum) { break; } } list.Clear(); return(GatherResult.Update); } return(result); }
protected override GatherResult Gather(List <Scenario> list, ref int continueChance, ref int maximum, ref bool random) { GatherResult result = base.Gather(list, ref continueChance, ref maximum, ref random); if (result == GatherResult.Success) { Scenarios.DumpStats(); if (!AcceptCancelDialog.Show(Localize("InitialHomelessPrompt"))) { return(GatherResult.Failure); } } return(result); }
/// <summary> /// LIST PUB IMAGES /// </summary> /// <param name="gatherResult"></param> /// <returns></returns> public static List <EntityPubImage> ListPubImages(GatherResult gatherResult) { var items = new List <EntityPubImage>(); for (int i = 10; i <= 20; i += 10) { items.Add(new EntityPubImage { Name = gatherResult.Camera.Name + "-PubImage" + i.ToString(), DemoWaitMs = i * 1000, GenerateImageTimeoutMs = 13000, Camera = gatherResult.Camera }); } return(items); }
/// <summary> /// Retrieve already installed packages /// </summary> private async Task GatherInstalledPackagesAsync(IEnumerable <PackageIdentity> installedPackages, HashSet <string> allPrimaryTargets, CancellationToken token) { foreach (var installedPackage in installedPackages) { // Skip installed packages which are targets, this is important for upgrade and reinstall if (!allPrimaryTargets.Contains(installedPackage.Id)) { var packageInfo = await _packagesFolderResource.ResolvePackage(installedPackage, _context.TargetFramework, _context.ResolutionContext.SourceCacheContext, _context.Log, token); // Installed packages should exist, but if they do not an attempt will be made to find them in the sources. if (packageInfo != null) { // Create a request and result to match the other packages var request = new GatherRequest( source: null, package: installedPackage, ignoreExceptions: false, order: GetNextRequestId(), isInstalledPackage: true); var packages = new List <SourcePackageDependencyInfo>() { packageInfo }; var result = new GatherResult(request, packages); _results.Add(result); } else { // retrieve the package info from another source if it does not exist in local QueueWork(_allResources, installedPackage, ignoreExceptions: true, isInstalledPackage: true); } } } }
/// <summary> /// 根据api链接和html节点 获取完整的解析结果 /// </summary> /// <param name="link"></param> /// <param name="htmlNode"></param> /// <returns></returns> private GatherResult GetGatherResult(string link, HtmlNode htmlNode) { var res = HttpClient.GetAsync(link).Result; string html = res.Content.ReadAsStringAsync().Result; string json = string.Join(null, html.SkipWhile(c => c != '{').TakeWhile(c => c != ';')); TensionJsonResult tensionJsonResult = JsonConvert.DeserializeObject <TensionJsonResult>(json); var result = new GatherResult { Title = $"{htmlNode.Descendants("h2").FirstOrDefault(x => x.HasClass("result_title"))?.InnerText}", Description = $"{htmlNode.Descendants("span").FirstOrDefault(x => x.HasClass("desc_text"))?.InnerText}", Pic = $"https:{htmlNode.Descendants("a").FirstOrDefault(x => x.HasClass("result_figure")).Descendants("img").First().Attributes["src"].Value}", OwinPlat = $"{tensionJsonResult?.PlaylistItem?.name}", OwinApi = link, DramaList = tensionJsonResult?.PlaylistItem?.videoPlayList.Select(x => new Drama { Title = x.title, Pic = x.pic, Link = x.playUrl }) }; return(result); }
/// <summary> /// LOG GATHER RESULT /// </summary> /// <param name="gatherResult"></param> /// <returns></returns> public static GatherResult LogGatherResult(GatherResult gatherResult) { LogVerbose("Gather success for camera: " + gatherResult.Camera.Name + ", raw filename: " + gatherResult.RawImageName + " (thread " + Thread.CurrentThread.ManagedThreadId.ToString() + ")"); return(gatherResult); }
protected ScenarioResult Run(ScenarioFrame frame) { try { if (Scenarios == null) { return(ScenarioResult.Failure); } string name = "Duration " + UnlocalizedName; if (!Main.SecondCycle) { name = "First " + name; } using (Common.TestSpan span = new Common.TestSpan(Scenarios, name)) { AddTry(); if (!Test()) { AllowFailCleanup(); return(ScenarioResult.Failure); } AddAllowed(); List <Scenario> list = new List <Scenario>(); int continueChance = ContinueChance; int maximum = 0; bool random = true; GatherResult result = GatherResult.Failure; string gatherName = "Gather " + UnlocalizedName; if (!Main.SecondCycle) { gatherName = "First " + gatherName; } using (Common.TestSpan gatherSpan = new Common.TestSpan(Scenarios, gatherName)) { result = Gather(list, ref continueChance, ref maximum, ref random); } switch (result) { case GatherResult.Update: return(Update(frame)); case GatherResult.Failure: IncStat("Gathering Failure"); return(ScenarioResult.Failure); } // Stops the PushAndPrint() routine from firing mPushed = true; AddStat("Gathered", list.Count); if (list.Count == 0) { return(ScenarioResult.Failure); } if (maximum <= 0) { maximum = list.Count; } if (continueChance != 100) { AddStat("Chance", continueChance); } bool first = true; int count = 0; if (random) { while (list.Count > 0) { int index = RandomUtil.GetInt(list.Count - 1); Scenario item = list[index]; list.RemoveAt(index); item.mFirst = first; first = false; Add(frame, item, continueChance); count++; if (count > maximum) { AddStat("Maximum", count); break; } } } else { foreach (Scenario item in list) { item.mFirst = first; first = false; Add(frame, item, continueChance); count++; if (count > maximum) { AddStat("Maximum", count); break; } } } return(ScenarioResult.Success); } } catch (ResetException) { throw; } catch (Exception e) { Common.Exception(ToString(), e); return(ScenarioResult.Failure); } }