Exemple #1
0
        public static async Task <TaskListItem> RetryAddTaskList(IList <object> obj)
        {
            var restRequest = new RestRequest(Method.POST)
            {
                RequestFormat = DataFormat.Json,
                Resource      = "https://www.googleapis.com/tasks/v1/users/@me/lists",
                Timeout       = GTaskSettings.RequestTimeout
            };
            var ignored = "{title:\"" + ((TaskListItem)obj[0]).title + "\"}";

            restRequest.AddParameter("application/json", ignored, ParameterType.RequestBody);

            //Make the call
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.OK)
                {
                    if (obj.Count > 1)
                    {
                        var callback = obj[1] as Action <bool>;
                        if (callback != null)
                        {
                            callback(true);
                        }
                    }

                    var TaskListObject = JObject.Parse(restResponse.Content);

                    var TaskList = new TaskListItem((string)TaskListObject.SelectToken("title"),
                                                    (string)TaskListObject.SelectToken("id"),
                                                    (string)TaskListObject.SelectToken("kind"),
                                                    (string)TaskListObject.SelectToken("selfLink"),
                                                    (string)TaskListObject.SelectToken("updated"));

                    return(TaskList);
                }
            }
            catch
            {
            }

            return(null);
        }
Exemple #2
0
        public static async Task <bool> UpdateTaskStatus(string parentListId, string currentTaskId, string due, bool isChecked)
        {
            //const string message = "Fiddlesticks.. I wasn't able to Update the Task,  can you try again?";
            var restRequest = new RestRequest(Method.PUT)
            {
                RequestFormat = DataFormat.Json,
                Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/{0}/tasks/{1}", parentListId, currentTaskId),
                Timeout       = GTaskSettings.RequestTimeout
            };
            var check   = (bool)isChecked ? "completed" : "needsAction";
            var dueDate = ",due: \"" + due + "\"";
            var param   = string.Empty;

            //Conditional on if there is a due date or not, if there isn't it sets it to No Due Date automatically
            //if there is we send it to retain the date an item was completed

            if (due != null)
            {
                param = "{id:\"" + currentTaskId + "\",status:\"" + check + "\"" + dueDate + "}";
            }
            else
            {
                param = "{id:\"" + currentTaskId + "\",status:\"" + check + "\"}";
            }
            restRequest.AddParameter("application/json", param, ParameterType.RequestBody);

            //Make the call
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.OK)
                {
                    //success
                    return(true);
                }
            }
            catch
            {
            }

            return(false);
        }
Exemple #3
0
        public static async Task <TaskItem> RetryAddTask(IList <object> obj)
        {
            //const string message = "Golly Gee, There was an error Creating the Task, can you try it again?";
            var restRequest = new RestRequest(Method.POST)
            {
                RequestFormat = DataFormat.Json,
                Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/{0}/tasks", obj[2]),
                Timeout       = GTaskSettings.RequestTimeout
            };
            string dueDate = string.Empty;

            if (!string.IsNullOrEmpty(((TaskItem)obj[0]).due))
            {
                TaskItem t = ((TaskItem)obj[0]);
                dueDate = ",due: \"" + t.due + "\"";
            }
            var info = "{title:\"" + ((TaskItem)obj[0]).title + "\",notes:\"" + ((TaskItem)obj[0]).notes + "\"" + dueDate + "}";

            info = info.Replace("\r", "\\n");
            restRequest.AddParameter("application/json", info, ParameterType.RequestBody);

            //Make the call
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.OK)
                {
                    //Success
                    var      m       = JObject.Parse(restResponse.Content);
                    TaskItem newTask = new TaskItem((string)m.SelectToken("id"),
                                                    (string)m.SelectToken("kind"),
                                                    ((string)m.SelectToken("title")) ==
                                                    String.Empty
                                                            ? "Empty"
                                                            : (string)
                                                    m.SelectToken("title"),
                                                    ((TaskItem)obj[0]).notes,
                                                    obj[2].ToString(),
                                                    (string)
                                                    m.SelectToken("position"),
                                                    (string)m.SelectToken("updated"),
                                                    (string)m.SelectToken("due"),
                                                    (string)m.SelectToken("deleted"),
                                                    (string)m.SelectToken("hidden"),
                                                    (string)m.SelectToken("status"),
                                                    (string)
                                                    m.SelectToken("selfLink"),
                                                    (string)
                                                    m.SelectToken("completed"),
                                                    (string)
                                                    m.SelectToken("updated")
                                                    );

                    return(newTask);
                }
            }
            catch
            {
            }

            return(null);
        }
