コード例 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (string.IsNullOrWhiteSpace(RemoteDefinitionLocation))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No URL or path defined for definition");
                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 (InPreSolve)
            {
                var inputSchema = _remoteDefinition.CreateSolveInput(DA, _cacheResultsOnServer, out List <string> warnings);
                if (warnings != null && warnings.Count > 0)
                {
                    foreach (var warning in warnings)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, warning);
                    }
                    return;
                }
                if (inputSchema != null)
                {
                    var task = System.Threading.Tasks.Task.Run(() => _remoteDefinition.Solve(inputSchema, _cacheResultsInMemory));
                    TaskList.Add(task);
                }
                return;
            }

            if (!GetSolveResults(DA, out var schema))
            {
                var inputSchema = _remoteDefinition.CreateSolveInput(DA, _cacheResultsOnServer, out List <string> 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);
            }
        }
コード例 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (string.IsNullOrWhiteSpace(RemoteDefinitionLocation))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No URL or path defined for definition");
                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 (InPreSolve)
            {
                List <string> warnings;
                string        inputJson = _remoteDefinition.CreateInputJson(DA, _cacheSolveResults, out warnings);
                if (warnings != null && warnings.Count > 0)
                {
                    foreach (var warning in warnings)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, warning);
                    }
                    return;
                }
                if (inputJson != null)
                {
                    var task = System.Threading.Tasks.Task.Run(() => _remoteDefinition.PostToServer(inputJson));
                    TaskList.Add(task);
                }
                return;
            }

            if (!GetSolveResults(DA, out var schema))
            {
                List <string> warnings;
                string        inputJson = _remoteDefinition.CreateInputJson(DA, _cacheSolveResults, out warnings);
                if (warnings != null && warnings.Count > 0)
                {
                    foreach (var warning in warnings)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, warning);
                    }
                    return;
                }
                if (inputJson != null)
                {
                    schema = _remoteDefinition.PostToServer(inputJson);
                }
                else
                {
                    schema = null;
                }
            }

            if (schema != null)
            {
                _remoteDefinition.SetComponentOutputs(schema, DA, Params.Output, this);
            }
            else
            {
                if (!_remoteDefinition.PathIsAppServer && !System.IO.File.Exists(_remoteDefinition.Path))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"No definition at {_remoteDefinition.Path}");
                }
            }
        }