/// <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 input = null; string uploadPath = null; string text = null; var upload = false; if (!DA.GetData(0, ref input)) { return; } if (!DA.GetData(1, ref uploadPath)) { return; } if (!DA.GetData(2, ref text)) { return; } DA.GetData(3, ref upload); // Get Cache to see if we already did this var cacheKey = input + uploadPath + text; var cachedValues = StringCache.getCache(cacheKey); DA.DisableGapLogic(); var response = string.Empty; if (cachedValues == null || upload == true) { const string queueName = "upload"; // Get queue lock var queueLock = StringCache.getCache(queueName); if (queueLock != "true") { try { cachedValues = UploadFile.UploadTextFile(input, uploadPath, text, upload); StringCache.setCache(cacheKey, cachedValues); StringCache.setCache(this.InstanceGuid.ToString(), ""); if (upload) { StringCache.setCache(cacheKey + "create", "true"); } } catch (Exception e) { StringCache.AppendCache(this.InstanceGuid.ToString(), e.Message); StringCache.setCache(cacheKey, "error"); StringCache.setCache(cacheKey + "create", ""); } ExpireSolutionThreadSafe(true); StringCache.setCache(queueName, ""); } } HandleErrors(); // Read from Cache if (cachedValues != null) { DA.SetData(0, cachedValues); Message = ""; if (StringCache.getCache(cacheKey + "create") == "true") { Message = "File Uploaded"; } } }