Exemple #1
0
        public RhinoModule(IRouteCacheProvider routeCacheProvider)
        {
            Get[""]             = _ => FixedEndpoints.HomePage(Context);
            Get["/healthcheck"] = _ => "healthy";
            Get["version"]      = _ => FixedEndpoints.GetVersion(Context);
            Get["sdk/csharp"]   = _ => FixedEndpoints.CSharpSdk(Context);
            Post["hammertime"]  = _ => FixedEndpoints.HammerTime(Context);

            Get["/sdk"] = _ =>
            {
                var result = new StringBuilder("<!DOCTYPE html><html><body>");
                var cache  = routeCacheProvider.GetCache();
                result.AppendLine($" <a href=\"/sdk/csharp\">C# SDK</a><BR>");
                result.AppendLine("<p>API<br>");

                int route_index = 0;
                foreach (var module in cache)
                {
                    foreach (var route in module.Value)
                    {
                        var method = route.Item2.Method;
                        var path   = route.Item2.Path;
                        if (method == "GET")
                        {
                            route_index += 1;
                            result.AppendLine($"{route_index} <a href='{path}'>{path}</a><BR>");
                        }
                    }
                }

                result.AppendLine("</p></body></html>");
                return(result.ToString());
            };

            foreach (string nameSpace in new List <string>()
            {
                "Rhino.Geometry", "Rhino.Geometry.Intersect"
            })
            {
                foreach (var endpoint in CreateEndpoints(typeof(Rhino.RhinoApp).Assembly, nameSpace))
                {
                    string key = endpoint.Path.ToLowerInvariant();
                    Get[key]  = _ => endpoint.Get(Context);
                    Post[key] = _ => endpoint.Post(Context);
                }
            }
        }
Exemple #2
0
        public RhinoModule(IRouteCacheProvider routeCacheProvider)
        {
            Get[""]              = _ => FixedEndpoints.HomePage(Context);
            Get["/healthcheck"]  = _ => "healthy";
            Get["version"]       = _ => FixedEndpoints.GetVersion(Context);
            Get["servertime"]    = _ => FixedEndpoints.ServerTime(Context);
            Get["sdk/csharp"]    = _ => FixedEndpoints.CSharpSdk(Context);
            Post["hammertime"]   = _ => FixedEndpoints.HammerTime(Context);
            Post["/grasshopper"] = _ => ResthopperEndpoints.Grasshopper(Context);
            Post["/io"]          = _ => ResthopperEndpoints.GetIoNames(Context);

            Get["/sdk"] = _ =>
            {
                var result = new StringBuilder("<!DOCTYPE html><html><body>");
                var cache  = routeCacheProvider.GetCache();
                result.AppendLine($" <a href=\"/sdk/csharp\">C# SDK</a><BR>");
                result.AppendLine("<p>API<br>");

                int route_index = 0;
                foreach (var module in cache)
                {
                    foreach (var route in module.Value)
                    {
                        var method = route.Item2.Method;
                        var path   = route.Item2.Path;
                        if (method == "GET")
                        {
                            route_index += 1;
                            result.AppendLine($"{route_index} <a href='{path}'>{path}</a><BR>");
                        }
                    }
                }

                result.AppendLine("</p></body></html>");
                return(result.ToString());
            };

            foreach (string nameSpace in new List <string>()
            {
                "Rhino.Geometry", "Rhino.Geometry.Intersect"
            })
            {
                foreach (var endpoint in CreateEndpoints(typeof(Rhino.RhinoApp).Assembly, nameSpace))
                {
                    string key = endpoint.Path.ToLowerInvariant();
                    Get[key]  = _ => endpoint.Get(Context);
                    Post[key] = _ =>
                    {
                        var r = endpoint.Post(Context);
                        r.ContentType = "application/json";
                        return(r);
                    };
                }
            }

            // Load GH at startup so it can get initialized on the main thread
            var pluginObject = Rhino.RhinoApp.GetPlugInObject("Grasshopper");
            var runheadless  = pluginObject?.GetType().GetMethod("RunHeadless");

            if (runheadless != null)
            {
                runheadless.Invoke(pluginObject, null);
            }

            //var script = Rhino.Runtime.PythonScript.Create();
            //if( script != null )
            //{
            //    foreach( var endpoint in GeometryEndPoint.Create(typeof(Python)) )
            //    {
            //        string key = endpoint.Path.ToLowerInvariant();
            //        Get[key] = _ => endpoint.Get(Context);
            //        Post[key] = _ => endpoint.Post(Context);
            //    }
            //}
        }