public void GetTasks(string listId, string filter, TaskArrayCallback callback) { if (SearchMode == SearchMode.LocalOnly || SearchMode == SearchMode.LocalAndRemote) { // Local search mode... use our client side parser for the query. if (!string.IsNullOrEmpty(filter)) { try { var lexicalAnalyzer = new Search.LexicalAnalyzer(); var tokens = lexicalAnalyzer.Tokenize(filter); var astRoot = lexicalAnalyzer.BuildAst(tokens); bool includeArchivedLists = astRoot.NeedsArchivedLists(); var resultTasks = new List<Task>(); var searchableTaskLists = GetSearchableTaskLists(includeArchivedLists); if (listId != RtmElement.UnsyncedId) searchableTaskLists = searchableTaskLists.Where(tl => tl.Id == listId); foreach (var list in searchableTaskLists) { foreach (var task in list.Tasks) { var context = new Search.SearchContext(task, UserSettings.DateFormat); if (astRoot.ShouldInclude(context)) resultTasks.Add(task); } } callback(resultTasks.ToArray()); return; } catch (Exception) { if (SearchMode == SearchMode.LocalAndRemote && Syncing) { // Log the error and move on to the remote search. //IronCowTraceSource.TraceSource.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, e.Message); //IronCowTraceSource.TraceSource.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 0, "Due to previous error message, falling back to remote server query."); } else { throw; } } } } if (!Syncing) { callback(new Task[0]); return; } // If we get here, we need to perform a remote search. Dictionary<string, string> parameters = new Dictionary<string, string>(); if (listId != RtmElement.UnsyncedId) parameters["list_id"] = listId.ToString(); if (filter != null) parameters["filter"] = "(" + filter + ") AND status:Incomplete"; else parameters["filter"] = "status:Incomplete"; GetResponse("rtm.tasks.getList", parameters, (response) => { List<Task> tasks = new List<Task>(); foreach (var list in response.Tasks) { foreach (var series in list.TaskSeries) { foreach (var task in series.Tasks) { //Task newTask = taskList.Tasks.GetById(series.Id, task.Id, true); Task newTask = GetTask(task.Id); tasks.Add(newTask); } } } callback(tasks.ToArray()); }); }
public void GetTasksFromFilter(string filter, TaskArrayCallback callback) { GetTasks(RtmElement.UnsyncedId, filter, callback); }
public void GetTasks(string listId, TaskArrayCallback callback) { GetTasks(listId, null, callback); }