Closed AdamDudley closed 11 years ago
Yep, brill. I really should sort out those redundant Complete methods...
Thanks. I'd like to make the code more Task centric. So you can write nicer looking code (in my opinion) simply write:
AsanaWorkspace ws = AsanaTasks.GetWorkspacesTask().Result.First();
AsanaProject testProject = AsanaTasks.GetProjectByIdTask(2186215619984).Result;
I've added a class in my code, (example below). But to get it working properly, I'll need to overload every Get function, for example, so each can have a separate errorCallback (so that the individual task can error).
I was thinking if they are overloads, then at least it wont break any existing code.
I'm not sure what your thoughts are?
For example, I have tasks like:
static public Asana connectedAsana { get; set; }
#region Workspace
static TaskCompletionSource<IEnumerable<AsanaWorkspace>> _workspaceTask;
static public Task<IEnumerable<AsanaWorkspace>> GetWorkspacesTask()
{
_workspaceTask = new TaskCompletionSource<IEnumerable<AsanaWorkspace>>();
//Get workspaces
AsanaCollectionResponseEventHandler workspacesHandler = WorkItemsCallback;
connectedAsana.GetWorkspaces(workspacesHandler);
return _workspaceTask.Task;
}
static private void WorkItemsCallback(IAsanaObjectCollection response)
{
_workspaceTask.SetResult(response.OfType<AsanaWorkspace>());
}
#endregion
#region Project
static TaskCompletionSource<IEnumerable<AsanaProject>> _projectsTask;
public static Task<IEnumerable<AsanaProject>> GetProjectsInWorkspaceTask(AsanaWorkspace workspace)
{
_projectsTask = new TaskCompletionSource<IEnumerable<AsanaProject>>();
//Get projects that belong to this workspace
AsanaCollectionResponseEventHandler callback = ProjectsCallback;
connectedAsana.GetProjectsInWorkspace(workspace, callback);
return _projectsTask.Task;
}
private static void ProjectsCallback(IAsanaObjectCollection response)
{
_projectsTask.SetResult(response.OfType<AsanaProject>());
}
And then I have to have a generic error like so
static public void errorCallbackVar(string arg1, string arg2, string arg3)
{
//We will have to try and set an exception everywhere, since we don't know where we were up to.
Exception asanaException = new Exception(arg1 + arg2 + arg3);
if (_workspaceTask != null) _workspaceTask.TrySetException(asanaException);
if (_projectsTask != null) _projectsTask.TrySetException(asanaException);
Added AsanaTeam to Project. Added GetTeamsInWorkspace function. Updated AsanaProject to include connected AsanaTeam.
Example usage: