Ejemplo n.º 1
0
        TaskSet ITasks.GetTasks(TaskQuery query)
        {
            var factory = new ItemFactory <Task>("task")
                          .Element <int>("Id", "id")
                          .Element <string>("Name", "title")
                          .Element <string>("Tag", "tag")
                          .Element <Folder>("Folder", new ItemFactory <Folder>("folder")
                                            .Value <int>("Id"))
                          .Element <Context>("Context", new ItemFactory <Context>("context")
                                             .Attribute <int>("Id", "id")
                                             .Value <string>("Name"))
                          .Element <Goal>("Goal", new ItemFactory <Goal>("goal")
                                          .Attribute <int>("Id", "id")
                                          .Value <string>("Name"))
                          .Element <DateTime>("Added", "added")
                          .Element <DateTime>("Modified", "modified")
                          .Element <DateTime>("Start", "startdate")
                          .Element <DateTime>("Due", "duedate")
                          .Element <DateTime>("Due", "duetime")
                          .Element <DateTime>("Start", "starttime")
                          .Element <int>("Reminder", "reminder")
                          .Element <DateTime>("Completed", "completed")
                          .Element <Frequency>("Repeat", "repeat")
                          .Element <string>("AdvancedRepeat", "rep_advanced")
                          .Element <Status>("Status", "status")
                          .Element <bool>("HasStar", "star")
                          .Element <Priority>("Priority", "priority")
                          .Element <int>("Length", "length")
                          .Element <string>("Note", "note");

            var results = new TaskSet();
            var tasks   = new List <Task>();

            var builder = new StringBuilder();

            if (!String.IsNullOrEmpty(query.Name))
            {
                builder.AppendFormat("title={0};", encodeString(query.Name));
            }
            if (!String.IsNullOrEmpty(query.Tag))
            {
                builder.AppendFormat("tag={0};", encodeString(query.Tag));
            }
            if (query.Folder != null)
            {
                builder.AppendFormat("folder={0};", query.Folder.Id);
            }
            if (query.Context != null)
            {
                builder.AppendFormat("context={0};", query.Context.Id);
            }
            if (query.Goal != null)
            {
                builder.AppendFormat("goal={0};", query.Goal.Id);
            }
            if (query.Priority.HasValue)
            {
                builder.AppendFormat("priority={0};", (int)query.Priority);
            }
            if (query.Repeat.HasValue)
            {
                builder.AppendFormat("repeat={0};", (int)query.Repeat);
            }
            if (query.Status.HasValue)
            {
                builder.AppendFormat("status={0};;", (int)query.Status);
            }
            if (query.Parent != null)
            {
                builder.AppendFormat("parent={0};", query.Parent.Id);
            }
            if (query.ShorterThan.HasValue)
            {
                builder.AppendFormat("shorter={0};", query.ShorterThan);
            }
            if (query.LongerThan.HasValue)
            {
                builder.AppendFormat("longer={0};", query.LongerThan);
            }
            if (query.Before.HasValue)
            {
                builder.AppendFormat("before={0};", query.Before);
            }
            if (query.After.HasValue)
            {
                builder.AppendFormat("after={0};", query.After);
            }
            if (query.StartBefore.HasValue)
            {
                builder.AppendFormat("startbefore={0};", query.StartBefore);
            }
            if (query.StartAfter.HasValue)
            {
                builder.AppendFormat("startafter={0};", query.StartAfter);
            }
            if (query.ModifiedBefore.HasValue)
            {
                builder.AppendFormat("modbefore={0};", query.ModifiedBefore);
            }
            if (query.ModifiedAfter.HasValue)
            {
                builder.AppendFormat("modafter={0};", query.ModifiedAfter);
            }
            if (query.CompletedBefore.HasValue)
            {
                builder.AppendFormat("compbefore={0};", query.CompletedBefore);
            }
            if (query.CompletedAfter.HasValue)
            {
                builder.AppendFormat("compafter={0};", query.CompletedAfter);
            }
            if (query.NotCompleted.HasValue)
            {
                builder.AppendFormat("notcomp={0};", query.NotCompleted.Value ? 1 : 0);
            }
            if (query.HasStar.HasValue)
            {
                builder.AppendFormat("star={0};", query.HasStar.Value ? 1 : 0);
            }
            if (query.Id.HasValue)
            {
                builder.AppendFormat("id={0};", query.Id);
            }
            if (query.PageStart.HasValue)
            {
                builder.AppendFormat("start={0};", query.PageStart);
            }
            if (query.PageCount.HasValue)
            {
                builder.AppendFormat("end={0};", query.PageCount);
            }

            var response = SendRequest("getTasks", builder.ToString());

            foreach (var thisElement in response.Descendants(XName.Get("task", "")))
            {
                tasks.Add(factory.Create(thisElement));
            }

            results.Tasks     = tasks;
            results.Number    = ReadAttribute <int>(response.Root, "num");
            results.Total     = ReadAttribute <int>(response.Root, "total");
            results.PageStart = ReadAttribute <int>(response.Root, "start");
            results.PageCount = ReadAttribute <int>(response.Root, "end");
            return(results);
        }