/// <summary>
        /// Exposed method for users to call when trying to download the meta data of the Projects the current
        /// logged in user is able to access.
        /// </summary>
        /// <param name="callBack">A method callback which takes a <c>Project</c> array.</param>
        /// <returns>An async Task which can be awaited with a coroutine or just ignored.</returns>
        /// <remarks>If download was successful, the resulting array is passed back. If failed, null
        /// is passed. Need to be using the <c>SpeckleCore</c> namespace to access this type.</remarks>
        public virtual async Task GetAllProjectMetaDataForUserAsync(Action <Project[]> callBack)
        {
            if (loggedInUser == null)
            {
                throw new UnauthorizedAccessException("Need to be logged in before getting project data.");
            }

            SpeckleApiClient userProjectsClient = new SpeckleApiClient(serverUrl.Trim());

            userProjectsClient.AuthToken = loggedInUser.Apitoken;

            ResponseProject projectsGet = await userProjectsClient.ProjectGetAllAsync();

            if (projectsGet == null)
            {
                Debug.LogError("Could not get projects for user");

                callBack?.Invoke(null);
            }
            else
            {
                List <Project> projects = projectsGet.Resources;

                Debug.Log("Got " + projects.Count + " projects for user");

                callBack?.Invoke(projects.ToArray());
            }
        }
Exemplo n.º 2
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)
        {
            Account Account = null;

            DA.GetData("Account", ref Account);


            if (Account == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not set the account");
                return;
            }

            if (SelectedProject == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Right click this component to select a project");
            }


            DA.SetData("Selected Project", SelectedProject);
            DA.SetDataList("Projects", UserProjects);

            Client.BaseUrl = Account.RestApi; Client.AuthToken = Account.Token;
            Client.ProjectGetAllAsync().ContinueWith(tsk =>
            {
                if (tsk.Result.Success == false)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, tsk.Result.Message);
                    return;
                }
                var newProjects = tsk.Result.Resources.ToList();
                var notUpdated  = UserProjects.Select(x => x._id).SequenceEqual(newProjects.Select(x => x._id));

                if (!notUpdated)
                {
                    UserProjects = tsk.Result.Resources.ToList();
                    Rhino.RhinoApp.MainApplicationWindow.Invoke(ExpireComponent);
                }
            });
        }
Exemplo n.º 3
0
        static async Task TestProjects(SpeckleApiClient myClient)
        {
            string projectId = "lol";

            Console.WriteLine();
            try
            {
                Console.WriteLine("Creating a project.");
                var Response = await myClient.ProjectCreateAsync(new Project()
                {
                    Name = "A simple project"
                });

                Console.WriteLine("OK: " + Response.Resource.ToJson());

                projectId = Response.Resource._id;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Updating a project.");
                var Response = await myClient.ProjectUpdateAsync(projectId, new Project()
                {
                    Name = "A more complicated project", Private = false
                });

                Console.WriteLine("OK: " + Response.Resource.ToJson());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting a project.");
                var Response = await myClient.ProjectGetAsync(projectId);

                Console.WriteLine("OK: " + Response.Resource.ToJson());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Getting all users projects.");
                var Response = await myClient.ProjectGetAllAsync();

                Console.WriteLine("OK: " + Response.Resources.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine();
            try
            {
                Console.WriteLine("Deleteing  a project.");
                var Response = await myClient.ProjectDeleteAsync(projectId);

                Console.WriteLine("OK: " + Response.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }