Exemplo n.º 1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            dgTasks.DataSource = _dgBindingSource;
            string apiToken = null;

            const string apiTokenFileName = @"todoist.apitoken";

            if (File.Exists(apiTokenFileName))
            {
                apiToken = File.ReadAllText(apiTokenFileName);
            }

            if (string.IsNullOrEmpty(apiToken) || string.IsNullOrWhiteSpace(apiToken))
            {
                using (ApiTokenInputBox inputBox = new ApiTokenInputBox())
                {
                    inputBox.ShowDialog();
                    apiToken = inputBox.ApiToken;
                    using (StreamWriter streamwriter = File.CreateText(apiTokenFileName))
                    {
                        streamwriter.Write(apiToken);
                        streamwriter.Close();
                    }
                }
            }

            TodoistHelper.Initialize(apiToken);
        }
Exemplo n.º 2
0
        private async void GetResources()
        {
            _allResources = await TodoistHelper.GetResources();

            IReadOnlyCollection <Item>    tasks        = _allResources.Items;
            IReadOnlyCollection <Project> projects     = _allResources.Projects;
            IReadOnlyCollection <Note>    taskComments = _allResources.Notes;

            IList <TodoistTask> todoistTasks = new List <TodoistTask>();

            foreach (Item task in tasks.Where(task =>
                                              (task.IsChecked ?? false) == false &&
                                              (task.InHistory ?? false) == false &&
                                              (task.IsDeleted ?? false) == false &&
                                              (task.IsArchived ?? false) == false &&
                                              (task.Indent ?? 1) == 1 &&
                                              ((task.ResponsibleUid ?? 0) == MichaelId || (task.ResponsibleUid ?? 0) == 0)
                                              ))
            {
                Item task1 = task;
                IEnumerable <Note> notes   = taskComments.Where(comment => comment.ItemId == task1.Id);
                Project            project = projects.FirstOrDefault(proj => proj.Id == task.ProjectId);
                if (project != null)
                {
                    TodoistTask newTask = new TodoistTask
                    {
                        Content     = task.Content,
                        DueDateUtc  = task.DueDateUtc,
                        DateString  = task.DateString,
                        ProjectName = project.Name
                    };
                    foreach (Note note in notes)
                    {
                        newTask.Comments.Add(new TaskComment {
                            Content = note.Content, DateUtc = note.Posted
                        });
                    }
                    todoistTasks.Add(newTask);
                }
            }

            _dgBindingSource.DataSource = todoistTasks.OrderBy(task => task.ProjectName).ThenBy(task => task.DueDateUtc).ThenBy(task => task.Content);
        }