public Task Solve(RemoteDefinition remoteDefinition, bool useMemoryCache, Action completedCallback) { _workingTask = Task.Run(() => { Output = remoteDefinition.Solve(_input, useMemoryCache); completedCallback(); }); return(_workingTask); }
protected override void SolveInstance(IGH_DataAccess DA) { if (!_enabledThisSolve) { return; } // Don't allow hops components to run on compute for now. if (_isHeadless) { AddRuntimeMessage( GH_RuntimeMessageLevel.Error, "Hops components are not allowed to run in external definitions. Please help us understand why you need this by emailing [email protected]"); return; } if (_showPathInput && DA.Iteration == 0) { string path = ""; if (!DA.GetData("_Path", ref path)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No URL or path defined for definition"); return; } if (!string.Equals(path, RemoteDefinitionLocation)) { RebuildWithNewPathAndRecompute(path); return; } } if (string.IsNullOrWhiteSpace(RemoteDefinitionLocation)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No URL or path defined for definition"); return; } if (_showEnabledInput && DA.Iteration == 0) { bool enabled = true; if (DA.GetData("_Enabled", ref enabled) && enabled == false) { _enabledThisSolve = false; return; } } if (InPreSolve) { if (_workingSolveList.SolvedFor(_solveSerialNumber)) { var solvedTask = Task.FromResult(_workingSolveList.SolvedSchema(DA.Iteration)); TaskList.Add(solvedTask); return; } List <string> warnings; var inputSchema = _remoteDefinition.CreateSolveInput(DA, _cacheResultsOnServer, out warnings); if (warnings != null && warnings.Count > 0) { foreach (var warning in warnings) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, warning); } return; } if (inputSchema != null) { _workingSolveList.Add(inputSchema); } return; } if (TaskList.Count == 0) { _workingSolveList.StartSolving(_synchronous); if (!_synchronous) { Message = "solving..."; return; } else { for (int i = 0; i < _workingSolveList.Count; i++) { var output = _workingSolveList.SolvedSchema(i); TaskList.Add(Task.FromResult(output)); } } } if (!GetSolveResults(DA, out var schema)) { List <string> warnings; var inputSchema = _remoteDefinition.CreateSolveInput(DA, _cacheResultsOnServer, out warnings); if (warnings != null && warnings.Count > 0) { foreach (var warning in warnings) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, warning); } return; } if (inputSchema != null) { schema = _remoteDefinition.Solve(inputSchema, _cacheResultsInMemory); } else { schema = null; } } if (DA.Iteration == 0) { // TODO: Having to clear the output data seems like a bug in the // TaskCapable components logic. We need to investigate this further. foreach (var output in Params.Output) { output.ClearData(); } } if (schema != null) { _remoteDefinition.SetComponentOutputs(schema, DA, Params.Output, this); } }