/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { string inputJson = null; var epwFile = ""; var method = 0; var probes = new List <string>(); var thresholds = new List <string>(); var cpus = 4; var dependentOn = "Probe"; var create = false; if (!DA.GetData(0, ref inputJson)) { return; } if (inputJson == "error") { return; } if (!DA.GetData(1, ref epwFile)) { return; } DA.GetData(2, ref method); if (!DA.GetDataList(3, probes)) { return; } DA.GetDataList(4, thresholds); DA.GetData(5, ref cpus); DA.GetData(6, ref dependentOn); DA.GetData(8, ref create); // Get Cache to see if we already did this var cacheKey = string.Join("", probes) + epwFile + inputJson + method; var cachedValues = StringCache.getCache(cacheKey); DA.DisableGapLogic(); if (cachedValues == null || create) { const string queueName = "outdoorComfortSimulation"; // Get queue lock var queueLock = StringCache.getCache(queueName); if (queueLock != "true") { StringCache.setCache(queueName, "true"); StringCache.setCache(InstanceGuid.ToString(), ""); StringCache.setCache(cacheKey, null); QueueManager.addToQueue(queueName, () => { try { cachedValues = OutdoorComfort.CreateComfortTask( inputJson, epwFile, Presets[method], probes, thresholds, ComponentUtils.ValidateCPUs(cpus), dependentOn, create ); StringCache.setCache(cacheKey, cachedValues); if (create) { StringCache.setCache(cacheKey + "create", "true"); } } catch (NoObjectFoundException) { StringCache.setCache(cacheKey + "create", ""); } catch (Exception e) { StringCache.AppendCache(InstanceGuid.ToString(), e.Message + "\n"); StringCache.setCache(cacheKey, "error"); StringCache.setCache(cacheKey + "create", ""); } ExpireSolutionThreadSafe(true); Thread.Sleep(2000); StringCache.setCache(queueName, ""); }); } } HandleErrors(); // Read from Cache if (cachedValues != null) { DA.SetData(0, cachedValues); Message = ""; if (StringCache.getCache(cacheKey + "create") == "true") { Message = "Task Created"; } } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { string folder = null; var refresh = false; if (!DA.GetData(0, ref folder)) { return; } DA.GetData(1, ref refresh); var cacheKey = folder; var cachedValues = StringCache.getCache(cacheKey); DA.DisableGapLogic(); if (cachedValues == null || refresh) { const string queueName = "comfortResults"; StringCache.setCache(InstanceGuid.ToString(), ""); // Get queue lock var queueLock = StringCache.getCache(queueName); if (queueLock != "true") { StringCache.setCache(queueName, "true"); StringCache.setCache(cacheKey + "progress", "Loading..."); QueueManager.addToQueue(queueName, () => { try { var results = OutdoorComfort.ReadComfortResults(folder); (comfortOutput, comfortLegend) = TransposeThresholdMatrix(results); StringCache.setCache(cacheKey + "progress", "Done"); StringCache.setCache(cacheKey, "results"); StringCache.setCache(InstanceGuid.ToString(), ""); } catch (Exception e) { StringCache.setCache(InstanceGuid.ToString(), e.Message); StringCache.setCache(cacheKey, "error"); StringCache.setCache(cacheKey + "progress", ""); } ExpireSolutionThreadSafe(true); Thread.Sleep(2000); StringCache.setCache(queueName, ""); }); ExpireSolutionThreadSafe(true); } } // Handle Errors HandleErrors(); if (comfortOutput != null) { foreach (var key in comfortOutput.Keys) { AddToOutput(DA, key, comfortOutput[key]); } info = UpdateInfo( comfortLegend["patch"], comfortLegend["threshold"].Select(threshold => new Thresholds.ComfortThreshold { Field = threshold }) .ToList() ); } if (info != null) { DA.SetDataTree(0, info); } Message = StringCache.getCache(cacheKey + "progress"); }