/// <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 auth = null; string projectName = null; int? projectNumber = null; var excludeChildren = true; var refresh = false; if (!DA.GetData(0, ref auth)) { return; } if (!DA.GetData(1, ref projectName)) { return; } DA.GetData(2, ref projectNumber); DA.GetData(3, ref excludeChildren); DA.GetData(4, ref refresh); // Get Cache to see if we already did this var cacheKey = projectName + projectNumber + excludeChildren; var cachedValues = StringCache.getCache(cacheKey); DA.DisableGapLogic(); if (cachedValues == null || refresh == true) { var queueName = "ListTasks" + cacheKey; // Get queue lock var queueLock = StringCache.getCache(queueName); if (queueLock != "true") { StringCache.setCache(queueName, "true"); StringCache.setCache(cacheKey, null); QueueManager.addToQueue(queueName, () => { try { cachedValues = ProjectAndTask.GetTasks( auth, projectName, projectNumber, excludeChildren ); StringCache.setCache(cacheKey, cachedValues); StringCache.setCache(this.InstanceGuid.ToString(), ""); } catch (NoObjectFoundException) { StringCache.setCache(cacheKey + "create", ""); } catch (Exception e) { StringCache.setCache(InstanceGuid.ToString(), e.Message); StringCache.setCache(cacheKey, "error"); } ExpireSolutionThreadSafe(true); Thread.Sleep(2000); StringCache.setCache(queueName, ""); }); } } HandleErrors(); // Read from Cache if (cachedValues != null) { var outputs = cachedValues.Split(';'); if (outputs.Length > 1) { outputs = outputs.OrderBy(task => task).ToArray(); } DA.SetDataList(0, outputs); } }
/// <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 auth = null; string projectName = null; int? projectNumber = null; string taskName = null; string overrides = null; var create = false; if (!DA.GetData(0, ref auth)) { return; } if (!DA.GetData(1, ref projectName)) { return; } DA.GetData(2, ref projectNumber); if (!DA.GetData(3, ref taskName)) { return; } DA.GetData(4, ref overrides); DA.GetData(5, ref create); ValidateName(taskName); ValidateName(projectName); // Get Cache to see if we already did this var cacheKey = projectName + taskName + overrides; var cachedValues = StringCache.getCache(cacheKey); DA.DisableGapLogic(); if (cachedValues == null || create) { var queueName = "ProjectAndTask" + cacheKey; // Get queue lock var queueLock = StringCache.getCache(queueName); if (queueLock != "true") { StringCache.setCache(queueName, "true"); StringCache.setCache(cacheKey, null); QueueManager.addToQueue(queueName, () => { try { var results = ProjectAndTask.GetOrCreate( auth, projectName, projectNumber, taskName, overrides, create ); cachedValues = results; StringCache.setCache(cacheKey, cachedValues); StringCache.setCache(this.InstanceGuid.ToString(), ""); if (create) { StringCache.setCache(cacheKey + "create", "true"); } } catch (Exception e) { StringCache.setCache(InstanceGuid.ToString(), e.Message); StringCache.setCache(cacheKey, "error"); StringCache.setCache(cacheKey + "create", ""); } ExpireSolutionThreadSafe(true); Thread.Sleep(2000); StringCache.setCache(queueName, ""); }); } } // Read from Cache if (cachedValues != null) { var outputs = cachedValues; DA.SetData(0, outputs); Message = ""; if (StringCache.getCache(cacheKey + "create") == "true") { Message = "Task Created"; } } // Handle Errors var errors = StringCache.getCache(InstanceGuid.ToString()); if (!string.IsNullOrEmpty(errors)) { var messageLevel = GH_RuntimeMessageLevel.Error; if (errors.Contains("No object found")) { errors = "Could not find the desired project. Click create to create a new project."; messageLevel = GH_RuntimeMessageLevel.Warning; } AddRuntimeMessage(messageLevel, errors); } }