Esempio n. 1
0
        /// <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 username = null;
            string password = null;
            string url      = null;

            if (!DA.GetData(0, ref username))
            {
                return;
            }
            if (!DA.GetData(1, ref password))
            {
                return;
            }
            if (!DA.GetData(2, ref url))
            {
                return;
            }

            var client = new ComputeClient(url);
            var tokens = client.Auth(username, password);
            var output = new Inputs
            {
                Auth = tokens,
                Url  = url
            };

            DA.SetData(0, output.ToJson());
        }
Esempio n. 2
0
        public void ComputeClient_GetToken()
        {
            var tokens = client.Auth(user.username, user.password);

            Console.WriteLine($"Got access token: {tokens.Access}");

            Console.Write($"Decoded token: {ComputeClient.DecodeTokenToJson(tokens.Access)}");

            Assert.IsNotNull(tokens.Access, "_value should be true");
        }
        public void TestProjectList()
        {
            // Get the JWT access tokens as usual
            var tokens = client.Auth(user.username, user.password);

            Console.WriteLine($"Got access token: {tokens.Access}");

            // Instantiate the Project object
            //var projects = new ComputeCS.Projects(client);

            // Get a list of Projects for this user
            var projects = new GenericViewSet <Project>(tokens, user.host, "/api/project/").List();

            Console.Write($"Got projects: {JsonConvert.SerializeObject(projects)}");

            Assert.IsNotEmpty(projects, "Got empty project list");
        }
Esempio n. 4
0
        public void SetUp()
        {
            client = new ComputeClient(user.host);

            // Get the JWT access tokens as usual
            var tokens = client.Auth(user.username, user.password);

            Console.WriteLine($"Got access token: {tokens.Access}");

            // Core input string (from previous/upstream component(s))
            core_input = new Inputs {
                Auth = tokens,
                Url  = user.host
            }.ToJson();

            // Input parameters (these will be input into the component)
            project_name   = "Project Test";
            project_number = 1;
            task_name      = "Test Task";
            create         = false;
        }
Esempio n. 5
0
        public void SetUp()
        {
            client = new ComputeClient(user.host);

            // Get the JWT access tokens as usual
            var tokens = client.Auth(user.username, user.password);

            Console.WriteLine($"Got access token: {tokens.Access}");

            // Core input string (from previous/upstream component(s))
            core_input = new Inputs {
                Auth        = tokens,
                Url         = user.host,
                Project     = project,
                Task        = task,
                Mesh        = mesh,
                CFDSolution = solution
            }.ToJson();

            // Input parameters (these will be input into the component)
            compute = false;
        }
Esempio n. 6
0
        /// <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 username = null;
            string password = null;
            var    url      = "https://compute.procedural.build";
            var    retry    = false;

            if (!DA.GetData(0, ref username))
            {
                return;
            }
            if (!DA.GetData(1, ref password))
            {
                return;
            }
            DA.GetData(2, ref url);
            DA.GetData(3, ref retry);

            var client = new ComputeClient(url);

            if (retry)
            {
                StringCache.ClearCache();
            }

            //Async Execution
            var cacheKey     = username + password + url;
            var cachedTokens = StringCache.getCache(cacheKey);

            DA.DisableGapLogic();
            if (cachedTokens == null)
            {
                var queueName = "login";
                // Get queue lock
                var queueLock = StringCache.getCache(queueName);
                if (queueLock != "true")
                {
                    StringCache.setCache(queueName, "true");
                    QueueManager.addToQueue(queueName, () =>
                    {
                        try
                        {
                            var results = client.Auth(username, password);

                            if (results.ErrorMessages != null)
                            {
                                StringCache.setCache(cacheKey, "error");
                                throw new Exception(results.ErrorMessages.First());
                            }
                            if (results.ErrorMessages == null)
                            {
                                StringCache.ClearCache();
                                cachedTokens = results.ToJson();
                                StringCache.setCache(cacheKey, cachedTokens);
                            }
                        }
                        catch (Exception e)
                        {
                            StringCache.setCache(InstanceGuid.ToString(), e.Message);
                        }

                        ExpireSolutionThreadSafe(true);
                        Thread.Sleep(2000);
                        StringCache.setCache(queueName, "");
                    });
                }
            }


            // Read from Cache
            var errors = StringCache.getCache(InstanceGuid.ToString());

            if (errors != null)
            {
                if (errors.Contains("(401) Unauthorized"))
                {
                    errors = "Could not login with the provided credentials. Try again.";
                }

                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, errors);
            }

            var tokens = new AuthTokens();

            if (cachedTokens != null)
            {
                tokens = tokens.FromJson(cachedTokens);
                var output = new Inputs
                {
                    Auth = tokens,
                    Url  = url
                };
                DA.SetData(0, output.ToJson());
            }
        }