Exemple #4
0
        public static async Task <string> MoveTask(string TaskListID, string Id, string PrevID)
        {
            //const string message = "I'm having issues moving this task, can you try again?";

            var restRequest = new RestRequest(Method.POST)
            {
                Timeout = GTaskSettings.RequestTimeout
            };

            if (PrevID == "")
            {
                restRequest.RequestFormat = DataFormat.Json;
                restRequest.Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/" + TaskListID + "/tasks/" + Id + "/move?");
            }
            else
            {
                restRequest.RequestFormat = DataFormat.Json;
                restRequest.Resource      = String.Format("https://www.googleapis.com/tasks/v1/lists/" + TaskListID + "/tasks/" + Id + "/move?previous=" + PrevID);
            }

            restRequest.AddParameter("application/json", ParameterType.RequestBody);

            //Make the call
            var restResponse = await GTaskSettings.ExecuteRestTask(restRequest);

            try
            {
                if (restResponse.StatusCode == HttpStatusCode.OK)
                {
                    // Get the new position from the response
                    var    m        = JObject.Parse(restResponse.Content);
                    string position = (string)m.SelectToken("position");

                    //success
                    return(position);
                }
            }
            catch
            {
            }

            // Get the locally stored list
            List <TaskListItem> TaskListList = await TaskListHelper.GetTaskListFromApplicationStorage(false);

            // Check that the task list and tasks are available in local storage
            if (TaskListList.Where(x => x.id == TaskListID).Count() == 0 ||
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).Count() == 0)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(PrevID))
            {
                // The item has been moved to the first position
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().position = "0";
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().updated  = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z"); // DateTime.UtcNow.ToString();
            }
            else
            {
                // Check that the prev id item is available in local storage
                if (TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == PrevID).Count() == 0)
                {
                    return(null);
                }

                // get the position of the prev id item
                double position = double.Parse(TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == PrevID).First().position);

                // Set the position of the item to 1+ the position of the previous item
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().position = (position + 1).ToString();
                TaskListList.Where(x => x.id == TaskListID).First().taskList.Where(x => x.id == Id).First().updated  = DateTime.UtcNow.ToString("yyyy-MM-dd'T'hh:mm:ss.00Z"); // DateTime.UtcNow.ToString();
            }

            //submit the task list to local storage
            await TaskListHelper.SubmitToLocalStorage(TaskListList);

            return(null);
        }
