Ejemplo n.º 1
0
        private IEnumerable <Action> GetSyncNoteRequest(NoteItem note, NoteItem previous, bool isNew)
        {
            var tasks = Program.Service.Tasks;

            if (isNew)
            {
                NoteItem previousSaved = previous;
                yield return(() => note.RelatedTask = tasks.Insert(note.RelatedTask, taskList.Id).Execute());

                yield return(() =>
                {
                    var req = tasks.Move(taskList.Id, note.RelatedTask.Id);
                    if (previousSaved != null)
                    {
                        req.Previous = previousSaved.RelatedTask.Id;
                    }
                    note.RelatedTask = req.Execute();
                });
            }
            else
            {
                yield return
                    (() =>
                {
                    var req = tasks.Update(note.RelatedTask, taskList.Id, note.RelatedTask.Id);
                    note.RelatedTask = req.Execute();
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Synchronizes this client with the remote server.
        /// </summary>
        public void ClientSync()
        {
            // TODO(mlinder): Implement batching here.
            lock (sync)
            {
                var requests = new List <Action>();

                // Add changes/inserts.
                NoteItem previous = null;
                foreach (NoteItem currentNote in (from Control c in Controls where c is NoteItem select c).Reverse())
                {
                    NoteItem note = currentNote;
                    if (note.ClientSync())
                    {
                        bool isNew = String.IsNullOrEmpty(note.RelatedTask.Id);
                        requests.AddRange(GetSyncNoteRequest(note, previous, isNew));
                    }
                    previous = note;
                }

                // Add deletes.
                foreach (NoteItem note in deletedNotes)
                {
                    NoteItem noteb = note;
                    if (note.RelatedTask != null && !String.IsNullOrEmpty(note.RelatedTask.Id))
                    {
                        requests.Add(() => Program.Service.Tasks.Delete(taskList.Id, noteb.RelatedTask.Id).Execute());
                    }
                }
                deletedNotes.Clear();

                // Execute all requests.
                requests.ForEach(action => action());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes a note from the note list.
        /// </summary>
        public void DeleteNote(NoteItem note)
        {
            if (Controls.Count <= 1)
            {
                return; // Don't remove the last note.
            }

            Controls.Remove(note);
            deletedNotes.Add(note);
            ((NoteItem)Controls[0]).FocusNote();
            UpdateHeight();
        }
        /// <summary>
        /// Loads the specified note and adds it to the form.
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public NoteItem AddNote(Task task)
        {
            var newNote = new NoteItem(this, task);

            // Insert the new control as the first element, as it will be displayed on the bottom.
            var all = (from Control c in Controls select c).ToArray();
            SuspendLayout();
            Controls.Clear();
            Controls.Add(newNote);
            Controls.AddRange(all);
            UpdateHeight();
            ResumeLayout();
            
            return newNote;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the specified note and adds it to the form.
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public NoteItem AddNote(Task task)
        {
            var newNote = new NoteItem(this, task);

            // Insert the new control as the first element, as it will be displayed on the bottom.
            var all = (from Control c in Controls select c).ToArray();

            SuspendLayout();
            Controls.Clear();
            Controls.Add(newNote);
            Controls.AddRange(all);
            UpdateHeight();
            ResumeLayout();

            return(newNote);
        }
 /// <summary>
 /// Deletes a note from the note list.
 /// </summary>
 public void DeleteNote(NoteItem note)
 {
     if (Controls.Count <= 1)
     {
         return; // Don't remove the last note.
     }
     
     Controls.Remove(note);
     deletedNotes.Add(note);
     ((NoteItem)Controls[0]).FocusNote();
     UpdateHeight();
 }
        private IEnumerable<Action> GetSyncNoteRequest(NoteItem note, NoteItem previous, bool isNew)
        {
            var tasks = Program.Service.Tasks;

            if (isNew)
            {
                NoteItem previousSaved = previous;
                yield return () => note.RelatedTask = tasks.Insert(note.RelatedTask, taskList.Id).Execute();
                yield return () =>
                                 {
                                     var req = tasks.Move(taskList.Id, note.RelatedTask.Id);
                                     if (previousSaved != null)
                                     {
                                         req.Previous = previousSaved.RelatedTask.Id;
                                     }
                                     note.RelatedTask = req.Execute();
                                 };
            }
            else
            {
                yield return
                    () =>
                        {
                            var req = tasks.Update(note.RelatedTask, taskList.Id, note.RelatedTask.Id);
                            note.RelatedTask = req.Execute();
                        };
            }
        }