acron0 / AsanaNet

.NET API for Asana (www.asana.com)
MIT License
38 stars 29 forks source link

Updating already existing objects and collections #14

Closed niieani closed 10 years ago

niieani commented 11 years ago

Here's an example implementation of how this could be done:

https://github.com/niieani/AsanaNet/commit/6410ed0a0559fb9fba83dfed2383fc2609229486

With it, it's basically possible to do this:

        private IAsanaObjectCollection _asanaProjects;

        public async Task getProjectsWithDetails()
        {
            List<Task> ProjectDetailsWorkers = new List<Task>();
            await _asana.GetProjectsInWorkspace(_asanaWorkspace, projects =>
            {
                ProjectDetailsWorkers = projects.RefreshAll<AsanaProject>();
                _asanaProjects = projects;
            });
            Task.WaitAll(ProjectDetailsWorkers.ToArray());
        }

Which means that we get all the details of each project automatically, and we don't need to manually query for each project. Queries will be done asynchronously and what's returned by RefreshAll<OBJECT>() or Refresh() is a Task, so we can Wait, or trigger whatever we want (a progress bar going forward for example).

Let me know what you think about it. If you like it, we can mirror the technique across the rest of AsanaObjects.