Exemple #5
0
        /// <summary>
        /// Load the task lists and all associated data from the api
        /// </summary>
        /// <param name="alertWhenNoConnection">Alert the user that we could not connect to the api</param>
        /// <returns>Boolean result</returns>
        public static async Task <List <TaskListItem> > LoadTaskDataFromApi(bool alertWhenNoConnection = false)
        {
            try
            {
                await LoginHelper.RefreshTokenCodeAwait(true);

                var settings = IsolatedStorageSettings.ApplicationSettings;

                // Get the Task Lists
                #region Get Task Lists
                var restRequest = new RestRequest(Method.GET)
                {
                    Resource =
                        "https://www.googleapis.com/tasks/v1/users/@me/lists?access_token=" + GTaskSettings.AccessToken,
                    Timeout = GTaskSettings.RequestTimeout
                };

                //Make the call
                var restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                //Store Lists
                var TaskListObject = JObject.Parse(restResponse.Content);

                var TaskListList = TaskListObject["items"].Select(m => new TaskListItem((string)m.SelectToken("title"),
                                                                                        (string)m.SelectToken("id"),
                                                                                        (string)m.SelectToken("kind"),
                                                                                        (string)m.SelectToken("selfLink"),
                                                                                        (string)m.SelectToken("updated"))).ToList();

                //Check to see if pageToken exists
                //If so - iterate until empty
                var pageToken = string.Empty;
                if (TaskListObject["nextPageToken"] != null)
                {
                    pageToken = TaskListObject["nextPageToken"].ToString();
                }

                while (pageToken != string.Empty)
                {
                    restRequest = new RestRequest(Method.GET)
                    {
                        Resource =
                            "https://www.googleapis.com/tasks/v1/users/@me/lists?pageToken=" + pageToken + "&access_token=" + GTaskSettings.AccessToken,
                        Timeout = GTaskSettings.RequestTimeout
                    };

                    restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                    TaskListObject = JObject.Parse(restResponse.Content);

                    //Add the new list to the current list
                    TaskListList.AddRange(TaskListObject["items"].Select(m => new TaskListItem((string)m.SelectToken("title"),
                                                                                               (string)m.SelectToken("id"),
                                                                                               (string)m.SelectToken("kind"),
                                                                                               (string)m.SelectToken("selfLink"),
                                                                                               (string)m.SelectToken("updated"))));

                    //reset the pageToken
                    pageToken = string.Empty;
                    if (TaskListObject["nextPageToken"] != null)
                    {
                        pageToken = TaskListObject["nextPageToken"].ToString();
                    }
                }
                #endregion

                // Get the Task Items
                #region Get Task Items
                // Loop through the task list list and get the tasks for each list
                foreach (TaskListItem list in TaskListList)
                {
                    // Instantiate the task list
                    list.taskList = new List <TaskItem>();

                    //If user wants to see Hidden (Completed) tasks, then display them. Else return current list
                    restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?access_token=" + GTaskSettings.AccessToken;
                    if (GTaskSettings.HideCompleted == false)
                    {
                        restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?showHidden=True&access_token=" + GTaskSettings.AccessToken;
                    }

                    //Make the call
                    restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                    var TaskObject = JObject.Parse(restResponse.Content);
                    if (!restResponse.Content.Contains("Limit Exceeded"))
                    {
                        if (TaskObject != null && TaskObject["items"] != null)
                        {
                            list.taskList = TaskObject["items"].Select(m => new TaskItem((string)m.SelectToken("id"),
                                                                                         (string)m.SelectToken("kind"),
                                                                                         ((string)m.SelectToken("title")) ==
                                                                                         String.Empty
                                                            ? "Empty"
                                                            : (string)
                                                                                         m.SelectToken("title"),
                                                                                         (string)m.SelectToken("notes"),
                                                                                         list.id,
                                                                                         (string)
                                                                                         m.SelectToken("position"),
                                                                                         (string)m.SelectToken("update"),
                                                                                         (string)m.SelectToken("due"),
                                                                                         (string)m.SelectToken("deleted"),
                                                                                         (string)m.SelectToken("hidden"),
                                                                                         (string)m.SelectToken("status"),
                                                                                         (string)
                                                                                         m.SelectToken("selfLink"),
                                                                                         (string)
                                                                                         m.SelectToken("completed"),
                                                                                         (string)
                                                                                         m.SelectToken("updated")
                                                                                         )).ToList();
                        }

                        //Check to see if pageToken exists
                        //If so - iterate until empty
                        pageToken = string.Empty;
                        if (TaskObject["nextPageToken"] != null)
                        {
                            pageToken = TaskObject["nextPageToken"].ToString();
                        }

                        while (pageToken != string.Empty)
                        {
                            //If user wants to see Hidden (Completed) tasks, then display them. Else return current list
                            restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?pageToken=" + pageToken + "&access_token=" + GTaskSettings.AccessToken;
                            if (GTaskSettings.HideCompleted == false)
                            {
                                restRequest.Resource = "https://www.googleapis.com/tasks/v1/lists/" + list.id + "/tasks?pageToken=" + pageToken + "&showHidden=True&access_token=" + GTaskSettings.AccessToken;
                            }

                            restResponse = await GTaskSettings.ExecuteRestTask(restRequest, false);

                            TaskObject = JObject.Parse(restResponse.Content);

                            //Add the new list to the current list
                            list.taskList.AddRange(TaskObject["items"].Select(
                                                       m => new TaskItem((string)m.SelectToken("id"),
                                                                         (string)m.SelectToken("kind"),
                                                                         ((string)m.SelectToken("title")) ==
                                                                         String.Empty
                                                            ? "Empty"
                                                            : (string)
                                                                         m.SelectToken("title"),
                                                                         (string)m.SelectToken("notes"),
                                                                         (string)m.SelectToken("parent"),
                                                                         (string)
                                                                         m.SelectToken("position"),
                                                                         (string)m.SelectToken("update"),
                                                                         (string)m.SelectToken("due"),
                                                                         (string)m.SelectToken("deleted"),
                                                                         (string)m.SelectToken("hidden"),
                                                                         (string)m.SelectToken("status"),
                                                                         (string)
                                                                         m.SelectToken("selfLink"),
                                                                         (string)
                                                                         m.SelectToken("completed"),
                                                                         (string)
                                                                         m.SelectToken("updated")
                                                                         )).ToList());

                            //reset the pageToken
                            pageToken = string.Empty;
                            if (TaskObject["nextPageToken"] != null)
                            {
                                pageToken = TaskObject["nextPageToken"].ToString();
                            }
                        }
                    }
                    else
                    {
                    }
                }
                #endregion

                return(TaskListList);
            }
            catch (Exception)//e)
            {
                return(null);
            }
        }